optimize chutes further
This commit is contained in:
parent
b9657e8bbc
commit
0b4ec5b84b
3 changed files with 35 additions and 17 deletions
|
@ -23,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 boolean isEmpty;
|
||||
private TileEntity outputTile;
|
||||
|
||||
@Override
|
||||
|
@ -37,6 +38,8 @@ public class TileHopper extends TileBuildCraft implements IInventory {
|
|||
}
|
||||
|
||||
inventory.readFromNBT(p);
|
||||
|
||||
refreshInventoryFlags();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,7 +52,8 @@ public class TileHopper extends TileBuildCraft implements IInventory {
|
|||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
if (worldObj.isRemote || worldObj.getTotalWorldTime() % 2 != 0) {
|
||||
if (worldObj.isRemote || isEmpty ||
|
||||
worldObj.getTotalWorldTime() % 2 != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -66,21 +70,18 @@ public class TileHopper extends TileBuildCraft implements IInventory {
|
|||
}
|
||||
}
|
||||
|
||||
ITransactor transactor = null;
|
||||
|
||||
ITransactor transactor = Transactor.getTransactorFor(outputTile);
|
||||
|
||||
if (transactor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int internalSlot = 0; internalSlot < inventory.getSizeInventory(); internalSlot++) {
|
||||
ItemStack stackInSlot = inventory.getStackInSlot(internalSlot);
|
||||
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);
|
||||
|
@ -89,6 +90,18 @@ public class TileHopper extends TileBuildCraft implements IInventory {
|
|||
}
|
||||
}
|
||||
|
||||
private void refreshInventoryFlags() {
|
||||
isEmpty = true;
|
||||
|
||||
for (int internalSlot = 0; internalSlot < inventory.getSizeInventory(); internalSlot++) {
|
||||
ItemStack stackInSlot = inventory.getStackInSlot(internalSlot);
|
||||
if (stackInSlot != null && stackInSlot.stackSize > 0) {
|
||||
isEmpty = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* IInventory Implementation *
|
||||
*/
|
||||
|
@ -104,17 +117,22 @@ public class TileHopper extends TileBuildCraft implements IInventory {
|
|||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slotId, int count) {
|
||||
return inventory.decrStackSize(slotId, count);
|
||||
ItemStack output = inventory.decrStackSize(slotId, count);
|
||||
refreshInventoryFlags();
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slotId) {
|
||||
return inventory.getStackInSlotOnClosing(slotId);
|
||||
ItemStack output = inventory.getStackInSlotOnClosing(slotId);
|
||||
refreshInventoryFlags();
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slotId, ItemStack itemStack) {
|
||||
inventory.setInventorySlotContents(slotId, itemStack);
|
||||
refreshInventoryFlags();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -38,14 +38,11 @@ import net.minecraft.util.MovingObjectPosition;
|
|||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.BuildCraftTransport;
|
||||
import buildcraft.api.core.BCLog;
|
||||
import buildcraft.api.core.BlockIndex;
|
||||
|
@ -54,6 +51,7 @@ import buildcraft.api.events.PipePlacedEvent;
|
|||
import buildcraft.api.events.RobotPlacementEvent;
|
||||
import buildcraft.api.gates.GateExpansions;
|
||||
import buildcraft.api.gates.IGateExpansion;
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
import buildcraft.api.transport.PipeWire;
|
||||
import buildcraft.core.BlockBuildCraft;
|
||||
|
@ -791,7 +789,7 @@ public class BlockGenericPipe extends BlockBuildCraft {
|
|||
DockingStation station = pipe.container.getStation(rayTraceResult.sideHit);
|
||||
|
||||
if (!station.isTaken()) {
|
||||
if (((ItemRobot) currentItem.getItem()).getRobotNBT(currentItem) == null) {
|
||||
if (ItemRobot.getRobotNBT(currentItem) == null) {
|
||||
return true;
|
||||
}
|
||||
RobotPlacementEvent robotEvent = new RobotPlacementEvent(player, ((NBTTagCompound) currentItem.stackTagCompound.getTag("board")).getString("id"));
|
||||
|
@ -802,7 +800,7 @@ public class BlockGenericPipe extends BlockBuildCraft {
|
|||
EntityRobot robot = ((ItemRobot) currentItem.getItem())
|
||||
.createRobot(currentItem, world);
|
||||
robot.setUniqueRobotId(robot.getRegistry().getNextRobotId());
|
||||
robot.getBattery().setEnergy(EntityRobot.MAX_ENERGY);
|
||||
robot.getBattery().setEnergy(EntityRobotBase.MAX_ENERGY);
|
||||
|
||||
float px = x + 0.5F + rayTraceResult.sideHit.offsetX * 0.5F;
|
||||
float py = y + 0.5F + rayTraceResult.sideHit.offsetY * 0.5F;
|
||||
|
|
|
@ -355,6 +355,7 @@ public class ItemFacade extends ItemBuildCraft implements IFacadeItem {
|
|||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block[] getBlocksForFacade(ItemStack stack) {
|
||||
FacadeState[] states = getFacadeStates(stack);
|
||||
Block[] blocks = new Block[states.length];
|
||||
|
@ -364,6 +365,7 @@ public class ItemFacade extends ItemBuildCraft implements IFacadeItem {
|
|||
return blocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getMetaValuesForFacade(ItemStack stack) {
|
||||
FacadeState[] states = getFacadeStates(stack);
|
||||
int[] meta = new int[states.length];
|
||||
|
|
Loading…
Reference in a new issue