use of binnie.core.machines.power.ITankMachine in project Binnie by ForestryMC.
the class ContainerCraftGUI method sendTankChanges.
private void sendTankChanges() {
ITankMachine tanks = Machine.getInterface(ITankMachine.class, this.window.getInventory());
if (tanks != null && this.window.isServer()) {
for (int i = 0; i < tanks.getTankInfos().length; ++i) {
final TankInfo tank = tanks.getTankInfos()[i];
if (!this.getTankInfo(i).equals(tank)) {
this.syncedNBT.put("tank-update-" + i, this.createTankNBT(i, tank));
this.syncedTanks.put(i, tank);
}
}
}
}
use of binnie.core.machines.power.ITankMachine in project Binnie by ForestryMC.
the class TransferRequest method transfer.
public TransferResult transfer(@Nullable EntityPlayer player, boolean doAdd) {
ItemStack item = this.returnItem;
if (item.isEmpty() || this.destination == null) {
return TransferResult.FAILURE;
}
if (this.transferLiquids && this.destination instanceof ITankMachine && item.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) {
ITankMachine tankMachine = (ITankMachine) this.destination;
IFluidHandler fluidHandler = tankMachine.getHandler(targetTanks);
if (fluidHandler != null) {
ItemStack singleCopy = ItemHandlerHelper.copyStackWithSize(item, 1);
FluidActionResult fluidActionResult;
if (this.origin != null && doAdd) {
IItemHandler itemHandler = new InvWrapper(this.origin);
fluidActionResult = FluidUtil.tryEmptyContainerAndStow(singleCopy, fluidHandler, itemHandler, Fluid.BUCKET_VOLUME, player, doAdd);
if (!fluidActionResult.isSuccess()) {
fluidActionResult = FluidUtil.tryFillContainerAndStow(singleCopy, fluidHandler, itemHandler, Fluid.BUCKET_VOLUME, player, doAdd);
}
} else {
fluidActionResult = FluidUtil.tryEmptyContainer(singleCopy, fluidHandler, Fluid.BUCKET_VOLUME, player, doAdd);
if (!fluidActionResult.isSuccess()) {
fluidActionResult = FluidUtil.tryFillContainer(singleCopy, fluidHandler, Fluid.BUCKET_VOLUME, player, doAdd);
}
}
if (fluidActionResult.isSuccess()) {
if (item.getCount() == 1) {
return new TransferResult(fluidActionResult.result);
} else {
ItemStack itemCopy = item.copy();
itemCopy.shrink(1);
return new TransferResult(fluidActionResult.result, itemCopy);
}
}
return TransferResult.FAILURE;
}
}
if (!item.isEmpty()) {
for (final int slot : this.targetSlots) {
if (this.destination.isItemValidForSlot(slot, item) || this.ignoreReadOnly) {
if (this.destination instanceof IInventorySlots) {
InventorySlot inventorySlot = ((IInventorySlots) this.destination).getSlot(slot);
if (inventorySlot != null && inventorySlot.isRecipe()) {
continue;
}
}
ItemStack stackInSlot = this.destination.getStackInSlot(slot);
if (!stackInSlot.isEmpty()) {
if (item.isStackable()) {
final ItemStack merged = stackInSlot.copy();
final NonNullList<ItemStack> newStacks = mergeStacks(item.copy(), merged.copy());
item = newStacks.get(0);
if (!areItemsEqual(merged, newStacks.get(1))) {
this.insertedSlots.add(new TransferSlot(slot, this.destination));
}
if (doAdd) {
this.destination.setInventorySlotContents(slot, newStacks.get(1));
}
if (item.isEmpty()) {
return new TransferResult(ItemStack.EMPTY);
}
}
}
}
}
}
if (!item.isEmpty()) {
for (final int slot : this.targetSlots) {
if (this.destination.isItemValidForSlot(slot, item) || this.ignoreReadOnly) {
if (this.destination instanceof IInventorySlots) {
InventorySlot inventorySlot = ((IInventorySlots) this.destination).getSlot(slot);
if (inventorySlot != null && inventorySlot.isRecipe()) {
continue;
}
}
if (this.destination.getStackInSlot(slot).isEmpty()) {
this.insertedSlots.add(new TransferSlot(slot, this.destination));
if (doAdd) {
this.destination.setInventorySlotContents(slot, item.copy());
}
return new TransferResult(ItemStack.EMPTY);
}
}
}
}
this.setReturnItem(item);
return new TransferResult(item);
}
Aggregations