summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorfeildmaster <admin@feildmaster.com>2012-03-25 18:06:43 -0500
committerWarren Loo <evilseph@gmail.com>2012-03-25 19:46:55 -0400
commit80db22b643ca55f116474b3285a07d447ab188ee (patch)
tree9d14c2c7b913c7bd7506e17c262942e5153c25b7 /src/main
parentc30e339af6dd7594cca7e0c1ca31f0ea34a0afa9 (diff)
downloadcraftbukkit-80db22b643ca55f116474b3285a07d447ab188ee.tar
craftbukkit-80db22b643ca55f116474b3285a07d447ab188ee.tar.gz
craftbukkit-80db22b643ca55f116474b3285a07d447ab188ee.tar.lz
craftbukkit-80db22b643ca55f116474b3285a07d447ab188ee.tar.xz
craftbukkit-80db22b643ca55f116474b3285a07d447ab188ee.zip
Refactor code to be more efficient.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/net/minecraft/server/Block.java8
-rw-r--r--src/main/java/net/minecraft/server/BlockDeadBush.java5
-rw-r--r--src/main/java/net/minecraft/server/BlockLeaves.java5
-rw-r--r--src/main/java/net/minecraft/server/BlockLongGrass.java5
-rw-r--r--src/main/java/net/minecraft/server/BlockPistonExtension.java2
-rw-r--r--src/main/java/net/minecraft/server/BlockSnow.java3
-rw-r--r--src/main/java/net/minecraft/server/BlockTNT.java3
-rw-r--r--src/main/java/net/minecraft/server/BlockVine.java5
-rw-r--r--src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java19
9 files changed, 25 insertions, 30 deletions
diff --git a/src/main/java/net/minecraft/server/Block.java b/src/main/java/net/minecraft/server/Block.java
index 43430951..3244351d 100644
--- a/src/main/java/net/minecraft/server/Block.java
+++ b/src/main/java/net/minecraft/server/Block.java
@@ -164,7 +164,7 @@ public class Block {
public final Material material;
public float frictionFactor;
private String name;
- public ArrayList<ItemStack> dropList = new ArrayList<ItemStack>(1); // CraftBukkit
+ public final ArrayList<ItemStack> dropList = new ArrayList<ItemStack>(1); // CraftBukkit
protected Block(int i, Material material) {
this.bR = true;
@@ -362,7 +362,7 @@ public class Block {
protected void a(World world, int i, int j, int k, ItemStack itemstack) {
// CraftBukkit start - the logic of this function is moved into finishDrop
- // This is such a hackish change it's rediculous.
+ // This is such a hackish change it's ridiculous.
this.dropList.add(itemstack);
}
@@ -550,6 +550,7 @@ public class Block {
this.dropList.clear();
}
+ // Blocks that have different drops in certain situations need to override this. IE: Sheers on BlockLeaves
public ArrayList<ItemStack> calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) {
// CraftBukkit end
if (this.h() && EnchantmentManager.hasSilkTouchEnchantment(entityhuman.inventory)) {
@@ -563,7 +564,8 @@ public class Block {
this.dropNaturally(world, i, j, k, l, 1.0F, i1); // CraftBukkit
}
- return this.dropList; // CraftBukkit
+
+ return this.dropList;
}
protected boolean h() {
diff --git a/src/main/java/net/minecraft/server/BlockDeadBush.java b/src/main/java/net/minecraft/server/BlockDeadBush.java
index 60f53b88..fdb4573f 100644
--- a/src/main/java/net/minecraft/server/BlockDeadBush.java
+++ b/src/main/java/net/minecraft/server/BlockDeadBush.java
@@ -1,6 +1,5 @@
package net.minecraft.server;
-import java.util.ArrayList; // CraftBukkit
import java.util.Random;
public class BlockDeadBush extends BlockFlower {
@@ -38,13 +37,13 @@ public class BlockDeadBush extends BlockFlower {
}
// CraftBukkit start - Calculate drops
- public ArrayList<ItemStack> calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) {
+ public java.util.ArrayList<ItemStack> calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) {
if (!world.isStatic && entityhuman.U() != null && entityhuman.U().id == Item.SHEARS.id) {
this.a(world, i, j, k, new ItemStack(Block.DEAD_BUSH, 1, l));
- return this.dropList;
} else {
return super.calculateDrops(world, entityhuman, i, j, k, l);
}
+ return this.dropList;
}
// CraftBukkit end
}
diff --git a/src/main/java/net/minecraft/server/BlockLeaves.java b/src/main/java/net/minecraft/server/BlockLeaves.java
index 6345fafc..02b7ab12 100644
--- a/src/main/java/net/minecraft/server/BlockLeaves.java
+++ b/src/main/java/net/minecraft/server/BlockLeaves.java
@@ -1,6 +1,5 @@
package net.minecraft.server;
-import java.util.ArrayList; // CraftBukkit
import java.util.Random;
import org.bukkit.event.block.LeavesDecayEvent; // CraftBukkit
@@ -173,13 +172,13 @@ public class BlockLeaves extends BlockTransparant {
}
// CraftBukkit start - Calculate drops
- public ArrayList<ItemStack> calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) {
+ public java.util.ArrayList<ItemStack> calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) {
if (!world.isStatic && entityhuman.U() != null && entityhuman.U().id == Item.SHEARS.id) {
this.a(world, i, j, k, new ItemStack(Block.LEAVES.id, 1, l & 3));
- return this.dropList;
} else {
return super.calculateDrops(world, entityhuman, i, j, k, l);
}
+ return this.dropList;
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/server/BlockLongGrass.java b/src/main/java/net/minecraft/server/BlockLongGrass.java
index f98ae327..391407bf 100644
--- a/src/main/java/net/minecraft/server/BlockLongGrass.java
+++ b/src/main/java/net/minecraft/server/BlockLongGrass.java
@@ -1,6 +1,5 @@
package net.minecraft.server;
-import java.util.ArrayList; // CraftBukkit
import java.util.Random;
public class BlockLongGrass extends BlockFlower {
@@ -38,13 +37,13 @@ public class BlockLongGrass extends BlockFlower {
}
// CraftBukkit start - Calculate drops
- public ArrayList<ItemStack> calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) {
+ public java.util.ArrayList<ItemStack> calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) {
if (!world.isStatic && entityhuman.U() != null && entityhuman.U().id == Item.SHEARS.id) {
this.a(world, i, j, k, new ItemStack(Block.LONG_GRASS, 1, l));
- return this.dropList;
} else {
return super.calculateDrops(world, entityhuman, i, j, k, l);
}
+ return this.dropList;
}
// CraftBukkit end
}
diff --git a/src/main/java/net/minecraft/server/BlockPistonExtension.java b/src/main/java/net/minecraft/server/BlockPistonExtension.java
index 3ead3a4a..0cb2fa38 100644
--- a/src/main/java/net/minecraft/server/BlockPistonExtension.java
+++ b/src/main/java/net/minecraft/server/BlockPistonExtension.java
@@ -14,7 +14,7 @@ public class BlockPistonExtension extends Block {
}
// CraftBukkit start - Support getDrops() in BlockBreakEvent
- public ArrayList<ItemStack> calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int d) {
+ public java.util.ArrayList<ItemStack> calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int d) {
super.calculateDrops(world, entityhuman, i, j, k, d);
int l = world.getData(i, j, k) & 0x7;
if (l > 5 || l < 0) return this.dropList;
diff --git a/src/main/java/net/minecraft/server/BlockSnow.java b/src/main/java/net/minecraft/server/BlockSnow.java
index ea63188a..24c52a35 100644
--- a/src/main/java/net/minecraft/server/BlockSnow.java
+++ b/src/main/java/net/minecraft/server/BlockSnow.java
@@ -1,6 +1,5 @@
package net.minecraft.server;
-import java.util.ArrayList; // CraftBukkit
import java.util.Random;
import org.bukkit.craftbukkit.event.CraftEventFactory;
@@ -74,7 +73,7 @@ public class BlockSnow extends Block {
}
// CraftBukkit start - Calculate drops
- public ArrayList<ItemStack> calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) {
+ public java.util.ArrayList<ItemStack> calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) {
this.a(world, i, j, k, new ItemStack(Item.SNOW_BALL.id, 1, 1));
return this.dropList;
}
diff --git a/src/main/java/net/minecraft/server/BlockTNT.java b/src/main/java/net/minecraft/server/BlockTNT.java
index 3aaf8c6d..9a1f0398 100644
--- a/src/main/java/net/minecraft/server/BlockTNT.java
+++ b/src/main/java/net/minecraft/server/BlockTNT.java
@@ -1,6 +1,5 @@
package net.minecraft.server;
-import java.util.ArrayList; // CraftBukkit
import java.util.Random;
public class BlockTNT extends Block {
@@ -57,7 +56,7 @@ public class BlockTNT extends Block {
}
// CraftBukkit start - Calculate drops
- public ArrayList<ItemStack> calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) {
+ public java.util.ArrayList<ItemStack> calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) {
if ((l & 1) == 0) {
this.a(world, i, j, k, new ItemStack(Block.TNT.id, 1, 0));
}
diff --git a/src/main/java/net/minecraft/server/BlockVine.java b/src/main/java/net/minecraft/server/BlockVine.java
index 93d8876b..816d6734 100644
--- a/src/main/java/net/minecraft/server/BlockVine.java
+++ b/src/main/java/net/minecraft/server/BlockVine.java
@@ -1,6 +1,5 @@
package net.minecraft.server;
-import java.util.ArrayList; // CraftBukkit
import java.util.Random;
public class BlockVine extends Block {
@@ -298,13 +297,13 @@ public class BlockVine extends Block {
}
// CraftBukkit start - Calculate drops
- public ArrayList<ItemStack> calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) {
+ public java.util.ArrayList<ItemStack> calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) {
if (!world.isStatic && entityhuman.U() != null && entityhuman.U().id == Item.SHEARS.id) {
this.a(world, i, j, k, new ItemStack(Block.VINE, 1, 0));
- return this.dropList;
} else {
return super.calculateDrops(world, entityhuman, i, j, k, l);
}
+ return this.dropList;
}
// CraftBukkit end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index 243c3339..91b60add 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -1,8 +1,6 @@
package org.bukkit.craftbukkit.event;
import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -18,7 +16,6 @@ import net.minecraft.server.EntityItem;
import net.minecraft.server.EntityLiving;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.EntityPotion;
-import net.minecraft.server.IInventory;
import net.minecraft.server.InventoryCrafting;
import net.minecraft.server.Item;
import net.minecraft.server.ItemStack;
@@ -512,12 +509,13 @@ public class CraftEventFactory {
return event;
}
+ private static final List<org.bukkit.inventory.ItemStack> drops = new java.util.ArrayList<org.bukkit.inventory.ItemStack>();
+
public static boolean callBlockBreakEvent(World world, int x, int y, int z, int id, int data, boolean creative, EntityHuman player) {
net.minecraft.server.Block blockType = net.minecraft.server.Block.byId[id];
if (blockType == null) { // Illegal block ID
return true;
}
- Block block = world.getWorld().getBlockAt(x, y, z);
// Tell client the block is gone immediately then process events
if (world.getTileEntity(x, y, z) == null) {
@@ -528,10 +526,12 @@ public class CraftEventFactory {
((EntityPlayer) player).netServerHandler.sendPacket(packet);
}
- List<ItemStack> calculatedDrops = blockType.calculateDrops(world, player, x, y, z, data);
- List<org.bukkit.inventory.ItemStack> drops = new ArrayList<org.bukkit.inventory.ItemStack>(calculatedDrops.size());
+ Block block = world.getWorld().getBlockAt(x, y, z);
+ List<ItemStack> toDrop = blockType.calculateDrops(world, player, x, y, z, data);
+ drops.clear();
+
if (!creative && player.b(blockType)) {
- for (ItemStack stack : calculatedDrops) {
+ for (ItemStack stack : toDrop) {
drops.add(new CraftItemStack(stack));
}
}
@@ -540,17 +540,16 @@ public class CraftEventFactory {
world.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
- blockType.dropList.clear();
+ toDrop.clear();
// Let the client know the block still exists
((EntityPlayer) player).netServerHandler.sendPacket(new Packet53BlockChange(x, y, z, world));
return true;
}
- ArrayList<ItemStack> toDrop = new ArrayList<ItemStack>(drops.size());
+ toDrop.clear();
for (org.bukkit.inventory.ItemStack stack : drops) {
toDrop.add(CraftItemStack.createNMSItemStack(stack));
}
- blockType.dropList = toDrop;
return false; // Event not cancelled
}