use of net.minecraftforge.fluids.FluidStack in project LogisticsPipes by RS485.
the class LogisticsFluidContainer method addInformation.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
super.addInformation(par1ItemStack, par2EntityPlayer, par3List, par4);
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
FluidStack stack = SimpleServiceLocator.logisticsFluidManager.getFluidFromContainer(ItemIdentifierStack.getFromStack(par1ItemStack));
if (stack != null) {
par3List.add("Type: " + stack.getFluid().getLocalizedName(stack));
par3List.add("Value: " + stack.amount + "mB");
}
}
}
use of net.minecraftforge.fluids.FluidStack in project LogisticsPipes by RS485.
the class PipeFluidUpdate method writeData.
@Override
public void writeData(LPDataOutput output) {
super.writeData(output);
for (int i = 0; i < renderCache.length; i++) {
bits.set(i, renderCache[i] != null);
}
output.writeBitSet(bits);
for (FluidStack aRenderCache : renderCache) {
if (aRenderCache != null) {
output.writeInt(FluidRegistry.getFluidID(aRenderCache.getFluid()));
output.writeInt(aRenderCache.amount);
output.writeNBTTagCompound(aRenderCache.tag);
}
}
}
use of net.minecraftforge.fluids.FluidStack 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.fluids.FluidStack in project LogisticsPipes by RS485.
the class PipeFluidExtractor method extractFrom.
private void extractFrom(IFluidHandler container, ForgeDirection side) {
int i = side.ordinal();
FluidStack contained = ((PipeFluidTransportLogistics) transport).getTankInfo(side)[0].fluid;
int amountMissing = ((PipeFluidTransportLogistics) transport).getSideCapacity() - (contained != null ? contained.amount : 0);
if (liquidToExtract[i] < Math.min(PipeFluidExtractor.flowRate, amountMissing)) {
if (this.useEnergy(PipeFluidExtractor.energyPerFlow)) {
liquidToExtract[i] += Math.min(PipeFluidExtractor.flowRate, amountMissing);
}
}
FluidStack extracted = container.drain(side.getOpposite(), liquidToExtract[i] > PipeFluidExtractor.flowRate ? PipeFluidExtractor.flowRate : liquidToExtract[i], false);
int inserted = 0;
if (extracted != null) {
inserted = ((PipeFluidTransportLogistics) transport).fill(side, extracted, true);
container.drain(side.getOpposite(), inserted, true);
}
liquidToExtract[i] -= inserted;
}
use of net.minecraftforge.fluids.FluidStack 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