Solved Emulate a player walking using EntityPlayer without packets

Discussion in 'Plugin Development' started by Cirno, Jul 22, 2013.

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

    Cirno

    I have an entity that extends EntityPlayer currently, and I want the Entity to walk in a certain direction. I know I can send packet 0X1F to move 4 blocks at a time, but is there way to make it walk without packets?
     
  2. Offline

    xTrollxDudex

    Cirno
    Very unlikely to the point I would say no I dont think thats possible. Let me do some research...
     
  3. Offline

    Cirno

    I forgot to also mention; is it possible to get the EntityPlayer to act like a regular entity, as in, being able to fall and etc.?
     
  4. Offline

    xTrollxDudex

    Cirno
    That beats me.
     
  5. Offline

    Cirno

    Fixed; I just have to call move(x,y,z) :3
     
  6. Offline

    xigsag

    Cirno
    OP, how 2 u spawn entityplayer?
     
  7. Offline

    Cirno

    Code:java
    1. public class EntityMika extends EntityPlayer {
    2.  
    3. public EntityMikaASM(Object ms, Object w, String naem){
    4. super((MinecraftServer)ms, (World)w, naem, new PlayerInteractManager((World)w));
    5. playerConnection = new com.tenko.asm.network.ServerConnection(this);
    6.  
    7. this.playerInteractManager.setGameMode(EnumGamemode.SURVIVAL);
    8. }

    World is NMS world btw. My actual code to spawn them is extremely messy and sloppy.
     
    xigsag likes this.
  8. Offline

    xigsag

    Cirno
    I love you.


    What's this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  9. Offline

    Cirno

    That's the playerConnection; ServerConnection is just a dummy connection that extends PlayerConnection that's blank.

    Code:Java
    1. public class ServerConnectionASM extends PlayerConnection {
    2.  
    3. public ServerConnectionASM(EntityPlayer entityplayer){
    4. super(MinecraftServer.getServer(), new ServerNetworkManagerASM(), entityplayer);
    5. }
    6.  
    7. @Override
    8. public boolean a(){
    9. return true;
    10. }
    11.  
    12. @Override
    13. public void a(double d0, double d1, double d2, float f, float f1){}
    14.  
    15. @Override
    16. public boolean b(){
    17. return false;
    18. }
    19.  
    20. @Override
    21. public void onUnhandledPacket(Packet p){}
    22.  
    23. @Override
    24. public void sendPacket(Packet p){}
    25.  
    26. @Override
    27. public int lowPriorityCount(){
    28. return 0;
    29. }
    30. }


    That's the same from ServerNetworkManagerASM, it just implements INetworkManager
     
    xigsag likes this.
  10. Offline

    xigsag

    Cirno
    One last question. How do I instantiate the entity so I can actually spawn it? I know this is a stupid question, but It's a simple one at least, right? :D

    For Example,
    Code:java
    1. PlayerEntity playerent = new PlayerEntity(obj, obj, string);

    What do I put as parameters?
     
  11. Offline

    Cirno

    Code:java
    1. public static Object getNMSServer(){
    2. try {
    3. Class<?> craftserver = Class.forName("org.bukkit.craftbukkit." + version + ".CraftServer");
    4. Object cbs = craftserver.cast(Bukkit.getServer());
    5. return cbs.getClass().getMethod("getServer").invoke(cbs);
    6. } catch (ClassNotFoundException|IllegalAccessException|IllegalArgumentException|InvocationTargetException|NoSuchMethodException|SecurityException e){
    7. e.printStackTrace();
    8. }
    9.  
    10. return null;
    11. }

    Code:java
    1. public static Object getNMSWorld(World w){
    2. try {
    3. Class<?> craftWorld = Class.forName("org.bukkit.craftbukkit." + version + ".CraftWorld");
    4. Object cbWorld = craftWorld.cast(w);
    5. return cbWorld.getClass().getMethod("getHandle").invoke(cbWorld);
    6. } catch (IllegalAccessException|IllegalArgumentException|InvocationTargetException|NoSuchMethodException|SecurityException|ClassNotFoundException e){
    7. e.printStackTrace();
    8. }
    9. return null;
    10. }

    Call it like this:
    new PlayerEntity(getNMSServer(), getNMSWorld(Bukkit.getWorld("worldname")), "namehereplox");
     
  12. Offline

    xTrollxDudex

    Cirno
    You deserve a promotion for knowing this O.O
     
  13. Offline

    Cirno

    Uh, what? If I deserved a promotion for knowing this, then doesn't anyone that knows how to manipulate NMS Entities deserve it too? Anyways, I'm going to request this thread gets locked before we get even more offtrack :p
     
  14. Offline

    Jade Retired Staff

    Locked. Please stay on topic in the future.
     
Thread Status:
Not open for further replies.

Share This Page