Work on Precision Sawmill, added Sawdust, finished ChanceMachine tile and recipe foundation

This commit is contained in:
Aidan C. Brady 2014-01-12 23:55:42 -05:00
parent 763c5decb1
commit 19b36e901b
17 changed files with 261 additions and 32 deletions

View file

@ -0,0 +1,49 @@
package mekanism.api;
import java.util.Random;
import mekanism.common.util.StackUtils;
import net.minecraft.item.ItemStack;
public class ChanceOutput
{
private static Random rand = new Random();
public ItemStack primaryOutput;
public ItemStack secondaryOutput;
public double secondaryChance;
public ChanceOutput(ItemStack primary, ItemStack secondary, double chance)
{
primaryOutput = primary;
secondaryOutput = secondary;
secondaryChance = chance;
}
public ChanceOutput(ItemStack primary)
{
primaryOutput = primary;
}
public boolean checkSecondary()
{
return rand.nextDouble() >= secondaryChance;
}
public boolean hasPrimary()
{
return primaryOutput != null;
}
public boolean hasSecondary()
{
return secondaryOutput != null;
}
public ChanceOutput copy()
{
return new ChanceOutput(StackUtils.copy(primaryOutput), StackUtils.copy(secondaryOutput), secondaryChance);
}
}

View file

@ -64,10 +64,10 @@ import mekanism.client.render.tileentity.RenderTeleporter;
import mekanism.client.sound.Sound;
import mekanism.client.sound.SoundHandler;
import mekanism.common.CommonProxy;
import mekanism.common.EnergyDisplay.EnergyType;
import mekanism.common.IElectricChest;
import mekanism.common.IInvConfiguration;
import mekanism.common.Mekanism;
import mekanism.common.EnergyDisplay.EnergyType;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.entity.EntityBalloon;
import mekanism.common.entity.EntityObsidianTNT;
@ -100,6 +100,7 @@ import mekanism.common.tile.TileEntityLogisticalSorter;
import mekanism.common.tile.TileEntityMetallurgicInfuser;
import mekanism.common.tile.TileEntityObsidianTNT;
import mekanism.common.tile.TileEntityOsmiumCompressor;
import mekanism.common.tile.TileEntityPrecisionSawmill;
import mekanism.common.tile.TileEntityPurificationChamber;
import mekanism.common.tile.TileEntityRotaryCondensentrator;
import mekanism.common.tile.TileEntitySalinationController;
@ -292,6 +293,7 @@ public class ClientProxy extends CommonProxy
ClientRegistry.registerTileEntity(TileEntityElectrolyticSeparator.class, "ElectrolyticSeparator", new RenderElectrolyticSeparator());
GameRegistry.registerTileEntity(TileEntitySalinationController.class, "SalinationController");
GameRegistry.registerTileEntity(TileEntitySalinationValve.class, "SalinationValve");
ClientRegistry.registerTileEntity(TileEntityPrecisionSawmill.class, "PrecisionSawmill", new RenderConfigurableMachine());
}
@Override

View file

@ -0,0 +1,6 @@
package mekanism.client.gui;
public class GuiChanceMachine
{
}

View file

@ -0,0 +1,6 @@
package mekanism.client.gui;
public class GuiPrecisionSawmill
{
}

View file

