Files
Mekanism-Community-Edition/src/main/java/mekanism/common/base/IFactory.java
T
Dave Smith 95ca29fa19 Squashed commit of the following:
commit 0d4dc5991e572793134c0c1af8bb35db528071ad
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 19:25:28 2019 -0500

    IntelliJ inspections, Unused Import

commit c757d3236b6304b1d3295ad392b88677bccf3003
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 19:09:24 2019 -0500

    IntelliJ inspections, Constant conditions & exceptions

commit c63a821ef9fc705941052a876cc1ef950471912e
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 17:41:31 2019 -0500

    IntelliJ inspections, @NotNull/@Nullable problems

commit 506bbfd3241336082b17e5d47f8cec496666dcff
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 16:50:46 2019 -0500

    IntelliJ inspections, Unused label

commit bad10c2428346b5feb1816e4a78d7cc2bc1259f0
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:33:54 2019 -0500

    IntelliJ inspections, Unused assignment

commit bfe633afbfb6380d0f5ee2e8ab14f8981a455681
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:32:02 2019 -0500

    IntelliJ inspections, 'equals()' between objects of inconvertible types

commit 6d179f8639fad1a7c3fa01467c003a8fd309da09
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:29:28 2019 -0500

    IntelliJ inspections, Unused import

commit c21f1cfa5566308237dc8bddb8b79908e272a637
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:25:41 2019 -0500

    IntelliJ inspections, Unused import

commit e5d9e03af582c7315b057861b8f0019e46157dee
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:23:10 2019 -0500

    IntelliJ inspections, Redundant 'throws' clause

commit 1c589ba5740411a5595e9fda177696670bc7b7df
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:21:07 2019 -0500

    IntelliJ inspections, Static member referenced by instance variable

commit 6c17e9ca7fb22a0e285337133659e826f3bfdfee
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:20:02 2019 -0500

    IntelliJ inspections, Catch block may ignore exception

commit 42b3cd788ceb7d6ce657d582bbbd8345a2ec5676
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:16:29 2019 -0500

    IntelliJ inspections, Unnecessary label on 'break' statement

commit f6abc3c66f3aca147edb274720cdb94bff568b0b
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:15:29 2019 -0500

    IntelliJ inspections, Too weak variable type leads to unnecessary cast

commit 6356d1fea8d55907ae1c7b011223fbbc07236c1f
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:11:17 2019 -0500

    IntelliJ inspections, Redundant type cast

commit 559c1a2ff523fd7e23f3750d5c801af73876f1d0
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:04:45 2019 -0500

    IntelliJ inspections, Redundant type arguments

commit ae816ec2a79cf4c8fee776db651a54f68c1dacaa
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:01:27 2019 -0500

    IntelliJ inspections, Redundant Collection operation

commit 1da69b8baff922b98a32163c7d5f90aa77a6a8bc
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:00:55 2019 -0500

    IntelliJ inspections, Redundant array creation

commit 7e3ef81a3597c596d2206c93442e950ac9183de0
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:00:11 2019 -0500

    IntelliJ inspections, Condition is covered by further condition

commit f298bbb9f31ecbe935ef6cbf98b56951434a05f8
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:58:10 2019 -0500

    IntelliJ inspections, Redundant 'Collection.addAll()' call

commit ce715c5cd724c4dc71ff2cb53e5bc12f16289f12
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:56:56 2019 -0500

    IntelliJ inspections, 'Collection.toArray()' call style

commit 0bde4b0eb23ac5d8f40a410ed55315e4a422a30c
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:55:40 2019 -0500

    IntelliJ inspections, Calls to 'Arrays.asList()' with too few arguments

commit 6d06d11dcf9c077ed6b216a0bbd61434b10fc610
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:52:26 2019 -0500

    IntelliJ inspections, Pointless arithmetic expression

commit 6501d725af1eda5127489f77fd723396002b29b2
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:42:32 2019 -0500

    IntelliJ inspections, Anonymous type can be replaced with lambda

commit 85341ae5df9d63fb0ad7281c260c77d064adf0c2
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:41:40 2019 -0500

    IntelliJ inspections, Explicit type can be replaced with <>

commit 7e2feae7189b92cb513499aed113d4a2634622c6
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:38:47 2019 -0500

    IntelliJ inspections, Unnecessary 'null' check before method call

commit 2c75a38fe9a969f832cd5777f4fad81ef47d037b
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:37:33 2019 -0500

    IntelliJ inspections, 'switch' statement with too few branches

commit 2e2aff57f7910aef5a68f41a1918e2c8a98509ec
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:34:50 2019 -0500

    IntelliJ inspections, Simplifiable conditional statement

