use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.
the class LogisticsTileGenericPipe method initialize.
public void initialize(CoreUnroutedPipe pipe) {
blockType = getBlockType();
if (pipe == null) {
LogisticsPipes.log.log(Level.WARN, "Pipe failed to initialize at {0},{1},{2}, deleting", xCoord, yCoord, zCoord);
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
return;
}
this.pipe = pipe;
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = getTile(o);
if (tile instanceof LogisticsTileGenericPipe) {
((LogisticsTileGenericPipe) tile).scheduleNeighborChange();
}
SimpleServiceLocator.buildCraftProxy.notifyOfChange(this, tile, o);
}
bindPipe();
computeConnections();
scheduleRenderUpdate();
if (pipe.needsInit()) {
pipe.initialize();
}
initialized = true;
}
use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.
the class LogisticsTileGenericPipe method computeConnections.
private void computeConnections() {
TileBuffer[] cache = getTileCache();
if (cache == null) {
return;
}
boolean[] pipeTDConnectionsBufferOld = pipeTDConnectionsBuffer.clone();
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
TileBuffer t = cache[side.ordinal()];
t.refresh();
pipeConnectionsBuffer[side.ordinal()] = canPipeConnect(t.getTile(), side);
if (pipeConnectionsBuffer[side.ordinal()]) {
pipeBCConnectionsBuffer[side.ordinal()] = SimpleServiceLocator.buildCraftProxy.isTileGenericPipe(t.getTile());
pipeTDConnectionsBuffer[side.ordinal()] = SimpleServiceLocator.thermalDynamicsProxy.isItemDuct(t.getTile());
} else {
pipeBCConnectionsBuffer[side.ordinal()] = false;
pipeTDConnectionsBuffer[side.ordinal()] = false;
}
}
if (!Arrays.equals(pipeTDConnectionsBufferOld, pipeTDConnectionsBuffer)) {
tdPart.connectionsChanged();
}
}
use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.
the class FluidRoutedPipe method endReached.
public boolean endReached(LPTravelingItemServer arrivingItem, TileEntity tile) {
if (canInsertToTanks() && MainProxy.isServer(getWorld())) {
getCacheHolder().trigger(CacheTypes.Inventory);
if (arrivingItem.getItemIdentifierStack() == null || !(arrivingItem.getItemIdentifierStack().getItem().isFluidContainer())) {
return false;
}
if (getRouter().getSimpleID() != arrivingItem.getDestination()) {
return false;
}
int filled = 0;
FluidStack liquid = SimpleServiceLocator.logisticsFluidManager.getFluidFromContainer(arrivingItem.getItemIdentifierStack());
if (isConnectableTank(tile, arrivingItem.output, false)) {
List<Pair<TileEntity, ForgeDirection>> adjTanks = getAdjacentTanks(false);
//Try to put liquid into all adjacent tanks.
for (Pair<TileEntity, ForgeDirection> pair : adjTanks) {
IFluidHandler tank = (IFluidHandler) pair.getValue1();
ForgeDirection dir = pair.getValue2();
filled = tank.fill(dir.getOpposite(), liquid.copy(), true);
liquid.amount -= filled;
if (liquid.amount != 0) {
continue;
}
return true;
}
//Try inserting the liquid into the pipe side tank
filled = ((PipeFluidTransportLogistics) transport).sideTanks[arrivingItem.output.ordinal()].fill(liquid, true);
if (filled == liquid.amount) {
return true;
}
liquid.amount -= filled;
}
//Try inserting the liquid into the pipe internal tank
filled = ((PipeFluidTransportLogistics) transport).internalTank.fill(liquid, true);
if (filled == liquid.amount) {
return true;
}
//If liquids still exist,
liquid.amount -= filled;
//TODO: FIX THIS
if (this instanceof IRequireReliableFluidTransport) {
((IRequireReliableFluidTransport) this).liquidNotInserted(FluidIdentifier.get(liquid), liquid.amount);
}
IRoutedItem routedItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(SimpleServiceLocator.logisticsFluidManager.getFluidContainer(liquid));
Pair<Integer, Integer> replies = SimpleServiceLocator.logisticsFluidManager.getBestReply(liquid, getRouter(), routedItem.getJamList());
int dest = replies.getValue1();
routedItem.setDestination(dest);
routedItem.setTransportMode(TransportMode.Passive);
this.queueRoutedItem(routedItem, arrivingItem.output.getOpposite());
return true;
}
return false;
}
use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.
the class PipeFluidBasic method sinkAmount.
@Override
public int sinkAmount(FluidStack stack) {
if (!guiOpenedBy.isEmpty()) {
//Don't sink when the gui is open
return 0;
}
FluidIdentifier ident = FluidIdentifier.get(stack);
if (filterInv.getStackInSlot(0) == null) {
return 0;
}
if (!ident.equals(FluidIdentifier.get(filterInv.getIDStackInSlot(0).getItem()))) {
return 0;
}
int onTheWay = this.countOnRoute(ident);
int freeSpace = -onTheWay;
for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(true)) {
FluidTank tank = ((PipeFluidTransportLogistics) transport).sideTanks[pair.getValue2().ordinal()];
freeSpace += ident.getFreeSpaceInsideTank((IFluidHandler) pair.getValue1(), pair.getValue2().getOpposite());
freeSpace += ident.getFreeSpaceInsideTank(tank);
if (freeSpace >= stack.amount) {
return stack.amount;
}
}
return freeSpace;
}
use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.
the class PipeFluidProvider method enabledUpdateEntity.
@Override
public void enabledUpdateEntity() {
super.enabledUpdateEntity();
if (!getFluidOrderManager().hasOrders(ResourceType.PROVIDER) || !isNthTick(6)) {
return;
}
LogisticsFluidOrder order = getFluidOrderManager().peekAtTopRequest(ResourceType.PROVIDER);
int amountToSend, attemptedAmount;
amountToSend = attemptedAmount = Math.min(order.getAmount(), 5000);
for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(false)) {
if (amountToSend <= 0) {
break;
}
boolean fallback = true;
if (SimpleServiceLocator.specialTankHandler.hasHandlerFor(pair.getValue1())) {
ISpecialTankHandler handler = SimpleServiceLocator.specialTankHandler.getTankHandlerFor(pair.getValue1());
if (handler instanceof ISpecialTankAccessHandler) {
fallback = false;
FluidStack drained = ((ISpecialTankAccessHandler) handler).drainFrom(pair.getValue1(), order.getFluid(), amountToSend, false);
if (drained != null && drained.amount > 0 && order.getFluid().equals(FluidIdentifier.get(drained))) {
drained = ((ISpecialTankAccessHandler) handler).drainFrom(pair.getValue1(), order.getFluid(), amountToSend, true);
int amount = drained.amount;
amountToSend -= amount;
ItemIdentifierStack stack = SimpleServiceLocator.logisticsFluidManager.getFluidContainer(drained);
IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stack);
item.setDestination(order.getRouter().getSimpleID());
item.setTransportMode(TransportMode.Active);
this.queueRoutedItem(item, pair.getValue2());
getFluidOrderManager().sendSuccessfull(amount, false, item);
if (amountToSend <= 0) {
break;
}
}
}
}
if (fallback) {
FluidTankInfo[] tanks = ((IFluidHandler) pair.getValue1()).getTankInfo(pair.getValue2().getOpposite());
if (tanks != null) {
for (FluidTankInfo tank : tanks) {
if (tank == null) {
continue;
}
FluidStack liquid;
if ((liquid = tank.fluid) != null && liquid.getFluidID() != 0) {
if (order.getFluid().equals(FluidIdentifier.get(liquid))) {
int amount = Math.min(liquid.amount, amountToSend);
FluidStack drained = ((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), amount, false);
if (drained != null && drained.amount > 0 && order.getFluid().equals(FluidIdentifier.get(drained))) {
drained = ((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), amount, true);
while (drained.amount < amountToSend) {
FluidStack addition = ((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), amountToSend - drained.amount, false);
if (addition != null && addition.amount > 0 && order.getFluid().equals(FluidIdentifier.get(addition))) {
addition = ((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), amountToSend - drained.amount, true);
drained.amount += addition.amount;
} else {
break;
}
}
amount = drained.amount;
amountToSend -= amount;
ItemIdentifierStack stack = SimpleServiceLocator.logisticsFluidManager.getFluidContainer(drained);
IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stack);
item.setDestination(order.getRouter().getSimpleID());
item.setTransportMode(TransportMode.Active);
this.queueRoutedItem(item, pair.getValue2());
getFluidOrderManager().sendSuccessfull(amount, false, item);
if (amountToSend <= 0) {
break;
}
}
}
}
}
}
}
}
if (amountToSend >= attemptedAmount) {
getFluidOrderManager().sendFailed();
}
}
Aggregations