optimize quarry and chute tile entity lookups

This commit is contained in:
asiekierka 2014-10-20 16:16:18 +02:00
parent 10b224b21c
commit b9657e8bbc
2 changed files with 27 additions and 16 deletions

View file

@ -8,14 +8,13 @@
*/
package buildcraft.factory;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.inventory.ITransactor;
import buildcraft.core.inventory.SimpleInventory;
@ -24,6 +23,7 @@ import buildcraft.core.inventory.Transactor;
public class TileHopper extends TileBuildCraft implements IInventory {
private final SimpleInventory inventory = new SimpleInventory(4, "Hopper", 64);
private TileEntity outputTile;
@Override
public void readFromNBT(NBTTagCompound nbtTagCompound) {
@ -53,24 +53,34 @@ public class TileHopper extends TileBuildCraft implements IInventory {
return;
}
TileEntity tile = this.getWorldObj().getTileEntity(xCoord, yCoord - 1, zCoord);
if (outputTile == null || outputTile.isInvalid()) {
Block block = worldObj.getBlock(xCoord, yCoord - 1, zCoord);
outputTile = null;
if (tile == null) {
return;
if (block.hasTileEntity(worldObj.getBlockMetadata(xCoord, yCoord - 1, zCoord))) {
outputTile = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord);
}
ITransactor transactor = Transactor.getTransactorFor(tile);
if (transactor == null) {
if (outputTile == null) {
return;
}
}
ITransactor transactor = null;
for (int internalSlot = 0; internalSlot < inventory.getSizeInventory(); internalSlot++) {
ItemStack stackInSlot = inventory.getStackInSlot(internalSlot);
if (stackInSlot == null) {
if (stackInSlot == null || stackInSlot.stackSize == 0) {
continue;
}
if (transactor == null) {
transactor = Transactor.getTransactorFor(outputTile);
if (transactor == null) {
return;
}
}
ItemStack clonedStack = stackInSlot.copy().splitStack(1);
if (transactor.add(clonedStack, ForgeDirection.UP, true).stackSize > 0) {
inventory.decrStackSize(internalSlot, 1);

View file

@ -406,6 +406,7 @@ public class TileQuarry extends TileAbstractBuilder implements IMachine, ISidedI
int k = targetZ;
Block block = worldObj.getBlock(i, j, k);
int meta = worldObj.getBlockMetadata(i, j, k);
if (isQuarriableBlock(i, j, k)) {
// Share this with mining well!
@ -427,9 +428,9 @@ public class TileQuarry extends TileAbstractBuilder implements IMachine, ISidedI
j,
k,
Block.getIdFromBlock(block)
+ (worldObj.getBlockMetadata(i, j, k) << 12));
+ (meta << 12));
if (worldObj.getTileEntity(i, j, k) != null) {
if (block.hasTileEntity(meta)) {
worldObj.removeTileEntity(i, j, k);
}