NMS How to override default Minecraft mobs

Discussion in 'Resources' started by TeeePeee, Jan 6, 2014.

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

    winjw7

    Code:java
    1. protected void aD()
    2. {
    3. super.aD();
    4. this.getAttributeInstance(GenericAttributes.e).setValue(300.0D); // Original 3.0D
    5. }


    I get an error in eclipse that says: The return type is incompatible with EntityLiving.aD()
    I'm using craftbukkit-1.7.9-R0.3-20140603.002405-1.jar, Any help is apreciated, Thanks! (Please put the code i need to change and if you need the whole class i will)
     
  2. Offline

    RingOfStorms

    This is why you shouldn't just copy paste and not understand what is happening. In order to properly update your plugin from a previously working version, you need to read what the aD method used to be, then find it again in the updated version. It most likely changed names and so you need to compare versions and change the aD to the new name.
     
  3. Offline

    teej107

    NMS FTW!
     
  4. Offline

    winjw7

    yea, sorry was in a hurry, Don't ussally just copy and paste. I got it working now thoe, thanks!
     
  5. Offline

    synquall

    If you're using 1.8, you have to change this:

    Code:
    for (String field : new String[]{"as", "at", "au", "av"}) {
    to

    Code:
    for (String field : new String[]{"at", "au", "av", "aw"}) {
     
  6. Offline

    jusjus112

    TeeePeee
    Very nice tutorial, but when is this updated to 1.7.5?
     
  7. The thing with relying on NMS is that it is your responsibility to keep on top of it and learn to update it yourself :)
     
  8. Offline

    ChipDev

    Bookmarked! This tutorial is very very good ;)
    o
    o
    k
    M
    a
    r
    k
    e
    d
     
  9. Offline

    John00708

    Um.. noob question, what has changed that I need to be aware of for 1.7.9? I'd really appreciate an answer! :)
     
  10. Offline

    jusjus112

    @TeeePeee
    How can i spawn this custom mobs, with the normal bukkit method with spawnEntity() doenst work!
    How do i spawn this little mobs?
     
  11. Offline

    RingOfStorms

    It is the very first code example on the original post. In short, you don't just use spawnEntity(), but if you read any of the post you should've known that.
     
  12. Offline

    DemKazoo

    Mostretarded question found here probably, But I'm conufsed. Is there a possible way to set a custom display name, and make sure it's visible on NMS entities?
     
  13. Offline

    RingOfStorms

    setCustomName, setCustomNameVisible
     
    DemKazoo likes this.
  14. Offline

    DemKazoo

    @RingOfStorms ye, figured it out myself. Had a little derp moment :/
     
  15. Offline

    callum2904

    Do you by any chance know what the aD changed to? Iv looked for a while now and this is pretty much the first time i have used NMS code so i'm not too sure what to be searching for.

    EDIT: I had a look through the spiggot 1.8 build i was using and I found that it uses -> aW() <- from what I know.
     
    Last edited by a moderator: Dec 29, 2014
  16. Offline

    DemKazoo

    aC()
     
    ChipDev likes this.
  17. Offline

    callum2904

    It has changed again during the update from 1.7.9 to snapshot builds of 1.8 from spigot which uses the aW() method.
     
    ChipDev likes this.
  18. Offline

    ChipDev

    Last edited: Jan 1, 2015
  19. Offline

    TeeePeee

    Just wanted to say that I've returned now from my long absence, so I can again field any questions :)
     
    Monkey_Swag, Europia79 and ChipDev like this.
  20. Offline

    CaptainDirt

    @TeeePeee I tried making a Villager class to stop the Villager from moving (I got this off another thread) but I get this error:
    Code:
    package cd.handlers.custom;
    
    import java.lang.reflect.Field;
    
    import net.minecraft.server.v1_7_R3.EntityHuman;
    import net.minecraft.server.v1_7_R3.EntityVillager;
    import net.minecraft.server.v1_7_R3.GenericAttributes;
    import net.minecraft.server.v1_7_R3.PathfinderGoalLookAtPlayer;
    import net.minecraft.server.v1_7_R3.PathfinderGoalSelector;
    import net.minecraft.server.v1_7_R3.World;
    
    import org.bukkit.craftbukkit.v1_7_R3.util.UnsafeList;
    
    public class CustomEntityVillager extends EntityVillager
        {
    
            public CustomEntityVillager(World world, int i)
                {
                    super(world);
    
                    this.setProfession(i);
                    // Removes all pathfinders already registered in the villager
                    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 e)
                        {
                            e.printStackTrace();
                        }
                    setUp();
                }
    
            public void setUp()
                {
                    // Make the villager look at players
                    this.goalSelector.a(10, new PathfinderGoalLookAtPlayer(this,
                            EntityHuman.class, 8.0F));
                }
    
            @Override
            protected void aC()
                {
                    super.aC();
                    // Make his walk speed 0 so he doesn't walk around on his own
                    this.getAttributeInstance(GenericAttributes.d).setValue(0.0D);
                    // Make his health to max a double can be
                    this.getAttributeInstance(GenericAttributes.a).setValue(
                            Double.MAX_VALUE);
                    // Make his knockback resistance max double can be
                    this.getAttributeInstance(GenericAttributes.c).setValue(
                            Double.MAX_VALUE);
                }
    
            @Override
            public void move(double d0, double d1, double d2)
                {
                }
        }
    But I get this error:
    Code:
    [23:28:51 WARN]: java.lang.NoSuchMethodException: cd.
    handlers.custom.CustomEntityVillager.<init>(net.minecraft.server.v1_7_R3.World)
    [23:28:51 WARN]:        at java.lang.Class.getConstructor0(Unknown Source)
    [23:28:51 WARN]:        at java.lang.Class.getConstructor(Unknown Source)
    [23:28:51 WARN]:        at net.minecraft.server.v1_7_R3.EntityTypes.a(SourceFile
    :166)
    [23:28:51 WARN]:        at net.minecraft.server.v1_7_R3.ItemMonsterEgg.spawnCrea
    ture(ItemMonsterEgg.java:108)
    [23:28:51 WARN]:        at net.minecraft.server.v1_7_R3.ItemMonsterEgg.a(ItemMon
    sterEgg.java:97)
    [23:28:51 WARN]:        at net.minecraft.server.v1_7_R3.ItemMonsterEgg.interactW
    ith(ItemMonsterEgg.java:37)
    [23:28:51 WARN]:        at net.minecraft.server.v1_7_R3.ItemStack.placeItem(Item
    Stack.java:102)
    [23:28:51 WARN]:        at net.minecraft.server.v1_7_R3.PlayerInteractManager.in
    teract(PlayerInteractManager.java:390)
    [23:28:51 WARN]:        at net.minecraft.server.v1_7_R3.PlayerConnection.a(Playe
    rConnection.java:629)
    [23:28:51 WARN]:        at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.a
    (SourceFile:60)
    [23:28:51 WARN]:        at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.h
    andle(SourceFile:9)
    [23:28:51 WARN]:        at net.minecraft.server.v1_7_R3.NetworkManager.a(Network
    Manager.java:157)
    [23:28:51 WARN]:        at net.minecraft.server.v1_7_R3.ServerConnection.c(Sourc
    eFile:134)
    [23:28:51 WARN]:        at net.minecraft.server.v1_7_R3.MinecraftServer.v(Minecr
    aftServer.java:667)
    [23:28:51 WARN]:        at net.minecraft.server.v1_7_R3.DedicatedServer.v(Dedica
    tedServer.java:260)
    [23:28:51 WARN]:        at net.minecraft.server.v1_7_R3.MinecraftServer.u(Minecr
    aftServer.java:558)
    [23:28:51 WARN]:        at net.minecraft.server.v1_7_R3.MinecraftServer.run(Mine
    craftServer.java:469)
    [23:28:51 WARN]:        at net.minecraft.server.v1_7_R3.ThreadServerApplication.
    run(SourceFile:628)
    [23:28:51 WARN]: Skipping Entity with id 120
    Code:
    ZOMBIE("Zombie", 54, EntityType.ZOMBIE, EntityZombie.class,
                    CustomEntityZombie.class), VILLAGER("Villager", 120,
                    EntityType.VILLAGER, EntityVillager.class,
                    CustomEntityVillager.class);
     
    Last edited: Jan 13, 2015
  21. Offline

    KungFuGoat

    The fields have changed to "at", "au", "av", "aw" in 1.8

    EDIT: I see some other people have already pointed that out :(
     
  22. Offline

    TeeePeee

    @CaptainDirt
    Make an initializer without the integer parameter. Something like (and forgive me lack of formatting, I'm on my mobile)

    public CustomEntityVillager(World world) {
    this(world, 0);
    }

    Bukkit (at least used to) create an instance of an EntityLiving by fetching a constructor for the class with only a World parameter, and without having one, it can't find it to create the object.
     
  23. Offline

    CaptainDirt

    EDIT: I got it fixed, but now I have a new question, when I try to stop the Villager from moving it doesn't move it runs around weird then teleports back to the location it was at.
     
    Last edited: Jan 14, 2015
  24. Offline

    TeeePeee

    @CaptainDirt
    That may be a problem with setting GenericAttributes.d to 0.0? Although I'm not sure. If changing that doesn't fix it, I'll check it out more when I'm on my laptop.
     
  25. Offline

    CaptainDirt

  26. Offline

    stonebloodtv

    The register does'nt match (Spigot and Bukkit version on 1.8..)

    Can you upgrade the tutorial code please ?
    Thank's :)

    Show Spoiler

    Code:
    (CraftServer.java:355)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlug
    ins(CraftServer.java:315)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(Cra
    ftServer.java:744)
    [10:11:11 WARN]:        at org.bukkit.Bukkit.reload(Bukkit.java:534)
    [10:11:11 WARN]:        at org.bukkit.command.defaults.ReloadCommand.execute(Rel
    oadCommand.java:23)
    [10:11:11 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCo
    mmandMap.java:141)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCo
    mmand(CraftServer.java:645)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchSe
    rverCommand(CraftServer.java:631)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.aM(Dedic
    atedServer.java:353)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.z(Dedica
    tedServer.java:317)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.y(Minecr
    aftServer.java:623)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.run(Mine
    craftServer.java:526)
    [10:11:11 WARN]:        at java.lang.Thread.run(Unknown Source)
    [10:11:11 WARN]: java.lang.ClassCastException: net.minecraft.server.v1_8_R1.Biom
    eDecorator cannot be cast to java.util.List
    [10:11:11 WARN]:        at fr.eclozion.rpg.entity.CustomEntityRegister.registerE
    ntities(CustomEntityRegister.java:87)
    [10:11:11 WARN]:        at fr.eclozion.rpg.Main.onEnable(Main.java:74)
    [10:11:11 WARN]:        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlug
    in.java:321)
    [10:11:11 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(
    JavaPluginLoader.java:335)
    [10:11:11 WARN]:        at org.bukkit.plugin.SimplePluginManager.enablePlugin(Si
    mplePluginManager.java:405)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin
    (CraftServer.java:355)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlug
    ins(CraftServer.java:315)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(Cra
    ftServer.java:744)
    [10:11:11 WARN]:        at org.bukkit.Bukkit.reload(Bukkit.java:534)
    [10:11:11 WARN]:        at org.bukkit.command.defaults.ReloadCommand.execute(Rel
    oadCommand.java:23)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.aM(Dedic
    atedServer.java:353)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.z(Dedica
    tedServer.java:317)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.y(Minecr
    aftServer.java:623)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.run(Mine
    craftServer.java:526)
    [10:11:11 WARN]:        at java.lang.Thread.run(Unknown Source)
    [10:11:11 WARN]: java.lang.ClassCastException: net.minecraft.server.v1_8_R1.Biom
    eDecorator cannot be cast to java.util.List
    [10:11:11 WARN]:        at fr.eclozion.rpg.entity.CustomEntityRegister.registerE
    ntities(CustomEntityRegister.java:87)
    [10:11:11 WARN]:        at fr.eclozion.rpg.Main.onEnable(Main.java:74)
    [10:11:11 WARN]:        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlug
    in.java:321)
    [10:11:11 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(
    JavaPluginLoader.java:335)
    [10:11:11 WARN]:        at org.bukkit.plugin.SimplePluginManager.enablePlugin(Si
    mplePluginManager.java:405)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin
    (CraftServer.java:355)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlug
    ins(CraftServer.java:315)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(Cra
    ftServer.java:744)
    [10:11:11 WARN]:        at org.bukkit.Bukkit.reload(Bukkit.java:534)
    [10:11:11 WARN]:        at org.bukkit.command.defaults.ReloadCommand.execute(Rel
    oadCommand.java:23)
    [10:11:11 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCo
    mmandMap.java:141)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCo
    mmand(CraftServer.java:645)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchSe
    rverCommand(CraftServer.java:631)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.aM(Dedic
    atedServer.java:353)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.z(Dedica
    tedServer.java:317)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.y(Minecr
    aftServer.java:623)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.run(Mine
    craftServer.java:526)
    [10:11:11 WARN]:        at java.lang.Thread.run(Unknown Source)
    [10:11:11 WARN]: java.lang.ClassCastException: net.minecraft.server.v1_8_R1.Biom
    eDecorator cannot be cast to java.util.List
    [10:11:11 WARN]:        at fr.eclozion.rpg.entity.CustomEntityRegister.registerE
    ntities(CustomEntityRegister.java:87)
    [10:11:11 WARN]:        at fr.eclozion.rpg.Main.onEnable(Main.java:74)
    [10:11:11 WARN]:        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlug
    in.java:321)
    [10:11:11 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(
    JavaPluginLoader.java:335)
    [10:11:11 WARN]:        at org.bukkit.plugin.SimplePluginManager.enablePlugin(Si
    mplePluginManager.java:405)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin
    (CraftServer.java:355)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlug
    ins(CraftServer.java:315)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(Cra
    ftServer.java:744)
    [10:11:11 WARN]:        at org.bukkit.Bukkit.reload(Bukkit.java:534)
    [10:11:11 WARN]:        at org.bukkit.command.defaults.ReloadCommand.execute(Rel
    oadCommand.java:23)
    [10:11:11 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCo
    mmandMap.java:141)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCo
    mmand(CraftServer.java:645)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchSe
    rverCommand(CraftServer.java:631)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.aM(Dedic
    atedServer.java:353)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.z(Dedica
    tedServer.java:317)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.y(Minecr
    aftServer.java:623)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.run(Mine
    craftServer.java:526)
    [10:11:11 WARN]:        at java.lang.Thread.run(Unknown Source)
    [10:11:11 WARN]: java.lang.ClassCastException: net.minecraft.server.v1_8_R1.Biom
    eDecorator cannot be cast to java.util.List
    [10:11:11 WARN]:        at fr.eclozion.rpg.entity.CustomEntityRegister.registerE
    ntities(CustomEntityRegister.java:87)
    [10:11:11 WARN]:        at fr.eclozion.rpg.Main.onEnable(Main.java:74)
    [10:11:11 WARN]:        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlug
    in.java:321)
    [10:11:11 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(
    JavaPluginLoader.java:335)
    [10:11:11 WARN]:        at org.bukkit.plugin.SimplePluginManager.enablePlugin(Si
    mplePluginManager.java:405)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin
    (CraftServer.java:355)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlug
    ins(CraftServer.java:315)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(Cra
    ftServer.java:744)
    [10:11:11 WARN]:        at org.bukkit.Bukkit.reload(Bukkit.java:534)
    [10:11:11 WARN]:        at org.bukkit.command.defaults.ReloadCommand.execute(Rel
    oadCommand.java:23)
    [10:11:11 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCo
    mmandMap.java:141)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCo
    mmand(CraftServer.java:645)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchSe
    rverCommand(CraftServer.java:631)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.aM(Dedic
    atedServer.java:353)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.z(Dedica
    tedServer.java:317)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.y(Minecr
    aftServer.java:623)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.run(Mine
    craftServer.java:526)
    [10:11:11 WARN]:        at java.lang.Thread.run(Unknown Source)
    [10:11:11 WARN]: java.lang.ClassCastException: net.minecraft.server.v1_8_R1.Biom
    eDecorator cannot be cast to java.util.List
    [10:11:11 WARN]:        at fr.eclozion.rpg.entity.CustomEntityRegister.registerE
    ntities(CustomEntityRegister.java:87)
    [10:11:11 WARN]:        at fr.eclozion.rpg.Main.onEnable(Main.java:74)
    [10:11:11 WARN]:        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlug
    in.java:321)
    [10:11:11 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(
    JavaPluginLoader.java:335)
    [10:11:11 WARN]:        at org.bukkit.plugin.SimplePluginManager.enablePlugin(Si
    mplePluginManager.java:405)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin
    (CraftServer.java:355)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlug
    ins(CraftServer.java:315)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(Cra
    ftServer.java:744)
    [10:11:11 WARN]:        at org.bukkit.Bukkit.reload(Bukkit.java:534)
    [10:11:11 WARN]:        at org.bukkit.command.defaults.ReloadCommand.execute(Rel
    oadCommand.java:23)
    [10:11:11 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCo
    mmandMap.java:141)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCo
    mmand(CraftServer.java:645)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchSe
    rverCommand(CraftServer.java:631)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.aM(Dedic
    atedServer.java:353)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.z(Dedica
    tedServer.java:317)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.y(Minecr
    aftServer.java:623)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.run(Mine
    craftServer.java:526)
    [10:11:11 WARN]:        at java.lang.Thread.run(Unknown Source)
    [10:11:11 WARN]: java.lang.ClassCastException: net.minecraft.server.v1_8_R1.Biom
    eDecorator cannot be cast to java.util.List
    [10:11:11 WARN]:        at fr.eclozion.rpg.entity.CustomEntityRegister.registerE
    ntities(CustomEntityRegister.java:87)
    [10:11:11 WARN]:        at fr.eclozion.rpg.Main.onEnable(Main.java:74)
    [10:11:11 WARN]:        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlug
    in.java:321)
    [10:11:11 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(
    JavaPluginLoader.java:335)
    [10:11:11 WARN]:        at org.bukkit.plugin.SimplePluginManager.enablePlugin(Si
    mplePluginManager.java:405)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin
    (CraftServer.java:355)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlug
    ins(CraftServer.java:315)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(Cra
    ftServer.java:744)
    [10:11:11 WARN]:        at org.bukkit.Bukkit.reload(Bukkit.java:534)
    [10:11:11 WARN]:        at org.bukkit.command.defaults.ReloadCommand.execute(Rel
    oadCommand.java:23)
    [10:11:11 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCo
    mmandMap.java:141)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCo
    mmand(CraftServer.java:645)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchSe
    rverCommand(CraftServer.java:631)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.aM(Dedic
    atedServer.java:353)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.z(Dedica
    tedServer.java:317)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.y(Minecr
    aftServer.java:623)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.run(Mine
    craftServer.java:526)
    [10:11:11 WARN]:        at java.lang.Thread.run(Unknown Source)
    [10:11:11 WARN]: java.lang.ClassCastException: net.minecraft.server.v1_8_R1.Biom
    eDecorator cannot be cast to java.util.List
    [10:11:11 WARN]:        at fr.eclozion.rpg.entity.CustomEntityRegister.registerE
    ntities(CustomEntityRegister.java:87)
    [10:11:11 WARN]:        at fr.eclozion.rpg.Main.onEnable(Main.java:74)
    [10:11:11 WARN]:        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlug
    in.java:321)
    [10:11:11 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(
    JavaPluginLoader.java:335)
    [10:11:11 WARN]:        at org.bukkit.plugin.SimplePluginManager.enablePlugin(Si
    mplePluginManager.java:405)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin
    (CraftServer.java:355)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlug
    ins(CraftServer.java:315)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(Cra
    ftServer.java:744)
    [10:11:11 WARN]:        at org.bukkit.Bukkit.reload(Bukkit.java:534)
    [10:11:11 WARN]:        at org.bukkit.command.defaults.ReloadCommand.execute(Rel
    oadCommand.java:23)
    [10:11:11 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCo
    mmandMap.java:141)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCo
    mmand(CraftServer.java:645)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchSe
    rverCommand(CraftServer.java:631)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.aM(Dedic
    atedServer.java:353)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.z(Dedica
    tedServer.java:317)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.y(Minecr
    aftServer.java:623)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.run(Mine
    craftServer.java:526)
    [10:11:11 WARN]:        at java.lang.Thread.run(Unknown Source)
    [10:11:11 WARN]: java.lang.ClassCastException: net.minecraft.server.v1_8_R1.Biom
    eDecorator cannot be cast to java.util.List
    [10:11:11 WARN]:        at fr.eclozion.rpg.entity.CustomEntityRegister.registerE
    ntities(CustomEntityRegister.java:87)
    [10:11:11 WARN]:        at fr.eclozion.rpg.Main.onEnable(Main.java:74)
    [10:11:11 WARN]:        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlug
    in.java:321)
    [10:11:11 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(
    JavaPluginLoader.java:335)
    [10:11:11 WARN]:        at org.bukkit.plugin.SimplePluginManager.enablePlugin(Si
    mplePluginManager.java:405)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin
    (CraftServer.java:355)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlug
    ins(CraftServer.java:315)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(Cra
    ftServer.java:744)
    [10:11:11 WARN]:        at org.bukkit.Bukkit.reload(Bukkit.java:534)
    [10:11:11 WARN]:        at org.bukkit.command.defaults.ReloadCommand.execute(Rel
    oadCommand.java:23)
    [10:11:11 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCo
    mmandMap.java:141)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCo
    mmand(CraftServer.java:645)
    [10:11:11 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchSe
    rverCommand(CraftServer.java:631)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.aM(Dedic
    atedServer.java:353)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.z(Dedica
    tedServer.java:317)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.y(Minecr
    aftServer.java:623)
    [10:11:11 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.run(Mine
    craftServer.java:526)
    [10:11:11 WARN]:        at java.lang.Thread.run(Unknown Source)
    [10:11:11 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [10:11:11 INFO]: CONSOLE: Reload complete.
    >
     
  27. just wondering, how could I make this to work only for specific mobs?
     
  28. Offline

    cowchickcen

    How would I stop all the mobs from being custom, just the ones spawned in with code.
     
  29. Offline

    bars96

    @TeeePeee,
    http://pastebin.com/AL91XrHf
    If uncomment goal/target selectors (Entity AI tasks), zombie don't attack players.
    If it commented, they attack players, but GenericAttributes (Shared monster attributes) works only on zombies which spawned via spawn egg. What the problem?
     
  30. Offline

    GrandpaMizery

    This is the code I used, which I believe is the same as the original post. I Using Spigot and craftbukkit.APIs

    Code:
    package me.grandpamizery;
    
    import java.lang.reflect.Field;
    import java.util.List;
    import java.util.Map;
    
    import org.bukkit.entity.EntityType;
    
    import net.minecraft.server.v1_8_R1.BiomeBase;
    import net.minecraft.server.v1_8_R1.BiomeMeta;
    import net.minecraft.server.v1_8_R1.EntityCow;
    import net.minecraft.server.v1_8_R1.EntityInsentient;
    import net.minecraft.server.v1_8_R1.EntityTypes;
    public enum CustomEntityType {
    // ZOMBIE("Zombie", 54, EntityType.ZOMBIE, EntityZombie.class, CustomEntityZombie.class);
        GM_COW("Cow", 92, EntityType.COW, EntityCow.class, CustomEntityCow.class);
        private String name;
        private int id;
        private EntityType entityType;
        private Class<? extends EntityInsentient> nmsClass;
        private Class<? extends EntityInsentient> customClass;
        private CustomEntityType(String name, int id, EntityType entityType, Class<? extends EntityInsentient> nmsClass, Class<? extends EntityInsentient> customClass) {
            this.name = name;
            this.id = id;
            this.entityType = entityType;
            this.nmsClass = nmsClass;
            this.customClass = customClass;
        }
        public String getName() {
            return name;
        }
        public int getID() {
            return id;
        }
        public EntityType getEntityType() {
            return entityType;
        }
        public Class<? extends EntityInsentient> getNMSClass() {
            return nmsClass;
        }
        public Class<? extends EntityInsentient> getCustomClass() {
            return customClass;
        }
        /**
        * Register our entities.
        */
        public static void registerEntities() {
                for (CustomEntityType entity : values())
                    a(entity.getCustomClass(), entity.getName(), entity.getID());
                // BiomeBase#biomes became private.
                BiomeBase[] biomes;
                try {
                    biomes = (BiomeBase[]) getPrivateStatic(BiomeBase.class, "biomes");
                } catch (Exception exc) {
                    // Unable to fetch.
                    return;
                }
                for (BiomeBase biomeBase : biomes) {
                    if (biomeBase == null)
                        break;
                    // This changed names from J, K, L and M.
                    for (String field : new String[] { "as", "at", "au", "av" })
                        try {
                            Field list = BiomeBase.class.getDeclaredField(field);
                            list.setAccessible(true);
                            @SuppressWarnings("unchecked")
                            List<BiomeMeta> mobList = (List<BiomeMeta>) list.get(biomeBase);
                            // Write in our custom class.
                            for (BiomeMeta meta : mobList)
                                for (CustomEntityType entity : values())
                                    if (entity.getNMSClass().equals(meta.b))
                                        meta.b = entity.getCustomClass();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                }
        }
        /**
        * Unregister our entities to prevent memory leaks. Call on disable.
        */
        public static void unregisterEntities() {
            for (CustomEntityType entity : values()) {
                // Remove our class references.
                try {
                    ((Map) getPrivateStatic(EntityTypes.class, "d")).remove(entity.getCustomClass());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                try {
                    ((Map) getPrivateStatic(EntityTypes.class, "f")).remove(entity.getCustomClass());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            for (CustomEntityType entity : values())
                try {
                    // Unregister each entity by writing the NMS back in place of the custom class.
                    a(entity.getNMSClass(), entity.getName(), entity.getID());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            // Biomes#biomes was made private so use reflection to get it.
            BiomeBase[] biomes;
            try {
                biomes = (BiomeBase[]) getPrivateStatic(BiomeBase.class, "biomes");
            } catch (Exception exc) {
                // Unable to fetch.
                return;
            }
            for (BiomeBase biomeBase : biomes) {
                if (biomeBase == null)
                    break;
                // The list fields changed names but update the meta regardless.
                for (String field : new String[] { "as", "at", "au", "av" })
                    try {
                        Field list = BiomeBase.class.getDeclaredField(field);
                        list.setAccessible(true);
                        @SuppressWarnings("unchecked")
                        List<BiomeMeta> mobList = (List<BiomeMeta>) list.get(biomeBase);
                        // Make sure the NMS class is written back over our custom class.
                        for (BiomeMeta meta : mobList)
                            for (CustomEntityType entity : values())
                                if (entity.getCustomClass().equals(meta.b))
                                    meta.b = entity.getNMSClass();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
            }
        }
        /**
        * A convenience method.
        * @param clazz The class.
        * @param f The string representation of the private static field.
        * @return The object found
        * @throws Exception if unable to get the object.
        */
        private static Object getPrivateStatic(Class clazz, String f) throws Exception {
            Field field = clazz.getDeclaredField(f);
            field.setAccessible(true);
            return field.get(null);
        }
        /*
        * Since 1.7.2 added a check in their entity registration, simply bypass it and write to the maps ourself.
        */
        private static void a(Class paramClass, String paramString, int paramInt) {
            try {
                ((Map) getPrivateStatic(EntityTypes.class, "c")).put(paramString, paramClass);
                ((Map) getPrivateStatic(EntityTypes.class, "d")).put(paramClass, paramString);
                ((Map) getPrivateStatic(EntityTypes.class, "e")).put(Integer.valueOf(paramInt), paramClass);
                ((Map) getPrivateStatic(EntityTypes.class, "f")).put(paramClass, Integer.valueOf(paramInt));
                ((Map) getPrivateStatic(EntityTypes.class, "g")).put(paramString, Integer.valueOf(paramInt));
            } catch (Exception exc) {
                // Unable to register the new class.
            }
        }
    }
    This is the error I am getting:
    Code:
    [16:16:41 WARN]: java.lang.ClassCastException: net.minecraft.server.v1_8_R1.Biom
    eDecorator cannot be cast to java.util.List
    [16:16:41 WARN]:        at me.grandpamizery.CustomEntityType.registerEntities(Cu
    stomEntityType.java:79)
    [16:16:41 WARN]:        at me.grandpamizery.Pets.onEnable(Pets.java:20)
    [16:16:41 WARN]:        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlug
    in.java:321)
    [16:16:41 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(
    JavaPluginLoader.java:335)
    [16:16:41 WARN]:        at org.bukkit.plugin.SimplePluginManager.enablePlugin(Si
    mplePluginManager.java:405)
    [16:16:41 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin
    (CraftServer.java:356)
    [16:16:41 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlug
    ins(CraftServer.java:316)
    [16:16:41 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.q(Minecr
    aftServer.java:402)
    [16:16:41 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.k(Minecr
    aftServer.java:370)
    [16:16:41 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.a(Minecr
    aftServer.java:325)
    [16:16:41 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.init(Ded
    icatedServer.java:211)
    [16:16:41 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.run(Mine
    craftServer.java:494)
    [16:16:41 WARN]:        at java.lang.Thread.run(Unknown Source)
    Seems a little strange.
     
Thread Status:
Not open for further replies.

Share This Page