mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-22 12:59:41 +00:00
Fix purification chamber being able to accept wrong gases directly from IGasItems #5502
Also improved handling overall for how IGasItem is treated by the GasConversionHandler, so that we better obey the gastank we are going to try and insert into
This commit is contained in:
7 files changed
+73
-89
No files matched your search
@@ -5,7 +5,6 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import javax.annotation.Nullable;
|
||||
import mekanism.api.gas.Gas;
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.common.InfuseStorage;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.block.states.BlockStateMachine.MachineType;
|
||||
@@ -174,14 +173,6 @@ public interface IFactory {
|
||||
return getRecipe(slotStack);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public GasStack getItemGas(ItemStack itemstack) {
|
||||
if (fuelType == MachineFuelType.ADVANCED) {
|
||||
return getTile().getItemGas(itemstack);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getSecondaryEnergyPerTick() {
|
||||
if (fuelType == MachineFuelType.ADVANCED) {
|
||||
return getTile().BASE_SECONDARY_ENERGY_PER_TICK;
|
||||
@@ -200,13 +191,6 @@ public interface IFactory {
|
||||
return fuelType == MachineFuelType.ADVANCED;
|
||||
}
|
||||
|
||||
public boolean isValidGas(Gas gas) {
|
||||
if (fuelType == MachineFuelType.ADVANCED) {
|
||||
return getTile().isValidGas(gas);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasRecipe(ItemStack itemStack) {
|
||||
if (itemStack.isEmpty()) {
|
||||
return false;
|
||||
|
||||
@@ -93,7 +93,7 @@ public class ContainerFactory extends ContainerMekanism<TileEntityFactory> {
|
||||
} else if (!mergeItemStack(slotStack, 0, 1, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (tileEntity.getRecipeType().getItemGas(slotStack) != null) {
|
||||
} else if (tileEntity.getItemGas(slotStack) != null) {
|
||||
if (transferExtraSlot(slotID, slotStack)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@@ -7,9 +7,12 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import mekanism.api.gas.Gas;
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.gas.GasTank;
|
||||
import mekanism.api.gas.IGasItem;
|
||||
import mekanism.common.MekanismFluids;
|
||||
import mekanism.common.recipe.ingredients.IMekanismIngredient;
|
||||
@@ -82,22 +85,40 @@ public class GasConversionHandler {
|
||||
ingredientToGas.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an item gas checking if it will be valid for a specific tank and if the type is also valid.
|
||||
*/
|
||||
@Nullable
|
||||
public static GasStack getItemGas(ItemStack itemStack, GasTank gasTank, Predicate<Gas> isValidGas) {
|
||||
return getItemGas(itemStack, gasTank.getNeeded(), (gas, quantity) -> {
|
||||
if (gas != null && gasTank.canReceive(gas) && isValidGas.test(gas)) {
|
||||
return new GasStack(gas, quantity);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the amount of ticks the declared itemstack can fuel this machine.
|
||||
*
|
||||
* @param itemStack - itemstack to check with
|
||||
* @param itemStack - itemstack to check with.
|
||||
* @param needed The max amount we need for use with IGasItem's so that we do not return a value that is too large, thus making it so it thinks there is no room.
|
||||
*
|
||||
* @return fuel ticks
|
||||
*/
|
||||
public static GasStack getItemGas(ItemStack itemStack, BiFunction<Gas, Integer, GasStack> getIfValid) {
|
||||
@Nullable
|
||||
public static GasStack getItemGas(ItemStack itemStack, int needed, BiFunction<Gas, Integer, GasStack> getIfValid) {
|
||||
if (itemStack.getItem() instanceof IGasItem) {
|
||||
IGasItem item = (IGasItem) itemStack.getItem();
|
||||
GasStack gas = item.getGas(itemStack);
|
||||
//Check to make sure it can provide the gas it contains
|
||||
if (gas != null && item.canProvideGas(itemStack, gas.getGas())) {
|
||||
GasStack gasStack = getIfValid.apply(gas.getGas(), 1);
|
||||
if (gasStack != null) {
|
||||
return gasStack;
|
||||
int amount = Math.min(needed, Math.min(gas.amount, item.getRate(itemStack)));
|
||||
if (amount > 0) {
|
||||
GasStack gasStack = getIfValid.apply(gas.getGas(), amount);
|
||||
if (gasStack != null) {
|
||||
return gasStack;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.util.Map;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.gas.Gas;
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.gas.IGasItem;
|
||||
import mekanism.api.transmitters.TransmissionType;
|
||||
import mekanism.common.SideData;
|
||||
import mekanism.common.block.states.BlockStateMachine.MachineType;
|
||||
@@ -12,7 +11,6 @@ import mekanism.common.recipe.RecipeHandler.Recipe;
|
||||
import mekanism.common.recipe.inputs.AdvancedMachineInput;
|
||||
import mekanism.common.recipe.machines.InjectionRecipe;
|
||||
import mekanism.common.tile.prefab.TileEntityAdvancedElectricMachine;
|
||||
import mekanism.common.util.GasUtils;
|
||||
import mekanism.common.util.InventoryUtils;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
@@ -46,19 +44,6 @@ public class TileEntityChemicalInjectionChamber extends TileEntityAdvancedElectr
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSecondaryFuel() {
|
||||
if (!inventory.get(1).isEmpty() && gasTank.getNeeded() > 0 && inventory.get(1).getItem() instanceof IGasItem) {
|
||||
GasStack gas = ((IGasItem) inventory.get(1).getItem()).getGas(inventory.get(1));
|
||||
if (gas != null && isValidGas(gas.getGas())) {
|
||||
GasStack removed = GasUtils.removeGas(inventory.get(1), gasTank.getGasType(), gasTank.getNeeded());
|
||||
gasTank.receive(removed, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
super.handleSecondaryFuel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidGas(Gas gas) {
|
||||
return Recipe.CHEMICAL_INJECTION_CHAMBER.containsRecipe(gas);
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.IConfigCardAccess.ISpecialConfigData;
|
||||
import mekanism.api.TileNetworkList;
|
||||
@@ -32,6 +33,7 @@ import mekanism.common.base.ITierUpgradeable;
|
||||
import mekanism.common.block.states.BlockStateMachine.MachineType;
|
||||
import mekanism.common.capabilities.Capabilities;
|
||||
import mekanism.common.integration.computer.IComputerIntegration;
|
||||
import mekanism.common.recipe.GasConversionHandler;
|
||||
import mekanism.common.recipe.RecipeHandler;
|
||||
import mekanism.common.recipe.inputs.AdvancedMachineInput;
|
||||
import mekanism.common.recipe.inputs.DoubleMachineInput;
|
||||
@@ -469,31 +471,38 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt
|
||||
return MekanismUtils.getSecondaryEnergyPerTickMean(this, type.getSecondaryEnergyPerTick());
|
||||
}
|
||||
|
||||
public void handleSecondaryFuel() {
|
||||
if (!inventory.get(4).isEmpty()) {
|
||||
if (recipeType.getFuelType() == MachineFuelType.ADVANCED && gasTank.getNeeded() > 0) {
|
||||
if (inventory.get(4).getItem() instanceof IGasItem) {
|
||||
GasStack gas = ((IGasItem) inventory.get(4).getItem()).getGas(inventory.get(4));
|
||||
if (gas != null && recipeType.isValidGas(gas.getGas())) {
|
||||
GasStack removed = GasUtils.removeGas(inventory.get(4), gasTank.getGasType(), gasTank.getNeeded());
|
||||
gasTank.receive(removed, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@Nullable
|
||||
public GasStack getItemGas(ItemStack itemStack) {
|
||||
if (recipeType.getFuelType() == MachineFuelType.ADVANCED) {
|
||||
return GasConversionHandler.getItemGas(itemStack, gasTank, recipeType.getTile()::isValidGas);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
GasStack stack = recipeType.getItemGas(inventory.get(4));
|
||||
int gasNeeded = gasTank.getNeeded();
|
||||
if (stack != null && stack.amount <= gasNeeded) {
|
||||
gasTank.receive(stack, true);
|
||||
inventory.get(4).shrink(1);
|
||||
public void handleSecondaryFuel() {
|
||||
ItemStack extra = inventory.get(4);
|
||||
if (!extra.isEmpty()) {
|
||||
if (recipeType.getFuelType() == MachineFuelType.ADVANCED && gasTank.getNeeded() > 0) {
|
||||
GasStack gasStack = getItemGas(extra);
|
||||
if (gasStack != null) {
|
||||
Gas gas = gasStack.getGas();
|
||||
if (gasTank.canReceive(gas) && gasTank.getNeeded() >= gasStack.amount) {
|
||||
if (extra.getItem() instanceof IGasItem) {
|
||||
IGasItem item = (IGasItem) extra.getItem();
|
||||
gasTank.receive(item.removeGas(extra, gasStack.amount), true);
|
||||
} else {
|
||||
gasTank.receive(gasStack, true);
|
||||
extra.shrink(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (recipeType == RecipeType.INFUSING) {
|
||||
InfuseObject pendingInfusionInput = InfuseRegistry.getObject(inventory.get(4));
|
||||
InfuseObject pendingInfusionInput = InfuseRegistry.getObject(extra);
|
||||
if (pendingInfusionInput != null) {
|
||||
if (infuseStored.getType() == null || infuseStored.getType() == pendingInfusionInput.type) {
|
||||
if (infuseStored.getAmount() + pendingInfusionInput.stored <= maxInfuse) {
|
||||
infuseStored.increase(pendingInfusionInput);
|
||||
inventory.get(4).shrink(1);
|
||||
extra.shrink(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -564,7 +573,7 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt
|
||||
return ChargeUtils.canBeDischarged(itemstack);
|
||||
} else if (slotID == 4) {
|
||||
if (recipeType.getFuelType() == MachineFuelType.ADVANCED) {
|
||||
return recipeType.getItemGas(itemstack) != null;
|
||||
return getItemGas(itemstack) != null;
|
||||
} else if (recipeType.getFuelType() == MachineFuelType.DOUBLE) {
|
||||
return recipeType.hasRecipeForExtra(itemstack);
|
||||
} else if (recipeType == RecipeType.INFUSING) {
|
||||
|
||||
@@ -3,14 +3,11 @@ package mekanism.common.tile;
|
||||
import java.util.Map;
|
||||
import mekanism.api.gas.Gas;
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.gas.IGasItem;
|
||||
import mekanism.common.block.states.BlockStateMachine.MachineType;
|
||||
import mekanism.common.recipe.RecipeHandler.Recipe;
|
||||
import mekanism.common.recipe.inputs.AdvancedMachineInput;
|
||||
import mekanism.common.recipe.machines.PurificationRecipe;
|
||||
import mekanism.common.tile.prefab.TileEntityAdvancedElectricMachine;
|
||||
import mekanism.common.util.GasUtils;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public class TileEntityPurificationChamber extends TileEntityAdvancedElectricMachine<PurificationRecipe> {
|
||||
@@ -37,20 +34,6 @@ public class TileEntityPurificationChamber extends TileEntityAdvancedElectricMac
|
||||
return gasTank.canReceive(type) && isValidGas(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSecondaryFuel() {
|
||||
ItemStack itemStack = inventory.get(1);
|
||||
if (!itemStack.isEmpty() && gasTank.getNeeded() > 0 && itemStack.getItem() instanceof IGasItem) {
|
||||
GasStack gas = ((IGasItem) itemStack.getItem()).getGas(itemStack);
|
||||
if (gas != null) {
|
||||
GasStack removed = GasUtils.removeGas(itemStack, gas.getGas(), gasTank.getNeeded());
|
||||
gasTank.receive(removed, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.handleSecondaryFuel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidGas(Gas gas) {
|
||||
return Recipe.PURIFICATION_CHAMBER.containsRecipe(gas);
|
||||
|
||||
@@ -2,6 +2,7 @@ package mekanism.common.tile.prefab;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.TileNetworkList;
|
||||
import mekanism.api.gas.Gas;
|
||||
@@ -9,6 +10,7 @@ import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.gas.GasTank;
|
||||
import mekanism.api.gas.GasTankInfo;
|
||||
import mekanism.api.gas.IGasHandler;
|
||||
import mekanism.api.gas.IGasItem;
|
||||
import mekanism.api.transmitters.TransmissionType;
|
||||
import mekanism.common.MekanismItems;
|
||||
import mekanism.common.SideData;
|
||||
@@ -110,19 +112,13 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
|
||||
/**
|
||||
* Gets the amount of ticks the declared itemstack can fuel this machine.
|
||||
*
|
||||
* @param itemstack - itemstack to check with
|
||||
* @param itemStack - itemstack to check with
|
||||
*
|
||||
* @return fuel ticks
|
||||
*/
|
||||
public GasStack getItemGas(ItemStack itemstack) {
|
||||
return GasConversionHandler.getItemGas(itemstack, this::getIfValid);
|
||||
}
|
||||
|
||||
private GasStack getIfValid(Gas gas, int quantity) {
|
||||
if (gas != null && gasTank.canReceive(gas) && isValidGas(gas)) {
|
||||
return new GasStack(gas, quantity);
|
||||
}
|
||||
return null;
|
||||
@Nullable
|
||||
public GasStack getItemGas(ItemStack itemStack) {
|
||||
return GasConversionHandler.getItemGas(itemStack, gasTank, this::isValidGas);
|
||||
}
|
||||
|
||||
public abstract boolean isValidGas(Gas gas);
|
||||
@@ -163,12 +159,18 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
|
||||
}
|
||||
|
||||
public void handleSecondaryFuel() {
|
||||
if (!inventory.get(1).isEmpty() && gasTank.getNeeded() > 0) {
|
||||
GasStack stack = getItemGas(inventory.get(1));
|
||||
int gasNeeded = gasTank.getNeeded();
|
||||
if (stack != null && gasTank.canReceive(stack.getGas()) && gasNeeded >= stack.amount) {
|
||||
gasTank.receive(stack, true);
|
||||
inventory.get(1).shrink(1);
|
||||
ItemStack itemStack = inventory.get(1);
|
||||
int needed = gasTank.getNeeded();
|
||||
if (!itemStack.isEmpty() && needed > 0) {
|
||||
GasStack gasStack = getItemGas(itemStack);
|
||||
if (gasStack != null && needed >= gasStack.amount) {
|
||||
if (itemStack.getItem() instanceof IGasItem) {
|
||||
IGasItem item = (IGasItem) itemStack.getItem();
|
||||
gasTank.receive(item.removeGas(itemStack, gasStack.amount), true);
|
||||
} else {
|
||||
gasTank.receive(gasStack, true);
|
||||
itemStack.shrink(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user