EntityFallingBlock Smooth movement

Discussion in 'Plugin Development' started by 12boulla, Oct 20, 2017.

Thread Status:
Not open for further replies.
  1. Hi,
    I am trying to make a plugin where a falling block follows players. I am using this code to send the packet:

    Code:
    for (Player pl : Bukkit.getServer().getOnlinePlayers()){
                            EntityFallingBlock entityfallingblock;
                            if(!blockMap.containsKey(pl)){
                                entityfallingblock = new EntityFallingBlock(((CraftWorld)Bukkit.getWorlds().get(0)).getHandle());
                                blockMap.put(pl, entityfallingblock);
                            }else{
                                entityfallingblock = blockMap.get(pl);
                            }
    
                            entityfallingblock.setLocation(pl.getLocation().getX(), pl.getLocation().getY(), pl.getLocation().getZ(), 0,0);
    
                            PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(entityfallingblock, 70, Material.JACK_O_LANTERN.getId());
    
                            for(Player player : Bukkit.getOnlinePlayers()){
                                ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
                            }
                        }

    I use this inside a BukkitRunnable that repeats every tick to update the position of the fallingblocks. However, this creates jittery movement, and I am not sure how to make the movement smooth (like in HiveMC hide and seek).
    Does anyone know how I can achieve smooth rather than jittery movement?
    Any help is greatly appreciated, thanks!
     
  2. Offline

    Zombie_Striker

    @12boulla
    Try setting the velocity of the falling sand.
     
  3. I have tried doing this but the sand simply stays where it is. I am not sure if I am doing it right, but I was trying to set the velocity to the players velocity, not sure how else to make it go to the player :/
     
  4. Online

    timtower Administrator Administrator Moderator

    Could you post your used code?
     
  5. I used this code when trying to achieve the movement in PlayerMovementEvent:
    Code:
    @EventHandler
        public void PlayerMovement(PlayerMoveEvent evt){
            EntityFallingBlock entityfallingblock;
            if(!blockMap.containsKey(evt.getPlayer())){
                entityfallingblock = new EntityFallingBlock(((CraftWorld)Bukkit.getWorlds().get(0)).getHandle());
                entityfallingblock.setLocation(evt.getPlayer().getLocation().getX(), evt.getPlayer().getLocation().getY(), evt.getPlayer().getLocation().getZ(), 0,0);
                blockMap.put(evt.getPlayer(), entityfallingblock);
            }else{
                entityfallingblock = blockMap.get(evt.getPlayer());
            }
    
            entityfallingblock.getBukkitEntity().setVelocity(evt.getPlayer().getVelocity());
    
            PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(entityfallingblock, 70, Material.JACK_O_LANTERN.getId());
    
            for(Player player : Bukkit.getOnlinePlayers()){
                ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
            }
    
        }
     
  6. Online

    timtower Administrator Administrator Moderator

    @12boulla And why do you send a packet? If you would spawn one then Bukkit will handle everything for you.
     
  7. I do it as I could not work out how to prevent the fallingblock from turning solid upon hitting the ground.
     
Thread Status:
Not open for further replies.

Share This Page