Solved Trying to prevent a player from mounting a horse

Discussion in 'Plugin Development' started by NortherKnight, Oct 12, 2015.

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

    NortherKnight

    Im working with the NMS and im trying to override the method private void i(EntityHuman entityhuman) but it dosent work even tho it is in the mc dev repository.

    ERROR: The method i(EntityHuman) of type CustomHorse must override or implement a supertype method
    The error is in the compiler

    Code:
    import net.minecraft.server.v1_8_R3.EntityHuman;
    Code:
    @Override
    private void i(EntityHuman entityhuman) {}
    link to mc dev net/minecraft/server: https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/EntityHorse.java
     
  2. Offline

    Scimiguy

    That McDev is for 1.7.10

    The obfuscation changes every update, so your i() may be completely different now
    @NortherKnight
     
  3. Offline

    Gonmarte

    @NortherKnight
    Try this
    Code:
      
        @EventHandler
        public void asd(PlayerInteractEntityEvent event) {
          
          
            if(event.getRightClicked() instanceof Horse) {
              
                event.setCancelled(true);
              
            }
          
        }
    
    
     
    Last edited: Oct 12, 2015
  4. Offline

    NortherKnight

    @Gonmarte That would work but i need the event to open a inventory and i dont want to disable mounting horses for every horse just the custom ones.
     
  5. Offline

    Zombie_Striker

    @NortherKnight
    Well, Can you show us your Entity class? What does it currently look like?
     
  6. Offline

    NortherKnight

    @Zombie_Striker
    Code:
    import java.lang.reflect.Field;
    import java.util.List;
    
    import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
    
    import net.minecraft.server.v1_8_R3.DamageSource;
    import net.minecraft.server.v1_8_R3.EntityHorse;
    import net.minecraft.server.v1_8_R3.EntityHuman;
    import net.minecraft.server.v1_8_R3.PathfinderGoalLookAtPlayer;
    import net.minecraft.server.v1_8_R3.PathfinderGoalRandomLookaround;
    import net.minecraft.server.v1_8_R3.PathfinderGoalSelector;
    
    public class CustomHorse extends EntityHorse
    {
        @SuppressWarnings({ "rawtypes" })
        public CustomHorse(net.minecraft.server.v1_8_R3.World world)
        {
            super(world);
    
            List goalB = (List)getPrivateField("b", PathfinderGoalSelector.class, goalSelector); goalB.clear();
            List goalC = (List)getPrivateField("c", PathfinderGoalSelector.class, goalSelector); goalC.clear();
            List targetB = (List)getPrivateField("b", PathfinderGoalSelector.class, targetSelector); targetB.clear();
            List targetC = (List)getPrivateField("c", PathfinderGoalSelector.class, targetSelector); targetC.clear();
           
            this.goalSelector.a(7, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 6.0F));
            this.goalSelector.a(8, new PathfinderGoalRandomLookaround(this));
        }
       
        public CustomHorse(org.bukkit.World world)
        {
            this(((CraftWorld)world).getHandle());
        }
       
        @SuppressWarnings("rawtypes")
        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;
        }
       
       
        @Override
        public void move(double d0, double d1, double d2)
        {
        }
       
        @Override
        public boolean damageEntity(DamageSource damagesource, float f)
        {
            return false;
        }
       
        @Override
        private void i(EntityHuman entityhuman) {}
       
    }
    
     
  7. Offline

    Zombie_Striker

    Looked back at the other posts:

    Update to 1.7.10 (in the link you gave)
    You may need to find the updated class.

    Try asking THIS GUY where he got the updated entity classes from.
     
  8. Offline

    NortherKnight

    @Zombie_Striker I tryed decompiling the spigot server 1_8_R3 but its still the same method and it still does not work i just can override the i method :/
     
  9. @NortherKnight
    The reason you can't override it is because the method is private (link), you're gonna have to find an alternative
     
  10. Offline

    NortherKnight

    @megamichiel yea but other then this method i cant find the alternative in the EntityHorse (methods are ingeniously named :/)
     
  11. Offline

    Xerox262

    That's because you're really not supposed to know what the methods are or what they do, why not just make a entity mount event and check if the entity being mounted is your horse?
     
  12. Offline

    NortherKnight

    @Xerox262
     
  13. Offline

    Xerox262

    You can give the horse a name then check if the name of the horse being mounted matches your custom horse's name.
     
  14. Offline

    NortherKnight

    @Xerox262 yea i did but it still says its name is Horse when all my other mobs work i double checked the code.
     
  15. Offline

    Xerox262

    It's not working? I decompiled the EntityHorse class and saw a method called ae with no paramaters, it appears to return if a horse has a passenger or not (false if it does and true if it doesn't) try overriding the ae method and returning false, it should trick it into thinking that it already has a passenger then disallow you to mount any custom horse

    https://gyazo.com/6297a0306cb8591d1dc3fd380ebae9df
     
  16. Offline

    NortherKnight

    @Xerox262 No dice tryed it dosent do anything (i tryed returning false/true)
     
  17. Offline

    Xerox262

    How're you spawning the horse? Are you sure it's your custom horse that is being spawned?
     
  18. Offline

    NortherKnight

    @Xerox262 yea since he cant move and has no collide
    His name should be CHorse like others but its not i dont know why
     
  19. Offline

    Xerox262

    Is CHorse showing up above it's head? and how are you getting the name again?
     
  20. Offline

    NortherKnight

    @Xerox262 I getting my name by checking it when i interact with an entity with the e.getRightClicked().getName()
     
  21. Offline

    Xerox262

    Why aren't you using entity mount event?
     
  22. @NortherKnight
    I looked through the EntityHorse class, and the a(EntityHuman) method might interest you. It's called whenever a player right clicks the entity.
     
  23. Offline

    NortherKnight

    @megamichiel yea it works now but it still changes the yaw and pitch of the player to match the horse + I dont know why the custom entity dosent have the name CHorse yet it behaves as a custom entity all my other entityes are working fine :/
     
  24. Offline

    NortherKnight

    Yea fixed the naming issue with overriding the setName but i still couldnt get the yaw and pitch to not change because its in a private method
     
  25. Offline

    Scimiguy

Thread Status:
Not open for further replies.

Share This Page