Autocrafting can now fill water bottles with water from the fluid storage - regular bottles or pattern for regular bottles are required, fixes #964
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
- Exposed pattern inventory for Pattern Grid (raoulvdberge)
|
- Exposed pattern inventory for Pattern Grid (raoulvdberge)
|
||||||
- Fixed crashes relating to scrollbar in GUIs (raoulvdberge)
|
- Fixed crashes relating to scrollbar in GUIs (raoulvdberge)
|
||||||
- Added advancements (raoulvdberge)
|
- Added advancements (raoulvdberge)
|
||||||
|
- Autocrafting can now fill water bottles with water from the fluid storage - regular bottles or pattern for regular bottles are required (raoulvdberge)
|
||||||
|
|
||||||
### 1.5.6
|
### 1.5.6
|
||||||
- Updated Forge to stable 2387 (raoulvdberge)
|
- Updated Forge to stable 2387 (raoulvdberge)
|
||||||
|
|||||||
@@ -20,12 +20,14 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.init.Items;
|
import net.minecraft.init.Items;
|
||||||
|
import net.minecraft.init.PotionTypes;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.inventory.ISidedInventory;
|
import net.minecraft.inventory.ISidedInventory;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.potion.PotionUtils;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
@@ -68,6 +70,8 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
public final class RSUtils {
|
public final class RSUtils {
|
||||||
public static final ItemStack EMPTY_BUCKET = new ItemStack(Items.BUCKET);
|
public static final ItemStack EMPTY_BUCKET = new ItemStack(Items.BUCKET);
|
||||||
|
public static final ItemStack EMPTY_BOTTLE = new ItemStack(Items.GLASS_BOTTLE);
|
||||||
|
public static final ItemStack WATER_BOTTLE = PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.WATER);
|
||||||
|
|
||||||
public static final Comparator<IStorage> STORAGE_COMPARATOR = (left, right) -> {
|
public static final Comparator<IStorage> STORAGE_COMPARATOR = (left, right) -> {
|
||||||
int compare = Integer.compare(right.getPriority(), left.getPriority());
|
int compare = Integer.compare(right.getPriority(), left.getPriority());
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import net.minecraft.nbt.NBTTagList;
|
|||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraftforge.common.util.Constants;
|
import net.minecraftforge.common.util.Constants;
|
||||||
|
import net.minecraftforge.fluids.Fluid;
|
||||||
|
import net.minecraftforge.fluids.FluidRegistry;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -207,9 +209,15 @@ public abstract class CraftingStep implements ICraftingStep {
|
|||||||
|
|
||||||
protected AvailableType isItemAvailable(IStackList<ItemStack> items, IStackList<FluidStack> fluids, ItemStack stack, ItemStack actualStack, int compare) {
|
protected AvailableType isItemAvailable(IStackList<ItemStack> items, IStackList<FluidStack> fluids, ItemStack stack, ItemStack actualStack, int compare) {
|
||||||
if (actualStack == null || actualStack.isEmpty() || !items.trackedRemove(actualStack, stack.getCount())) {
|
if (actualStack == null || actualStack.isEmpty() || !items.trackedRemove(actualStack, stack.getCount())) {
|
||||||
FluidStack fluidInItem = RSUtils.getFluidFromStack(stack, true).getValue();
|
FluidStack fluidInItem;
|
||||||
|
|
||||||
if (fluidInItem != null && RSUtils.hasFluidBucket(fluidInItem)) {
|
if (API.instance().getComparer().isEqual(stack, RSUtils.WATER_BOTTLE)) {
|
||||||
|
FluidStack fluidStack = fluids.get(new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME), compare);
|
||||||
|
ItemStack emptyBottle = items.get(RSUtils.EMPTY_BOTTLE, compare);
|
||||||
|
if (emptyBottle != null && fluidStack != null && !emptyBottle.isEmpty() && items.trackedRemove(RSUtils.EMPTY_BOTTLE, 1)) {
|
||||||
|
return AvailableType.FLUID;
|
||||||
|
}
|
||||||
|
} else if ((fluidInItem = RSUtils.getFluidFromStack(stack, true).getValue()) != null && RSUtils.hasFluidBucket(fluidInItem)) {
|
||||||
FluidStack fluidStack = fluids.get(fluidInItem, compare);
|
FluidStack fluidStack = fluids.get(fluidInItem, compare);
|
||||||
ItemStack bucket = items.get(RSUtils.EMPTY_BUCKET, compare);
|
ItemStack bucket = items.get(RSUtils.EMPTY_BUCKET, compare);
|
||||||
if (bucket != null && fluidStack != null && !bucket.isEmpty() && fluids.trackedRemove(fluidStack, fluidInItem.amount) && items.trackedRemove(bucket, 1)) {
|
if (bucket != null && fluidStack != null && !bucket.isEmpty() && fluids.trackedRemove(fluidStack, fluidInItem.amount) && items.trackedRemove(bucket, 1)) {
|
||||||
@@ -235,8 +243,15 @@ public abstract class CraftingStep implements ICraftingStep {
|
|||||||
actualInputs.add(input);
|
actualInputs.add(input);
|
||||||
} else {
|
} else {
|
||||||
boolean abort = true;
|
boolean abort = true;
|
||||||
FluidStack fluidInItem = RSUtils.getFluidFromStack(insertStack, true).getValue();
|
FluidStack fluidInItem;
|
||||||
if (fluidInItem != null) {
|
if (API.instance().getComparer().isEqual(insertStack, RSUtils.WATER_BOTTLE)) {
|
||||||
|
FluidStack fluidStack = network.extractFluid(new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME), Fluid.BUCKET_VOLUME, compare, true); // Simulate is true because we won't actually get the fluid out of the storage for bottles!
|
||||||
|
ItemStack emptyBottleStack = network.extractItem(RSUtils.EMPTY_BOTTLE, 1, compare, false);
|
||||||
|
if (fluidStack != null && fluidStack.amount == Fluid.BUCKET_VOLUME && emptyBottleStack != null) {
|
||||||
|
abort = false;
|
||||||
|
actualInputs.add(insertStack.copy());
|
||||||
|
}
|
||||||
|
} else if ((fluidInItem = RSUtils.getFluidFromStack(insertStack, true).getValue()) != null) {
|
||||||
FluidStack fluidStack = network.extractFluid(fluidInItem, fluidInItem.amount, compare, false);
|
FluidStack fluidStack = network.extractFluid(fluidInItem, fluidInItem.amount, compare, false);
|
||||||
ItemStack bucketStack = network.extractItem(RSUtils.EMPTY_BUCKET, 1, compare, false);
|
ItemStack bucketStack = network.extractItem(RSUtils.EMPTY_BUCKET, 1, compare, false);
|
||||||
if (fluidStack != null && fluidStack.amount == fluidInItem.amount && bucketStack != null) {
|
if (fluidStack != null && fluidStack.amount == fluidInItem.amount && bucketStack != null) {
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import com.raoulvdberge.refinedstorage.apiimpl.util.StackListItem;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraftforge.fluids.Fluid;
|
||||||
|
import net.minecraftforge.fluids.FluidRegistry;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
@@ -273,9 +275,46 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean doFluidCalculation(IStackList<ItemStack> networkList, IStackList<FluidStack> networkFluidList, ItemStack input, IStackList<ItemStack> toInsert, List<ICraftingStep> previousSteps) {
|
private boolean doFluidCalculation(IStackList<ItemStack> networkList, IStackList<FluidStack> networkFluidList, ItemStack input, IStackList<ItemStack> toInsert, List<ICraftingStep> previousSteps) {
|
||||||
FluidStack fluidInItem = RSUtils.getFluidFromStack(input, true).getValue();
|
FluidStack fluidInItem;
|
||||||
|
|
||||||
if (fluidInItem != null && RSUtils.hasFluidBucket(fluidInItem)) {
|
if (API.instance().getComparer().isEqual(input, RSUtils.WATER_BOTTLE)) {
|
||||||
|
FluidStack fluidInStorage = networkFluidList.get(new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME));
|
||||||
|
|
||||||
|
if (fluidInStorage == null || fluidInStorage.amount < Fluid.BUCKET_VOLUME) {
|
||||||
|
missing.add(input);
|
||||||
|
} else {
|
||||||
|
ItemStack emptyBottle = toInsert.get(RSUtils.EMPTY_BOTTLE);
|
||||||
|
boolean hasBottle = false;
|
||||||
|
if (emptyBottle != null && emptyBottle.getCount() > 0) {
|
||||||
|
hasBottle = toInsert.remove(RSUtils.EMPTY_BOTTLE, 1);
|
||||||
|
}
|
||||||
|
if (!hasBottle) {
|
||||||
|
emptyBottle = networkList.get(RSUtils.EMPTY_BOTTLE);
|
||||||
|
if (emptyBottle != null && emptyBottle.getCount() > 0) {
|
||||||
|
hasBottle = networkList.remove(RSUtils.EMPTY_BOTTLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ICraftingPattern emptyBottlePattern = network.getCraftingManager().getPattern(RSUtils.EMPTY_BOTTLE);
|
||||||
|
|
||||||
|
if (!hasBottle) {
|
||||||
|
if (emptyBottlePattern == null) {
|
||||||
|
missing.add(RSUtils.EMPTY_BOTTLE.copy());
|
||||||
|
} else {
|
||||||
|
toCraft.add(RSUtils.EMPTY_BOTTLE.copy());
|
||||||
|
previousSteps.add(calculate(networkList, networkFluidList, emptyBottlePattern, toInsert));
|
||||||
|
toInsert.remove(RSUtils.EMPTY_BOTTLE, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasBottle || emptyBottlePattern != null) {
|
||||||
|
toTake.add(RSUtils.EMPTY_BOTTLE.copy());
|
||||||
|
networkList.remove(RSUtils.EMPTY_BOTTLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else if ((fluidInItem = RSUtils.getFluidFromStack(input, true).getValue()) != null && RSUtils.hasFluidBucket(fluidInItem)) {
|
||||||
FluidStack fluidInStorage = networkFluidList.get(fluidInItem);
|
FluidStack fluidInStorage = networkFluidList.get(fluidInItem);
|
||||||
|
|
||||||
if (fluidInStorage == null || fluidInStorage.amount < fluidInItem.amount) {
|
if (fluidInStorage == null || fluidInStorage.amount < fluidInItem.amount) {
|
||||||
|
|||||||
Reference in New Issue
Block a user