diff options
author | sk89q <the.sk89q@gmail.com> | 2011-01-07 16:26:08 -0800 |
---|---|---|
committer | sk89q <the.sk89q@gmail.com> | 2011-01-07 16:26:08 -0800 |
commit | c9efe9454520fbe57a9d3e02eeb9d355915fb4dc (patch) | |
tree | c176b8fbac2f1e9e3bdf9d5d275306163205ec96 /src | |
parent | e968096fc72e80731405d7f5d48848e43a94d1c1 (diff) | |
download | craftbukkit-c9efe9454520fbe57a9d3e02eeb9d355915fb4dc.tar craftbukkit-c9efe9454520fbe57a9d3e02eeb9d355915fb4dc.tar.gz craftbukkit-c9efe9454520fbe57a9d3e02eeb9d355915fb4dc.tar.lz craftbukkit-c9efe9454520fbe57a9d3e02eeb9d355915fb4dc.tar.xz craftbukkit-c9efe9454520fbe57a9d3e02eeb9d355915fb4dc.zip |
Added passenger methods to Vehicle/LivingEntity.
Diffstat (limited to 'src')
4 files changed, 50 insertions, 2 deletions
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java index 69d854f4..759651c7 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -829,7 +829,10 @@ public abstract class Entity { return (double) J * 0.75D; } - public void e(Entity entity) { + public void setPassengerOf(Entity entity) { + // e(null) doesn't really fly for overloaded methods, + // so this method is needed + d = 0.0D; e = 0.0D; if (entity == null) { @@ -855,6 +858,10 @@ public abstract class Entity { k = entity; entity.j = this; } + + public void e(Entity entity) { + setPassengerOf(entity); + } public Vec3D C() { return null; diff --git a/src/main/java/org/bukkit/craftbukkit/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/CraftEntity.java index 535db390..909bfae8 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftEntity.java @@ -5,6 +5,7 @@ import net.minecraft.server.Entity; import net.minecraft.server.WorldServer; import org.bukkit.Location; import org.bukkit.Vector; +import org.bukkit.Vehicle; import org.bukkit.World; public abstract class CraftEntity implements org.bukkit.Entity { diff --git a/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java index 50a297f6..449ea62f 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java @@ -11,6 +11,7 @@ import org.bukkit.Arrow; import org.bukkit.Egg; import org.bukkit.LivingEntity; import org.bukkit.Snowball; +import org.bukkit.Vehicle; public class CraftLivingEntity extends CraftEntity implements LivingEntity { private EntityLiving entity; @@ -61,11 +62,36 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { return new CraftSnowball(server, snowball); } - @Override public Arrow shootArrow() { net.minecraft.server.World world = ((CraftWorld)getWorld()).getHandle(); EntityArrow snowball = new EntityArrow(world, entity); world.a(snowball); return new CraftArrow(server, snowball); } + + public boolean isInsideVehicle() { + return entity.k != null; + } + + public boolean leaveVehicle() { + if (entity.k == null) { + return false; + } + + entity.setPassengerOf(null); + return true; + } + + public Vehicle getVehicle() { + if (entity.k == null) { + return null; + } + + org.bukkit.Entity vehicle = ((CraftWorld)getWorld()).toCraftEntity(entity.k); + if (vehicle instanceof Vehicle) { + return (Vehicle)vehicle; + } + + return null; + } } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java b/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java index 3ffed501..ffc93da1 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java @@ -17,8 +17,22 @@ public abstract class CraftVehicle extends CraftEntity implements Vehicle { public Entity getPassenger() { return ((CraftWorld)getWorld()).toCraftEntity(getHandle().j); } + + public boolean setPassenger(Entity passenger) { + ((CraftEntity)passenger).getHandle().setPassengerOf(getHandle()); + return true; + } public boolean isEmpty() { return getHandle().j == null; } + + public boolean eject() { + if (getHandle().j == null) { + return false; + } + + getHandle().j.setPassengerOf(null); + return true; + } } |