commit 243f6a975f8b3da5e70a5c1a116db2aedd10900e
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:33:09 2019 -0500

    IntelliJ inspections, Duplicate condition in 'if' statement

commit a80c67fc30b737990e7805a8741dce120232badc
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:32:17 2019 -0500

    IntelliJ inspections, Unnecessary semicolon

commit 5a7220ee574c9d38d71db07e4fa995a56fee1eed
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:31:58 2019 -0500

    IntelliJ inspections, Unnecessary enum/interface modifier

commit f3a66f4462033d2f446c2961a1ad8e9cfde3ed36
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:30:36 2019 -0500

    IntelliJ inspections, Unnecessary conversion to String

commit 1662540be864db4669cd80c8c46a9b35be202b62
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:29:33 2019 -0500

    IntelliJ inspections, C styled array declaration
2019-03-07 21:53:20 -07:00

339 lines
8.2 KiB
Java

package mekanism.common.base;
import java.util.Locale;
import java.util.Map;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasStack;
import mekanism.common.InfuseStorage;
import mekanism.common.block.states.BlockStateMachine.MachineType;
import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.inputs.AdvancedMachineInput;
import mekanism.common.recipe.inputs.DoubleMachineInput;
import mekanism.common.recipe.inputs.InfusionInput;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.machines.AdvancedMachineRecipe;
import mekanism.common.recipe.machines.BasicMachineRecipe;
import mekanism.common.recipe.machines.DoubleMachineRecipe;
import mekanism.common.recipe.machines.MachineRecipe;
import mekanism.common.recipe.machines.MetallurgicInfuserRecipe;
import mekanism.common.tile.prefab.TileEntityAdvancedElectricMachine;
import mekanism.common.util.LangUtils;
import mekanism.common.util.StackUtils;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
/**
* Internal interface for managing various Factory types.
* @author AidanBrady
*
*/
public interface IFactory
{
/**
* Gets the recipe type this Smelting Factory currently has.
* @param itemStack - stack to check
* @return RecipeType ordinal
*/
int getRecipeType(ItemStack itemStack);
/**
* Sets the recipe type of this Smelting Factory to a new value.
* @param type - RecipeType ordinal
* @param itemStack - stack to set
*/
void setRecipeType(int type, ItemStack itemStack);
enum MachineFuelType {
BASIC,
ADVANCED,
DOUBLE
}
enum RecipeType implements IStringSerializable
{
SMELTING("Smelting", "smelter", MachineType.ENERGIZED_SMELTER, MachineFuelType.BASIC, false, Recipe.ENERGIZED_SMELTER),
ENRICHING("Enriching", "enrichment", MachineType.ENRICHMENT_CHAMBER, MachineFuelType.BASIC, false, Recipe.ENRICHMENT_CHAMBER),
CRUSHING("Crushing", "crusher", MachineType.CRUSHER, MachineFuelType.BASIC, false, Recipe.CRUSHER),
COMPRESSING("Compressing", "compressor", MachineType.OSMIUM_COMPRESSOR, MachineFuelType.ADVANCED, false, Recipe.OSMIUM_COMPRESSOR),
COMBINING("Combining", "combiner", MachineType.COMBINER, MachineFuelType.DOUBLE, false, Recipe.COMBINER),
PURIFYING("Purifying", "purifier", MachineType.PURIFICATION_CHAMBER, MachineFuelType.ADVANCED, true, Recipe.PURIFICATION_CHAMBER),
INJECTING("Injecting", "injection", MachineType.CHEMICAL_INJECTION_CHAMBER, MachineFuelType.ADVANCED, true, Recipe.CHEMICAL_INJECTION_CHAMBER),
INFUSING("Infusing", "metalinfuser", MachineType.METALLURGIC_INFUSER, MachineFuelType.BASIC, false, Recipe.METALLURGIC_INFUSER);
private String name;
private SoundEvent sound;
private MachineType type;
private MachineFuelType fuelType;
private boolean fuelSpeed;
private Recipe recipe;
private TileEntityAdvancedElectricMachine cacheTile;
public BasicMachineRecipe getRecipe(ItemStackInput input)
{
return RecipeHandler.getRecipe(input, recipe.get());
}
public BasicMachineRecipe getRecipe(ItemStack input)
{
return getRecipe(new ItemStackInput(input));
}
public AdvancedMachineRecipe getRecipe(AdvancedMachineInput input)
{
return RecipeHandler.getRecipe(input, recipe.get());
}
public AdvancedMachineRecipe getRecipe(ItemStack input, Gas gas)
{
return getRecipe(new AdvancedMachineInput(input, gas));
}
public DoubleMachineRecipe getRecipe(DoubleMachineInput input)
{
return RecipeHandler.getRecipe(input, recipe.get());
}
public DoubleMachineRecipe getRecipe(ItemStack input, ItemStack extra)
{
return getRecipe(new DoubleMachineInput(input, extra));
}
public MetallurgicInfuserRecipe getRecipe(InfusionInput input)
{
return RecipeHandler.getMetallurgicInfuserRecipe(input);
}
public MetallurgicInfuserRecipe getRecipe(ItemStack input, InfuseStorage storage)
{
return getRecipe(new InfusionInput(storage, input));
}
public MachineRecipe getAnyRecipe(ItemStack slotStack, ItemStack extraStack, Gas gasType, InfuseStorage infuse)
{
if(fuelType == MachineFuelType.ADVANCED)
{
return getRecipe(slotStack, gasType);
}
else if(fuelType == MachineFuelType.DOUBLE)
{
return getRecipe(slotStack, extraStack);
}
else if(this == INFUSING)
{
if(infuse.type != null)
{
return RecipeHandler.getMetallurgicInfuserRecipe(new InfusionInput(infuse, slotStack));
}
else {
for(Object obj : Recipe.METALLURGIC_INFUSER.get().entrySet())
{
Map.Entry entry = (Map.Entry)obj;
InfusionInput input = (InfusionInput)entry.getKey();
if(input.inputStack.isItemEqual(slotStack))
{
return (MetallurgicInfuserRecipe)entry.getValue();
}
}
}
}
return getRecipe(slotStack);
}
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;
}
return 0;
}
public boolean canReceiveGas(EnumFacing side, Gas type)
{
if(fuelType == MachineFuelType.ADVANCED)
{
return getTile().canReceiveGas(side, type);
}
return false;
}
public boolean canTubeConnect(EnumFacing side)
{
if(fuelType == MachineFuelType.ADVANCED)
{
return getTile().canTubeConnect(side);
}
return false;
}
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;
}
for(Object obj : recipe.get().entrySet())
{
if(((Map.Entry)obj).getKey() instanceof AdvancedMachineInput)
{
Map.Entry entry = (Map.Entry)obj;
ItemStack stack = ((AdvancedMachineInput)entry.getKey()).itemStack;
if(StackUtils.equalsWildcard(stack, itemStack))
{
return true;
}
}
}
return false;
}
public boolean hasRecipeForExtra(ItemStack extraStack)
{
if(extraStack.isEmpty())
{
return false;
}
for(Object obj : recipe.get().entrySet())
{
if(((Map.Entry)obj).getKey() instanceof DoubleMachineInput)
{
Map.Entry entry = (Map.Entry)obj;
ItemStack stack = ((DoubleMachineInput)entry.getKey()).extraStack;
if(StackUtils.equalsWildcard(stack, extraStack))
{
return true;
}
}
}
return false;
}
public TileEntityAdvancedElectricMachine getTile()
{
if(cacheTile == null)
{
MachineType type = MachineType.get(getStack());
cacheTile = (TileEntityAdvancedElectricMachine)type.create();
}
return cacheTile;
}
public double getEnergyUsage()
{
return type.getUsage();
}
public int getMaxSecondaryEnergy()
{
return 200;
}
public ItemStack getStack()
{
return type.getStack();
}
public String getTranslationKey()
{
return name;
}
public String getLocalizedName()
{
return LangUtils.localize("gui.factory." + name);
}
public SoundEvent getSound()
{
return sound;
}
public MachineFuelType getFuelType()
{
return fuelType;
}
public boolean fuelEnergyUpgrades()
{
return fuelSpeed;
}
public static RecipeType getFromMachine(Block block, int meta)
{
RecipeType type = null;
for(RecipeType iterType : RecipeType.values())
{
ItemStack machineStack = iterType.getStack();
if(Block.getBlockFromItem(machineStack.getItem()) == block && machineStack.getItemDamage() == meta)
{
type = iterType;
break;
}
}
return type;
}
RecipeType(String s, String s1, MachineType t, MachineFuelType ft, boolean b1, Recipe r)
{
name = s;
sound = new SoundEvent(new ResourceLocation("mekanism", "tile.machine." + s1));
type = t;
fuelType = ft;
fuelSpeed = b1;
recipe = r;
}
@Override
public String getName()
{
return name().toLowerCase(Locale.ROOT);
}
public MachineType getType()
{
return type;
}
}
}