optimize quarry and chute tile entity lookups
This commit is contained in:
parent
10b224b21c
commit
b9657e8bbc
2 changed files with 27 additions and 16 deletions
|
@ -8,14 +8,13 @@
|
||||||
*/
|
*/
|
||||||
package buildcraft.factory;
|
package buildcraft.factory;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
import buildcraft.core.TileBuildCraft;
|
import buildcraft.core.TileBuildCraft;
|
||||||
import buildcraft.core.inventory.ITransactor;
|
import buildcraft.core.inventory.ITransactor;
|
||||||
import buildcraft.core.inventory.SimpleInventory;
|
import buildcraft.core.inventory.SimpleInventory;
|
||||||
|
@ -24,7 +23,8 @@ import buildcraft.core.inventory.Transactor;
|
||||||
public class TileHopper extends TileBuildCraft implements IInventory {
|
public class TileHopper extends TileBuildCraft implements IInventory {
|
||||||
|
|
||||||
private final SimpleInventory inventory = new SimpleInventory(4, "Hopper", 64);
|
private final SimpleInventory inventory = new SimpleInventory(4, "Hopper", 64);
|
||||||
|
private TileEntity outputTile;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbtTagCompound) {
|
public void readFromNBT(NBTTagCompound nbtTagCompound) {
|
||||||
super.readFromNBT(nbtTagCompound);
|
super.readFromNBT(nbtTagCompound);
|
||||||
|
@ -53,23 +53,33 @@ public class TileHopper extends TileBuildCraft implements IInventory {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TileEntity tile = this.getWorldObj().getTileEntity(xCoord, yCoord - 1, zCoord);
|
if (outputTile == null || outputTile.isInvalid()) {
|
||||||
|
Block block = worldObj.getBlock(xCoord, yCoord - 1, zCoord);
|
||||||
if (tile == null) {
|
outputTile = null;
|
||||||
return;
|
|
||||||
|
if (block.hasTileEntity(worldObj.getBlockMetadata(xCoord, yCoord - 1, zCoord))) {
|
||||||
|
outputTile = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outputTile == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ITransactor transactor = Transactor.getTransactorFor(tile);
|
ITransactor transactor = null;
|
||||||
|
|
||||||
if (transactor == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int internalSlot = 0; internalSlot < inventory.getSizeInventory(); internalSlot++) {
|
for (int internalSlot = 0; internalSlot < inventory.getSizeInventory(); internalSlot++) {
|
||||||
ItemStack stackInSlot = inventory.getStackInSlot(internalSlot);
|
ItemStack stackInSlot = inventory.getStackInSlot(internalSlot);
|
||||||
if (stackInSlot == null) {
|
if (stackInSlot == null || stackInSlot.stackSize == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (transactor == null) {
|
||||||
|
transactor = Transactor.getTransactorFor(outputTile);
|
||||||
|
if (transactor == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ItemStack clonedStack = stackInSlot.copy().splitStack(1);
|
ItemStack clonedStack = stackInSlot.copy().splitStack(1);
|
||||||
if (transactor.add(clonedStack, ForgeDirection.UP, true).stackSize > 0) {
|
if (transactor.add(clonedStack, ForgeDirection.UP, true).stackSize > 0) {
|
||||||
|
|
|
@ -406,7 +406,8 @@ public class TileQuarry extends TileAbstractBuilder implements IMachine, ISidedI
|
||||||
int k = targetZ;
|
int k = targetZ;
|
||||||
|
|
||||||
Block block = worldObj.getBlock(i, j, k);
|
Block block = worldObj.getBlock(i, j, k);
|
||||||
|
int meta = worldObj.getBlockMetadata(i, j, k);
|
||||||
|
|
||||||
if (isQuarriableBlock(i, j, k)) {
|
if (isQuarriableBlock(i, j, k)) {
|
||||||
// Share this with mining well!
|
// Share this with mining well!
|
||||||
|
|
||||||
|
@ -427,9 +428,9 @@ public class TileQuarry extends TileAbstractBuilder implements IMachine, ISidedI
|
||||||
j,
|
j,
|
||||||
k,
|
k,
|
||||||
Block.getIdFromBlock(block)
|
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);
|
worldObj.removeTileEntity(i, j, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue