Work on the ARC

Properly implemented the fluid handling for the input/output buckets.
This commit is contained in:
WayofTime 2020-10-27 19:54:46 -04:00
parent 4dfa414a56
commit fea894a2b2
3 changed files with 81 additions and 17 deletions

View file

@ -54,7 +54,9 @@ public class ScreenAlchemicalReactionChamber extends ScreenBase<ContainerAlchemi
// inputTank.fill(new FluidStack(Fluids.WATER, 1000), FluidAction.EXECUTE);
ClientHandler.handleGuiTank(stack, tileARC.inputTank, this.guiLeft + 8, this.guiTop
+ 40, 16, 63, 194, 0, 16, 64, mouseX, mouseY, background.toString(), tooltip);
+ 40, 16, 63, 194, 1, 16, 63, mouseX, mouseY, background.toString(), tooltip);
ClientHandler.handleGuiTank(stack, tileARC.outputTank, this.guiLeft + 152, this.guiTop
+ 15, 16, 63, 194, 1, 16, 63, mouseX, mouseY, background.toString(), tooltip);
if (!tooltip.isEmpty())
GuiUtils.drawHoveringText(stack, tooltip, mouseX, mouseY, width, height, -1, font);
@ -83,6 +85,8 @@ public class ScreenAlchemicalReactionChamber extends ScreenBase<ContainerAlchemi
ClientHandler.handleGuiTank(stack, tileARC.inputTank, this.guiLeft + 8, this.guiTop
+ 40, 16, 63, 194, 1, 16, 63, mouseX, mouseY, background.toString(), null);
ClientHandler.handleGuiTank(stack, tileARC.outputTank, this.guiLeft + 152, this.guiTop
+ 15, 16, 63, 194, 1, 16, 63, mouseX, mouseY, background.toString(), null);
// int l = this.getCookProgressScaled(90);
// this.blit(stack, i + 115, j + 14 + 90 - l, 176, 90 - l, 18, l);

View file

@ -5,6 +5,7 @@ import java.util.List;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.fluid.Fluids;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.ItemStack;
@ -13,10 +14,14 @@ import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.fluids.FluidActionResult;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction;
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
import net.minecraftforge.fluids.capability.templates.FluidTank;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.registries.ObjectHolder;
import wayoftime.bloodmagic.tile.contailer.ContainerAlchemicalReactionChamber;
import wayoftime.bloodmagic.util.Constants;
@ -60,7 +65,7 @@ public class TileAlchemicalReactionChamber extends TileInventory implements ITic
inputTank.readFromNBT(inputTankTag);
CompoundNBT outputTankTag = tag.getCompound("outputtank");
inputTank.readFromNBT(outputTankTag);
outputTank.readFromNBT(outputTankTag);
}
@Override
@ -75,7 +80,7 @@ public class TileAlchemicalReactionChamber extends TileInventory implements ITic
tag.put("inputtank", inputTankTag);
CompoundNBT outputTankTag = new CompoundNBT();
inputTank.writeToNBT(outputTankTag);
outputTank.writeToNBT(outputTankTag);
tag.put("outputtank", outputTankTag);
return tag;
@ -89,24 +94,74 @@ public class TileAlchemicalReactionChamber extends TileInventory implements ITic
return;
}
ItemStack bucketStack = this.getStackInSlot(INPUT_BUCKET_SLOT);
if (world.getGameTime() % 20 == 0)
{
outputTank.fill(new FluidStack(Fluids.WATER, 100), FluidAction.EXECUTE);
}
ItemStack fullBucketStack = this.getStackInSlot(INPUT_BUCKET_SLOT);
ItemStack emptyBucketStack = this.getStackInSlot(OUTPUT_BUCKET_SLOT);
ItemStack[] outputInventory = new ItemStack[]
{ getStackInSlot(1), getStackInSlot(2), getStackInSlot(3), getStackInSlot(4), getStackInSlot(5) };
MultiSlotItemHandler outputSlotHandler = new MultiSlotItemHandler(outputInventory, 64);
// FluidActionResult res = FluidUtil.tryEmptyContainerAndStow(bucketStack, inputTank, outputSlotHandler, 1000, null, false);
FluidActionResult res = FluidUtil.tryEmptyContainerAndStow(bucketStack, inputTank, outputSlotHandler, 1000, null, true);
if (res.isSuccess())
{
// FluidUtil.tryEmptyContainerAndStow(bucketStack, inputTank, outputSlotHandler, 1000, null, true);
this.setInventorySlotContents(INPUT_BUCKET_SLOT, ItemStack.EMPTY);
if (!res.getResult().isEmpty())
if (!fullBucketStack.isEmpty() && inputTank.getSpace() >= 1000)
{
ItemStack testFullBucketStack = ItemHandlerHelper.copyStackWithSize(fullBucketStack, 1);
LazyOptional<IFluidHandlerItem> fluidHandlerWrapper = FluidUtil.getFluidHandler(testFullBucketStack);
if (fluidHandlerWrapper.isPresent())
{
IFluidHandlerItem fluidHandler = fluidHandlerWrapper.resolve().get();
FluidStack transferedStack = FluidUtil.tryFluidTransfer(inputTank, fluidHandler, 1000, false);
if (!transferedStack.isEmpty())
{
fluidHandler.drain(transferedStack, FluidAction.EXECUTE);
List<ItemStack> arrayList = new ArrayList<>();
arrayList.add(res.getResult());
arrayList.add(fluidHandler.getContainer());
if (outputSlotHandler.canTransferAllItemsToSlots(arrayList, true))
{
inputTank.fill(transferedStack, FluidAction.EXECUTE);
outputSlotHandler.canTransferAllItemsToSlots(arrayList, false);
if (fullBucketStack.getCount() > 1)
{
fullBucketStack.setCount(fullBucketStack.getCount() - 1);
} else
{
setInventorySlotContents(INPUT_BUCKET_SLOT, ItemStack.EMPTY);
}
}
}
}
}
if (!emptyBucketStack.isEmpty() && outputTank.getFluidAmount() >= 1000)
{
ItemStack testEmptyBucketStack = ItemHandlerHelper.copyStackWithSize(emptyBucketStack, 1);
LazyOptional<IFluidHandlerItem> fluidHandlerWrapper = FluidUtil.getFluidHandler(testEmptyBucketStack);
if (fluidHandlerWrapper.isPresent())
{
IFluidHandlerItem fluidHandler = fluidHandlerWrapper.resolve().get();
FluidStack transferedStack = FluidUtil.tryFluidTransfer(fluidHandler, outputTank, 1000, false);
if (!transferedStack.isEmpty())
{
fluidHandler.fill(transferedStack, FluidAction.EXECUTE);
List<ItemStack> arrayList = new ArrayList<>();
arrayList.add(fluidHandler.getContainer());
if (outputSlotHandler.canTransferAllItemsToSlots(arrayList, true))
{
outputTank.drain(transferedStack, FluidAction.EXECUTE);
outputSlotHandler.canTransferAllItemsToSlots(arrayList, false);
if (emptyBucketStack.getCount() > 1)
{
emptyBucketStack.setCount(emptyBucketStack.getCount() - 1);
} else
{
setInventorySlotContents(OUTPUT_BUCKET_SLOT, ItemStack.EMPTY);
}
}
}
}
}

View file

@ -140,6 +140,8 @@ public class MultiSlotItemHandler implements IItemHandler
copyList[i] = items[i].copy();
}
boolean hasStashedAll = true;
for (ItemStack stack : stackList)
{
if (stack.isEmpty())
@ -167,12 +169,14 @@ public class MultiSlotItemHandler implements IItemHandler
if (stack.getCount() <= m)
{
ItemStack copy = stack.copy();
if (!simulate)
{
ItemStack copy = stack.copy();
copy.grow(stackInSlot.getCount());
copyList[slot] = copy;
}
stack = ItemStack.EMPTY;
// System.out.println("Count: " + stack.getCount() + ", m: " + m);
break slots;
} else
@ -220,6 +224,7 @@ public class MultiSlotItemHandler implements IItemHandler
if (!stack.isEmpty())
{
hasStashedAll = false;
break;
}
}
@ -229,7 +234,7 @@ public class MultiSlotItemHandler implements IItemHandler
items = copyList;
}
return false;
return hasStashedAll;
}
@Override