Implemented new 1.2 entities - this fixes BUKKIT-872 and BUKKIT-885

This commit is contained in:
Nathan Adams 2012-03-01 18:02:16 +00:00
parent 5108569383
commit f1f9802ded
9 changed files with 213 additions and 100 deletions

View File

@ -781,6 +781,9 @@ public class CraftWorld implements World {
} else if (Arrow.class.isAssignableFrom(clazz)) { } else if (Arrow.class.isAssignableFrom(clazz)) {
entity = new EntityArrow(world); entity = new EntityArrow(world);
entity.setPositionRotation(x, y, z, 0, 0); entity.setPositionRotation(x, y, z, 0, 0);
} else if (ThrownExpBottle.class.isAssignableFrom(clazz)) {
entity = new EntityThrownExpBottle(world);
entity.setPositionRotation(x, y, z, 0, 0);
} else if (Fireball.class.isAssignableFrom(clazz)) { } else if (Fireball.class.isAssignableFrom(clazz)) {
if (SmallFireball.class.isAssignableFrom(clazz)) { if (SmallFireball.class.isAssignableFrom(clazz)) {
entity = new EntitySmallFireball(world); entity = new EntitySmallFireball(world);
@ -813,8 +816,12 @@ public class CraftWorld implements World {
} else { } else {
entity = new EntityCow(world); entity = new EntityCow(world);
} }
} else if (Snowman.class.isAssignableFrom(clazz)) { } else if (Golem.class.isAssignableFrom(clazz)) {
entity = new EntitySnowman(world); if (Snowman.class.isAssignableFrom(clazz)) {
entity = new EntitySnowman(world);
} else if (IronGolem.class.isAssignableFrom(clazz)) {
entity = new EntityIronGolem(world);
}
} else if (Creeper.class.isAssignableFrom(clazz)) { } else if (Creeper.class.isAssignableFrom(clazz)) {
entity = new EntityCreeper(world); entity = new EntityCreeper(world);
} else if (Ghast.class.isAssignableFrom(clazz)) { } else if (Ghast.class.isAssignableFrom(clazz)) {
@ -841,8 +848,12 @@ public class CraftWorld implements World {
} }
} else if (Squid.class.isAssignableFrom(clazz)) { } else if (Squid.class.isAssignableFrom(clazz)) {
entity = new EntitySquid(world); entity = new EntitySquid(world);
} else if (Wolf.class.isAssignableFrom(clazz)) { } else if (Tameable.class.isAssignableFrom(clazz)) {
entity = new EntityWolf(world); if (Wolf.class.isAssignableFrom(clazz)) {
entity = new EntityWolf(world);
} else if (Ocelot.class.isAssignableFrom(clazz)) {
entity = new EntityOcelot(world);
}
} else if (PigZombie.class.isAssignableFrom(clazz)) { } else if (PigZombie.class.isAssignableFrom(clazz)) {
entity = new EntityPigZombie(world); entity = new EntityPigZombie(world);
} else if (Zombie.class.isAssignableFrom(clazz)) { } else if (Zombie.class.isAssignableFrom(clazz)) {

View File

@ -51,7 +51,10 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
else { return new CraftCow(server, (EntityCow) entity); } else { return new CraftCow(server, (EntityCow) entity); }
} }
else if (entity instanceof EntityPig) { return new CraftPig(server, (EntityPig) entity); } else if (entity instanceof EntityPig) { return new CraftPig(server, (EntityPig) entity); }
else if (entity instanceof EntityWolf) { return new CraftWolf(server, (EntityWolf) entity); } else if (entity instanceof EntityTameableAnimal) {
if (entity instanceof EntityWolf) { return new CraftWolf(server, (EntityWolf) entity); }
else if (entity instanceof EntityOcelot) { return new CraftOcelot(server, (EntityOcelot) entity); }
}
else if (entity instanceof EntitySheep) { return new CraftSheep(server, (EntitySheep) entity); } else if (entity instanceof EntitySheep) { return new CraftSheep(server, (EntitySheep) entity); }
else { return new CraftAnimals(server, (EntityAnimal) entity); } else { return new CraftAnimals(server, (EntityAnimal) entity); }
} }
@ -79,7 +82,10 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
if (entity instanceof EntitySquid) { return new CraftSquid(server, (EntitySquid) entity); } if (entity instanceof EntitySquid) { return new CraftSquid(server, (EntitySquid) entity); }
else { return new CraftWaterMob(server, (EntityWaterAnimal) entity); } else { return new CraftWaterMob(server, (EntityWaterAnimal) entity); }
} }
else if (entity instanceof EntitySnowman) { return new CraftSnowman(server, (EntitySnowman) entity); } else if (entity instanceof EntityGolem) {
if (entity instanceof EntitySnowman) { return new CraftSnowman(server, (EntitySnowman) entity); }
else if (entity instanceof EntityIronGolem) { return new CraftIronGolem(server, (EntityIronGolem) entity); }
}
else if (entity instanceof EntityVillager) { return new CraftVillager(server, (EntityVillager) entity); } else if (entity instanceof EntityVillager) { return new CraftVillager(server, (EntityVillager) entity); }
else { return new CraftCreature(server, (EntityCreature) entity); } else { return new CraftCreature(server, (EntityCreature) entity); }
} }
@ -111,6 +117,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
else if (entity instanceof EntitySnowball) { return new CraftSnowball(server, (EntitySnowball) entity); } else if (entity instanceof EntitySnowball) { return new CraftSnowball(server, (EntitySnowball) entity); }
else if (entity instanceof EntityPotion) { return new CraftThrownPotion(server, (EntityPotion) entity); } else if (entity instanceof EntityPotion) { return new CraftThrownPotion(server, (EntityPotion) entity); }
else if (entity instanceof EntityEnderPearl) { return new CraftEnderPearl(server, (EntityEnderPearl) entity); } else if (entity instanceof EntityEnderPearl) { return new CraftEnderPearl(server, (EntityEnderPearl) entity); }
else if (entity instanceof EntityThrownExpBottle) { return new CraftThrownExpBottle(server, (EntityThrownExpBottle) entity); }
} }
else if (entity instanceof EntityFallingBlock) { return new CraftFallingSand(server, (EntityFallingBlock) entity); } else if (entity instanceof EntityFallingBlock) { return new CraftFallingSand(server, (EntityFallingBlock) entity); }
else if (entity instanceof EntityFireball) { else if (entity instanceof EntityFireball) {

View File

@ -0,0 +1,21 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityGolem;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Golem;
public class CraftGolem extends CraftCreature implements Golem {
public CraftGolem(CraftServer server, EntityGolem entity) {
super(server, entity);
}
@Override
public EntityGolem getHandle() {
return (EntityGolem) entity;
}
@Override
public String toString() {
return "CraftGolem";
}
}

View File

@ -0,0 +1,27 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityIronGolem;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.IronGolem;
public class CraftIronGolem extends CraftGolem implements IronGolem {
public CraftIronGolem(CraftServer server, EntityIronGolem entity) {
super(server, entity);
}
@Override
public EntityIronGolem getHandle() {
return (EntityIronGolem) entity;
}
@Override
public String toString() {
return "CraftIronGolem";
}
@Override
public EntityType getType() {
return EntityType.IRON_GOLEM;
}
}

View File

@ -0,0 +1,32 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityOcelot;
import org.apache.commons.lang.Validate;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Ocelot;
public class CraftOcelot extends CraftTameableAnimal implements Ocelot {
public CraftOcelot(CraftServer server, EntityOcelot wolf) {
super(server, wolf);
}
@Override
public EntityOcelot getHandle() {
return (EntityOcelot) entity;
}
public Type getCatType() {
return Type.getType(getHandle().getCatType());
}
public void setCatType(Type type) {
Validate.notNull(type, "Cat type cannot be null");
getHandle().setCatType(type.getId());
}
@Override
public EntityType getType() {
return EntityType.OCELOT;
}
}

View File

@ -1,12 +1,11 @@
package org.bukkit.craftbukkit.entity; package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntitySnowman; import net.minecraft.server.EntitySnowman;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Snowman; import org.bukkit.entity.Snowman;
public class CraftSnowman extends CraftCreature implements Snowman { public class CraftSnowman extends CraftGolem implements Snowman {
public CraftSnowman(CraftServer server, EntitySnowman entity) { public CraftSnowman(CraftServer server, EntitySnowman entity) {
super(server, entity); super(server, entity);
} }

View File

@ -0,0 +1,81 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityTameableAnimal;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
public class CraftTameableAnimal extends CraftAnimals implements Tameable, Creature {
private AnimalTamer owner;
public CraftTameableAnimal(CraftServer server, EntityTameableAnimal entity) {
super(server, entity);
}
@Override
public EntityTameableAnimal getHandle() {
return (EntityTameableAnimal)super.getHandle();
}
public AnimalTamer getOwner() {
if (owner == null && !("").equals(getOwnerName())) {
owner = getServer().getPlayer(getOwnerName());
if (owner == null) {
owner = getServer().getOfflinePlayer(getOwnerName());
}
}
return owner;
}
public String getOwnerName() {
return getHandle().getOwnerName();
}
public boolean isTamed() {
return getHandle().isTamed();
}
public void setOwner(AnimalTamer tamer) {
owner = tamer;
if (owner != null) {
setTamed(true);
getHandle().setPathEntity(null);
if (owner instanceof Player) {
setOwnerName(((Player) owner).getName());
} else {
setOwnerName("");
}
} else {
setTamed(false);
setOwnerName("");
}
}
public void setOwnerName(String ownerName) {
getHandle().setOwnerName(ownerName);
}
public void setTamed(boolean tame) {
getHandle().setTamed(tame);
}
public boolean isSitting() {
return getHandle().isSitting();
}
public void setSitting(boolean sitting) {
getHandle().setSitting(sitting);
getHandle().setPathEntity(null);
}
@Override
public String toString() {
return getClass().getSimpleName() + "{owner=" + getOwner() + ",tamed=" + isTamed() + "}";
}
}

View File

@ -0,0 +1,26 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityThrownExpBottle;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ThrownExpBottle;
public class CraftThrownExpBottle extends CraftProjectile implements ThrownExpBottle {
public CraftThrownExpBottle(CraftServer server, EntityThrownExpBottle entity) {
super(server, entity);
}
@Override
public EntityThrownExpBottle getHandle() {
return (EntityThrownExpBottle) entity;
}
@Override
public String toString() {
return "EntityThrownExpBottle";
}
public EntityType getType() {
return EntityType.THROWN_EXP_BOTTLE;
}
}

View File

@ -1,17 +1,11 @@
package org.bukkit.craftbukkit.entity; package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityWolf; import net.minecraft.server.EntityWolf;
import net.minecraft.server.PathEntity;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Wolf; import org.bukkit.entity.Wolf;
public class CraftWolf extends CraftAnimals implements Wolf { public class CraftWolf extends CraftTameableAnimal implements Wolf {
private AnimalTamer owner;
public CraftWolf(CraftServer server, EntityWolf wolf) { public CraftWolf(CraftServer server, EntityWolf wolf) {
super(server, wolf); super(server, wolf);
} }
@ -24,97 +18,12 @@ public class CraftWolf extends CraftAnimals implements Wolf {
getHandle().setAngry(angry); getHandle().setAngry(angry);
} }
public boolean isSitting() {
return getHandle().isSitting();
}
public void setSitting(boolean sitting) {
getHandle().setSitting(sitting);
// TODO determine what the following would do - it is affected every time a player makes their wolf sit or stand
// getHandle().ay = false;
setPath((PathEntity) null);
}
public boolean isTamed() {
return getHandle().isTamed();
}
public void setTamed(boolean tame) {
getHandle().setTamed(tame);
}
public AnimalTamer getOwner() {
// If the wolf has a previously set owner use that, otherwise try and find the player who owns it
if (owner == null && !("").equals(getOwnerName())) {
owner = getServer().getPlayer(getOwnerName());
if (owner == null) {
owner = getServer().getOfflinePlayer(getOwnerName());
}
}
return owner;
}
public void setOwner(AnimalTamer tamer) {
owner = tamer;
if (owner != null) {
setTamed(true); /* Make him tame */
setPath((PathEntity) null); /* Clear path */
/* Set owner */
// TODO persist owner to the persistence store
if (owner instanceof Player) {
setOwnerName(((Player) owner).getName());
} else {
setOwnerName("");
}
} else {
setTamed(false); /* Make him not tame */
setOwnerName(""); /* Clear owner */
}
}
/**
* The owner's name is how MC knows and persists the Wolf's owner. Since we choose to instead use an AnimalTamer, this functionality
* is used only as a backup. If the animal tamer is a player, we will store their name, otherwise we store an empty string.
*
* @return the owner's name, if they are a player; otherwise, the empty string or null.
*/
String getOwnerName() {
return getHandle().getOwnerName();
}
void setOwnerName(String ownerName) {
getHandle().setOwnerName(ownerName);
}
/**
* Only used internally at the moment, and there to set the path to null (that is stop the thing from running around)
* TODO use this later to extend the API, when we have Path classes in Bukkit
*
* @param pathentity currently the MC defined PathEntity class. Should be replaced with an API interface at some point.
*/
private void setPath(PathEntity pathentity) {
getHandle().setPathEntity(pathentity);
}
/*
* This method requires a(boolean) to be made visible. It will allow for hearts to be animated on a successful taming.
* TODO add this to the API, and make it visible
private void playTamingAnimation(boolean successful){
getHandle().a(successful);
}
*/
@Override @Override
public EntityWolf getHandle() { public EntityWolf getHandle() {
return (EntityWolf) entity; return (EntityWolf) entity;
} }
@Override @Override
public String toString() {
return "CraftWolf{anger=" + isAngry() + ",owner=" + getOwner() + ",tame=" + isTamed() + ",sitting=" + isSitting() + "}";
}
public EntityType getType() { public EntityType getType() {
return EntityType.WOLF; return EntityType.WOLF;
} }