diff --git a/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java b/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java new file mode 100644 index 0000000000..69a647b18b --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java @@ -0,0 +1,69 @@ +package org.bukkit.craftbukkit; + +import net.minecraft.server.EntityMinecart; +import org.bukkit.LivingEntity; +import org.bukkit.Minecart; +import org.bukkit.Vector; + +/** + * A minecart. + * + * @author sk89q + */ +public class CraftMinecart extends CraftVehicle implements Minecart { + /** + * Stores the minecart type ID, which is used by Minecraft to differentiate + * minecart types. Here we use subclasses. + */ + public enum Type { + Minecart(0), + StorageMinecart(1), + PoweredMinecart(2); + + private final int id; + + private Type(int id) { + this.id = id; + } + + public int getID() { + return id; + } + } + + protected EntityMinecart minecart; + + public CraftMinecart(CraftServer server, EntityMinecart entity) { + super(server, entity); + minecart = entity; + } + + @Override + public Vector getVelocity() { + return new Vector(minecart.s, minecart.t, minecart.u); + } + + public void setVelocity(Vector vel) { + minecart.s = vel.getX(); + minecart.t = vel.getY(); + minecart.u = vel.getZ(); + } + + public LivingEntity getPassenger() { + // @TODO: Implement + return null; + } + + public boolean isEmpty() { + return minecart.j == null; + } + + public void setDamage(int damage) { + minecart.a = damage; + } + + public int getDamage() { + return minecart.a; + } + +} diff --git a/src/main/java/org/bukkit/craftbukkit/CraftPoweredMinecart.java b/src/main/java/org/bukkit/craftbukkit/CraftPoweredMinecart.java new file mode 100644 index 0000000000..2a1a8f1f38 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftPoweredMinecart.java @@ -0,0 +1,17 @@ +package org.bukkit.craftbukkit; + +import net.minecraft.server.EntityMinecart; +import org.bukkit.PoweredMinecart; + +/** + * A powered minecart. + * + * @author sk89q + */ +public class CraftPoweredMinecart extends CraftMinecart + implements PoweredMinecart { + public CraftPoweredMinecart(CraftServer server, EntityMinecart entity) { + super(server, entity); + } + +} diff --git a/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java b/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java new file mode 100644 index 0000000000..0adf0a180e --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java @@ -0,0 +1,17 @@ +package org.bukkit.craftbukkit; + +import net.minecraft.server.EntityMinecart; +import org.bukkit.StorageMinecart; + +/** + * A storage minecart. + * + * @author sk89q + */ +public class CraftStorageMinecart extends CraftMinecart + implements StorageMinecart { + public CraftStorageMinecart(CraftServer server, EntityMinecart entity) { + super(server, entity); + } + +} diff --git a/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java b/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java new file mode 100644 index 0000000000..a5c03868c4 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java @@ -0,0 +1,16 @@ +package org.bukkit.craftbukkit; + +import net.minecraft.server.Entity; + +import org.bukkit.Vehicle; + +/** + * A vehicle. + * + * @author sk89q + */ +public abstract class CraftVehicle extends CraftEntity implements Vehicle { + public CraftVehicle(CraftServer server, Entity entity) { + super(server, entity); + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 9c03efff80..b82773e903 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -3,15 +3,19 @@ package org.bukkit.craftbukkit; import java.util.HashMap; import java.util.Map; + +import net.minecraft.server.EntityMinecart; import java.util.Random; import net.minecraft.server.WorldGenBigTree; -import net.minecraft.server.WorldGenTrees; import net.minecraft.server.WorldServer; import net.minecraft.server.EntityArrow; import org.bukkit.Arrow; import org.bukkit.Block; import org.bukkit.Chunk; import org.bukkit.Location; +import org.bukkit.Minecart; +import org.bukkit.PoweredMinecart; +import org.bukkit.StorageMinecart; import org.bukkit.Vector; import org.bukkit.World; @@ -88,6 +92,33 @@ public class CraftWorld implements World { return new CraftArrow(world.getServer(), arrow); } + public Minecart spawnMinecart(Location loc) { + EntityMinecart minecart = new EntityMinecart( + world, + loc.getX(), loc.getY(), loc.getZ(), + CraftMinecart.Type.Minecart.getID()); + world.a(minecart); + return new CraftMinecart(world.getServer(), minecart); + } + + public StorageMinecart spawnStorageMinecart(Location loc) { + EntityMinecart minecart = new EntityMinecart( + world, + loc.getX(), loc.getY(), loc.getZ(), + CraftMinecart.Type.StorageMinecart.getID()); + world.a(minecart); + return new CraftStorageMinecart(world.getServer(), minecart); + } + + public PoweredMinecart spawnPoweredMinecart(Location loc) { + EntityMinecart minecart = new EntityMinecart( + world, + loc.getX(), loc.getY(), loc.getZ(), + CraftMinecart.Type.PoweredMinecart.getID()); + world.a(minecart); + return new CraftPoweredMinecart(world.getServer(), minecart); + } + public boolean generateTree(Location loc) { WorldGenTrees treeGen = new WorldGenTrees(); return treeGen.a(world, rand,