refactor TileBuffers to be in TileBuildCraft, optimize tanks and hoppers further
This commit is contained in:
parent
86e2fde283
commit
e0c6a026c2
7 changed files with 39 additions and 61 deletions
|
@ -13,6 +13,7 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -35,7 +36,8 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
|
|||
private static Map<Class, TilePacketWrapper> updateWrappers = new HashMap<Class, TilePacketWrapper>();
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static Map<Class, TilePacketWrapper> descriptionWrappers = new HashMap<Class, TilePacketWrapper>();
|
||||
|
||||
|
||||
protected TileBuffer[] cache;
|
||||
protected HashSet<EntityPlayer> guiWatchers = new HashSet<EntityPlayer>();
|
||||
|
||||
private final TilePacketWrapper descriptionPacket;
|
||||
|
@ -81,10 +83,17 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
super.validate();
|
||||
cache = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
init = false;
|
||||
super.invalidate();
|
||||
cache = null;
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
|
@ -98,6 +107,7 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
|
|||
}
|
||||
|
||||
public void destroy() {
|
||||
cache = null;
|
||||
}
|
||||
|
||||
public void sendNetworkUpdate() {
|
||||
|
@ -219,4 +229,18 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
|
|||
protected void setBattery(RFBattery battery) {
|
||||
this.battery = battery;
|
||||
}
|
||||
|
||||
public Block getBlock(ForgeDirection side) {
|
||||
if (cache == null) {
|
||||
cache = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, false);
|
||||
}
|
||||
return cache[side.ordinal()].getBlock();
|
||||
}
|
||||
|
||||
public TileEntity getTile(ForgeDirection side) {
|
||||
if (cache == null) {
|
||||
cache = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, false);
|
||||
}
|
||||
return cache[side.ordinal()].getTile();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,6 @@ public abstract class TileEngine extends TileBuildCraft implements IPipeConnecti
|
|||
protected boolean lastPower = false;
|
||||
|
||||
private boolean checkOrientation = false;
|
||||
private TileBuffer[] tileCache;
|
||||
|
||||
@NetworkData
|
||||
private boolean isPumping = false; // Used for SMP synch
|
||||
|
@ -211,7 +210,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPipeConnecti
|
|||
if (!isOrientationValid()) {
|
||||
switchOrientation(true);
|
||||
} else {
|
||||
TileEntity tile = getTileBuffer(orientation).getTile();
|
||||
TileEntity tile = getTile(orientation);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,7 +218,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPipeConnecti
|
|||
getEnergyStage();
|
||||
engineUpdate();
|
||||
|
||||
TileEntity tile = getTileBuffer(orientation).getTile();
|
||||
TileEntity tile = getTile(orientation);
|
||||
|
||||
if (progressPart != 0) {
|
||||
progress += getPistonSpeed();
|
||||
|
@ -257,7 +256,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPipeConnecti
|
|||
}
|
||||
|
||||
private int getPowerToExtract() {
|
||||
TileEntity tile = getTileBuffer(orientation).getTile();
|
||||
TileEntity tile = getTile(orientation);
|
||||
|
||||
if (tile instanceof IEngine) {
|
||||
IEngine engine = (IEngine) tile;
|
||||
|
@ -279,7 +278,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPipeConnecti
|
|||
}
|
||||
|
||||
protected void sendPower() {
|
||||
TileEntity tile = getTileBuffer(orientation).getTile();
|
||||
TileEntity tile = getTile(orientation);
|
||||
if (isPoweredTile(tile, orientation)) {
|
||||
int extracted = getPowerToExtract();
|
||||
if (extracted <= 0) {
|
||||
|
@ -339,7 +338,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPipeConnecti
|
|||
}
|
||||
|
||||
public boolean isOrientationValid() {
|
||||
TileEntity tile = getTileBuffer(orientation).getTile();
|
||||
TileEntity tile = getTile(orientation);
|
||||
|
||||
return isPoweredTile(tile, orientation);
|
||||
}
|
||||
|
@ -356,7 +355,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPipeConnecti
|
|||
for (int i = orientation.ordinal() + 1; i <= orientation.ordinal() + 6; ++i) {
|
||||
ForgeDirection o = ForgeDirection.VALID_DIRECTIONS[i % 6];
|
||||
|
||||
TileEntity tile = getTileBuffer(o).getTile();
|
||||
TileEntity tile = getTile(o);
|
||||
|
||||
if ((!pipesOnly || tile instanceof IPipeTile) && isPoweredTile(tile, o)) {
|
||||
orientation = o;
|
||||
|
@ -370,25 +369,15 @@ public abstract class TileEngine extends TileBuildCraft implements IPipeConnecti
|
|||
return false;
|
||||
}
|
||||
|
||||
public TileBuffer getTileBuffer(ForgeDirection side) {
|
||||
if (tileCache == null) {
|
||||
tileCache = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, false);
|
||||
}
|
||||
|
||||
return tileCache[side.ordinal()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
tileCache = null;
|
||||
checkOrientation = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
super.validate();
|
||||
tileCache = null;
|
||||
checkOrientation = true;
|
||||
}
|
||||
|
||||
|
@ -526,7 +515,6 @@ public abstract class TileEngine extends TileBuildCraft implements IPipeConnecti
|
|||
public void onNeighborUpdate() {
|
||||
checkRedstonePower();
|
||||
checkOrientation = true;
|
||||
tileCache = null;
|
||||
}
|
||||
// RF support
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ public class TileEngineWood extends TileEngine {
|
|||
if (progressPart == 2 && !hasSent) {
|
||||
hasSent = true;
|
||||
|
||||
TileEntity tile = getTileBuffer(orientation).getTile();
|
||||
TileEntity tile = getTile(orientation);
|
||||
|
||||
if (tile instanceof IPipeTile && ((IPipeTile) tile).getPipeType() != PipeType.POWER) {
|
||||
super.sendPower();
|
||||
|
|
|
@ -24,7 +24,6 @@ public class TileHopper extends TileBuildCraft implements IInventory {
|
|||
|
||||
private final SimpleInventory inventory = new SimpleInventory(4, "Hopper", 64);
|
||||
private boolean isEmpty;
|
||||
private TileEntity outputTile;
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
@ -61,18 +60,7 @@ public class TileHopper extends TileBuildCraft implements IInventory {
|
|||
return;
|
||||
}
|
||||
|
||||
if (outputTile == null || outputTile.isInvalid()) {
|
||||
Block block = worldObj.getBlock(xCoord, yCoord - 1, zCoord);
|
||||
outputTile = null;
|
||||
|
||||
if (block.hasTileEntity(worldObj.getBlockMetadata(xCoord, yCoord - 1, zCoord))) {
|
||||
outputTile = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord);
|
||||
}
|
||||
|
||||
if (outputTile == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
TileEntity outputTile = getTile(ForgeDirection.DOWN);
|
||||
|
||||
ITransactor transactor = Transactor.getTransactorFor(outputTile);
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@ public class TilePump extends TileBuildCraft implements IHasWork, IFluidHandler
|
|||
private double tubeY = Double.NaN;
|
||||
private int aimY = 0;
|
||||
|
||||
private TileBuffer[] tileBuffer = null;
|
||||
private SafeTimeTracker timer = new SafeTimeTracker(REBUID_DELAY);
|
||||
private int tick = Utils.RANDOM.nextInt();
|
||||
private int numFluidBlocksFound = 0;
|
||||
|
@ -157,19 +156,11 @@ public class TilePump extends TileBuildCraft implements IHasWork, IFluidHandler
|
|||
}
|
||||
|
||||
private void pushToConsumers() {
|
||||
if (tileBuffer == null) {
|
||||
tileBuffer = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, false);
|
||||
if (cache == null) {
|
||||
cache = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, false);
|
||||
}
|
||||
|
||||
FluidUtils.pushFluidToConsumers(tank, 400, tileBuffer);
|
||||
}
|
||||
|
||||
private TileEntity getTile(ForgeDirection side) {
|
||||
if (tileBuffer == null) {
|
||||
tileBuffer = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, false);
|
||||
}
|
||||
|
||||
return tileBuffer[side.ordinal()].getTile();
|
||||
FluidUtils.pushFluidToConsumers(tank, 400, cache);
|
||||
}
|
||||
|
||||
private void createTube() {
|
||||
|
@ -429,13 +420,11 @@ public class TilePump extends TileBuildCraft implements IHasWork, IFluidHandler
|
|||
|
||||
@Override
|
||||
public void validate() {
|
||||
tileBuffer = null;
|
||||
super.validate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
tileBuffer = null;
|
||||
pumpLayerQueues.clear();
|
||||
destroyTube();
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ public class TileTank extends TileBuildCraft implements IFluidHandler {
|
|||
}
|
||||
|
||||
public static TileTank getTankBelow(TileTank tile) {
|
||||
TileEntity below = tile.getWorldObj().getTileEntity(tile.xCoord, tile.yCoord - 1, tile.zCoord);
|
||||
TileEntity below = tile.getTile(ForgeDirection.DOWN);
|
||||
if (below instanceof TileTank) {
|
||||
return (TileTank) below;
|
||||
} else {
|
||||
|
@ -140,7 +140,7 @@ public class TileTank extends TileBuildCraft implements IFluidHandler {
|
|||
}
|
||||
|
||||
public static TileTank getTankAbove(TileTank tile) {
|
||||
TileEntity above = tile.getWorldObj().getTileEntity(tile.xCoord, tile.yCoord + 1, tile.zCoord);
|
||||
TileEntity above = tile.getTile(ForgeDirection.UP);
|
||||
if (above instanceof TileTank) {
|
||||
return (TileTank) above;
|
||||
} else {
|
||||
|
|
|
@ -63,7 +63,6 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
private boolean craftable;
|
||||
private boolean justCrafted;
|
||||
private IRecipe currentRecipe;
|
||||
private TileBuffer[] cache;
|
||||
private InventoryCraftResult craftResult;
|
||||
private InternalInventoryCrafting internalInventoryCrafting;
|
||||
|
||||
|
@ -219,12 +218,6 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
return (getEnergy() * i) / REQUIRED_POWER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
cache = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
@ -361,10 +354,6 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
}
|
||||
|
||||
private void searchNeighborsForIngredients() {
|
||||
if (cache == null) {
|
||||
cache = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, false);
|
||||
}
|
||||
|
||||
for (IInvSlot slot : InventoryIterator.getIterable(craftingSlots, ForgeDirection.UP)) {
|
||||
ItemStack ingred = slot.getStackInSlot();
|
||||
|
||||
|
@ -376,7 +365,7 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
|
||||
if (InvUtils.countItems(invInput, ForgeDirection.UP, filter) < InvUtils.countItems(craftingSlots, ForgeDirection.UP, filter)) {
|
||||
for (ForgeDirection side : SEARCH_SIDES) {
|
||||
TileEntity tile = cache[side.ordinal()].getTile();
|
||||
TileEntity tile = getTile(side);
|
||||
|
||||
if (tile instanceof IInventory) {
|
||||
IInventory inv = InvUtils.getInventory((IInventory) tile);
|
||||
|
|
Loading…
Reference in a new issue