summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorsk89q <the.sk89q@gmail.com>2011-01-08 12:48:45 -0800
committersk89q <the.sk89q@gmail.com>2011-01-08 12:48:45 -0800
commitfd20876189f020df0cdf0bd4a45e6712f82fc29d (patch)
treecd1312b61b25b65b9a9050ab95eb92007eef890f /src/main/java
parente83d9f676d746cdf2b55936036513535d2cbef65 (diff)
downloadcraftbukkit-fd20876189f020df0cdf0bd4a45e6712f82fc29d.tar
craftbukkit-fd20876189f020df0cdf0bd4a45e6712f82fc29d.tar.gz
craftbukkit-fd20876189f020df0cdf0bd4a45e6712f82fc29d.tar.lz
craftbukkit-fd20876189f020df0cdf0bd4a45e6712f82fc29d.tar.xz
craftbukkit-fd20876189f020df0cdf0bd4a45e6712f82fc29d.zip
Implemented item drops.
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/CraftItemDrop.java23
-rw-r--r--src/main/java/org/bukkit/craftbukkit/CraftWorld.java27
2 files changed, 50 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftItemDrop.java b/src/main/java/org/bukkit/craftbukkit/CraftItemDrop.java
new file mode 100644
index 00000000..0def1825
--- /dev/null
+++ b/src/main/java/org/bukkit/craftbukkit/CraftItemDrop.java
@@ -0,0 +1,23 @@
+package org.bukkit.craftbukkit;
+
+import net.minecraft.server.EntityItem;
+import org.bukkit.ItemDrop;
+import org.bukkit.ItemStack;
+
+/**
+ * Represents an item drop.
+ *
+ * @author sk89q
+ */
+public class CraftItemDrop extends CraftEntity implements ItemDrop {
+ private EntityItem item;
+
+ public CraftItemDrop(CraftServer server, EntityItem ent) {
+ super(server, ent);
+ this.item = ent;
+ }
+
+ public ItemStack getItemStack() {
+ return new CraftItemStack(item.a);
+ }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 0edeead3..35f2a3a8 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -9,6 +9,7 @@ import java.util.Random;
import net.minecraft.server.EntityBoat;
import net.minecraft.server.EntityEgg;
+import net.minecraft.server.EntityItem;
import net.minecraft.server.EntityLiving;
import net.minecraft.server.EntityPlayerMP;
import net.minecraft.server.EntitySnowball;
@@ -22,6 +23,8 @@ import org.bukkit.Arrow;
import org.bukkit.Block;
import org.bukkit.Boat;
import org.bukkit.Chunk;
+import org.bukkit.ItemDrop;
+import org.bukkit.ItemStack;
import org.bukkit.Location;
import org.bukkit.Minecart;
import org.bukkit.PoweredMinecart;
@@ -110,6 +113,28 @@ public class CraftWorld implements World {
public WorldServer getHandle() {
return world;
}
+
+ public ItemDrop dropItem(Location loc, ItemStack item) {
+ net.minecraft.server.ItemStack stack =
+ new net.minecraft.server.ItemStack(
+ item.getTypeID(), item.getAmount(), item.getDamage());
+ EntityItem entity = new EntityItem(world, loc.getX(), loc.getY(),
+ loc.getZ(), stack);
+ entity.c = 10;
+ world.a(entity);
+ return new CraftItemDrop(world.getServer(), entity);
+ }
+
+ public ItemDrop dropItemNaturally(Location loc, ItemStack item) {
+ double xs = world.l.nextFloat() * 0.7F + (1.0F - 0.7F) * 0.5D;
+ double ys = world.l.nextFloat() * 0.7F + (1.0F - 0.7F) * 0.5D;
+ double zs = world.l.nextFloat() * 0.7F + (1.0F - 0.7F) * 0.5D;
+ loc = loc.clone();
+ loc.setX(loc.getX() + xs);
+ loc.setX(loc.getY() + ys);
+ loc.setX(loc.getZ() + zs);
+ return dropItem(loc, item);
+ }
public Arrow spawnArrow(Location loc, Vector velocity, float speed,
float spread) {
@@ -169,6 +194,8 @@ public class CraftWorld implements World {
public CraftEntity toCraftEntity(net.minecraft.server.Entity entity) {
if (entity instanceof CraftMappable) {
return ((CraftMappable)entity).getCraftEntity();
+ } else if (entity instanceof EntityItem) {
+ return new CraftItemDrop(world.getServer(), (EntityItem)entity);
} else if (entity instanceof EntityArrow) {
return new CraftArrow(world.getServer(), (EntityArrow)entity);
} else if (entity instanceof EntityEgg) {