summaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
authorZeerix <zeerix@draig.de>2012-01-12 03:10:10 +0100
committerErik Broes <erikbroes@grum.nl>2012-01-17 19:48:44 +0100
commit2cc70bb05588a9d99c6321e998472e76f998f04a (patch)
treeb683c4aa15892bef7f3d59932d41969b3f217c8c /src/main/java/org
parentfb1cfea89e46f198d683b045586437ef09ed311f (diff)
downloadcraftbukkit-2cc70bb05588a9d99c6321e998472e76f998f04a.tar
craftbukkit-2cc70bb05588a9d99c6321e998472e76f998f04a.tar.gz
craftbukkit-2cc70bb05588a9d99c6321e998472e76f998f04a.tar.lz
craftbukkit-2cc70bb05588a9d99c6321e998472e76f998f04a.tar.xz
craftbukkit-2cc70bb05588a9d99c6321e998472e76f998f04a.zip
[Bleeding] Implemented Block.breakNaturally and Block.getDrops
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
index 80ffc421..e44eb377 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
@@ -1,5 +1,10 @@
package org.bukkit.craftbukkit.block;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
import org.bukkit.block.BlockFace;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
@@ -12,6 +17,7 @@ import net.minecraft.server.EnumSkyBlock;
import org.bukkit.*;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.CraftChunk;
+import org.bukkit.inventory.ItemStack;
import org.bukkit.util.BlockVector;
public class CraftBlock implements Block {
@@ -347,6 +353,57 @@ public class CraftBlock implements Block {
public PistonMoveReaction getPistonMoveReaction() {
return PistonMoveReaction.getById(net.minecraft.server.Block.byId[this.getTypeId()].material.getPushReaction());
+ }
+
+ private boolean itemCausesDrops(ItemStack item) {
+ net.minecraft.server.Block block = net.minecraft.server.Block.byId[this.getTypeId()];
+ net.minecraft.server.Item itemType = item != null ? net.minecraft.server.Item.byId[item.getTypeId()] : null;
+ return block != null && (block.material.k() || (itemType != null && itemType.a(block)));
+ }
+
+ public boolean breakNaturally() {
+ net.minecraft.server.Block block = net.minecraft.server.Block.byId[this.getTypeId()];
+ byte data = getData();
+ setTypeId(Material.AIR.getId());
+ if (block != null) {
+ block.dropNaturally(chunk.getHandle().world, x, y, z, data, 1.0F, 0);
+ return true;
+ }
+ return false;
+ }
+
+ public boolean breakNaturally(ItemStack item) {
+ if (itemCausesDrops(item)) {
+ return breakNaturally();
+ } else {
+ return setTypeId(Material.AIR.getId());
+ }
+ }
+
+ public Collection<ItemStack> getDrops() {
+ List<ItemStack> drops = new ArrayList<ItemStack>();
+
+ net.minecraft.server.Block block = net.minecraft.server.Block.byId[this.getTypeId()];
+ if (block != null) {
+ byte data = getData();
+ // based on nms.Block.dropNaturally
+ int count = block.getDropCount(0, chunk.getHandle().world.random);
+ for (int i = 0; i < count; ++i) {
+ int item = block.getDropType(data, chunk.getHandle().world.random, 0);
+ if (item > 0) {
+ drops.add(new ItemStack(item, 1, (short) net.minecraft.server.Block.getDropData(block, data)));
+ }
+ }
+ }
+ return drops;
+ }
+
+ public Collection<ItemStack> getDrops(ItemStack item) {
+ if (itemCausesDrops(item)) {
+ return getDrops();
+ } else {
+ return Collections.emptyList();
+ }
}
}