net.Minecraft.server help needed

Discussion in 'Plugin Development' started by Taco, Aug 7, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Taco

    I know, I know, I shouldn't be using this, I should stick to the API. Problem is: What I want to do cannot be done via the API. So, here's my issue and what I'm trying to do.

    I'm trying to create a falling sand entity and set its velocity, though I'm not sure whether or not I'm on the right track or not.

    Here's my code so far:

    Code:
                        net.minecraft.server.World cWorld = ((CraftWorld)w).getHandle();
                            if(i==0)
                            {
                                diff = loc.subtract(event.getBlock().getLocation()).toVector();
                            }
                            EntityFallingBlock sand = new EntityFallingBlock(cWorld, loc.getX(), loc.getY(), loc.getZ(), block.getTypeId(), 0);
                            block.setTypeId(0);
                            sand.move(diff.getX(), diff.getY()+.02, diff.getZ());
                            sand.motX=diff.getX();
                            sand.motY=diff.getY();
                            sand.motZ=diff.getZ();
                            cWorld.addEntity(sand);
                            sand.spawnIn(cWorld);
    Any help is greatly appreciated, and if anyone could point me towards some sort of documentation of the net.minecraft.server stuff, or point me in the right direction, that'd help loads. (I know there's no official documentation for this, but even vague, unofficial documentation would be more than I have right now)

    Here's a visual of what happens with my current code:
    [​IMG]
    The piston glitches out like that, and the sand never moves. When the extra piston arm is broken, the sand floats there motionless and yields nothing when destroyed.
     
  2. Offline

    Digi

    Why can't you set velocity like this ?
    Code:
    Entity ent = world.spawn(location, FallingSand.class);
    
    sand.setVelocity(vector);
    ?
     
  3. Offline

    Taco

    It spews this error because bukkit doesn't properly add the net.minecraft.server entity:

    Code:
    17:04:53 [SEVERE] Could not pass event BlockPistonExtendEvent to MorePhysics Pi
    ton Standalone
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.j
    va:304)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.ja
    a:62)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.
    ava:460)
            at net.minecraft.server.BlockPiston.g(BlockPiston.java:75)
            at net.minecraft.server.BlockPiston.doPhysics(BlockPiston.java:52)
            at net.minecraft.server.World.k(World.java:518)
            at net.minecraft.server.World.applyPhysics(World.java:494)
            at net.minecraft.server.BlockButton.interact(BlockButton.java:156)
            at net.minecraft.server.ItemInWorldManager.interact(ItemInWorldManager.
    ava:296)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:636)
            at net.minecraft.server.Packet15Place.handle(SourceFile:39)
            at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113)
            at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:
    8)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:567)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.IllegalArgumentException: Don't know how to add class net.
    inecraft.server.EntityFallingBlock!
            at net.minecraft.server.EntityTrackerEntry.b(EntityTrackerEntry.java:40
    )
            at net.minecraft.server.EntityTrackerEntry.updatePlayer(EntityTrackerEn
    ry.java:235)
            at net.minecraft.server.EntityTrackerEntry.scanPlayers(EntityTrackerEnt
    y.java:281)
            at net.minecraft.server.EntityTracker.addEntity(EntityTracker.java:99)
            at net.minecraft.server.EntityTracker.track(EntityTracker.java:71)
            at net.minecraft.server.WorldManager.a(WorldManager.java:16)
            at net.minecraft.server.World.c(World.java:924)
            at net.minecraft.server.WorldServer.c(WorldServer.java:171)
            at net.minecraft.server.World.addEntity(World.java:917)
            at org.bukkit.craftbukkit.CraftWorld.spawn(CraftWorld.java:959)
            at org.bukkit.craftbukkit.CraftWorld.spawn(CraftWorld.java:782)
            at com.FriedTaco.taco.MorePhysics.MorePhysicsStandaloneBlockListener.on
    lockPistonExtend(MorePhysicsStandaloneBlockListener.java:83)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.j
    va:302)
            ... 16 more
    >
    Here's my current code. When my server lags enough, I can see the entity spawning and flying off somewhere, but I never see it falling back down.

    Code:
                            net.minecraft.server.World cWorld = ((CraftWorld)w).getHandle();
                            diff = b.get(0).getLocation().clone().subtract(event.getBlock().getLocation()).toVector();
                            final EntityFallingBlock sand = new EntityFallingBlock(cWorld, loc.getX(), loc.getY(), loc.getZ(), block.getTypeId(), 0);
                            cWorld.addEntity(sand);
                            final Entity sandBukkit = sand.getBukkitEntity();
                            final Vector vec = diff.clone();
                            plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
                                public void run() {
                                    block.getRelative((int)vec.getX(), (int)vec.getY(), (int)vec.getZ()).setTypeId(0);
                                    sandBukkit.teleport(loc.clone().add(0.5, 1.5, 0.5));
                                    sandBukkit.setVelocity(vec.multiply(0.2));
                                }
                            }, 2L);
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  4. Offline

    azazad

    Taco

    Using Bukkit API instead of nms stuff is generally a good idea, but I prefer more direct code.

    Code:
                        net.minecraft.server.World cWorld = ((CraftWorld)w).getHandle();
                            if(i==0)
                            {
                                diff = loc.subtract(event.getBlock().getLocation()).toVector();
                            }
                            EntityFallingBlock sand = new EntityFallingBlock(cWorld, loc.getX(), loc.getY(), loc.getZ(), block.getTypeId(), 0);
                            block.setTypeId(0);
                            sand.move(diff.getX(), diff.getY()+.02, diff.getZ());
                            sand.motX=diff.getX();
                            sand.motY=diff.getY();
                            sand.motZ=diff.getZ();
                            cWorld.addEntity(sand);
                            sand.spawnIn(cWorld);
    
    I may not know what I am saying here, but here goes. (Only had experience with EntityMinecarts.)

    Why do you call sand.move()? It is only supposed to be used in the entity's tick methods. If you want to move the sand in your code, use setPosition().

    Only the cWorld.addEntity() is likely to be necessary. I never needed a call to spawnIn() as well.
     
  5. Offline

    Taco


    Because honestly, I've no clue what any of this does. Also, my updated code is above, and it doesn't include the stuff you said was unnecessary. As I have it right now, the sand can be seen briefly if the server lags enough, but it never seems to lose velocity.
     
  6. Offline

    azazad

    I assume your code that worked in 1.2.5 has broken now, right? You can try using the blame or diff tool on Github to see what the CraftBukkit devs have changed in EntityFallingBlock. See if there are any plugin-breaking changes there.
     
  7. Offline

    Taco

    Nah, it's been broken since 1.1 actually, I've just now gotten the time to really sit down and look at it. I will give the github a peek and see what I can pull from that.
     
  8. Offline

    azazad

    MC 1.1: Is that when EntityFallingSand became EntityFallingBlock? I don't know, but that could break things.
     
  9. Offline

    Taco

    I think so. I'm still trying to figure out how to properly add an EntityFallingBlock into the world. It appeared to just be a class name change since it wasn't just sand anymore.
     
  10. Offline

    azazad

    Taco

    Wow, I looked at the source of BlockSand/BlockGravel and this is all the code it takes to spawn the block entity:
    Code:
                        EntityFallingBlock entityfallingblock = new EntityFallingBlock(world, (double) ((float) i + 0.5F), (double) ((float) j + 0.5F), (double) ((float) k + 0.5F), this.id, world.getData(i, j, k));
    
                        world.addEntity(entityfallingblock);
    
    That's it. The original sand/gravel block isn't even set to air. No wonder the piston dupe glitches worked, because for a split second both the sand block and the falling sand exist. I don't see why the Bukkit team hasn't fixed this yet by immediately changing the original block to air.

    All you have to do is set the motY and the sand should fling into the air, right?
     
  11. Offline

    Taco

    One would think, but that doesn't seem to work.
     
  12. Offline

    azazad

    ...

    Well, I'm stumped. Try digging around in CraftBukkit source some more. :D
     
  13. Offline

    Taco

    That's what I've been doing D:

    I tried using setPosition as suggested above, and I'm still not getting the results I want. Here's my current code.

    Code:
    net.minecraft.server.World cWorld = ((CraftWorld)w).getHandle();
                            diff = b.get(0).getLocation().clone().subtract(event.getBlock().getLocation()).toVector();
                            final EntityFallingBlock sand = new EntityFallingBlock(cWorld, (double) ((float) loc.getX() + 0.5F), (double) ((float) loc.getY() + 0.5F), (double) ((float) loc.getZ() + 0.5F), block.getTypeId(), cWorld.getData(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
                            cWorld.addEntity(sand);
                            sand.setPosition(loc.getX()+(diff.getX()*6),loc.getY()+(diff.getY()*6),loc.getZ()+(diff.getZ()*6));
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  14. Offline

    Taco

    I'm still bashing my head into a wall over this. My current code is below, and the entity appears to be spawning, since I can sometimes see two sand entites falling when the piston retracts, however, the sand refuses to take to the velocity I set.

    Code:
    net.minecraft.server.World cWorld = ((CraftWorld)w).getHandle();
       diff = b.get(0).getLocation().clone().subtract(event.getBlock().getLocation()).toVector();
       EntityFallingBlock sand = new EntityFallingBlock(cWorld, (double) ((float) loc.getX() + 0.5F), (double) ((float) loc.getY() + 0.5F), (double) ((float) loc.getZ() + 0.5F), block.getTypeId(), cWorld.getData(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
       cWorld.addEntity(sand);
                            sand.motX=diff.getX();
                            sand.motY=diff.getY();
                            sand.motZ=diff.getZ();
                            sand.velocityChanged=true;
     
Thread Status:
Not open for further replies.

Share This Page