diff options
author | sk89q <the.sk89q@gmail.com> | 2011-01-02 21:41:57 -0800 |
---|---|---|
committer | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-01-03 14:54:20 +0000 |
commit | 9d680354103466ec5f22b1a37f756e48504a3732 (patch) | |
tree | 88a6e9269b68e81ded46691170ed98d4c53594bf /src | |
parent | ca47ccf67421bbc2e6d7f40bd89cdc58d8d34d6e (diff) | |
download | craftbukkit-9d680354103466ec5f22b1a37f756e48504a3732.tar craftbukkit-9d680354103466ec5f22b1a37f756e48504a3732.tar.gz craftbukkit-9d680354103466ec5f22b1a37f756e48504a3732.tar.lz craftbukkit-9d680354103466ec5f22b1a37f756e48504a3732.tar.xz craftbukkit-9d680354103466ec5f22b1a37f756e48504a3732.zip |
Added minecart classes and World.spawn*Minecart(). Minecart.getPassenger() is still a stub that needs to be implemented (due to of a need of a MC entity -> CraftBukkit entity lookup) and StorageMinecart.getInventory() is waiting on the implementation of inventory.
Diffstat (limited to 'src')
5 files changed, 151 insertions, 1 deletions
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 00000000..69a647b1 --- /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 00000000..2a1a8f1f --- /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 00000000..0adf0a18 --- /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 00000000..a5c03868 --- /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 9c03efff..b82773e9 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, |