NMS Change walking sound of mob [1.7.5]

Discussion in 'Resources' started by Plugers11, Feb 8, 2015.

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

    Plugers11

    Hi guys !

    Last time i needed this code for my plugin and i think it's could be useful for you too ;)

    Let's start

    For example i will change sheep steps and change from sheep steps to hmm enderdragon steps ?

    We will change this to enderdragon


    Code:
    protected String t() {
            return "mob.sheep.say";
        }
    
        protected String aT() {
            return "mob.sheep.say";
        }

    Now we got our class



    Code:
    import java.lang.reflect.Field;
    
    import org.bukkit.craftbukkit.v1_7_R2.CraftWorld;
    import org.bukkit.craftbukkit.v1_7_R2.util.UnsafeList;
    
    import net.minecraft.server.v1_7_R2.EntitySheep;
    import net.minecraft.server.v1_7_R2.PathfinderGoalSelector;
    import org.bukkit.World;
    
    public class SheepEdited extends EntitySheep{
    
        public SheepEdited(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 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;
        }
    
    
        protected String t() {
            return "mob.sheep.say";
        }
    
        protected String aT() {
            return "mob.sheep.say";
        }
    }
    

    Now we will change all strings from t and aT to our ender dragon

    Enderdragon has 2 sounds
    Hit and growl

    Code:
    protected String t() {
            return "mob.enderdragon.growl";
        }
    
        protected String aT() {
            return "mob.enderdragon.hit";
        }

    So now our class is :

    Code:
    import java.lang.reflect.Field;
    
    import org.bukkit.craftbukkit.v1_7_R2.CraftWorld;
    import org.bukkit.craftbukkit.v1_7_R2.util.UnsafeList;
    
    import net.minecraft.server.v1_7_R2.EntitySheep;
    import net.minecraft.server.v1_7_R2.PathfinderGoalSelector;
    import org.bukkit.World;
    
    public class SheepEdited extends EntitySheep{
    
        public SheepEdited(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();
            }
        }
    
        protected String t() {
            return "mob.enderdragon.growl";
        }
    
        protected String aT() {
            return "mob.enderdragon.hit";
        }
    
    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;
        }
    
    }
    Now we need to spawn our sheep. We will make a enum with name : EntityTypes


    Code:
    import java.util.Map;
    
    import net.minecraft.server.v1_7_R2.Entity;
    import net.minecraft.server.v1_7_R2.EntityPlayer;
    
    import org.bukkit.Location;
    import org.bukkit.craftbukkit.v1_7_R2.CraftWorld;
    import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    
    public enum EntityTypes
    {
        Sheeep("Sheep", 91, SheepEdited.class);
    // The first : ,, Sheeep" is our argument, next is "Sheep", what's name of our entity, next is id of Sheep, all id u can find below this post, and the last one is our class of edited sheep, so its : SheepEdited.class.
    
        private EntityTypes(String name, int id, Class<? extends Entity> custom)
        {
            addToMaps(custom, name, id);
        }
    
      public static void spawnEntity(Entity entity, Location loc, Player p)
       {
         entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
         ((CraftWorld)loc.getWorld()).getHandle().addEntity(entity);
    //This code below is for set our player to passenger of entity
         EntityPlayer handle = ((CraftPlayer) p).getHandle();
         handle.setPassengerOf(entity);
       }
    
    
    private static void addToMaps(Class clazz, String name, int id)
      {
         ((Map)SheepEdited.getPrivateField("d", net.minecraft.server.v1_7_R2.EntityTypes.class, null)).put(clazz, name);
          ((Map)SheepEdited.getPrivateField("f", net.minecraft.server.v1_7_R2.EntityTypes.class, null)).put(clazz, Integer.valueOf(id));
      }
    }
    
    Ok we have now what we need ;)

    Now we need to use spawnEntity :D

    It's simple:

    Code:
    
    SheepEdited dr = new SheepEdited(p.getWorld());
    
                           EntityTypes.spawnEntity(dr, p.getLocation(), p);  //p is our player
    
    EntityTypes.spawnEntity(dr, p.getLocation(), p);
    
    


    ID:

    Code:
    
    MINECART_MOB_SPAWNER("MinecartMobSpawner", SpawnerMinecart.class, 47),
    CREEPER("Creeper", Creeper.class, 50),
    SKELETON("Skeleton", Skeleton.class, 51),
    SPIDER("Spider", Spider.class, 52),
    GIANT("Giant", Giant.class, 53),
    ZOMBIE("Zombie", Zombie.class, 54),
    SLIME("Slime", Slime.class, 55),
    GHAST("Ghast", Ghast.class, 56),
    PIG_ZOMBIE("PigZombie", PigZombie.class, 57),
    ENDERMAN("Enderman", Enderman.class, 58),
    CAVE_SPIDER("CaveSpider", CaveSpider.class, 59),
    SILVERFISH("Silverfish", Silverfish.class, 60),
    BLAZE("Blaze", Blaze.class, 61),
    MAGMA_CUBE("LavaSlime", MagmaCube.class, 62),
    ENDER_DRAGON("EnderDragon", EnderDragon.class, 63),
    WITHER("WitherBoss", Wither.class, 64),
    BAT("Bat", Bat.class, 65),
    WITCH("Witch", Witch.class, 66),
    PIG("Pig", Pig.class, 90),
    SHEEP("Sheep", Sheep.class, 91),
    COW("Cow", Cow.class, 92),
    CHICKEN("Chicken", Chicken.class, 93),
    SQUID("Squid", Squid.class, 94),
    WOLF("Wolf", Wolf.class, 95),
    MUSHROOM_COW("MushroomCow", MushroomCow.class, 96),
    SNOWMAN("SnowMan", Snowman.class, 97),
    OCELOT("Ozelot", Ocelot.class, 98),
    IRON_GOLEM("VillagerGolem", IronGolem.class, 99),
    HORSE("EntityHorse", Horse.class, 100),
    VILLAGER("Villager", Villager.class, 120),
    ENDER_CRYSTAL("EnderCrystal", EnderCrystal.class, 200),
    
    

    Thanks for reading :)

    Anyway sorry for my english :F



    FULL CODE:

    EntityTypes:

    Code:
    import java.util.Map;
    
    import net.minecraft.server.v1_7_R2.Entity;
    import net.minecraft.server.v1_7_R2.EntityPlayer;
    
    import org.bukkit.Location;
    import org.bukkit.craftbukkit.v1_7_R2.CraftWorld;
    import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    
    public enum EntityTypes
    {
        Sheeep("Sheep", 91, SheepEdited.class);
    // The first : ,, Sheeep" is our argument, next is "Sheep", what's name of our entity, next is id of Sheep, all id u can find below this post, and the last one is our class of edited sheep, so its : SheepEdited.class.
    
        private EntityTypes(String name, int id, Class<? extends Entity> custom)
        {
            addToMaps(custom, name, id);
        }
    
      public static void spawnEntity(Entity entity, Location loc, Player p)
       {
         entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
         ((CraftWorld)loc.getWorld()).getHandle().addEntity(entity);
    //This code below is for set our player to passenger of entity
         EntityPlayer handle = ((CraftPlayer) p).getHandle();
         handle.setPassengerOf(entity);
       }
    
    
    private static void addToMaps(Class clazz, String name, int id)
      {
         ((Map)SheepEdited.getPrivateField("d", net.minecraft.server.v1_7_R2.EntityTypes.class, null)).put(clazz, name);
          ((Map)SheepEdited.getPrivateField("f", net.minecraft.server.v1_7_R2.EntityTypes.class, null)).put(clazz, Integer.valueOf(id));
      }
    }
    

    SheepEdited:

    Code:
    import java.lang.reflect.Field;
    
    import org.bukkit.craftbukkit.v1_7_R2.CraftWorld;
    import org.bukkit.craftbukkit.v1_7_R2.util.UnsafeList;
    
    import net.minecraft.server.v1_7_R2.EntitySheep;
    import net.minecraft.server.v1_7_R2.PathfinderGoalSelector;
    import org.bukkit.World;
    
    public class SheepEdited extends EntitySheep{
    
        public SheepEdited(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();
            }
        }
    
        protected String t() {
            return "mob.enderdragon.growl";
        }
    
        protected String aT() {
            return "mob.enderdragon.hit";
        }
    
    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;
        }
    
    }
    Spawning mobs:


    Code:
    
    SheepEdited dr = new SheepEdited(p.getWorld());
    
                           EntityTypes.spawnEntity(dr, p.getLocation(), p);  //p is our player
    
    EntityTypes.spawnEntity(dr, p.getLocation(), p);
    
    
     
    Last edited: Feb 13, 2015
    GrandmaJam, ChipDev and leon3001 like this.
  2. Offline

    ProStriker123

  3. Offline

    ChipDev

    Does this work with cb 1.8?
     
  4. Invisible

    nverdier

    @ChipDev How could it? It uses 1.7 methods... Which generally change with every MC update...
     
  5. Offline

    ChipDev

    CMD-F
    Replace 1_7_R2 with 1_8_R1
     
  6. Offline

    Supereg

    In current 1.8 the methods are the following
    Code:
        protected String z() {
            return "mob.enderdragon.growl";
        }
    
        protected String bn() {
            return "mob.enderdragon.hit";
        }
     
  7. Invisible

    nverdier

    No,
     
  8. Offline

    ChipDev

    I know! I mean the imports :) I update my NMS sometimes.
    EDIT: Don't tell me I'm blind or anything..
    Sheeep("Sheep", 63, SheepEdited.class);

    What is EndDr? EndDragon?

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Feb 9, 2015
  9. Offline

    Plugers11

    @ChipDev where i put it ? XD

    I make new emmm ,,argument in enum :D" i don't have idea how to name it xDD
     
  10. Offline

    ChipDev


    1. private static void addToMaps(Class clazz, String name, int id)
    2. {
    3. ((Map)EndDr.getPrivateField("d", net.minecraft.server.v1_7_R2.EntityTypes.class, null)).put(clazz, name);
    4. ((Map)EndDr.getPrivateField("f", net.minecraft.server.v1_7_R2.EntityTypes.class, null)).put(clazz, Integer.valueOf(id));
    5. }

    Can someone please help me with this?

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

    Plugers11

    @ChipDev

    Ahhh
    I forgot to change it
    Sorry :///
    Done.
     
    ChipDev likes this.
  12. Offline

    ChipDev

    SheepEdited does not have that method; nor EntitySheep
     
  13. Offline

    ChipDev

    Just send me the project (PLUGIN .JAR) You made and I will decompile it :)
     
Thread Status:
Not open for further replies.

Share This Page