Refactor code to be more efficient.

Dieser Commit ist enthalten in:
feildmaster 2012-03-25 18:06:43 -05:00 committet von Warren Loo
Ursprung c30e339af6
Commit 80db22b643
9 geänderte Dateien mit 25 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -164,7 +164,7 @@ public class Block {
public final Material material; public final Material material;
public float frictionFactor; public float frictionFactor;
private String name; 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) { protected Block(int i, Material material) {
this.bR = true; this.bR = true;
@ -362,7 +362,7 @@ public class Block {
protected void a(World world, int i, int j, int k, ItemStack itemstack) { protected void a(World world, int i, int j, int k, ItemStack itemstack) {
// CraftBukkit start - the logic of this function is moved into finishDrop // 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); this.dropList.add(itemstack);
} }
@ -550,6 +550,7 @@ public class Block {
this.dropList.clear(); 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) { public ArrayList<ItemStack> calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) {
// CraftBukkit end // CraftBukkit end
if (this.h() && EnchantmentManager.hasSilkTouchEnchantment(entityhuman.inventory)) { 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 this.dropNaturally(world, i, j, k, l, 1.0F, i1); // CraftBukkit
} }
return this.dropList; // CraftBukkit
return this.dropList;
} }
protected boolean h() { protected boolean h() {

Datei anzeigen

@ -1,6 +1,5 @@
package net.minecraft.server; package net.minecraft.server;
import java.util.ArrayList; // CraftBukkit
import java.util.Random; import java.util.Random;
public class BlockDeadBush extends BlockFlower { public class BlockDeadBush extends BlockFlower {
@ -38,13 +37,13 @@ public class BlockDeadBush extends BlockFlower {
} }
// CraftBukkit start - Calculate drops // 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) { 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)); this.a(world, i, j, k, new ItemStack(Block.DEAD_BUSH, 1, l));
return this.dropList;
} else { } else {
return super.calculateDrops(world, entityhuman, i, j, k, l); return super.calculateDrops(world, entityhuman, i, j, k, l);
} }
return this.dropList;
} }
// CraftBukkit end // CraftBukkit end
} }

Datei anzeigen

@ -1,6 +1,5 @@
package net.minecraft.server; package net.minecraft.server;
import java.util.ArrayList; // CraftBukkit
import java.util.Random; import java.util.Random;
import org.bukkit.event.block.LeavesDecayEvent; // CraftBukkit import org.bukkit.event.block.LeavesDecayEvent; // CraftBukkit
@ -173,13 +172,13 @@ public class BlockLeaves extends BlockTransparant {
} }
// CraftBukkit start - Calculate drops // 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) { 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)); this.a(world, i, j, k, new ItemStack(Block.LEAVES.id, 1, l & 3));
return this.dropList;
} else { } else {
return super.calculateDrops(world, entityhuman, i, j, k, l); return super.calculateDrops(world, entityhuman, i, j, k, l);
} }
return this.dropList;
} }
// CraftBukkit end // CraftBukkit end

Datei anzeigen

@ -1,6 +1,5 @@
package net.minecraft.server; package net.minecraft.server;
import java.util.ArrayList; // CraftBukkit
import java.util.Random; import java.util.Random;
public class BlockLongGrass extends BlockFlower { public class BlockLongGrass extends BlockFlower {
@ -38,13 +37,13 @@ public class BlockLongGrass extends BlockFlower {
} }
// CraftBukkit start - Calculate drops // 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) { 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)); this.a(world, i, j, k, new ItemStack(Block.LONG_GRASS, 1, l));
return this.dropList;
} else { } else {
return super.calculateDrops(world, entityhuman, i, j, k, l); return super.calculateDrops(world, entityhuman, i, j, k, l);
} }
return this.dropList;
} }
// CraftBukkit end // CraftBukkit end
} }

Datei anzeigen

@ -14,7 +14,7 @@ public class BlockPistonExtension extends Block {
} }
// CraftBukkit start - Support getDrops() in BlockBreakEvent // 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); super.calculateDrops(world, entityhuman, i, j, k, d);
int l = world.getData(i, j, k) & 0x7; int l = world.getData(i, j, k) & 0x7;
if (l > 5 || l < 0) return this.dropList; if (l > 5 || l < 0) return this.dropList;

Datei anzeigen

@ -1,6 +1,5 @@
package net.minecraft.server; package net.minecraft.server;
import java.util.ArrayList; // CraftBukkit
import java.util.Random; import java.util.Random;
import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.craftbukkit.event.CraftEventFactory;
@ -74,7 +73,7 @@ public class BlockSnow extends Block {
} }
// CraftBukkit start - Calculate drops // 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)); this.a(world, i, j, k, new ItemStack(Item.SNOW_BALL.id, 1, 1));
return this.dropList; return this.dropList;
} }

