Start work on Pressurised Reaction Chamber.
This commit is contained in:
parent
d0c87e862a
commit
fef2d30194
7 changed files with 389 additions and 4 deletions
|
@ -28,7 +28,7 @@ public class ChemicalPair
|
|||
}
|
||||
|
||||
/**
|
||||
* If this is a valid
|
||||
* If this is a valid ChemicalPair
|
||||
* @return
|
||||
*/
|
||||
public boolean isValid()
|
||||
|
|
39
common/mekanism/api/PressurizedProducts.java
Normal file
39
common/mekanism/api/PressurizedProducts.java
Normal file
|
@ -0,0 +1,39 @@
|
|||
package mekanism.api;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.gas.GasTank;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class PressurizedProducts
|
||||
{
|
||||
private static Random rand = new Random();
|
||||
|
||||
private ItemStack probabilityOutput;
|
||||
private double probability;
|
||||
|
||||
private GasStack gasOutput;
|
||||
|
||||
public PressurizedProducts(ItemStack item, double chance, GasStack gas)
|
||||
{
|
||||
probabilityOutput = item;
|
||||
probability = chance;
|
||||
gasOutput = gas;
|
||||
}
|
||||
|
||||
public void fillTank(GasTank tank)
|
||||
{
|
||||
tank.receive(gasOutput, true);
|
||||
}
|
||||
|
||||
public void addProducts(ItemStack itemStack)
|
||||
{
|
||||
if(itemStack.isItemEqual(probabilityOutput) && rand.nextDouble() <= probability)
|
||||
{
|
||||
itemStack.stackSize += probabilityOutput.stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
121
common/mekanism/api/PressurizedReactants.java
Normal file
121
common/mekanism/api/PressurizedReactants.java
Normal file
|
@ -0,0 +1,121 @@
|
|||
package mekanism.api;
|
||||
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.gas.GasTank;
|
||||
import mekanism.common.util.StackUtils;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
|
||||
/**
|
||||
* An input of a gas, a fluid and an item for the pressurized reaction chamber
|
||||
*/
|
||||
public class PressurizedReactants
|
||||
{
|
||||
private ItemStack theSolid;
|
||||
private FluidStack theFluid;
|
||||
private GasStack theGas;
|
||||
|
||||
public PressurizedReactants(ItemStack solid, FluidStack fluid, GasStack gas)
|
||||
{
|
||||
theSolid = solid;
|
||||
theFluid = fluid;
|
||||
theGas = gas;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this is a valid PressurizedReactants
|
||||
*/
|
||||
public boolean isValid()
|
||||
{
|
||||
return theSolid != null && theFluid != null && theGas != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the needed amount of gas from each tank.
|
||||
* @param item - ItemStack to draw from
|
||||
* @param fluidTank - fluid tank to draw from
|
||||
* @param gasTank - gas tank to draw from
|
||||
*/
|
||||
public void use(ItemStack item, FluidTank fluidTank, GasTank gasTank)
|
||||
{
|
||||
if(meets(new PressurizedReactants(item, fluidTank.getFluid(), gasTank.getGas())))
|
||||
{
|
||||
item.stackSize -= theSolid.stackSize;
|
||||
fluidTank.drain(theFluid.amount, true);
|
||||
gasTank.draw(theGas.amount, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not this PressurizedReactants's ItemStack entry's item type is equal to the item type of the given item.
|
||||
* @param stack - stack to check
|
||||
* @return if the stack's item type is contained in this PressurizedReactants
|
||||
*/
|
||||
public boolean containsType(ItemStack stack)
|
||||
{
|
||||
if(stack == null || stack.stackSize == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return StackUtils.equalsWildcard(stack, theSolid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not this PressurizedReactants's FluidStack entry's fluid type is equal to the fluid type of the given fluid.
|
||||
* @param stack - stack to check
|
||||
* @return if the stack's fluid type is contained in this PressurizedReactants
|
||||
*/
|
||||
public boolean containsType(FluidStack stack)
|
||||
{
|
||||
if(stack == null || stack.amount == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return stack.isFluidEqual(theFluid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not this PressurizedReactants's GasStack entry's gas type is equal to the gas type of the given gas.
|
||||
* @param stack - stack to check
|
||||
* @return if the stack's gas type is contained in this PressurizedReactants
|
||||
*/
|
||||
public boolean containsType(GasStack stack)
|
||||
{
|
||||
if(stack == null || stack.amount == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return stack.isGasEqual(theGas);
|
||||
}
|
||||
|
||||
/**
|
||||
* Actual implementation of meetsInput(), performs the checks.
|
||||
* @param input - input to check
|
||||
* @return if the input meets this input's requirements
|
||||
*/
|
||||
private boolean meets(PressurizedReactants input)
|
||||
{
|
||||
if(input == null || !input.isValid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(StackUtils.equalsWildcard(input.theSolid, theSolid) || input.theFluid.getFluid() != theFluid.getFluid() || input.theGas.getGas() != theGas.getGas())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return input.theSolid.stackSize >= theSolid.stackSize && input.theFluid.amount >= theFluid.amount && input.theGas.amount >= theGas.amount;
|
||||
}
|
||||
|
||||
public PressurizedReactants copy()
|
||||
{
|
||||
return new PressurizedReactants(theSolid, theFluid, theGas);
|
||||
}
|
||||
|
||||
}
|
|
@ -345,6 +345,7 @@ public class Mekanism
|
|||
public static double chemicalWasherUsage;
|
||||
public static double chemicalCrystalizerUsage;
|
||||
public static double seismicVibratorUsage;
|
||||
public static double pressurizedReactionUsage;
|
||||
|
||||
/**
|
||||
* Adds all in-game crafting and smelting recipes.
|
||||
|
|
|
@ -50,6 +50,7 @@ import mekanism.common.tile.TileEntityFactory;
|
|||
import mekanism.common.tile.TileEntityLogisticalSorter;
|
||||
import mekanism.common.tile.TileEntityMetallurgicInfuser;
|
||||
import mekanism.common.tile.TileEntityOsmiumCompressor;
|
||||
import mekanism.common.tile.TileEntityPRC;
|
||||
import mekanism.common.tile.TileEntityPrecisionSawmill;
|
||||
import mekanism.common.tile.TileEntityPurificationChamber;
|
||||
import mekanism.common.tile.TileEntityRotaryCondensentrator;
|
||||
|
@ -175,6 +176,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds
|
|||
icons[5][2] = register.registerIcon("mekanism:SteelCasing");
|
||||
icons[9][0] = register.registerIcon("mekanism:SteelBlock");
|
||||
icons[9][1] = register.registerIcon("mekanism:SeismicVibrator");
|
||||
icons[10][0] = register.registerIcon("mekanism:PressurizedReactionChamber");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1126,7 +1128,8 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds
|
|||
CHEMICAL_DISSOLUTION_CHAMBER(Mekanism.machineBlock2ID, 6, "ChemicalDissolutionChamber", 35, 20000, TileEntityChemicalDissolutionChamber.class, true, false),
|
||||
CHEMICAL_WASHER(Mekanism.machineBlock2ID, 7, "ChemicalWasher", 36, 20000, TileEntityChemicalWasher.class, true, false),
|
||||
CHEMICAL_CRYSTALIZER(Mekanism.machineBlock2ID, 8, "ChemicalCrystalizer", 37, 20000, TileEntityChemicalCrystalizer.class, true, false),
|
||||
SEISMIC_VIBRATOR(Mekanism.machineBlock2ID, 9, "SeismicVibrator", 39, 20000, TileEntitySeismicVibrator.class, false, false);
|
||||
SEISMIC_VIBRATOR(Mekanism.machineBlock2ID, 9, "SeismicVibrator", 39, 20000, TileEntitySeismicVibrator.class, false, false),
|
||||
PRESSURIZED_REACTION_CHAMBER(Mekanism.machineBlock2ID, 10, "PressurizedReactionChamber", 40, 20000, TileEntityPRC.class, false, false);
|
||||
|
||||
public int typeId;
|
||||
public int meta;
|
||||
|
|
|
@ -6,6 +6,8 @@ import java.util.Map;
|
|||
import mekanism.api.AdvancedInput;
|
||||
import mekanism.api.ChanceOutput;
|
||||
import mekanism.api.ChemicalPair;
|
||||
import mekanism.api.PressurizedProducts;
|
||||
import mekanism.api.PressurizedReactants;
|
||||
import mekanism.api.gas.Gas;
|
||||
import mekanism.api.gas.GasRegistry;
|
||||
import mekanism.api.gas.GasStack;
|
||||
|
@ -388,7 +390,7 @@ public final class RecipeHandler
|
|||
}
|
||||
/**
|
||||
* Gets the output ItemStack of the AdvancedInput in the parameters.
|
||||
* @param itemstack - input AdvancedInput
|
||||
* @param input - input AdvancedInput
|
||||
* @param stackDecrease - whether or not to decrease the input slot's stack size
|
||||
* @param recipes - Map of recipes
|
||||
* @return output ItemStack
|
||||
|
@ -481,7 +483,8 @@ public final class RecipeHandler
|
|||
PRECISION_SAWMILL(new HashMap<ItemStack, ChanceOutput>()),
|
||||
CHEMICAL_DISSOLUTION_CHAMBER(new HashMap<ItemStack, FluidStack>()),
|
||||
CHEMICAL_WASHER(new HashMap<GasStack, GasStack>()),
|
||||
CHEMICAL_CRYSTALIZER(new HashMap<GasStack, ItemStack>());
|
||||
CHEMICAL_CRYSTALIZER(new HashMap<GasStack, ItemStack>()),
|
||||
PRESSURIZED_REACTION_CHAMBER(new HashMap<PressurizedReactants, PressurizedProducts>());
|
||||
|
||||
private HashMap recipes;
|
||||
|
||||
|
|
218
common/mekanism/common/tile/TileEntityPRC.java
Normal file
218
common/mekanism/common/tile/TileEntityPRC.java
Normal file
|
@ -0,0 +1,218 @@
|
|||
package mekanism.common.tile;
|
||||
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.SideData;
|
||||
import mekanism.common.block.BlockMachine.MachineType;
|
||||
import mekanism.common.recipe.RecipeHandler;
|
||||
import mekanism.common.tile.component.TileComponentEjector;
|
||||
import mekanism.common.tile.component.TileComponentUpgrade;
|
||||
import mekanism.common.util.ChargeUtils;
|
||||
import mekanism.common.util.InventoryUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class TileEntityPRC extends TileEntityBasicMachine
|
||||
{
|
||||
public TileEntityPRC()
|
||||
{
|
||||
super("PressurizedReactionChamber.ogg", "PressurizedReactionChamber", new ResourceLocation("mekanism", "gui/GuiPRC.png"), Mekanism.pressurizedReactionUsage, 200, MachineType.PRESSURIZED_REACTION_CHAMBER.baseEnergy);
|
||||
|
||||
sideOutputs.add(new SideData(EnumColor.GREY, InventoryUtils.EMPTY));
|
||||
sideOutputs.add(new SideData(EnumColor.DARK_RED, new int[] {0}));
|
||||
sideOutputs.add(new SideData(EnumColor.DARK_GREEN, new int[] {1}));
|
||||
sideOutputs.add(new SideData(EnumColor.DARK_BLUE, new int[] {2, 4}));
|
||||
sideOutputs.add(new SideData(EnumColor.ORANGE, new int[] {3}));
|
||||
|
||||
sideConfig = new byte[] {2, 1, 0, 0, 4, 3};
|
||||
|
||||
inventory = new ItemStack[2];
|
||||
|
||||
upgradeComponent = new TileComponentUpgrade(this, 3);
|
||||
ejectorComponent = new TileComponentEjector(this, sideOutputs.get(3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate()
|
||||
{
|
||||
super.onUpdate();
|
||||
|
||||
if(!worldObj.isRemote)
|
||||
{
|
||||
ChargeUtils.discharge(1, this);
|
||||
|
||||
if(canOperate() && MekanismUtils.canFunction(this) && getEnergy() >= MekanismUtils.getEnergyPerTick(getSpeedMultiplier(), getEnergyMultiplier(), ENERGY_PER_TICK))
|
||||
{
|
||||
setActive(true);
|
||||
|
||||
if((operatingTicks+1) < MekanismUtils.getTicks(getSpeedMultiplier(), TICKS_REQUIRED))
|
||||
{
|
||||
operatingTicks++;
|
||||
electricityStored -= MekanismUtils.getEnergyPerTick(getSpeedMultiplier(), getEnergyMultiplier(), ENERGY_PER_TICK);
|
||||
}
|
||||
else if((operatingTicks+1) >= MekanismUtils.getTicks(getSpeedMultiplier(), TICKS_REQUIRED))
|
||||
{
|
||||
operate();
|
||||
|
||||
operatingTicks = 0;
|
||||
electricityStored -= MekanismUtils.getEnergyPerTick(getSpeedMultiplier(), getEnergyMultiplier(), ENERGY_PER_TICK);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(prevEnergy >= getEnergy())
|
||||
{
|
||||
setActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
if(!canOperate())
|
||||
{
|
||||
operatingTicks = 0;
|
||||
}
|
||||
|
||||
prevEnergy = getEnergy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slotID, ItemStack itemstack)
|
||||
{
|
||||
if(slotID == 3)
|
||||
{
|
||||
return itemstack.itemID == Mekanism.SpeedUpgrade.itemID || itemstack.itemID == Mekanism.EnergyUpgrade.itemID;
|
||||
}
|
||||
else if(slotID == 0)
|
||||
{
|
||||
return RecipeHandler.isInRecipe(itemstack, getRecipes());
|
||||
}
|
||||
else if(slotID == 1)
|
||||
{
|
||||
return ChargeUtils.canBeDischarged(itemstack);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operate()
|
||||
{
|
||||
ChanceOutput output = RecipeHandler.getChanceOutput(inventory[0], true, getRecipes());
|
||||
|
||||
if(inventory[0].stackSize <= 0)
|
||||
{
|
||||
inventory[0] = null;
|
||||
}
|
||||
|
||||
if(output.hasPrimary())
|
||||
{
|
||||
if(inventory[2] == null)
|
||||
{
|
||||
inventory[2] = output.primaryOutput;
|
||||
}
|
||||
else {
|
||||
inventory[2].stackSize += output.primaryOutput.stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
if(output.hasSecondary() && output.checkSecondary())
|
||||
{
|
||||
if(inventory[4] == null)
|
||||
{
|
||||
inventory[4] = output.secondaryOutput;
|
||||
}
|
||||
else {
|
||||
inventory[4].stackSize += output.secondaryOutput.stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
onInventoryChanged();
|
||||
ejectorComponent.onOutput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canOperate()
|
||||
{
|
||||
if(inventory[0] == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ChanceOutput output = RecipeHandler.getChanceOutput(inventory[0], false, getRecipes());
|
||||
|
||||
if(output == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(output.hasPrimary())
|
||||
{
|
||||
if(inventory[2] != null)
|
||||
{
|
||||
if(!inventory[2].isItemEqual(output.primaryOutput))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if(inventory[2].stackSize + output.primaryOutput.stackSize > inventory[2].getMaxStackSize())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(output.hasSecondary())
|
||||
{
|
||||
if(inventory[4] != null)
|
||||
{
|
||||
if(!inventory[4].isItemEqual(output.secondaryOutput))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if(inventory[4].stackSize + output.secondaryOutput.stackSize > inventory[4].getMaxStackSize())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int slotID, ItemStack itemstack, int side)
|
||||
{
|
||||
if(slotID == 1)
|
||||
{
|
||||
return ChargeUtils.canBeOutputted(itemstack, false);
|
||||
}
|
||||
else if(slotID == 2 || slotID == 4)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map getRecipes()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getMethodNames()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue