Solved WASD entity control 1.8

Discussion in 'Plugin Help/Development/Requests' started by Funergy, Jan 12, 2015.

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

    Funergy

    Hello guys,
    I'm back here with my fancy posts :3


    Okay so I'm creating pets.
    they follow you with NMS and reflections.
    But now I want to let the people ride with it in 1.8


    Disclaimer:
    Sorry if I'm on the wrong place to ask!

    I have also seen the 1.7.5 version of it but the this.W
    is not working anymore in 1.8.
     
  2. Offline

    Epicballzy

    Have you done any work yet? Any code you can show us?
     
  3. Offline

    Funergy

    @Epicballzy Well I'm asking right now how to create the pet rideable with the WASD keys
    its not that I have any code about that. I have an class extending EntityPig

    @mythbusterma Maybe you know?
     
    Last edited: Jan 13, 2015
  4. Offline

    Epicballzy

  5. Offline

    Funergy

    @Epicballzy
     
  6. Offline

    Funergy

    b u m p
     
  7. Offline

    ChipDev

    I really want to know this too! I am working with all the slimes and stuff but the fields make me go crazy.
     
    Funergy likes this.
  8. Offline

    Funergy

    ChipDev likes this.
  9. Offline

    ChipDev

  10. Offline

    TGRHavoc

    @Funergy @ChipDev
    Just decompiled the EntityLiving class from the minecraft server and e (float, float) method looks like it still does what the "1.7.5 WASD Moving entity" tutorial suggests.

    (Assuming you're using the unofficial 1.8 made by Spigot, the next information should come in handy)
    It looks like"b(float yaw, float pitch)" may have been changed to "setYawPitch(float yaw, float pitch)". (Inside Entity.class)
    "W" may now be called "S" (Again, inside the Entity.class)
    "aO" may now be called "aI" (Capital I) (Entity.class)


    Hope this was useful
     
    Last edited: Feb 17, 2015
    Funergy and ChipDev like this.
  11. Offline

    ChipDev

    Wow. Thanks :)
     
  12. Offline

    Funergy

    @TGRHavoc There are still some fields that don't work.

    this.aM
    ((EntityLiving) this.passenger).bd
    ((EntityLiving) this.passenger).be

    and 1 method
    this.i
     
  13. Offline

    xTrollxDudex

    From the last update, I am unable to see any changes to W, so my suspicion is that Entity.java has not been updated for 1.8 yet. In that case, you'll have to manually find the field with a CraftBukkit jar. If you don't have one, I'll do it for you later on, I'm not at home right now.
     
  14. Offline

    Funergy

    @xTrollxDudex Well @TGRHavoc Posted the fields. but they weren't all the not working fields/methods
     
    ChipDev likes this.
  15. Offline

    ChipDev

    I think you have the EXACT same code as me :p
    This the the only thread not made by me that I am following <3
     
    Funergy likes this.
  16. Offline

    Funergy

    @ChipDev Well I have the code from that tutorial.
    I have been looking at the echopet source code since they support 1.8 but Its so hard to understand it omg.
     
  17. Offline

    ChipDev

    I bet we are lost twins.
    I did the same freaking thing o.o

    Maybe I should tag @DSH105
     
    Last edited by a moderator: Feb 17, 2015
  18. Offline

    Funergy

  19. Offline

    xTrollxDudex

    aM is now aG
    bd is now aX
    be is now aY

    The method i(float) is now j(float). Just to confirm, i(float) sets bp, which is now bk, which is set by j(float), so I'm quite sure that's the one you're looking for.
     
    ChipDev likes this.
  20. Offline

    Funergy

    @xTrollxDudex Okay thanks
    but I'm getting 1 more error
    this.al = this.aG = this.yaw;

    Required: int
    Found: float
     
  21. Offline

    xTrollxDudex

    You should cast but I'm not able to confirm whether that's a good idea at the moment.
     
  22. Offline

    Funergy

    @xTrollxDudex This is what I have right now but its not working :/
    Code:
     public void e(float sideMot, float forMot) {
            if (this.passenger == null || !(this.passenger instanceof EntityHuman)) {
                super.e(sideMot, forMot);
                this.S = 0.5F;    // Make sure the entity can walk over half slabs, instead of jumping
                return;
            }
            this.lastYaw = this.yaw = this.passenger.yaw;
            this.pitch = this.passenger.pitch * 0.5F;
    
            // Set the entity's pitch, yaw, head rotation etc.
            this.setYawPitch(this.yaw, this.pitch); //[url]https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/Entity.java#L163-L166[/url]
            float al =(float) this.al;
            al = this.aG = this.yaw;
    
            this.S = 1.0F;    // The custom entity will now automatically climb up 1 high blocks
    
            sideMot = ((EntityLiving) this.passenger).aX * 0.5F;
            forMot = ((EntityLiving) this.passenger).aY;
    
            if (forMot <= 0.0F) {
                forMot *= 0.25F;    // Make backwards slower
            }
            sideMot *= 0.75F;    // Also make sideways slower
    
            float speed = 0.35F;    // 0.2 is the default entity speed. I made it slightly faster so that riding is better than walking
            this.j(speed);    // Apply the speed|| before this.i(speed)
            super.e(sideMot, forMot);    // Apply the motion to the entity
    
        }
     
  23. Offline

    xTrollxDudex

    To be honest I'm not really familiar with this type of thing. You should contact DSH105
     
  24. Offline

    Funergy

    @xTrollxDudex Okay lets wait then
    @ChipDev @DSH105

    Anyone else that knows about these fields? (Bump)

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

    ChipDev

    My entity just doesn't move. Maybe @fireblast709 can help, or we can wait for DSH.
     
  26. Offline

    TGRHavoc

    Which fields?
     
  27. Offline

    ChipDev

    I guess we mean, well, that This code will not work in 1.8 :
    Code:
    package Utils;
    
    import java.lang.reflect.Field;
    
    import org.bukkit.Bukkit;
    import org.bukkit.World;
    import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
    import org.bukkit.craftbukkit.v1_8_R1.util.UnsafeList;
    
    import net.minecraft.server.v1_8_R1.EntityPig;
    import net.minecraft.server.v1_8_R1.EntityHuman;
    import net.minecraft.server.v1_8_R1.EntityLiving;
    import net.minecraft.server.v1_8_R1.EntityPig;
    import net.minecraft.server.v1_8_R1.PathfinderGoalSelector;
    
    public class PigEdited extends EntityPig{
       
         public PigEdited(World world) {
                super(((CraftWorld)world).getHandle());
        
                try {
                    Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
                    bField.setAccessible(true);
                    Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
                    cField.setAccessible(true);
                    bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
                    bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
                    cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
                    cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
                  
                } catch (Exception exc) {
                    exc.printStackTrace();
                }
            }
        
         public void e(float sideMot, float forMot) {
                if (this.passenger == null || !(this.passenger instanceof EntityHuman)) {
                    super.e(sideMot, forMot);
                    this.S = 0.5F;    // Make sure the entity can walk over half slabs, instead of jumping
                    return;
                }
            
                EntityHuman human = (EntityHuman) this.passenger;
                if (human.getBukkitEntity() != Bukkit.getPlayerExact("BlakeRS").getPlayer()) {
                    // Same as before
                    super.e(sideMot, forMot);
                    this.S = 0.5F;
                    return;
                }
            
                this.lastYaw = this.yaw = this.passenger.yaw;
                this.pitch = this.passenger.pitch * 0.5F;
            
                // Set the entity's pitch, yaw, head rotation etc.
                this.setYawPitch(this.yaw, this.pitch); //[url]https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/Entity.java#L163-L166[/url]
                this.al = (int) (this.aG = this.yaw);
            
                this.S = 1.0F;    // The custom entity will now automatically climb up 1 high blocks
            
                sideMot = (float) (((EntityLiving) this.passenger).aX * 0.5F);
                forMot = (float) ((EntityLiving) this.passenger).aY;
            
                if (forMot <= 0.0F) {
                    forMot *= 0.25F;    // Make backwards slower
                }
                sideMot *= 0.75F;    // Also make sideways slower
            
                float speed = 0.35F;    // 0.2 is the default entity speed. I made it slightly faster so that riding is better than walking
                this.j(speed);    // Apply the speed
                super.e(sideMot, forMot);    // Apply the motion to the entity
            
            
                Field jump = null;
                try {
                    jump = EntityLiving.class.getDeclaredField("bc");
                } catch (NoSuchFieldException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (SecurityException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                jump.setAccessible(true);
            
                if (jump != null && this.onGround) {    // Wouldn't want it jumping while on the ground would we?
                    try {
                        if (jump.getBoolean(this.passenger)) {
                            double jumpHeight = 0.5D;
                            this.motY = jumpHeight;    // Used all the time in NMS for entity jumping
                        }
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    }
                }
            }
            
            public static Object getPrivateField(String fieldName, Class clazz, Object object)
            {
                Field field;
                Object o = null;
                try
                {
                    field = clazz.getDeclaredField(fieldName);
                    field.setAccessible(true);
                    o = field.get(object);
                }
                catch(NoSuchFieldException e)
                {
                    e.printStackTrace();
                }
                catch(IllegalAccessException e)
                {
                    e.printStackTrace();
                }
                return o;
            }
    
    }
    
    
     
  28. Offline

    TGRHavoc

    @ChipDev @Funergy
    Oh no! I made a mistake the other day with "this.aO". It's not "a1/l" it's "aI" (Capital I).

    Just so others can confirm:
    Entity.class line 37 (aM) is now aG, two under that is aO, and two under aG = aI (New class)

    Edit:
    @ChipDev if "EntityLiving.class.getDeclaredField("bc");" is 1.7.x then the 1.8 version of "bc" is "aW"
     
    Last edited: Feb 17, 2015
    ChipDev likes this.
  29. Offline

    Funergy

    @TGRHavoc Still doesn't work and my code looks the same as @ChipDev But with the changes you said last post

    EDIT EDIT:
    Did some debuging
    ForMot only updates when running up blocks and pressing forward
    SideMot only updates when running up blocks and pressing Left and right button

    EDIT here is the code
    Code:
    @Override
        public void e(float sideMot, float forMot) {
            if (this.passenger == null || !(this.passenger instanceof EntityHuman)) {
                super.e(sideMot, forMot);
                this.S = 0.5F;    // Make sure the entity can walk over half slabs, instead of jumping
                return;
            }
            EntityHuman human = (EntityHuman) this.passenger;
            if (human.getBukkitEntity() != Bukkit.getPlayerExact("Funergy").getPlayer()) {
                // Same as before
                super.e(sideMot, forMot);
                this.S = 0.5F;
                return;
            }
            this.lastYaw = this.yaw = this.passenger.yaw;
            this.pitch = this.passenger.pitch * 0.5F;
    
            // Set the entity's pitch, yaw, head rotation etc.
            this.setYawPitch(this.yaw, this.pitch); //[url]https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/Entity.java#L163-L166[/url]
            this.aI = this.aG = this.yaw;
    
            this.S = 1.0F;    // The custom entity will now automatically climb up 1 high blocks
    
            sideMot = ((EntityLiving) this.passenger).aX * 0.5F;
            forMot = ((EntityLiving) this.passenger).aY;
    
            if (forMot <= 0.0F) {
                forMot *= 0.25F;    // Make backwards slower
            }
            sideMot *= 0.75F;    // Also make sideways slower
    
            float speed = 0.35F;    // 0.2 is the default entity speed. I made it slightly faster so that riding is better than walking
            this.j(speed);    // Apply the speed|| before this.i(speed)
            super.e(sideMot, forMot);    // Apply the motion to the entity
    
            Field jump = null;
            try {
                jump = EntityLiving.class.getDeclaredField("aW");
            } catch (NoSuchFieldException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (SecurityException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            jump.setAccessible(true);
    
            if (jump != null && this.onGround) {    // Wouldn't want it jumping while on the ground would we?
                try {
                    if (jump.getBoolean(this.passenger)) {
                        double jumpHeight = 0.5D;
                        this.motY = jumpHeight;    // Used all the time in NMS for entity jumping
                    }
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
    
        }
     
    Last edited: Feb 17, 2015
  30. @ChipDev Please stop randomly tagging people.
     
    Thury and TGRHavoc like this.
Thread Status:
Not open for further replies.

Share This Page