Created
August 13, 2013 21:53
-
-
Save riking/6226100 to your computer and use it in GitHub Desktop.
Bukkit-only entity copier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
Entity[] sourceEntities = sourceChunk.getEntities(); | |
for (Entity oent : sourceEntities) { | |
Entity nent; | |
if (oent instanceof Arrow) { | |
nent = world.spawnArrow(oent.getLocation(), oent.getVelocity(), (float) oent.getVelocity().length(), 0F); | |
} else if (oent instanceof FallingBlock) { | |
FallingBlock o = (FallingBlock) oent; | |
nent = world.spawnFallingBlock(oent.getLocation(), o.getBlockId(), o.getBlockData()); | |
} else if (oent instanceof Item) { | |
Item o = (Item) oent; | |
nent = world.dropItem(oent.getLocation(), o.getItemStack()); | |
Item n = (Item) nent; | |
n.setPickupDelay(o.getPickupDelay()); | |
} else if (oent instanceof LightningStrike) { | |
LightningStrike o = (LightningStrike) oent; | |
if (!o.isEffect()) { | |
nent = world.strikeLightning(o.getLocation()); | |
} else { | |
nent = world.strikeLightningEffect(o.getLocation()); | |
} | |
} else { | |
try { | |
nent = world.spawnEntity(oent.getLocation(), oent.getType()); | |
} catch (IllegalArgumentException e) { | |
TemplateWorlds.getInstance().getLogger().warning("Skipping entity of type " + oent.getType() + ": Cannot instantiate via Bukkit API"); | |
continue; | |
} | |
} | |
if (nent instanceof Entity) { | |
Entity o = (Entity) oent; | |
Entity n = (Entity) nent; | |
n.setFallDistance(o.getFallDistance()); | |
n.setFireTicks(o.getFireTicks()); | |
n.setLastDamageCause(o.getLastDamageCause()); | |
//n.setPassenger(o.getPassenger()); | |
n.setTicksLived(o.getTicksLived()); | |
n.setVelocity(o.getVelocity()); | |
// TODO metadata transfer? | |
} | |
if (nent instanceof Ageable) { | |
Ageable o = (Ageable) oent; | |
Ageable n = (Ageable) nent; | |
n.setAge(o.getAge()); | |
n.setBreed(o.canBreed()); | |
n.setAgeLock(o.getAgeLock()); | |
if (o.isAdult()) { | |
n.setAdult(); | |
} else { | |
n.setBaby(); | |
} | |
} | |
if (nent instanceof Boat) { | |
Boat o = (Boat) oent; | |
Boat n = (Boat) nent; | |
n.setMaxSpeed(o.getMaxSpeed()); | |
n.setOccupiedDeceleration(o.getOccupiedDeceleration()); | |
n.setUnoccupiedDeceleration(o.getUnoccupiedDeceleration()); | |
n.setWorkOnLand(o.getWorkOnLand()); | |
} | |
if (nent instanceof Creature) { | |
// NOOP | |
/* | |
Creature o = (Creature) oent; | |
Creature n = (Creature) nent; | |
// n.setTarget(o.getTarget()); | |
*/ | |
} | |
if (nent instanceof Creeper) { | |
Creeper o = (Creeper) oent; | |
Creeper n = (Creeper) nent; | |
n.setPowered(o.isPowered()); | |
} | |
if (nent instanceof Damageable) { | |
Damageable o = (Damageable) oent; | |
Damageable n = (Damageable) nent; | |
n.setMaxHealth(o.getMaxHealth()); | |
n.setHealth(o.getHealth()); | |
// TODO healthScale on beta/RB | |
} | |
if (nent instanceof Enderman) { | |
Enderman o = (Enderman) oent; | |
Enderman n = (Enderman) nent; | |
n.setCarriedMaterial(o.getCarriedMaterial()); | |
} | |
if (nent instanceof ExperienceOrb) { | |
ExperienceOrb o = (ExperienceOrb) oent; | |
ExperienceOrb n = (ExperienceOrb) nent; | |
n.setExperience(o.getExperience()); | |
} | |
if (nent instanceof Explosive) { | |
Explosive o = (Explosive) oent; | |
Explosive n = (Explosive) nent; | |
n.setYield(o.getYield()); | |
n.setIsIncendiary(o.isIncendiary()); | |
} | |
if (nent instanceof Fireball) { | |
Fireball o = (Fireball) oent; | |
Fireball n = (Fireball) nent; | |
n.setDirection(o.getDirection()); | |
} | |
if (nent instanceof Firework) { | |
Firework o = (Firework) oent; | |
Firework n = (Firework) nent; | |
n.setFireworkMeta(o.getFireworkMeta()); | |
} | |
if (nent instanceof Fish) { | |
Fish o = (Fish) oent; | |
Fish n = (Fish) nent; | |
n.setBiteChance(o.getBiteChance()); | |
} | |
if (nent instanceof Hanging) { | |
/* NOOP | |
Hanging o = (Hanging) oent; | |
Hanging n = (Hanging) nent; | |
*/ | |
} | |
if (nent instanceof Horse) { | |
Horse o = (Horse) oent; | |
Horse n = (Horse) nent; | |
n.setVariant(o.getVariant()); | |
n.setColor(o.getColor()); | |
n.setStyle(o.getStyle()); | |
n.setCarryingChest(o.isCarryingChest()); | |
n.setDomestication(o.getDomestication()); | |
n.setMaxDomestication(o.getMaxDomestication()); | |
n.setJumpStrength(o.getJumpStrength()); | |
} | |
if (nent instanceof IronGolem) { | |
IronGolem o = (IronGolem) oent; | |
IronGolem n = (IronGolem) nent; | |
n.setPlayerCreated(o.isPlayerCreated()); | |
} | |
if (nent instanceof ItemFrame) { | |
ItemFrame o = (ItemFrame) oent; | |
ItemFrame n = (ItemFrame) nent; | |
n.setItem(o.getItem()); | |
n.setRotation(o.getRotation()); | |
n.setFacingDirection(o.getFacing()); | |
} | |
//if (nent instanceof LeashHitch) { // TODO uncomment @ next beta / RB | |
//LeashHitch o = (LeashHitch) oent; | |
//LeashHitch n = (LeashHitch) nent; | |
//} | |
if (nent instanceof LivingEntity) { | |
LivingEntity o = (LivingEntity) oent; | |
LivingEntity n = (LivingEntity) nent; | |
for (PotionEffect eff : o.getActivePotionEffects()) { | |
n.addPotionEffect(eff, true); | |
} | |
n.setCanPickupItems(o.getCanPickupItems()); | |
n.setCustomName(o.getCustomName()); | |
n.setCustomNameVisible(o.isCustomNameVisible()); | |
if (!(nent instanceof HumanEntity)) { | |
EntityEquipment eo = o.getEquipment(); | |
EntityEquipment en = n.getEquipment(); | |
en.setArmorContents(eo.getArmorContents()); | |
en.setItemInHand(eo.getItemInHand()); | |
en.setBootsDropChance(eo.getBootsDropChance()); | |
en.setChestplateDropChance(eo.getChestplateDropChance()); | |
en.setHelmetDropChance(eo.getHelmetDropChance()); | |
en.setItemInHandDropChance(eo.getItemInHandDropChance()); | |
en.setLeggingsDropChance(eo.getLeggingsDropChance()); | |
} | |
n.setLastDamage(o.getLastDamage()); | |
//n.setLeashHolder(o.getLeashHolder()); | |
n.setMaximumAir(o.getMaximumAir()); | |
n.setMaximumNoDamageTicks(o.getMaximumNoDamageTicks()); | |
n.setNoDamageTicks(o.getNoDamageTicks()); | |
n.setRemainingAir(o.getRemainingAir()); | |
n.setRemoveWhenFarAway(o.getRemoveWhenFarAway()); | |
} | |
if (nent instanceof Minecart) { | |
Minecart o = (Minecart) oent; | |
Minecart n = (Minecart) nent; | |
n.setDamage(o.getDamage()); | |
n.setDerailedVelocityMod(o.getDerailedVelocityMod()); | |
n.setFlyingVelocityMod(o.getFlyingVelocityMod()); | |
n.setMaxSpeed(o.getMaxSpeed()); | |
n.setSlowWhenEmpty(o.isSlowWhenEmpty()); | |
} | |
if (nent instanceof Ocelot) { | |
Ocelot o = (Ocelot) oent; | |
Ocelot n = (Ocelot) nent; | |
n.setSitting(o.isSitting()); | |
n.setCatType(o.getCatType()); | |
} | |
if (nent instanceof Painting) { | |
Painting o = (Painting) oent; | |
Painting n = (Painting) nent; | |
n.setFacingDirection(o.getFacing(), true); | |
n.setArt(o.getArt(), true); | |
} | |
if (nent instanceof Pig) { | |
Pig o = (Pig) oent; | |
Pig n = (Pig) nent; | |
n.setSaddle(o.hasSaddle()); | |
} | |
if (nent instanceof PigZombie) { | |
PigZombie o = (PigZombie) oent; | |
PigZombie n = (PigZombie) nent; | |
n.setAnger(o.getAnger()); | |
} | |
if (nent instanceof Projectile) { | |
Projectile o = (Projectile) oent; | |
Projectile n = (Projectile) nent; | |
n.setShooter(o.getShooter()); | |
n.setBounce(o.doesBounce()); | |
} | |
if (nent instanceof Sheep) { | |
Sheep o = (Sheep) oent; | |
Sheep n = (Sheep) nent; | |
n.setColor(o.getColor()); | |
n.setSheared(o.isSheared()); | |
} | |
if (nent instanceof Skeleton) { | |
Skeleton o = (Skeleton) oent; | |
Skeleton n = (Skeleton) nent; | |
n.setSkeletonType(o.getSkeletonType()); | |
} | |
if (nent instanceof Slime) { | |
Slime o = (Slime) oent; | |
Slime n = (Slime) nent; | |
n.setSize(o.getSize()); | |
} | |
if (nent instanceof Tameable) { | |
Tameable o = (Tameable) oent; | |
Tameable n = (Tameable) nent; | |
n.setOwner(o.getOwner()); | |
//n.setTamed(o.isTamed()); | |
} | |
if (nent instanceof ThrownPotion) { | |
ThrownPotion o = (ThrownPotion) oent; | |
ThrownPotion n = (ThrownPotion) nent; | |
n.setItem(o.getItem()); | |
} | |
if (nent instanceof TNTPrimed) { | |
TNTPrimed o = (TNTPrimed) oent; | |
TNTPrimed n = (TNTPrimed) nent; | |
n.setFuseTicks(o.getFuseTicks()); | |
} | |
if (nent instanceof Vehicle) { | |
Vehicle o = (Vehicle) oent; | |
Vehicle n = (Vehicle) nent; | |
n.setVelocity(o.getVelocity()); | |
} | |
if (nent instanceof Villager) { | |
Villager o = (Villager) oent; | |
Villager n = (Villager) nent; | |
n.setProfession(o.getProfession()); | |
} | |
if (nent instanceof Wolf) { | |
Wolf o = (Wolf) oent; | |
Wolf n = (Wolf) nent; | |
n.setCollarColor(o.getCollarColor()); | |
n.setAngry(o.isAngry()); | |
n.setSitting(o.isSitting()); | |
} | |
if (nent instanceof Zombie) { | |
Zombie o = (Zombie) oent; | |
Zombie n = (Zombie) nent; | |
n.setBaby(o.isBaby()); | |
n.setVillager(o.isVillager()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment