From 2db3ea29a650c045fdaf155d636dbd77a07fa21f Mon Sep 17 00:00:00 2001 From: FearThe137 Date: Sat, 6 Dec 2014 22:45:51 +0100 Subject: [PATCH] Implement Rabbit types. --- nms-patches/EntityInsentient.patch | 17 ++++- nms-patches/EntityRabbit.patch | 25 +++++++ .../craftbukkit/entity/CraftRabbit.java | 67 ++++++++++++++++++- 3 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 nms-patches/EntityRabbit.patch diff --git a/nms-patches/EntityInsentient.patch b/nms-patches/EntityInsentient.patch index 1672b0e458..36f6f715b0 100644 --- a/nms-patches/EntityInsentient.patch +++ b/nms-patches/EntityInsentient.patch @@ -1,5 +1,5 @@ ---- ../work/decompile-8eb82bde//net/minecraft/server/EntityInsentient.java 2014-11-28 17:43:43.105707435 +0000 -+++ src/main/java/net/minecraft/server/EntityInsentient.java 2014-11-28 17:38:23.000000000 +0000 +--- ../work/decompile-8eb82bde//net/minecraft/server/EntityInsentient.java Sat Dec 6 21:48:11 2014 ++++ src/main/java/net/minecraft/server/EntityInsentient.java Sat Dec 6 21:18:38 2014 @@ -4,6 +4,15 @@ import java.util.List; import java.util.UUID; @@ -16,6 +16,17 @@ public abstract class EntityInsentient extends EntityLiving { public int a_; +@@ -13,8 +22,8 @@ + protected ControllerJump g; + private EntityAIBodyControl b; + protected NavigationAbstract navigation; +- protected final PathfinderGoalSelector goalSelector; +- protected final PathfinderGoalSelector targetSelector; ++ public PathfinderGoalSelector goalSelector; // PAIL protected final to public ++ public PathfinderGoalSelector targetSelector; // PAIL protected final to public + private EntityLiving goalTarget; + private EntitySenses bi; + private ItemStack[] equipment = new ItemStack[5]; @@ -39,7 +48,9 @@ for (int i = 0; i < this.dropChances.length; ++i) { this.dropChances[i] = 0.085F; @@ -161,4 +172,4 @@ + this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit this.unleash(false, true); } - } + } \ No newline at end of file diff --git a/nms-patches/EntityRabbit.patch b/nms-patches/EntityRabbit.patch new file mode 100644 index 0000000000..278933755c --- /dev/null +++ b/nms-patches/EntityRabbit.patch @@ -0,0 +1,25 @@ +--- ../work/decompile-8eb82bde//net/minecraft/server/EntityRabbit.java Sat Dec 6 21:44:10 2014 ++++ src/main/java/net/minecraft/server/EntityRabbit.java Sat Dec 6 21:33:23 2014 +@@ -21,6 +21,12 @@ + this.g = new ControllerJumpRabbit(this, this); + this.moveController = new ControllerMoveRabbit(this); + ((Navigation) this.getNavigation()).a(true); ++ this.initializePathFinderGoals(); // CraftBukkit - moved code ++ this.b(0.0D); ++ } ++ ++ // CraftBukkit start - code from constructor ++ public void initializePathFinderGoals(){ + this.navigation.a(2.5F); + this.goalSelector.a(1, new PathfinderGoalFloat(this)); + this.goalSelector.a(1, new PathfinderGoalRabbitPanic(this, 1.33D)); +@@ -31,8 +37,8 @@ + this.goalSelector.a(11, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 10.0F)); + this.bk = new PathfinderGoalRabbitAvoidTarget(this, new EntitySelectorRabbitWolf(this), 16.0F, 1.33D, 1.33D); + this.goalSelector.a(4, this.bk); +- this.b(0.0D); + } ++ // CraftBukkit end + + protected float bD() { + return this.moveController.a() && this.moveController.e() > this.locY + 0.5D ? 0.5F : this.br.b(); \ No newline at end of file diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftRabbit.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftRabbit.java index 62fc7ef24b..f3a28dddb7 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftRabbit.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftRabbit.java @@ -1,9 +1,12 @@ package org.bukkit.craftbukkit.entity; +import net.minecraft.server.World; import net.minecraft.server.EntityRabbit; +import net.minecraft.server.PathfinderGoalSelector; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.EntityType; import org.bukkit.entity.Rabbit; +import org.bukkit.craftbukkit.CraftWorld; public class CraftRabbit extends CraftAnimals implements Rabbit { @@ -11,13 +14,75 @@ public class CraftRabbit extends CraftAnimals implements Rabbit { super(server, entity); } + @Override + public EntityRabbit getHandle() { + return (EntityRabbit) entity; + } + @Override public String toString() { - return "CraftRabbit"; + return "CraftRabbit{RabbitType=" + getRabbitType() + "}"; } @Override public EntityType getType() { return EntityType.RABBIT; } + + @Override + public Type getRabbitType() { + int type = getHandle().cl(); + return CraftMagicMapping.fromMagic(type); + } + + @Override + public void setRabbitType(Type type) { + EntityRabbit entity = getHandle(); + if (getRabbitType() == Type.THE_KILLER_BUNNY) { + // Reset goals and target finders. + World world = ((CraftWorld) this.getWorld()).getHandle(); + entity.goalSelector = new PathfinderGoalSelector(world != null && world.methodProfiler != null ? world.methodProfiler : null); + entity.targetSelector = new PathfinderGoalSelector(world != null && world.methodProfiler != null ? world.methodProfiler : null); + entity.initializePathFinderGoals(); + } + + entity.r(CraftMagicMapping.toMagic(type)); // PAIL: Rename + } + + private static class CraftMagicMapping { + + private static final int[] types = new int[Type.values().length]; + private static final Type[] reverse = new Type[Type.values().length]; + + static { + set(Type.BROWN, 0); + set(Type.WHITE, 1); + set(Type.BLACK, 2); + set(Type.BLACK_AND_WHITE, 3); + set(Type.GOLD, 4); + set(Type.SALT_AND_PEPPER, 5); + set(Type.THE_KILLER_BUNNY, 99); + } + + private static void set(Type type, int value) { + types[type.ordinal()] = value; + if (value < reverse.length) { + reverse[value] = type; + } + } + + public static Type fromMagic(int magic) { + if (magic > 0 && magic < reverse.length) { + return reverse[magic]; + } else if (magic == 99) { + return Type.THE_KILLER_BUNNY; + } else { + return null; + } + } + + public static int toMagic(Type type) { + return types[type.ordinal()]; + } + } }