[UnSolved] Controlling a falling block entity

Discussion in 'Plugin Development' started by Jogy34, Jun 2, 2013.

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

    Jogy34

    For a plugin that I'm making I'm basically trying to make a falling block that follows a player. The problem that I keep coming to is that the entity will always fall whatever I do and if I try to set it's velocity it won't effect it. I currently have a class that extends EntityFallingBlock and I've tried overwriting the l_() method which is fired when the world ticks the entities and I've also tried creating a new update() method that fires every tick from one of bukkit's repeating tasks. In these I've tried setting the position of the block to the player's position along with setting it's velocity to the player's velocity. I've also tried setting the motY variable from 0.4 up to 10 and I've also tried overwriting the move() method but neither of those worked. What actually happens from that is the block is set to the player's location and then it starts to slowly fall down, slower than a normal falling block would, and then about 3 seconds later it would repeat. The horizontal movement wasn't affected at all. If you want to see my code then just ask and I'll post it.
     
  2. Offline

    Nitnelave

    Show us your extended class, but I believe the problem might be that the client makes client-side predictions about how the block will move. Try always setting its velocity a little bit upwards (as well as resetting its position), to see if you can make if bob instead of fall.
     
  3. Offline

    Jogy34

    Tried that too, still didn't work. Setting the velocity doesn't seem to do anything. Anyways here's the code, at least the update() and l_() methods:

    Code:java
    1.  
    2. @Override
    3. public void l_() //this is fired every time a world ticks all of it's entities
    4. {
    5. Player p = Bukkit.getServer().getPlayer(owner); //owner is just a string passed into the constructor
    6. if(p == null)
    7. {
    8. this.die();
    9. }
    10. }
    11.  
    12. public void update() //I tried doing firing this from my own repeating that that fires every tick
    13. {
    14. Player p = Bukkit.getServer().getPlayer(owner);
    15. if(p != null)
    16. {
    17. //((CraftPlayer) p).getHandle()
    18. this.motY = 10;
    19. this.locX = p.getLocation().getX();
    20. this.locY = p.getLocation().getY();
    21. this.locZ = p.getLocation().getZ();
    22.  
    23. this.getBukkitEntity().setVelocity(p.getVelocity());
    24. }
    25. }
    26.  
     
  4. Offline

    Nitnelave

    Have a look at the native implementation of l_ : you need to update every field (lastX/Y/Z, motX/Y/Z, etc...)

    Code:
    
        public void l_() {
            if (this.id == 0) {
                this.die();
            } else {
                this.lastX = this.locX;
                this.lastY = this.locY;
                this.lastZ = this.locZ;
                ++this.c;
                this.motY -= 0.03999999910593033D;
                this.move(this.motX, this.motY, this.motZ);
                this.motX *= 0.9800000190734863D;
                this.motY *= 0.9800000190734863D;
                this.motZ *= 0.9800000190734863D;
                if (!this.world.isStatic) {
                    int i = MathHelper.floor(this.locX);
                    int j = MathHelper.floor(this.locY);
                    int k = MathHelper.floor(this.locZ);
    
                    if (this.c == 1) {
                        // CraftBukkit - compare data and call event
                        if (this.c != 1 || this.world.getTypeId(i, j, k) != this.id || this.world.getData(i, j, k) != this.data || CraftEventFactory.callEntityChangeBlockEvent(this, i, j, k, 0, 0).isCancelled()) {
                            this.die();
                            return;
                        }
    
                        this.world.setAir(i, j, k);
                    }
    
                    if (this.onGround) {
                        this.motX *= 0.699999988079071D;
                        this.motZ *= 0.699999988079071D;
                        this.motY *= -0.5D;
                        if (this.world.getTypeId(i, j, k) != Block.PISTON_MOVING.id) {
                            this.die();
                            // CraftBukkit start
                            if (!this.f && this.world.mayPlace(this.id, i, j, k, true, 1, (Entity) null, (ItemStack) null) && !BlockSand.canFall(this.world, i, j - 1, k) /* mimic the false conditions of setTypeIdAndData */ && i >= -30000000 && k >= -30000000 && i < 30000000 && k < 30000000 && j > 0 && j < 256 && !(this.world.getTypeId(i, j, k) == this.id && this.world.getData(i, j, k) == this.data)) {
                                if (CraftEventFactory.callEntityChangeBlockEvent(this, i, j, k, this.id, this.data).isCancelled()) {
                                    return;
                                }
                                this.world.setTypeIdAndData(i, j, k, this.id, this.data, 3);
                                // CraftBukkit end
    
                                if (Block.byId[this.id] instanceof BlockSand) {
                                    ((BlockSand) Block.byId[this.id]).a_(this.world, i, j, k, this.data);
                                }
    
                                if (this.tileEntityData != null && Block.byId[this.id] instanceof IContainer) {
                                    TileEntity tileentity = this.world.getTileEntity(i, j, k);
    
                                    if (tileentity != null) {
                                        NBTTagCompound nbttagcompound = new NBTTagCompound();
    
                                        tileentity.b(nbttagcompound);
                                        Iterator iterator = this.tileEntityData.c().iterator();
    
                                        while (iterator.hasNext()) {
                                            NBTBase nbtbase = (NBTBase) iterator.next();
    
                                            if (!nbtbase.getName().equals("x") && !nbtbase.getName().equals("y") && !nbtbase.getName().equals("z")) {
                                                nbttagcompound.set(nbtbase.getName(), nbtbase.clone());
                                            }
                                        }
    
                                        tileentity.a(nbttagcompound);
                                        tileentity.update();
                                    }
                                }
                            } else if (this.dropItem && !this.f) {
                                this.a(new ItemStack(this.id, 1, Block.byId[this.id].getDropData(this.data)), 0.0F);
                            }
                        }
                    } else if (this.c > 100 && !this.world.isStatic && (j < 1 || j > 256) || this.c > 600) {
                        if (this.dropItem) {
                            this.a(new ItemStack(this.id, 1, Block.byId[this.id].getDropData(this.data)), 0.0F);
                        }
    
                        this.die();
                    }
                }
            }
        }
    
     
  5. Offline

    whyundead3

    I don't know if your issue is still unsolved, but if it is I was able to control falling blocks. Just ask me if you need it.
     
  6. Offline

    creepers84

    Yes, how?
     
  7. Offline

    whyundead3

    Here you are! If you know how velocity works you should be able to control proj how ever you want!
    Code:java
    1. Byte blockData = 0x0;
    2. FallingBlock proj = w.spawnFallingBlock(loc, Material.STONE, blockData);
    3. proj.setVelocity(new Vector(x,y,z));
     
Thread Status:
Not open for further replies.

Share This Page