@ -53,6 +53,7 @@ import mekanism.common.tile.TileEntityLogisticalSorter;
import mekanism.common.tile.TileEntityMetallurgicInfuser;
import mekanism.common.tile.TileEntityObsidianTNT;
import mekanism.common.tile.TileEntityOsmiumCompressor;
import mekanism.common.tile.TileEntityPrecisionSawmill;
import mekanism.common.tile.TileEntityPurificationChamber;
import mekanism.common.tile.TileEntityRotaryCondensentrator;
import mekanism.common.tile.TileEntitySalinationController;
@ -110,6 +111,7 @@ public class CommonProxy
GameRegistry.registerTileEntity(TileEntityElectrolyticSeparator.class, "ElectrolyticSeparator");
GameRegistry.registerTileEntity(TileEntitySalinationController.class, "SalinationController");
GameRegistry.registerTileEntity(TileEntitySalinationValve.class, "SalinationValve");
GameRegistry.registerTileEntity(TileEntityPrecisionSawmill.class, "PrecisionSawmill");
}
/**
@ -210,6 +212,7 @@ public class CommonProxy
Mekanism.chemicalInfuserUsage = Mekanism.configuration.get("usage", "ChemicalInfuserUsage", 200D).getDouble(200D);
Mekanism.chemicalInjectionChamberUsage = Mekanism.configuration.get("usage", "ChemicalInjectionChamberUsage", 400D).getDouble(400D);
Mekanism.electrolyticSeparatorUsage = Mekanism.configuration.get("usage", "ElectrolyticSeparatorUsage", 50D).getDouble(50D);
Mekanism.precisionSawmillUsage = Mekanism.configuration.get("usage", "PrecisionSawmillUsage", 50D).getDouble(50D);
Mekanism.configuration.save();
}

View file

@ -245,6 +245,7 @@ public class Mekanism
public static Item Shard;
public static Item ElectrolyticCore;
public static Item CompressedRedstone;
public static Item Sawdust;
//Blocks
public static Block BasicBlock;
@ -310,6 +311,7 @@ public class Mekanism
public static double chemicalInfuserUsage;
public static double chemicalInjectionChamberUsage;
public static double electrolyticSeparatorUsage;
public static double precisionSawmillUsage;
/**
* Adds all in-game crafting and smelting recipes.
@ -514,7 +516,6 @@ public class Mekanism
"EPE", "IEG", "EPE", Character.valueOf('E'), Mekanism.EnrichedAlloy, Character.valueOf('P'), "dustOsmium", Character.valueOf('I'), "dustIron", Character.valueOf('G'), "dustGold"
}));
for(RecipeType type : RecipeType.values())
{
CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(MekanismUtils.getFactory(FactoryTier.BASIC, type), new Object[] {
@ -708,6 +709,7 @@ public class Mekanism
Shard = new ItemShard(configuration.getItem("Shard", 11227).getInt());
ElectrolyticCore = new ItemMekanism(configuration.getItem("ElectrolyticCore", 11228).getInt()).setUnlocalizedName("ElectrolyticCore");
CompressedRedstone = new ItemMekanism(configuration.getItem("CompressedRedstone", 11229).getInt()).setUnlocalizedName("CompressedRedstone");
Sawdust = new ItemMekanism(configuration.getItem("Sawdust", 11230).getInt()).setUnlocalizedName("Sawdust");
configuration.save();
@ -741,6 +743,7 @@ public class Mekanism
GameRegistry.registerItem(Shard, "Shard");
GameRegistry.registerItem(ElectrolyticCore, "ElectrolyticCore");
GameRegistry.registerItem(CompressedRedstone, "CompressedRedstone");
GameRegistry.registerItem(Sawdust, "Sawdust");
}
/**
@ -780,6 +783,10 @@ public class Mekanism
OreDictionary.registerOre("universalCable", new ItemStack(PartTransmitter, 8, 0));
OreDictionary.registerOre("battery", EnergyTablet.getUnchargedItem());
//GregoriousT, should I use "sawdust" or "dustSaw"? I'll use both.
OreDictionary.registerOre("sawdust", Sawdust);
OreDictionary.registerOre("dustSaw", Sawdust);
OreDictionary.registerOre("dustIron", new ItemStack(Dust, 1, 0));
OreDictionary.registerOre("dustGold", new ItemStack(Dust, 1, 1));
OreDictionary.registerOre("dustOsmium", new ItemStack(Dust, 1, 2));

View file

@ -1,20 +1,56 @@
package mekanism.common.block;
import buildcraft.api.tools.IToolWrench;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import java.util.Random;
import mekanism.api.Coord4D;
import mekanism.api.energy.IEnergizedItem;
import mekanism.client.ClientProxy;
import mekanism.common.*;
import mekanism.common.IActiveState;
import mekanism.common.IBoundingBlock;
import mekanism.common.IElectricChest;
import mekanism.common.IFactory;
import mekanism.common.IFactory.RecipeType;
import mekanism.common.IInvConfiguration;
import mekanism.common.IRedstoneControl;
import mekanism.common.ISpecialBounds;
import mekanism.common.ISustainedInventory;
import mekanism.common.ISustainedTank;
import mekanism.common.IUpgradeManagement;
import mekanism.common.ItemAttacher;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.miner.MinerFilter;
import mekanism.common.network.PacketElectricChest;
import mekanism.common.network.PacketElectricChest.ElectricChestPacketType;
import mekanism.common.network.PacketLogisticalSorterGui;
import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
import mekanism.common.tile.*;
import mekanism.common.tile.TileEntityAdvancedFactory;
import mekanism.common.tile.TileEntityBasicBlock;
import mekanism.common.tile.TileEntityChargepad;
import mekanism.common.tile.TileEntityChemicalInfuser;
import mekanism.common.tile.TileEntityChemicalInjectionChamber;
import mekanism.common.tile.TileEntityChemicalOxidizer;
import mekanism.common.tile.TileEntityCombiner;
import mekanism.common.tile.TileEntityContainerBlock;
import mekanism.common.tile.TileEntityCrusher;
import mekanism.common.tile.TileEntityDigitalMiner;
import mekanism.common.tile.TileEntityElectricBlock;
import mekanism.common.tile.TileEntityElectricChest;
import mekanism.common.tile.TileEntityElectricPump;
import mekanism.common.tile.TileEntityElectrolyticSeparator;
import mekanism.common.tile.TileEntityEliteFactory;
import mekanism.common.tile.TileEntityEnergizedSmelter;
import mekanism.common.tile.TileEntityEnrichmentChamber;
import mekanism.common.tile.TileEntityFactory;
import mekanism.common.tile.TileEntityLogisticalSorter;
import mekanism.common.tile.TileEntityMetallurgicInfuser;
import mekanism.common.tile.TileEntityOsmiumCompressor;
import mekanism.common.tile.TileEntityPrecisionSawmill;
import mekanism.common.tile.TileEntityPurificationChamber;
import mekanism.common.tile.TileEntityRotaryCondensentrator;
import mekanism.common.tile.TileEntityTeleporter;
import mekanism.common.transporter.TransporterFilter;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.TransporterUtils;
@ -40,9 +76,9 @@ import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import java.util.List;
import java.util.Random;
import buildcraft.api.tools.IToolWrench;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Block class for handling multiple machine block IDs.
@ -563,6 +599,11 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds
{
for(MachineType type : MachineType.values())
{
if(type == MachineType.PRECISION_SAWMILL) //TODO
{
continue;
}
if(type.typeId == blockID)
{
if(type == MachineType.BASIC_FACTORY || type == MachineType.ADVANCED_FACTORY || type == MachineType.ELITE_FACTORY)
@ -1074,8 +1115,8 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds
CHEMICAL_OXIDIZER(Mekanism.machineBlock2ID, 1, "ChemicalOxidizer", 29, 20000, TileEntityChemicalOxidizer.class, true, false),
CHEMICAL_INFUSER(Mekanism.machineBlock2ID, 2, "ChemicalInfuser", 30, 20000, TileEntityChemicalInfuser.class, true, false),
CHEMICAL_INJECTION_CHAMBER(Mekanism.machineBlock2ID, 3, "ChemicalInjectionChamber", 31, Mekanism.chemicalInjectionChamberUsage*400, TileEntityChemicalInjectionChamber.class, false, true),
ELECTROLYTIC_SEPARATOR(Mekanism.machineBlock2ID, 4, "ElectrolyticSeparator", 32, 20000, TileEntityElectrolyticSeparator.class, true, false);
ELECTROLYTIC_SEPARATOR(Mekanism.machineBlock2ID, 4, "ElectrolyticSeparator", 32, 20000, TileEntityElectrolyticSeparator.class, true, false),
PRECISION_SAWMILL(Mekanism.machineBlock2ID, 5, "PrecisionSawmill", 33, Mekanism.precisionSawmillUsage*400, TileEntityPrecisionSawmill.class, false, true);
public int typeId;
public int meta;

View file

@ -0,0 +1,6 @@
package mekanism.common.inventory.container;
public class ContainerChanceMachine
{
}

View file

@ -68,6 +68,7 @@ public class PacketConfigSync implements IMekanismPacket
Mekanism.chemicalInfuserUsage = dataStream.readDouble();
Mekanism.chemicalInjectionChamberUsage = dataStream.readDouble();
Mekanism.electrolyticSeparatorUsage = dataStream.readDouble();
Mekanism.precisionSawmillUsage = dataStream.readDouble();
for(IModule module : Mekanism.modulesLoaded)
{
@ -119,6 +120,7 @@ public class PacketConfigSync implements IMekanismPacket
dataStream.writeDouble(Mekanism.chemicalInfuserUsage);
dataStream.writeDouble(Mekanism.chemicalInjectionChamberUsage);
dataStream.writeDouble(Mekanism.electrolyticSeparatorUsage);
dataStream.writeDouble(Mekanism.precisionSawmillUsage);
for(IModule module : Mekanism.modulesLoaded)
{

View file

@ -3,6 +3,7 @@ package mekanism.common.recipe;
import java.util.HashMap;
import java.util.Map;
import mekanism.api.ChanceOutput;
import mekanism.api.ChemicalPair;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
@ -88,7 +89,7 @@ public final class RecipeHandler
/**
* Add a Chemical Infuser recipe.
* @param input - input ChemicalInput
* @param input - input ChemicalPair
* @param output - output GasStack
*/
public static void addChemicalInfuserRecipe(ChemicalPair input, GasStack output)
@ -126,6 +127,16 @@ public final class RecipeHandler
Recipe.ELECTROLYTIC_SEPARATOR.put(fluid, products);
}
/**
* Add an Precision Sawmill recipe.
* @param input - input ItemStack
* @param output - output ChanceOutput
*/
public static void addPrecisionSawmillRecipe(ItemStack input, ChanceOutput output)
{
Recipe.PRECISION_SAWMILL.put(input, output);
}
/**
* Gets the InfusionOutput of the InfusionInput in the parameters.
* @param infusion - input Infusion
@ -225,6 +236,36 @@ public final class RecipeHandler
return null;
}
/**
* Gets the output ChanceOutput of the ItemStack in the parameters.
* @param itemstack - input ItemStack
* @param stackDecrease - whether or not to decrease the input slot's stack size
* @param recipes - Map of recipes
* @return output ChanceOutput
*/
public static ChanceOutput getChanceOutput(ItemStack itemstack, boolean stackDecrease, Map<ItemStack, ChanceOutput> recipes)
{
if(itemstack != null)
{
for(Map.Entry entry : recipes.entrySet())
{
ItemStack stack = (ItemStack)entry.getKey();
if(StackUtils.equalsWildcard(stack, itemstack) && itemstack.stackSize >= stack.stackSize)
{
if(stackDecrease)
{
itemstack.stackSize -= stack.stackSize;
}
return ((ChanceOutput)entry.getValue()).copy();
}
}
}
return null;
}
/**
* Gets the output ItemStack of the ItemStack in the parameters.
* @param itemstack - input ItemStack
@ -318,7 +359,8 @@ public final class RecipeHandler
CHEMICAL_INFUSER(new HashMap<ChemicalPair, GasStack>()),
CHEMICAL_OXIDIZER(new HashMap<ItemStack, GasStack>()),
CHEMICAL_INJECTION_CHAMBER(new HashMap<ItemStack, ItemStack>()),
ELECTROLYTIC_SEPARATOR(new HashMap<FluidStack, ChemicalPair>());
ELECTROLYTIC_SEPARATOR(new HashMap<FluidStack, ChemicalPair>()),
PRECISION_SAWMILL(new HashMap<ItemStack, ChanceOutput>());
private HashMap recipes;

View file

@ -2,8 +2,8 @@ package mekanism.common.tile;
import java.util.Map;
import mekanism.api.ChanceOutput;
import mekanism.api.EnumColor;
import mekanism.api.ListUtils;
import mekanism.common.Mekanism;
import mekanism.common.SideData;
import mekanism.common.recipe.RecipeHandler;
@ -101,19 +101,33 @@ public class TileEntityChanceMachine extends TileEntityBasicMachine
@Override
public void operate()
{
ItemStack itemstack = RecipeHandler.getOutput(inventory[0], true, getRecipes());
ChanceOutput output = RecipeHandler.getChanceOutput(inventory[0], true, getRecipes());
if(inventory[0].stackSize <= 0)
{
inventory[0] = null;
}
if(inventory[2] == null)
if(output.hasPrimary())
{
inventory[2] = itemstack;
if(inventory[2] == null)
{
inventory[2] = output.primaryOutput;
}
else {
inventory[2].stackSize += output.primaryOutput.stackSize;
}
}
else {
inventory[2].stackSize += itemstack.stackSize;
if(output.hasSecondary() && output.checkSecondary())
{
if(inventory[4] == null)
{
inventory[4] = output.secondaryOutput;
}
else {
inventory[4].stackSize += output.secondaryOutput.stackSize;
}
}
onInventoryChanged();
@ -123,30 +137,47 @@ public class TileEntityChanceMachine extends TileEntityBasicMachine
@Override
public boolean canOperate()
{
if(inventory[0] == null)
if(inventory[0] == null)
{
return false;
}
ItemStack itemstack = RecipeHandler.getOutput(inventory[0], false, getRecipes());
ChanceOutput output = RecipeHandler.getChanceOutput(inventory[0], false, getRecipes());
if(itemstack == null)
if(output == null)
{
return false;
}
if(inventory[2] == null)
if(output.hasPrimary())
{
return true;
if(inventory[2] != null && !inventory[2].isItemEqual(output.primaryOutput))
{
return false;
}
else {
if(inventory[2].stackSize + output.primaryOutput.stackSize > inventory[2].getMaxStackSize())
{
return false;
}
}
}
if(!inventory[2].isItemEqual(itemstack))
if(output.hasSecondary())
{
return false;
}
else {
return inventory[2].stackSize + itemstack.stackSize <= inventory[2].getMaxStackSize();
if(inventory[4] != null && !inventory[4].isItemEqual(output.secondaryOutput))
{
return false;
}
else {
if(inventory[4].stackSize + output.secondaryOutput.stackSize > inventory[4].getMaxStackSize())
{
return false;
}
}
}
return true;
}
@Override
@ -156,7 +187,7 @@ public class TileEntityChanceMachine extends TileEntityBasicMachine
{
return ChargeUtils.canBeOutputted(itemstack, false);
}
else if(slotID == 2)
else if(slotID == 2 || slotID == 4)
{
return true;
}

View file

@ -0,0 +1,22 @@
package mekanism.common.tile;
import java.util.Map;
import mekanism.common.Mekanism;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.recipe.RecipeHandler.Recipe;
import net.minecraft.util.ResourceLocation;
public class TileEntityPrecisionSawmill extends TileEntityChanceMachine
{
public TileEntityPrecisionSawmill()
{
super("PrecisionSawmill.ogg", "PrecisionSawmill", new ResourceLocation("mekanism", "gui/GuiPrecisionSawmill.png"), Mekanism.precisionSawmillUsage, 200, MachineType.PRECISION_SAWMILL.baseEnergy);
}
@Override
public Map getRecipes()
{
return Recipe.PRECISION_SAWMILL.get();
}
}

View file

@ -132,6 +132,16 @@ public final class StackUtils
return ret;
}
public static ItemStack copy(ItemStack stack)
{
if(stack == null)
{
return null;
}
return stack.copy();
}
public static int getSize(ItemStack stack)
{
return stack != null ? stack.stackSize : 0;

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View file

@ -28,6 +28,7 @@ item.GasMask.name=Gas Mask
item.Dictionary.name=Dictionary
item.ElectrolyticCore.name=Electrolytic Core
item.CompressedRedstone.name=Compressed Redstone
item.Sawdust=Sawdust
//Gas Tank
tile.GasTank.GasTank.name=Gas Tank
@ -76,6 +77,7 @@ tile.MachineBlock2.ChemicalInfuser.name=Chemical Infuser
tile.MachineBlock2.ChemicalCombiner.name=Chemical Combiner
tile.MachineBlock2.ChemicalInjectionChamber.name=Chemical Injection Chamber
tile.MachineBlock2.ElectrolyticSeparator.name=Electrolytic Separator
tile.MachineBlock2.PrecisionSawmill.name=Precision Sawmill
//Ore Block
tile.OreBlock.OsmiumOre.name=Osmium Ore

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB