mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-24 22:04:34 +00:00
Fix #1473 New Bottler issues
This commit is contained in:
1 parent
2191d00f3d
commit
411cbd913c
3 files changed
+64
-32
No files matched your search
@@ -53,6 +53,10 @@ public final class FluidHelper {
|
||||
}
|
||||
|
||||
public static FillStatus fillContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill, boolean doFill) {
|
||||
return fillContainers(fluidHandler, inv, inputSlot, outputSlot, fluidToFill, getEmptyContainer(inv.getStackInSlot(inputSlot)), doFill);
|
||||
}
|
||||
|
||||
public static FillStatus fillContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill, ItemStack emptyStack, boolean doFill) {
|
||||
if (fluidToFill == null) {
|
||||
return FillStatus.INVALID_INPUT;
|
||||
}
|
||||
@@ -66,13 +70,19 @@ public final class FluidHelper {
|
||||
ItemStack filled = input.copy();
|
||||
filled.stackSize = 1;
|
||||
|
||||
if(emptyStack == null){
|
||||
emptyStack = filled;
|
||||
}
|
||||
|
||||
IFluidHandler fluidFilledHandler = FluidUtil.getFluidHandler(filled);
|
||||
if (fluidFilledHandler == null) {
|
||||
IFluidHandler fluidEmptyHandler = FluidUtil.getFluidHandler(emptyStack);
|
||||
if (fluidFilledHandler == null || emptyStack != null && fluidEmptyHandler == null) {
|
||||
return FillStatus.INVALID_INPUT;
|
||||
}
|
||||
|
||||
int containerEmptyCapacity = fluidEmptyHandler.fill(new FluidStack(fluidToFill, Integer.MAX_VALUE), false);
|
||||
int containerCapacity = fluidFilledHandler.fill(new FluidStack(fluidToFill, Integer.MAX_VALUE), false);
|
||||
if (containerCapacity <= 0) {
|
||||
if (containerCapacity <= 0 && containerEmptyCapacity <= 0) {
|
||||
return FillStatus.INVALID_INPUT;
|
||||
}
|
||||
|
||||
@@ -90,7 +100,7 @@ public final class FluidHelper {
|
||||
return FillStatus.INVALID_INPUT;
|
||||
}
|
||||
|
||||
boolean moveToOutput = fluidInContainer.amount >= containerCapacity;
|
||||
boolean moveToOutput = fluidInContainer.amount >= containerEmptyCapacity;
|
||||
if (moveToOutput) {
|
||||
if (output != null && (output.stackSize >= output.getMaxStackSize() || !InventoryUtil.isItemEqual(filled, output))) {
|
||||
return FillStatus.NO_SPACE;
|
||||
@@ -145,7 +155,7 @@ public final class FluidHelper {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static FillStatus drainContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot) {
|
||||
public static FillStatus drainContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, boolean doDrain) {
|
||||
ItemStack input = inv.getStackInSlot(inputSlot);
|
||||
if (input == null) {
|
||||
return FillStatus.INVALID_INPUT;
|
||||
@@ -158,23 +168,26 @@ public final class FluidHelper {
|
||||
}
|
||||
|
||||
if (outputStack == null || drainedItemSimulated.stackSize == 0 || ItemStackUtil.isIdenticalItem(outputStack, drainedItemSimulated) && outputStack.stackSize + drainedItemSimulated.stackSize < outputStack.getMaxStackSize()) {
|
||||
ItemStack drainedItem = FluidUtil.tryEmptyContainer(input, fluidHandler, Fluid.BUCKET_VOLUME, null, true);
|
||||
|
||||
if (drainedItem != null) {
|
||||
if(drainedItem.stackSize > 0){
|
||||
ItemStack newStack = drainedItem.copy();
|
||||
if(outputStack != null){
|
||||
newStack.stackSize+=outputStack.stackSize;
|
||||
}
|
||||
if (isFillableContainerAndEmpty(newStack)) {
|
||||
inv.setInventorySlotContents(outputSlot, newStack);
|
||||
if(doDrain){
|
||||
ItemStack drainedItem = FluidUtil.tryEmptyContainer(input, fluidHandler, Fluid.BUCKET_VOLUME, null, true);
|
||||
|
||||
if (drainedItem != null) {
|
||||
if(drainedItem.stackSize > 0){
|
||||
ItemStack newStack = drainedItem.copy();
|
||||
if(outputStack != null){
|
||||
newStack.stackSize+=outputStack.stackSize;
|
||||
}
|
||||
if (isFillableContainerAndEmpty(newStack)) {
|
||||
inv.setInventorySlotContents(outputSlot, newStack);
|
||||
inv.decrStackSize(inputSlot, 1);
|
||||
}
|
||||
}else {
|
||||
inv.decrStackSize(inputSlot, 1);
|
||||
}
|
||||
}else {
|
||||
inv.decrStackSize(inputSlot, 1);
|
||||
return FillStatus.SUCCESS;
|
||||
}
|
||||
return FillStatus.SUCCESS;
|
||||
}
|
||||
return FillStatus.SUCCESS;
|
||||
}
|
||||
|
||||
return FillStatus.NO_SPACE;
|
||||
@@ -200,7 +213,23 @@ public final class FluidHelper {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static ItemStack getEmptyContainer(ItemStack container){
|
||||
if(container == null){
|
||||
return null;
|
||||
}
|
||||
ItemStack empty = container.copy();
|
||||
empty.stackSize = 1;
|
||||
IFluidHandler fluidHandler = FluidUtil.getFluidHandler(empty);
|
||||
if (fluidHandler == null) {
|
||||
return null;
|
||||
}
|
||||
if(fluidHandler.drain(Integer.MAX_VALUE, true) != null){
|
||||
return empty;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isFillableContainerWithRoom(ItemStack container) {
|
||||
IFluidHandler fluidHandler = FluidUtil.getFluidHandler(container);
|
||||
if (fluidHandler == null) {
|
||||
|
||||
@@ -32,9 +32,9 @@ public class BottlerRecipe {
|
||||
return null;
|
||||
}
|
||||
|
||||
FluidStack fill = fluidHandler.drain(Integer.MAX_VALUE, true);
|
||||
if (fill != null && fill.amount > 0) {
|
||||
return new BottlerRecipe(empty, fill, filled, false);
|
||||
FluidStack drained = fluidHandler.drain(Integer.MAX_VALUE, true);
|
||||
if (drained != null && drained.amount > 0) {
|
||||
return new BottlerRecipe(empty, drained, filled, false);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -73,9 +73,9 @@ public class BottlerRecipe {
|
||||
this.outputStack = outputStack;
|
||||
this.fillRecipe = fillRecipe;
|
||||
}
|
||||
|
||||
|
||||
public boolean matchEmpty(ItemStack emptyCan, FluidStack resource) {
|
||||
return emptyCan != null && resource != null && emptyCan.isItemEqual(inputStack) && resource.containsFluid(fluid) && fillRecipe;
|
||||
return emptyCan != null && resource != null && emptyCan.isItemEqual(inputStack) && resource.isFluidEqual(fluid) && fillRecipe;
|
||||
}
|
||||
|
||||
public boolean matchFilled(ItemStack filledCan) {
|
||||
|
||||
@@ -178,7 +178,7 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid
|
||||
if(currentRecipe.fillRecipe){
|
||||
status = FluidHelper.fillContainers(tankManager, this, InventoryBottler.SLOT_RIGHT_PROCESSING, InventoryBottler.SLOT_OUTPUT_FULL_CONTAINER, currentRecipe.fluid.getFluid(), true);
|
||||
}else{
|
||||
status = FluidHelper.drainContainers(tankManager, this, InventoryBottler.SLOT_LEFT_PROCESSING, InventoryBottler.SLOT_OUTPUT_EMPTY_CONTAINER);
|
||||
status = FluidHelper.drainContainers(tankManager, this, InventoryBottler.SLOT_LEFT_PROCESSING, InventoryBottler.SLOT_OUTPUT_EMPTY_CONTAINER, true);
|
||||
}
|
||||
if(status == FluidHelper.FillStatus.SUCCESS){
|
||||
currentRecipe = null;
|
||||
@@ -246,9 +246,15 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid
|
||||
@Override
|
||||
public void onPickupFromSlot(int slotIndex, EntityPlayer player) {
|
||||
if(slotIndex == InventoryBottler.SLOT_LEFT_PROCESSING){
|
||||
setTicksPerWorkCycle(0);
|
||||
if(currentRecipe != null && !currentRecipe.fillRecipe){
|
||||
currentRecipe = null;
|
||||
setTicksPerWorkCycle(0);
|
||||
}
|
||||
}else if(slotIndex == InventoryBottler.SLOT_RIGHT_PROCESSING){
|
||||
setTicksPerWorkCycle(0);
|
||||
if(currentRecipe != null && currentRecipe.fillRecipe){
|
||||
currentRecipe = null;
|
||||
setTicksPerWorkCycle(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,11 +296,7 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid
|
||||
if (currentRecipe != null) {
|
||||
IFluidTankProperties properties = tankManager.getTankProperties()[0];
|
||||
if(properties != null){
|
||||
if(properties.getContents() != null && properties.getContents().amount >= properties.getCapacity()){
|
||||
emptyStatus = FillStatus.NO_SPACE_FLUID;
|
||||
}else{
|
||||
emptyStatus = FillStatus.SUCCESS;
|
||||
}
|
||||
emptyStatus = FluidHelper.drainContainers(tankManager, this, InventoryBottler.SLOT_LEFT_PROCESSING, InventoryBottler.SLOT_OUTPUT_EMPTY_CONTAINER, false);
|
||||
}else{
|
||||
emptyStatus = FillStatus.SUCCESS;
|
||||
}
|
||||
@@ -304,7 +306,7 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid
|
||||
if(emptyStatus == null || emptyStatus != FillStatus.SUCCESS){
|
||||
checkFillRecipe();
|
||||
if (currentRecipe == null) {
|
||||
fillStatus = FluidHelper.FillStatus.NO_FLUID;
|
||||
return false;
|
||||
}else{
|
||||
fillStatus = FluidHelper.fillContainers(tankManager, this, InventoryBottler.SLOT_RIGHT_PROCESSING, InventoryBottler.SLOT_OUTPUT_FULL_CONTAINER, currentRecipe.fluid.getFluid(), false);
|
||||
}
|
||||
@@ -320,6 +322,7 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid
|
||||
errorLogic.setCondition(fillStatus == FluidHelper.FillStatus.NO_SPACE, EnumErrorCode.NO_SPACE_INVENTORY);
|
||||
errorLogic.setCondition(emptyStatus == FluidHelper.FillStatus.NO_SPACE_FLUID, EnumErrorCode.NO_SPACE_TANK);
|
||||
if(emptyStatus == FillStatus.INVALID_INPUT || fillStatus == FillStatus.INVALID_INPUT || errorLogic.hasErrors()){
|
||||
currentRecipe = null;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user