Custom Mobs Sink Into Ground [NMS]

Discussion in 'Plugin Development' started by Zwander, May 16, 2014.

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

    Zwander

    I have a custom EntitySlime that bounces on collision with solid blocks. Here is its tick method:

    Code:java
    1. @Override
    2. public void h(){
    3. //Save old velocity
    4. double oldMotX=motX;
    5. double oldMotY=motY;
    6. double oldMotZ=motZ;
    7. //Move the grenade
    8. super.move(motX,motY,motZ);
    9. //If stopped, bounce
    10. if (motX==0){
    11. motX=-oldMotX*0.7;
    12. }
    13. if (motY==0){
    14. motY=-oldMotY*0.7;
    15. motX=oldMotX*0.8;
    16. motZ=oldMotZ*0.7;
    17. //If velocity is very low, stop/
    18. if (motY<=0.15 && motY>0){
    19. motY=0;
    20. }
    21. Bukkit.getLogger().info("Bounce");
    22. }
    23. //If not bouncing on ground, add gravity
    24. else{
    25. motY-=0.08;
    26. }
    27. if (motZ==0){
    28. motZ=-oldMotZ*0.7;
    29. }
    30. //Debugging
    31. Bukkit.getLogger().info("YPOS "+locY);
    32. Bukkit.getLogger().info("motY "+motY);
    33.  
    34. }


    What happens is, at certain velocities the slime just sinks through the ground. The debug checks show that server side it is still above ground. Then after a few seconds it pops up tot he top and starts acting propperly.

    [​IMG]

    And then...

    [​IMG]

    Pop! It comes back up to where it should be.

    I'm sure it has something to do with the packets being sent with the wrong velocity or something similar, but I have no idea how to fix it.
     
  2. Offline

    Shevchik

    That is stupid client prediction i think.
     
  3. Offline

    Zwander

    Yea I know, but there must be a way to fix it :S
    The problem is, it also prevents you from being able to hit the slime. . Which is really bad.
     
  4. Offline

    Shevchik

    Try to manually resend the entity velocity packet each tick, maybe it will help.
     
  5. Zwander Mind add the way youre spawning the entity? and the entity class maybe?
     
  6. Offline

    Zwander

    Someone_Like_You
    Here is the spawning code:
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender,Command command,String tags,String[] args){
    3. if (sender instanceof Player){
    4. //Get the player
    5. Player player=((Player)(sender));
    6. //Get he world
    7. World w=player.getWorld();
    8. //Get the location
    9. Location loc=player.getLocation();
    10. //Get the NMS world
    11. net.minecraft.server.v1_7_R3.World nmsWorld = ((CraftWorld) w).getHandle();
    12. //Construct the entity
    13. CustomEntity customEntity= new CustomEntity(nmsWorld);
    14. //Set the entities pos.
    15. customEntity.setPosition(loc.getX(), loc.getY()+1, loc.getZ());
    16. //Add the entity to the world
    17. nmsWorld.addEntity(customEntity);
    18. //Get the bukkit entity
    19. Entity e=customEntity.getBukkitEntity();
    20. //Set the entities velocity to the players direction vector
    21. e.setVelocity(player.getLocation().getDirection());
    22. //set display name
    23. ((LivingEntity) e).setCustomName("");
    24. ((LivingEntity)e).setCustomNameVisible(true);
    25. }
    26. return true;
    27.  
    28. }



    The CustomEntityClass extends EntitySlime. The only other method it overrides is the damageEntity method. This prevents it from taking damage.

    Shevchik
    By spamming
    Code:java
    1. PacketPlayOutEntityTeleport p2=new PacketPlayOutEntityTeleport(this);
    2. this.sendPackets(p2, 50);
    3. PacketPlayOutEntityVelocity p =new PacketPlayOutEntityVelocity(this);
    4. this.sendPackets(p, 50);
    5.  
    6. //Send packets looks like this:
    7. private void sendPackets(Packet packet,double radius){
    8. Player[] pList=Bukkit.getOnlinePlayers();
    9. for (Player p:pList){
    10. if (bukkitEnt.getLocation().distanceSquared(p.getLocation())<(radius*radius)){
    11. ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
    12. }
    13. }
    14. }


    Every tick, the glitch is mostly fixed. I am however worried about the bandwidth/efficiency cost. I'd also like to cancel wherever the packets are usually sent from because I get the feeling they are being sent before the velocity updates occur.
     
  7. Zwander I had that problem too, discovered that if the entity Y velocity > 0 it will happend. Im not sure, trying to think... maybe try send packet of normal slime entity, if it is not hapenning with normal slime, then maybe send the normal slime packet. and afterwards send your slimy-nade packet?... btw, epic idea haha. and why are you using packets and not actual entity?
    EDIT: perhaps add to the entity teleport packet more to the Y?...
     
  8. Offline

    Zwander

    Someone_Like_You

    I am using actual entities. The packets are sent to force the client to update
     
  9. Zwander have you tried sending the entity teleport packet 0.5~ above the entity spawn location so it will render for the player as its not in the ground?..
     
  10. Offline

    Zwander

    It works the way it is, the issue is that its effectively spamming the client with packets.
     
Thread Status:
Not open for further replies.

Share This Page