779 lines
26 KiB
Java
Raw Normal View History

2015-07-26 16:51:12 +02:00
package com.plotsquared.bukkit.object.entity;
2015-02-10 03:21:59 +11:00
2015-07-31 00:25:16 +10:00
import org.bukkit.Art;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Rotation;
import org.bukkit.World;
2015-02-10 03:21:59 +11:00
import org.bukkit.block.BlockFace;
2015-07-31 00:25:16 +10:00
import org.bukkit.entity.Ageable;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Guardian;
import org.bukkit.entity.Horse;
2015-02-10 03:21:59 +11:00
import org.bukkit.entity.Horse.Color;
import org.bukkit.entity.Horse.Style;
import org.bukkit.entity.Horse.Variant;
2015-07-31 00:25:16 +10:00
import org.bukkit.entity.Item;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Painting;
import org.bukkit.entity.Rabbit;
2015-02-15 18:40:55 +11:00
import org.bukkit.entity.Rabbit.Type;
2015-07-31 00:25:16 +10:00
import org.bukkit.entity.Sheep;
import org.bukkit.entity.Skeleton;
2015-02-15 18:40:55 +11:00
import org.bukkit.entity.Skeleton.SkeletonType;
2015-07-31 00:25:16 +10:00
import org.bukkit.entity.Tameable;
2015-02-10 03:21:59 +11:00
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
2015-04-17 16:39:45 +10:00
import org.bukkit.util.EulerAngle;
2015-02-10 03:21:59 +11:00
import org.bukkit.util.Vector;
2015-07-31 00:25:16 +10:00
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.entity.AgeableStats;
import com.intellectualcrafters.plot.object.entity.ArmorStandStats;
import com.intellectualcrafters.plot.object.entity.EntityBaseStats;
import com.intellectualcrafters.plot.object.entity.HorseStats;
2015-09-11 20:09:22 +10:00
public class EntityWrapper
{
2015-02-10 03:21:59 +11:00
public short id;
public float yaw;
public float pitch;
public double x;
public double y;
public double z;
public short depth;
public EntityBaseStats base = null;
// Extended
public ItemStack stack;
public ItemStack[] inventory;
public byte dataByte;
public byte dataByte2;
public String dataString;
public LivingEntityStats lived;
public AgeableStats aged;
public TameableStats tamed;
private HorseStats horse;
2015-04-17 16:39:45 +10:00
private ArmorStandStats stand;
2015-02-23 12:32:27 +11:00
private int hash;
2015-09-11 20:09:22 +10:00
@Override
2015-09-11 20:09:22 +10:00
public boolean equals(final Object obj)
{
return hash == obj.hashCode();
}
2015-09-11 20:09:22 +10:00
@Override
2015-09-11 20:09:22 +10:00
public int hashCode()
{
return hash;
}
2015-09-11 20:09:22 +10:00
public void storeInventory(final InventoryHolder held)
{
inventory = held.getInventory().getContents().clone();
2015-02-10 03:21:59 +11:00
}
2015-02-23 12:32:27 +11:00
2015-09-11 20:09:22 +10:00
private void restoreLiving(final LivingEntity entity)
{
if (lived.loot)
{
entity.setCanPickupItems(lived.loot);
2015-02-10 03:21:59 +11:00
}
2015-09-11 20:09:22 +10:00
if (lived.name != null)
{
entity.setCustomName(lived.name);
entity.setCustomNameVisible(lived.visible);
2015-02-10 03:21:59 +11:00
}
2015-09-11 20:09:22 +10:00
if ((lived.potions != null) && (lived.potions.size() > 0))
{
entity.addPotionEffects(lived.potions);
2015-02-12 15:53:49 +11:00
}
2015-09-11 20:09:22 +10:00
entity.setRemainingAir(lived.air);
entity.setRemoveWhenFarAway(lived.persistent);
if (lived.equipped)
{
2015-02-20 17:34:19 +11:00
final EntityEquipment equipment = entity.getEquipment();
2015-09-11 20:09:22 +10:00
equipment.setItemInHand(lived.hands);
equipment.setHelmet(lived.helmet);
equipment.setChestplate(lived.chestplate);
equipment.setLeggings(lived.leggings);
equipment.setBoots(lived.boots);
2015-02-10 03:21:59 +11:00
}
2015-09-11 20:09:22 +10:00
if (lived.leashed)
{
2015-02-10 03:21:59 +11:00
// TODO leashes
2015-02-20 17:34:19 +11:00
// World world = entity.getWorld();
// Entity leash = world.spawnEntity(new Location(world, Math.floor(x) + lived.leash_x, Math.floor(y) + lived.leash_y, Math.floor(z) + lived.leash_z), EntityType.LEASH_HITCH);
// entity.setLeashHolder(leash);
2015-02-10 03:21:59 +11:00
}
}
2015-02-23 12:32:27 +11:00
2015-09-11 20:09:22 +10:00
private void restoreInventory(final InventoryHolder entity)
{
entity.getInventory().setContents(inventory);
2015-02-10 03:21:59 +11:00
}
2015-02-23 12:32:27 +11:00
2015-09-11 20:09:22 +10:00
public void storeLiving(final LivingEntity lived)
{
2015-02-10 03:21:59 +11:00
this.lived = new LivingEntityStats();
2015-02-12 15:53:49 +11:00
this.lived.potions = lived.getActivePotionEffects();
2015-02-10 03:21:59 +11:00
this.lived.loot = lived.getCanPickupItems();
this.lived.name = lived.getCustomName();
this.lived.visible = lived.isCustomNameVisible();
this.lived.health = (float) lived.getHealth();
this.lived.air = (short) lived.getRemainingAir();
this.lived.persistent = lived.getRemoveWhenFarAway();
this.lived.leashed = lived.isLeashed();
2015-09-11 20:09:22 +10:00
if (this.lived.leashed)
{
2015-02-10 03:21:59 +11:00
final Location loc = lived.getLeashHolder().getLocation();
2015-09-11 20:09:22 +10:00
this.lived.leash_x = (short) (x - loc.getBlockX());
this.lived.leash_y = (short) (y - loc.getBlockY());
this.lived.leash_z = (short) (z - loc.getBlockZ());
2015-02-10 03:21:59 +11:00
}
final EntityEquipment equipment = lived.getEquipment();
this.lived.equipped = equipment != null;
2015-09-11 20:09:22 +10:00
if (this.lived.equipped)
{
2015-02-10 03:21:59 +11:00
this.lived.hands = equipment.getItemInHand().clone();
this.lived.boots = equipment.getBoots().clone();
this.lived.leggings = equipment.getLeggings().clone();
this.lived.chestplate = equipment.getChestplate().clone();
this.lived.helmet = equipment.getHelmet().clone();
}
}
2015-02-23 12:32:27 +11:00
2015-09-11 20:09:22 +10:00
private void restoreTameable(final Tameable entity)
{
if (tamed.tamed)
{
if (tamed.owner != null)
{
2015-02-10 03:21:59 +11:00
entity.setTamed(true);
2015-09-11 20:09:22 +10:00
entity.setOwner(tamed.owner);
2015-02-10 03:21:59 +11:00
}
}
}
2015-02-23 12:32:27 +11:00
2015-09-11 20:09:22 +10:00
private void restoreAgeable(final Ageable entity)
{
if (!aged.adult)
{
2015-02-10 03:21:59 +11:00
entity.setBaby();
}
2015-09-11 20:09:22 +10:00
if (aged.locked)
{
entity.setAgeLock(aged.locked);
2015-02-10 03:21:59 +11:00
}
2015-09-11 20:09:22 +10:00
if (aged.age > 0)
{
entity.setAge(aged.age);
2015-07-31 20:47:10 +10:00
}
2015-02-10 03:21:59 +11:00
}
2015-02-23 12:32:27 +11:00
2015-09-11 20:09:22 +10:00
public void storeAgeable(final Ageable aged)
{
2015-02-10 03:21:59 +11:00
this.aged = new AgeableStats();
this.aged.age = aged.getAge();
this.aged.locked = aged.getAgeLock();
this.aged.adult = aged.isAdult();
}
2015-02-23 12:32:27 +11:00
2015-09-11 20:09:22 +10:00
public void storeTameable(final Tameable tamed)
{
2015-02-10 03:21:59 +11:00
this.tamed = new TameableStats();
this.tamed.owner = tamed.getOwner();
this.tamed.tamed = tamed.isTamed();
}
2015-02-23 12:32:27 +11:00
2015-02-10 03:21:59 +11:00
@SuppressWarnings("deprecation")
2015-09-11 20:09:22 +10:00
public EntityWrapper(final org.bukkit.entity.Entity entity, final short depth)
{
hash = entity.getEntityId();
2015-02-10 03:21:59 +11:00
this.depth = depth;
final Location loc = entity.getLocation();
2015-09-11 20:09:22 +10:00
yaw = loc.getYaw();
pitch = loc.getPitch();
x = loc.getX();
y = loc.getY();
z = loc.getZ();
id = entity.getType().getTypeId();
if (depth == 0) { return; }
base = new EntityBaseStats();
2015-02-10 03:21:59 +11:00
final Entity p = entity.getPassenger();
2015-09-11 20:09:22 +10:00
if (p != null)
{
base.passenger = new EntityWrapper(p, depth);
2015-02-10 03:21:59 +11:00
}
2015-09-11 20:09:22 +10:00
base.fall = entity.getFallDistance();
base.fire = (short) entity.getFireTicks();
base.age = entity.getTicksLived();
2015-02-10 03:21:59 +11:00
final Vector velocity = entity.getVelocity();
2015-09-11 20:09:22 +10:00
base.v_x = velocity.getX();
base.v_y = velocity.getY();
base.v_z = velocity.getZ();
if (depth == 1) { return; }
switch (entity.getType())
{
2015-02-10 03:21:59 +11:00
case ARROW:
case BOAT:
case COMPLEX_PART:
case EGG:
case ENDER_CRYSTAL:
case ENDER_PEARL:
case ENDER_SIGNAL:
case EXPERIENCE_ORB:
case FALLING_BLOCK:
case FIREBALL:
case FIREWORK:
case FISHING_HOOK:
case LEASH_HITCH:
case LIGHTNING:
case MINECART:
case MINECART_COMMAND:
case MINECART_MOB_SPAWNER:
case MINECART_TNT:
case PLAYER:
case PRIMED_TNT:
case SLIME:
case SMALL_FIREBALL:
case SNOWBALL:
case MINECART_FURNACE:
case SPLASH_POTION:
case THROWN_EXP_BOTTLE:
case WEATHER:
case WITHER_SKULL:
2015-09-11 20:09:22 +10:00
case UNKNOWN:
{
2015-02-10 03:21:59 +11:00
// Do this stuff later
return;
}
2015-09-11 20:09:22 +10:00
default:
{
2015-07-31 00:25:16 +10:00
PS.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
2015-02-10 03:21:59 +11:00
return;
}
// MISC //
2015-09-11 20:09:22 +10:00
case DROPPED_ITEM:
{
2015-02-10 03:21:59 +11:00
final Item item = (Item) entity;
2015-09-11 20:09:22 +10:00
stack = item.getItemStack();
2015-02-10 03:21:59 +11:00
return;
}
2015-09-11 20:09:22 +10:00
case ITEM_FRAME:
{
2015-02-10 03:21:59 +11:00
final ItemFrame itemframe = (ItemFrame) entity;
2015-09-11 20:09:22 +10:00
x = Math.floor(x);
y = Math.floor(y);
z = Math.floor(z);
dataByte = getOrdinal(Rotation.values(), itemframe.getRotation());
stack = itemframe.getItem().clone();
2015-02-10 03:21:59 +11:00
return;
}
2015-09-11 20:09:22 +10:00
case PAINTING:
{
2015-02-10 03:21:59 +11:00
final Painting painting = (Painting) entity;
2015-09-11 20:09:22 +10:00
x = Math.floor(x);
y = Math.floor(y);
z = Math.floor(z);
2015-02-10 03:21:59 +11:00
final Art a = painting.getArt();
2015-09-11 20:09:22 +10:00
dataByte = getOrdinal(BlockFace.values(), painting.getFacing());
2015-02-20 17:34:19 +11:00
final int h = a.getBlockHeight();
2015-09-11 20:09:22 +10:00
if ((h % 2) == 0)
{
y -= 1;
2015-02-10 03:21:59 +11:00
}
2015-09-11 20:09:22 +10:00
dataString = a.name();
2015-02-10 03:21:59 +11:00
return;
}
// END MISC //
// INVENTORY HOLDER //
2015-09-11 20:09:22 +10:00
case MINECART_CHEST:
{
2015-02-10 03:21:59 +11:00
storeInventory((InventoryHolder) entity);
return;
}
2015-09-11 20:09:22 +10:00
case MINECART_HOPPER:
{
2015-02-10 03:21:59 +11:00
storeInventory((InventoryHolder) entity);
return;
}
// START LIVING ENTITY //
// START AGEABLE //
// START TAMEABLE //
2015-09-11 20:09:22 +10:00
case HORSE:
{
2015-02-10 03:21:59 +11:00
final Horse horse = (Horse) entity;
this.horse = new HorseStats();
this.horse.jump = horse.getJumpStrength();
this.horse.chest = horse.isCarryingChest();
this.horse.variant = getOrdinal(Variant.values(), horse.getVariant());
this.horse.style = getOrdinal(Style.values(), horse.getStyle());
this.horse.color = getOrdinal(Color.values(), horse.getColor());
storeTameable((Tameable) entity);
storeAgeable((Ageable) entity);
storeLiving((LivingEntity) entity);
storeInventory((InventoryHolder) entity);
return;
}
// END INVENTORY HOLDER //
case WOLF:
2015-09-11 20:09:22 +10:00
case OCELOT:
{
2015-02-10 03:21:59 +11:00
storeTameable((Tameable) entity);
storeAgeable((Ageable) entity);
storeLiving((LivingEntity) entity);
return;
}
// END AMEABLE //
2015-09-11 20:09:22 +10:00
case SHEEP:
{
2015-02-10 03:21:59 +11:00
final Sheep sheep = (Sheep) entity;
2015-09-11 20:09:22 +10:00
dataByte = (byte) ((sheep).isSheared() ? 1 : 0);
dataByte2 = sheep.getColor().getDyeData();
2015-02-10 03:21:59 +11:00
storeAgeable((Ageable) entity);
storeLiving((LivingEntity) entity);
return;
}
case VILLAGER:
case CHICKEN:
case COW:
case MUSHROOM_COW:
2015-09-11 20:09:22 +10:00
case PIG:
{
2015-02-10 03:21:59 +11:00
storeAgeable((Ageable) entity);
storeLiving((LivingEntity) entity);
return;
}
// END AGEABLE //
2015-09-11 20:09:22 +10:00
case RABBIT:
{ // NEW
dataByte = getOrdinal(Type.values(), ((Rabbit) entity).getRabbitType());
2015-02-10 03:21:59 +11:00
storeAgeable((Ageable) entity);
storeLiving((LivingEntity) entity);
return;
}
2015-09-11 20:09:22 +10:00
case GUARDIAN:
{ // NEW
dataByte = (byte) (((Guardian) entity).isElder() ? 1 : 0);
2015-02-10 03:21:59 +11:00
storeLiving((LivingEntity) entity);
return;
}
2015-09-11 20:09:22 +10:00
case SKELETON:
{ // NEW
dataByte = (byte) ((Skeleton) entity).getSkeletonType().getId();
2015-02-10 03:21:59 +11:00
storeLiving((LivingEntity) entity);
return;
}
2015-09-11 20:09:22 +10:00
case ARMOR_STAND:
{ // NEW
// CHECK positions
2015-02-10 03:21:59 +11:00
final ArmorStand stand = (ArmorStand) entity;
2015-09-11 20:09:22 +10:00
inventory = new ItemStack[] { stand.getItemInHand().clone(), stand.getHelmet().clone(), stand.getChestplate().clone(), stand.getLeggings().clone(), stand.getBoots().clone() };
2015-02-10 03:21:59 +11:00
storeLiving((LivingEntity) entity);
2015-04-17 16:39:45 +10:00
this.stand = new ArmorStandStats();
2015-09-11 20:09:22 +10:00
final EulerAngle head = stand.getHeadPose();
2015-04-17 16:39:45 +10:00
this.stand.head[0] = (float) head.getX();
this.stand.head[1] = (float) head.getY();
this.stand.head[2] = (float) head.getZ();
2015-09-11 20:09:22 +10:00
final EulerAngle body = stand.getBodyPose();
2015-04-17 16:39:45 +10:00
this.stand.body[0] = (float) body.getX();
this.stand.body[1] = (float) body.getY();
this.stand.body[2] = (float) body.getZ();
2015-09-11 20:09:22 +10:00
final EulerAngle leftLeg = stand.getLeftLegPose();
2015-04-17 16:39:45 +10:00
this.stand.leftLeg[0] = (float) leftLeg.getX();
this.stand.leftLeg[1] = (float) leftLeg.getY();
this.stand.leftLeg[2] = (float) leftLeg.getZ();
2015-09-11 20:09:22 +10:00
final EulerAngle rightLeg = stand.getRightLegPose();
2015-04-17 16:39:45 +10:00
this.stand.rightLeg[0] = (float) rightLeg.getX();
this.stand.rightLeg[1] = (float) rightLeg.getY();
this.stand.rightLeg[2] = (float) rightLeg.getZ();
2015-09-11 20:09:22 +10:00
final EulerAngle leftArm = stand.getLeftArmPose();
2015-04-17 16:39:45 +10:00
this.stand.leftArm[0] = (float) leftArm.getX();
this.stand.leftArm[1] = (float) leftArm.getY();
this.stand.leftArm[2] = (float) leftArm.getZ();
2015-09-11 20:09:22 +10:00
final EulerAngle rightArm = stand.getRightArmPose();
2015-04-17 16:39:45 +10:00
this.stand.rightArm[0] = (float) rightArm.getX();
this.stand.rightArm[1] = (float) rightArm.getY();
this.stand.rightArm[2] = (float) rightArm.getZ();
2015-09-11 20:09:22 +10:00
if (stand.hasArms())
{
2015-04-17 16:41:41 +10:00
this.stand.arms = true;
2015-04-17 16:39:45 +10:00
}
2015-09-11 20:09:22 +10:00
if (!stand.hasBasePlate())
{
2015-04-17 16:39:45 +10:00
this.stand.noplate = true;
}
2015-09-11 20:09:22 +10:00
if (!stand.hasGravity())
{
2015-04-17 16:39:45 +10:00
this.stand.nogravity = true;
}
2015-09-11 20:09:22 +10:00
if (!stand.isVisible())
{
2015-04-17 16:39:45 +10:00
this.stand.invisible = true;
}
2015-09-11 20:09:22 +10:00
if (stand.isSmall())
{
2015-04-17 16:39:45 +10:00
this.stand.small = true;
}
2015-02-10 03:21:59 +11:00
return;
}
case ENDERMITE: // NEW
case BAT:
case ENDER_DRAGON:
case GHAST:
case MAGMA_CUBE:
case SQUID:
case PIG_ZOMBIE:
case ZOMBIE:
case WITHER:
case WITCH:
case SPIDER:
case CAVE_SPIDER:
case SILVERFISH:
case GIANT:
case ENDERMAN:
case CREEPER:
case BLAZE:
case SNOWMAN:
2015-09-11 20:09:22 +10:00
case IRON_GOLEM:
{
2015-02-10 03:21:59 +11:00
storeLiving((LivingEntity) entity);
return;
}
// END LIVING //
}
}
2015-02-23 12:32:27 +11:00
2015-02-10 03:21:59 +11:00
@SuppressWarnings("deprecation")
2015-09-11 20:09:22 +10:00
public Entity spawn(final World world, final int x_offset, final int z_offset)
{
final Location loc = new Location(world, x + x_offset, y, z + z_offset);
loc.setYaw(yaw);
loc.setPitch(pitch);
if (id == -1) { return null; }
final EntityType type = EntityType.fromId(id);
2015-02-15 18:40:55 +11:00
Entity entity;
2015-09-11 20:09:22 +10:00
switch (type)
{
case DROPPED_ITEM:
{
return world.dropItem(loc, stack);
2015-02-15 18:40:55 +11:00
}
case PLAYER:
2015-09-11 20:09:22 +10:00
case LEASH_HITCH:
{
2015-02-15 18:40:55 +11:00
return null;
}
2015-09-11 20:09:22 +10:00
case ITEM_FRAME:
{
entity = world.spawn(loc, ItemFrame.class);
break;
}
2015-09-11 20:09:22 +10:00
case PAINTING:
{
entity = world.spawn(loc, Painting.class);
break;
}
2015-02-15 18:40:55 +11:00
default:
entity = world.spawnEntity(loc, type);
break;
}
2015-09-11 20:09:22 +10:00
if (depth == 0) { return entity; }
if (base.passenger != null)
{
try
{
entity.setPassenger(base.passenger.spawn(world, x_offset, z_offset));
}
catch (final Exception e)
{}
2015-02-10 03:21:59 +11:00
}
2015-09-11 20:09:22 +10:00
if (base.fall != 0)
{
entity.setFallDistance(base.fall);
}
if (base.fire != 0)
{
entity.setFireTicks(base.fire);
2015-02-10 03:21:59 +11:00
}
2015-09-11 20:09:22 +10:00
if (base.age != 0)
{
entity.setTicksLived(base.age);
2015-02-10 03:21:59 +11:00
}
2015-09-11 20:09:22 +10:00
entity.setVelocity(new Vector(base.v_x, base.v_y, base.v_z));
if (depth == 1) { return entity; }
switch (entity.getType())
{
2015-02-10 03:21:59 +11:00
case ARROW:
case BOAT:
case COMPLEX_PART:
case EGG:
case ENDER_CRYSTAL:
case ENDER_PEARL:
case ENDER_SIGNAL:
case EXPERIENCE_ORB:
case FALLING_BLOCK:
case FIREBALL:
case FIREWORK:
case FISHING_HOOK:
case LEASH_HITCH:
case LIGHTNING:
case MINECART:
case MINECART_COMMAND:
case MINECART_MOB_SPAWNER:
case MINECART_TNT:
case PLAYER:
case PRIMED_TNT:
case SLIME:
case SMALL_FIREBALL:
case SNOWBALL:
case SPLASH_POTION:
case THROWN_EXP_BOTTLE:
case WEATHER:
case WITHER_SKULL:
case MINECART_FURNACE:
2015-09-11 20:09:22 +10:00
case UNKNOWN:
{
2015-02-10 03:21:59 +11:00
// Do this stuff later
return entity;
}
2015-09-11 20:09:22 +10:00
default:
{
2015-07-31 00:25:16 +10:00
PS.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
2015-02-10 03:21:59 +11:00
return entity;
}
// MISC //
2015-09-11 20:09:22 +10:00
case ITEM_FRAME:
{
2015-02-10 03:21:59 +11:00
final ItemFrame itemframe = (ItemFrame) entity;
2015-09-11 20:09:22 +10:00
itemframe.setRotation(Rotation.values()[dataByte]);
itemframe.setItem(stack);
2015-02-10 03:21:59 +11:00
return entity;
}
2015-09-11 20:09:22 +10:00
case PAINTING:
{
2015-02-10 03:21:59 +11:00
final Painting painting = (Painting) entity;
2015-09-11 20:09:22 +10:00
painting.setFacingDirection(BlockFace.values()[dataByte], true);
painting.setArt(Art.getByName(dataString), true);
2015-02-10 03:21:59 +11:00
return entity;
}
// END MISC //
// INVENTORY HOLDER //
2015-09-11 20:09:22 +10:00
case MINECART_CHEST:
{
2015-02-10 03:21:59 +11:00
restoreInventory((InventoryHolder) entity);
return entity;
}
2015-09-11 20:09:22 +10:00
case MINECART_HOPPER:
{
2015-02-10 03:21:59 +11:00
restoreInventory((InventoryHolder) entity);
return entity;
}
// START LIVING ENTITY //
// START AGEABLE //
// START TAMEABLE //
2015-09-11 20:09:22 +10:00
case HORSE:
{
2015-02-10 03:21:59 +11:00
final Horse horse = (Horse) entity;
horse.setJumpStrength(this.horse.jump);
horse.setCarryingChest(this.horse.chest);
horse.setVariant(Variant.values()[this.horse.variant]);
horse.setStyle(Style.values()[this.horse.style]);
horse.setColor(Color.values()[this.horse.color]);
restoreTameable((Tameable) entity);
restoreAgeable((Ageable) entity);
restoreLiving((LivingEntity) entity);
restoreInventory((InventoryHolder) entity);
return entity;
}
// END INVENTORY HOLDER //
case WOLF:
2015-09-11 20:09:22 +10:00
case OCELOT:
{
2015-02-10 03:21:59 +11:00
restoreTameable((Tameable) entity);
restoreAgeable((Ageable) entity);
restoreLiving((LivingEntity) entity);
return entity;
}
// END AMEABLE //
2015-09-11 20:09:22 +10:00
case SHEEP:
{
2015-02-10 03:21:59 +11:00
final Sheep sheep = (Sheep) entity;
2015-09-11 20:09:22 +10:00
if (dataByte == 1)
{
2015-02-10 03:21:59 +11:00
sheep.setSheared(true);
}
2015-09-11 20:09:22 +10:00
if (dataByte2 != 0)
{
sheep.setColor(DyeColor.getByDyeData(dataByte2));
2015-02-10 03:21:59 +11:00
}
restoreAgeable((Ageable) entity);
restoreLiving((LivingEntity) entity);
return entity;
}
case VILLAGER:
case CHICKEN:
case COW:
case MUSHROOM_COW:
2015-09-11 20:09:22 +10:00
case PIG:
{
2015-02-10 03:21:59 +11:00
restoreAgeable((Ageable) entity);
restoreLiving((LivingEntity) entity);
return entity;
}
// END AGEABLE //
2015-09-11 20:09:22 +10:00
case RABBIT:
{ // NEW
if (dataByte != 0)
{
((Rabbit) entity).setRabbitType(Type.values()[dataByte]);
2015-02-10 03:21:59 +11:00
}
restoreAgeable((Ageable) entity);
restoreLiving((LivingEntity) entity);
return entity;
}
2015-09-11 20:09:22 +10:00
case GUARDIAN:
{ // NEW
if (dataByte != 0)
{
2015-02-10 03:21:59 +11:00
((Guardian) entity).setElder(true);
}
restoreLiving((LivingEntity) entity);
return entity;
}
2015-09-11 20:09:22 +10:00
case SKELETON:
{ // NEW
if (dataByte != 0)
{
((Skeleton) entity).setSkeletonType(SkeletonType.values()[dataByte]);
2015-02-10 03:21:59 +11:00
}
storeLiving((LivingEntity) entity);
return entity;
}
2015-09-11 20:09:22 +10:00
case ARMOR_STAND:
{ // NEW
// CHECK positions
2015-02-10 03:21:59 +11:00
final ArmorStand stand = (ArmorStand) entity;
2015-09-11 20:09:22 +10:00
if (inventory[0] != null)
{
stand.setItemInHand(inventory[0]);
2015-02-10 03:21:59 +11:00
}
2015-09-11 20:09:22 +10:00
if (inventory[1] != null)
{
stand.setHelmet(inventory[1]);
2015-02-10 03:21:59 +11:00
}
2015-09-11 20:09:22 +10:00
if (inventory[2] != null)
{
stand.setChestplate(inventory[2]);
2015-02-10 03:21:59 +11:00
}
2015-09-11 20:09:22 +10:00
if (inventory[3] != null)
{
stand.setLeggings(inventory[3]);
2015-02-10 03:21:59 +11:00
}
2015-09-11 20:09:22 +10:00
if (inventory[4] != null)
{
stand.setBoots(inventory[4]);
2015-02-10 03:21:59 +11:00
}
2015-09-11 20:09:22 +10:00
if ((this.stand.head[0] != 0) || (this.stand.head[1] != 0) || (this.stand.head[2] != 0))
{
final EulerAngle pose = new EulerAngle(this.stand.head[0], this.stand.head[1], this.stand.head[2]);
2015-04-17 16:39:45 +10:00
stand.setHeadPose(pose);
}
2015-09-11 20:09:22 +10:00
if ((this.stand.body[0] != 0) || (this.stand.body[1] != 0) || (this.stand.body[2] != 0))
{
final EulerAngle pose = new EulerAngle(this.stand.body[0], this.stand.body[1], this.stand.body[2]);
2015-04-17 16:39:45 +10:00
stand.setBodyPose(pose);
}
2015-09-11 20:09:22 +10:00
if ((this.stand.leftLeg[0] != 0) || (this.stand.leftLeg[1] != 0) || (this.stand.leftLeg[2] != 0))
{
final EulerAngle pose = new EulerAngle(this.stand.leftLeg[0], this.stand.leftLeg[1], this.stand.leftLeg[2]);
2015-04-17 16:39:45 +10:00
stand.setLeftLegPose(pose);
}
2015-09-11 20:09:22 +10:00
if ((this.stand.rightLeg[0] != 0) || (this.stand.rightLeg[1] != 0) || (this.stand.rightLeg[2] != 0))
{
final EulerAngle pose = new EulerAngle(this.stand.rightLeg[0], this.stand.rightLeg[1], this.stand.rightLeg[2]);
2015-04-17 16:39:45 +10:00
stand.setRightLegPose(pose);
}
2015-09-11 20:09:22 +10:00
if ((this.stand.leftArm[0] != 0) || (this.stand.leftArm[1] != 0) || (this.stand.leftArm[2] != 0))
{
final EulerAngle pose = new EulerAngle(this.stand.leftArm[0], this.stand.leftArm[1], this.stand.leftArm[2]);
2015-04-17 16:39:45 +10:00
stand.setLeftArmPose(pose);
}
2015-09-11 20:09:22 +10:00
if ((this.stand.rightArm[0] != 0) || (this.stand.rightArm[1] != 0) || (this.stand.rightArm[2] != 0))
{
final EulerAngle pose = new EulerAngle(this.stand.rightArm[0], this.stand.rightArm[1], this.stand.rightArm[2]);
2015-04-17 16:39:45 +10:00
stand.setRightArmPose(pose);
}
2015-09-11 20:09:22 +10:00
if (this.stand.invisible)
{
2015-04-17 16:39:45 +10:00
stand.setVisible(false);
}
2015-09-11 20:09:22 +10:00
if (this.stand.arms)
{
2015-04-17 16:41:41 +10:00
stand.setArms(true);
2015-04-17 16:39:45 +10:00
}
2015-09-11 20:09:22 +10:00
if (this.stand.nogravity)
{
2015-04-17 16:39:45 +10:00
stand.setGravity(false);
}
2015-09-11 20:09:22 +10:00
if (this.stand.noplate)
{
2015-04-17 16:39:45 +10:00
stand.setBasePlate(false);
}
2015-09-11 20:09:22 +10:00
if (this.stand.small)
{
2015-04-17 16:39:45 +10:00
stand.setSmall(true);
}
2015-02-10 03:21:59 +11:00
restoreLiving((LivingEntity) entity);
return entity;
}
case ENDERMITE: // NEW
case BAT:
case ENDER_DRAGON:
case GHAST:
case MAGMA_CUBE:
case SQUID:
case PIG_ZOMBIE:
case ZOMBIE:
case WITHER:
case WITCH:
case SPIDER:
case CAVE_SPIDER:
case SILVERFISH:
case GIANT:
case ENDERMAN:
case CREEPER:
case BLAZE:
case SNOWMAN:
2015-09-11 20:09:22 +10:00
case IRON_GOLEM:
{
2015-02-10 03:21:59 +11:00
restoreLiving((LivingEntity) entity);
return entity;
}
// END LIVING //
}
}
2015-02-23 12:32:27 +11:00
2015-09-11 20:09:22 +10:00
private byte getOrdinal(final Object[] list, final Object value)
{
for (byte i = 0; i < list.length; i++)
{
if (list[i].equals(value)) { return i; }
2015-02-10 03:21:59 +11:00
}
return 0;
}
}