summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorFearThe137 <admin@fearthe1337.com>2014-12-06 22:45:51 +0100
committermd_5 <git@md-5.net>2014-12-24 09:11:25 +1100
commit2db3ea29a650c045fdaf155d636dbd77a07fa21f (patch)
tree5d1a585e9de82baefa1657b2215a92dbc4b5fb6e /src/main/java
parent81ab957aa53278e8642b0b30ec6aacc9d42fcd4e (diff)
downloadcraftbukkit-2db3ea29a650c045fdaf155d636dbd77a07fa21f.tar
craftbukkit-2db3ea29a650c045fdaf155d636dbd77a07fa21f.tar.gz
craftbukkit-2db3ea29a650c045fdaf155d636dbd77a07fa21f.tar.lz
craftbukkit-2db3ea29a650c045fdaf155d636dbd77a07fa21f.tar.xz
craftbukkit-2db3ea29a650c045fdaf155d636dbd77a07fa21f.zip
Implement Rabbit types.
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftRabbit.java67
1 files changed, 66 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftRabbit.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftRabbit.java
index 62fc7ef2..f3a28ddd 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 {
@@ -12,12 +15,74 @@ public class CraftRabbit extends CraftAnimals implements Rabbit {
}
@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()];
+ }
+ }
}