Skip to content

Commit

Permalink
Add rabbit pet to 1.8.0 module
Browse files Browse the repository at this point in the history
  • Loading branch information
DSH105 committed May 16, 2015
1 parent ff30467 commit 26ac4a6
Showing 1 changed file with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.dsh105.echopet.compat.nms.v1_8_R1.entity.type;

import com.dsh105.echopet.compat.api.entity.*;
import com.dsh105.echopet.compat.api.entity.type.nms.IEntityRabbitPet;
import com.dsh105.echopet.compat.nms.v1_8_R1.entity.EntityAgeablePet;
import com.dsh105.echopet.compat.nms.v1_8_R1.entity.EntityPet;
import net.minecraft.server.v1_8_R1.World;
import org.bukkit.entity.Rabbit;

@EntitySize(width = 0.6F, height = 0.7F)
@EntityPetType(petType = PetType.RABBIT)
public class EntityRabbitPet extends EntityAgeablePet implements IEntityRabbitPet {

private int jumpDelay;

public EntityRabbitPet(World world) {
super(world);
}

public EntityRabbitPet(World world, IPet pet) {
super(world, pet);
this.jumpDelay = this.random.nextInt(15) + 10;
}

@Override
protected String getIdleSound() {
return "mob.rabbit.idle";
}

@Override
protected String getDeathSound() {
return "mob.rabbit.hurt";
}

@Override
public Rabbit.Type getRabbitType() {
return TypeMapping.fromMagic(this.datawatcher.getByte(18));
}

@Override
public void setRabbitType(Rabbit.Type type) {
this.datawatcher.watch(18, Byte.valueOf((byte) TypeMapping.toMagic(type)));
}

@Override
protected void initDatawatcher() {
super.initDatawatcher();
this.datawatcher.a(18, Byte.valueOf((byte)0));
}

@Override
public void onLive() {
super.onLive();
// same as the slime
if (this.onGround && this.jumpDelay-- <= 0) {
getControllerJump().a();
this.jumpDelay = this.random.nextInt(15) + 10;
this.world.broadcastEntityEffect(this, (byte) 1);
}
}

static class TypeMapping {

private static final int[] NMS_TYPES = new int[Rabbit.Type.values().length];
private static final Rabbit.Type[] INVERSE = new Rabbit.Type[Rabbit.Type.values().length];

static {
set(Rabbit.Type.BROWN, 0);
set(Rabbit.Type.WHITE, 1);
set(Rabbit.Type.BLACK, 2);
set(Rabbit.Type.BLACK_AND_WHITE, 3);
set(Rabbit.Type.GOLD, 4);
set(Rabbit.Type.SALT_AND_PEPPER, 5);
set(Rabbit.Type.THE_KILLER_BUNNY, 99);
}

private static void set(Rabbit.Type type, int magicValue) {
NMS_TYPES[type.ordinal()] = magicValue;
if (magicValue < INVERSE.length) {
INVERSE[magicValue] = type;
}
}

protected static Rabbit.Type fromMagic(int magicValue) {
if (magicValue < INVERSE.length) {
return INVERSE[magicValue];
} else if (magicValue == 99) {
return Rabbit.Type.THE_KILLER_BUNNY;
}
// a default
return Rabbit.Type.BROWN;
}

protected static int toMagic(Rabbit.Type type) {
return NMS_TYPES[type.ordinal()];
}

}
}

0 comments on commit 26ac4a6

Please sign in to comment.