Datei anzeigen

@ -1,6 +1,5 @@
package net.minecraft.server; package net.minecraft.server;
import java.util.ArrayList; // CraftBukkit
import java.util.Random; import java.util.Random;
public class BlockTNT extends Block { public class BlockTNT extends Block {
@ -57,7 +56,7 @@ public class BlockTNT extends Block {
} }
// CraftBukkit start - Calculate drops // 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) { if ((l & 1) == 0) {
this.a(world, i, j, k, new ItemStack(Block.TNT.id, 1, 0)); this.a(world, i, j, k, new ItemStack(Block.TNT.id, 1, 0));
} }

Datei anzeigen

@ -1,6 +1,5 @@
package net.minecraft.server; package net.minecraft.server;
import java.util.ArrayList; // CraftBukkit
import java.util.Random; import java.util.Random;
public class BlockVine extends Block { public class BlockVine extends Block {
@ -298,13 +297,13 @@ public class BlockVine extends Block {
} }
// CraftBukkit start - Calculate drops // 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) { if (!world.isStatic && entityhuman.U() != null && entityhuman.U().id == Item.SHEARS.id) {
this.a(world, i, j, k, new ItemStack(Block.VINE, 1, 0)); this.a(world, i, j, k, new ItemStack(Block.VINE, 1, 0));
return this.dropList;
} else { } else {
return super.calculateDrops(world, entityhuman, i, j, k, l); return super.calculateDrops(world, entityhuman, i, j, k, l);
} }
return this.dropList;
} }
// CraftBukkit end // CraftBukkit end
} }

Datei anzeigen

@ -1,8 +1,6 @@
package org.bukkit.craftbukkit.event; package org.bukkit.craftbukkit.event;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -18,7 +16,6 @@ import net.minecraft.server.EntityItem;
import net.minecraft.server.EntityLiving; import net.minecraft.server.EntityLiving;
import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntityPlayer;
import net.minecraft.server.EntityPotion; import net.minecraft.server.EntityPotion;
import net.minecraft.server.IInventory;
import net.minecraft.server.InventoryCrafting; import net.minecraft.server.InventoryCrafting;
import net.minecraft.server.Item; import net.minecraft.server.Item;
import net.minecraft.server.ItemStack; import net.minecraft.server.ItemStack;
@ -512,12 +509,13 @@ public class CraftEventFactory {
return event; 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) { 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]; net.minecraft.server.Block blockType = net.minecraft.server.Block.byId[id];
if (blockType == null) { // Illegal block ID if (blockType == null) { // Illegal block ID
return true; return true;
} }
Block block = world.getWorld().getBlockAt(x, y, z);
// Tell client the block is gone immediately then process events // Tell client the block is gone immediately then process events
if (world.getTileEntity(x, y, z) == null) { if (world.getTileEntity(x, y, z) == null) {
@ -528,10 +526,12 @@ public class CraftEventFactory {
((EntityPlayer) player).netServerHandler.sendPacket(packet); ((EntityPlayer) player).netServerHandler.sendPacket(packet);
} }
List<ItemStack> calculatedDrops = blockType.calculateDrops(world, player, x, y, z, data); Block block = world.getWorld().getBlockAt(x, y, z);
List<org.bukkit.inventory.ItemStack> drops = new ArrayList<org.bukkit.inventory.ItemStack>(calculatedDrops.size()); List<ItemStack> toDrop = blockType.calculateDrops(world, player, x, y, z, data);
drops.clear();
if (!creative && player.b(blockType)) { if (!creative && player.b(blockType)) {
for (ItemStack stack : calculatedDrops) { for (ItemStack stack : toDrop) {
drops.add(new CraftItemStack(stack)); drops.add(new CraftItemStack(stack));
} }
} }
@ -540,17 +540,16 @@ public class CraftEventFactory {
world.getServer().getPluginManager().callEvent(event); world.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
blockType.dropList.clear(); toDrop.clear();
// Let the client know the block still exists // Let the client know the block still exists
((EntityPlayer) player).netServerHandler.sendPacket(new Packet53BlockChange(x, y, z, world)); ((EntityPlayer) player).netServerHandler.sendPacket(new Packet53BlockChange(x, y, z, world));
return true; return true;
} }
ArrayList<ItemStack> toDrop = new ArrayList<ItemStack>(drops.size()); toDrop.clear();
for (org.bukkit.inventory.ItemStack stack : drops) { for (org.bukkit.inventory.ItemStack stack : drops) {
toDrop.add(CraftItemStack.createNMSItemStack(stack)); toDrop.add(CraftItemStack.createNMSItemStack(stack));
} }
blockType.dropList = toDrop;
return false; // Event not cancelled return false; // Event not cancelled
} }