Fix factories and smelting.

This commit is contained in:
Ben Spiers 2014-09-05 18:31:10 +01:00
parent 29c94f9dd8
commit 3c547fa0aa
9 changed files with 80 additions and 40 deletions

View file

@ -242,6 +242,7 @@ public final class StackUtils
public static int hashItemStack(ItemStack stack) public static int hashItemStack(ItemStack stack)
{ {
return stack.getItem().getUnlocalizedName(stack).hashCode() << 8 | stack.getItemDamage(); String name = stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ? stack.getItem().getUnlocalizedName() : stack.getItem().getUnlocalizedName(stack);
return name.hashCode() << 8 | stack.getItemDamage();
} }
} }

View file

@ -23,6 +23,11 @@ public class TileSound extends Sound implements IResettableSound {
this(source, values.getSoundLocation(), values.getVolume(), values.getPitch(), values.shouldRepeat(), values.getRepeatDelay(), values.getSoundPosition().xPos, values.getSoundPosition().yPos, values.getSoundPosition().zPos); this(source, values.getSoundLocation(), values.getVolume(), values.getPitch(), values.shouldRepeat(), values.getRepeatDelay(), values.getSoundPosition().xPos, values.getSoundPosition().yPos, values.getSoundPosition().zPos);
} }
public TileSound(IHasSound source, ISoundSource values, ResourceLocation location)
{
this(source, location, values.getVolume(), values.getPitch(), values.shouldRepeat(), values.getRepeatDelay(), values.getSoundPosition().xPos, values.getSoundPosition().yPos, values.getSoundPosition().zPos);
}
public TileSound(IHasSound source, String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) public TileSound(IHasSound source, String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z)
{ {
this(source, sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR); this(source, sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
@ -80,7 +85,7 @@ public class TileSound extends Sound implements IResettableSound {
ticks++; ticks++;
} }
if(!source.shouldPlaySound()) if(!(source.shouldPlaySound() && source.getSound() == this))
{ {
beginFadeOut = true; beginFadeOut = true;
ticks = 0; ticks = 0;

View file

@ -57,11 +57,14 @@ import mekanism.common.network.PacketTransmitterUpdate.TransmitterUpdateMessage;
import mekanism.common.recipe.BinRecipe; import mekanism.common.recipe.BinRecipe;
import mekanism.common.recipe.MekanismRecipe; import mekanism.common.recipe.MekanismRecipe;
import mekanism.common.recipe.RecipeHandler; import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.machines.SmeltingRecipe;
import mekanism.common.recipe.outputs.ItemStackOutput;
import mekanism.common.tile.TileEntityAdvancedBoundingBlock; import mekanism.common.tile.TileEntityAdvancedBoundingBlock;
import mekanism.common.tile.TileEntityBoundingBlock; import mekanism.common.tile.TileEntityBoundingBlock;
import mekanism.common.tile.TileEntityCardboardBox; import mekanism.common.tile.TileEntityCardboardBox;
import mekanism.common.tile.TileEntityElectricBlock; import mekanism.common.tile.TileEntityElectricBlock;
import mekanism.common.tile.TileEntityEnergizedSmelter;
import mekanism.common.tile.TileEntityEntangledBlock; import mekanism.common.tile.TileEntityEntangledBlock;
import mekanism.common.tile.TileEntitySalinationBlock; import mekanism.common.tile.TileEntitySalinationBlock;
import mekanism.common.tile.TileEntitySalinationValve; import mekanism.common.tile.TileEntitySalinationValve;
@ -960,12 +963,13 @@ public class Mekanism
} }
//Load cached furnace recipes //Load cached furnace recipes
TileEntityEnergizedSmelter.furnaceRecipes.clear(); Recipe.ENERGIZED_SMELTER.get().clear();
for(Object obj : FurnaceRecipes.smelting().getSmeltingList().entrySet()) for(Object obj : FurnaceRecipes.smelting().getSmeltingList().entrySet())
{ {
Map.Entry<ItemStack, ItemStack> entry = (Map.Entry<ItemStack, ItemStack>)obj; Map.Entry<ItemStack, ItemStack> entry = (Map.Entry<ItemStack, ItemStack>)obj;
TileEntityEnergizedSmelter.furnaceRecipes.put(entry.getKey(), entry.getValue()); SmeltingRecipe recipe = new SmeltingRecipe(new ItemStackInput(entry.getKey()), new ItemStackOutput(entry.getValue()));
Recipe.ENERGIZED_SMELTER.put(recipe);
} }
event.registerServerCommand(new CommandMekanism()); event.registerServerCommand(new CommandMekanism());

View file

@ -4,24 +4,20 @@ import java.util.Map;
import mekanism.api.gas.Gas; import mekanism.api.gas.Gas;
import mekanism.api.gas.GasStack; import mekanism.api.gas.GasStack;
import mekanism.common.recipe.inputs.AdvancedMachineInput;
import mekanism.api.util.StackUtils; import mekanism.api.util.StackUtils;
import mekanism.common.block.BlockMachine.MachineType; import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.recipe.RecipeHandler; import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.RecipeHandler.Recipe; import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.inputs.AdvancedMachineInput;
import mekanism.common.recipe.inputs.ItemStackInput; import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.inputs.MachineInput;
import mekanism.common.recipe.machines.AdvancedMachineRecipe; import mekanism.common.recipe.machines.AdvancedMachineRecipe;
import mekanism.common.recipe.machines.BasicMachineRecipe; import mekanism.common.recipe.machines.BasicMachineRecipe;
import mekanism.common.recipe.machines.MachineRecipe; import mekanism.common.recipe.machines.MachineRecipe;
import mekanism.common.recipe.outputs.ItemStackOutput;
import mekanism.common.recipe.outputs.MachineOutput;
import mekanism.common.tile.TileEntityAdvancedElectricMachine; import mekanism.common.tile.TileEntityAdvancedElectricMachine;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
@ -48,7 +44,7 @@ public interface IFactory
public static enum RecipeType public static enum RecipeType
{ {
SMELTING("smelting", "smelter", MachineType.ENERGIZED_SMELTER.getStack(), false, null), SMELTING("smelting", "smelter", MachineType.ENERGIZED_SMELTER.getStack(), false, Recipe.ENERGIZED_SMELTER),
ENRICHING("enriching", "enrichment", MachineType.ENRICHMENT_CHAMBER.getStack(), false, Recipe.ENRICHMENT_CHAMBER), ENRICHING("enriching", "enrichment", MachineType.ENRICHMENT_CHAMBER.getStack(), false, Recipe.ENRICHMENT_CHAMBER),
CRUSHING("crushing", "crusher", MachineType.CRUSHER.getStack(), false, Recipe.CRUSHER), CRUSHING("crushing", "crusher", MachineType.CRUSHER.getStack(), false, Recipe.CRUSHER),
COMPRESSING("compressing", "compressor", MachineType.OSMIUM_COMPRESSOR.getStack(), true, Recipe.OSMIUM_COMPRESSOR), COMPRESSING("compressing", "compressor", MachineType.OSMIUM_COMPRESSOR.getStack(), true, Recipe.OSMIUM_COMPRESSOR),
@ -65,11 +61,6 @@ public interface IFactory
public BasicMachineRecipe getRecipe(ItemStackInput input) public BasicMachineRecipe getRecipe(ItemStackInput input)
{ {
if(this == SMELTING)
{
return null;
}
return RecipeHandler.getRecipe(input, recipe.get()); return RecipeHandler.getRecipe(input, recipe.get());
} }
@ -211,7 +202,7 @@ public interface IFactory
private RecipeType(String s, String s1, ItemStack is, boolean b, Recipe r) private RecipeType(String s, String s1, ItemStack is, boolean b, Recipe r)
{ {
name = s; name = s;
sound = new ResourceLocation("mekanism", s1); sound = new ResourceLocation("mekanism", "tile.machine." + s1);
stack = is; stack = is;
usesFuel = b; usesFuel = b;
recipe = r; recipe = r;

View file

@ -5,7 +5,6 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import mekanism.api.gas.GasStack; import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.api.infuse.InfuseType; import mekanism.api.infuse.InfuseType;
import mekanism.api.util.StackUtils; import mekanism.api.util.StackUtils;
import mekanism.common.recipe.inputs.AdvancedMachineInput; import mekanism.common.recipe.inputs.AdvancedMachineInput;
@ -36,6 +35,7 @@ import mekanism.common.recipe.machines.PressurizedRecipe;
import mekanism.common.recipe.machines.PurificationRecipe; import mekanism.common.recipe.machines.PurificationRecipe;
import mekanism.common.recipe.machines.SawmillRecipe; import mekanism.common.recipe.machines.SawmillRecipe;
import mekanism.common.recipe.machines.SeparatorRecipe; import mekanism.common.recipe.machines.SeparatorRecipe;
import mekanism.common.recipe.machines.SmeltingRecipe;
import mekanism.common.recipe.machines.WasherRecipe; import mekanism.common.recipe.machines.WasherRecipe;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -483,6 +483,7 @@ public final class RecipeHandler
public static enum Recipe public static enum Recipe
{ {
ENERGIZED_SMELTER(new HashMap<ItemStackInput, SmeltingRecipe>()),
ENRICHMENT_CHAMBER(new HashMap<ItemStackInput, EnrichmentRecipe>()), ENRICHMENT_CHAMBER(new HashMap<ItemStackInput, EnrichmentRecipe>()),
OSMIUM_COMPRESSOR(new HashMap<AdvancedMachineInput, OsmiumCompressorRecipe>()), OSMIUM_COMPRESSOR(new HashMap<AdvancedMachineInput, OsmiumCompressorRecipe>()),
COMBINER(new HashMap<AdvancedMachineInput, CombinerRecipe>()), COMBINER(new HashMap<AdvancedMachineInput, CombinerRecipe>()),

View file

@ -0,0 +1,25 @@
package mekanism.common.recipe.machines;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.outputs.ItemStackOutput;
import net.minecraft.item.ItemStack;
public class SmeltingRecipe extends BasicMachineRecipe<SmeltingRecipe>
{
public SmeltingRecipe(ItemStackInput input, ItemStackOutput output)
{
super(input, output);
}
public SmeltingRecipe(ItemStack input, ItemStack output)
{
super(input, output);
}
@Override
public SmeltingRecipe copy()
{
return new SmeltingRecipe(getInput().copy(), getOutput().copy());
}
}

View file

@ -1,25 +1,23 @@
package mekanism.common.tile; package mekanism.common.tile;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import mekanism.api.MekanismConfig.usage; import mekanism.api.MekanismConfig.usage;
import mekanism.common.block.BlockMachine.MachineType; import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.machines.SmeltingRecipe;
import net.minecraft.item.ItemStack; public class TileEntityEnergizedSmelter extends TileEntityElectricMachine<SmeltingRecipe>
public class TileEntityEnergizedSmelter extends TileEntityElectricMachine
{ {
public static Map<ItemStack, ItemStack> furnaceRecipes = new HashMap<ItemStack, ItemStack>();
public TileEntityEnergizedSmelter() public TileEntityEnergizedSmelter()
{ {
super("smelter", "EnergizedSmelter", usage.energizedSmelterUsage, 200, MachineType.ENERGIZED_SMELTER.baseEnergy); super("smelter", "EnergizedSmelter", usage.energizedSmelterUsage, 200, MachineType.ENERGIZED_SMELTER.baseEnergy);
} }
@Override @Override
public Map getRecipes() public Map<ItemStackInput, SmeltingRecipe> getRecipes()
{ {
return furnaceRecipes; return Recipe.ENERGIZED_SMELTER.get();
} }
} }

View file

@ -16,6 +16,8 @@ import mekanism.api.gas.IGasHandler;
import mekanism.api.gas.IGasItem; import mekanism.api.gas.IGasItem;
import mekanism.api.gas.ITubeConnection; import mekanism.api.gas.ITubeConnection;
import mekanism.api.util.StackUtils; import mekanism.api.util.StackUtils;
import mekanism.client.sound.IResettableSound;
import mekanism.client.sound.TileSound;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.MekanismItems; import mekanism.common.MekanismItems;
import mekanism.common.SideData; import mekanism.common.SideData;
@ -29,7 +31,6 @@ import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketTileEntity.TileEntityMessage; import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.recipe.machines.AdvancedMachineRecipe; import mekanism.common.recipe.machines.AdvancedMachineRecipe;
import mekanism.common.recipe.machines.BasicMachineRecipe; import mekanism.common.recipe.machines.BasicMachineRecipe;
import mekanism.common.recipe.machines.MachineRecipe;
import mekanism.common.tile.component.TileComponentEjector; import mekanism.common.tile.component.TileComponentEjector;
import mekanism.common.tile.component.TileComponentUpgrade; import mekanism.common.tile.component.TileComponentUpgrade;
import mekanism.common.util.ChargeUtils; import mekanism.common.util.ChargeUtils;
@ -39,7 +40,6 @@ import mekanism.common.util.MekanismUtils;
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.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.Optional.Interface; import cpw.mods.fml.common.Optional.Interface;
import cpw.mods.fml.common.Optional.Method; import cpw.mods.fml.common.Optional.Method;
@ -87,7 +87,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
public int updateDelay; public int updateDelay;
/** This machine's recipe type. */ /** This machine's recipe type. */
public RecipeType recipeType; public RecipeType recipeType = RecipeType.SMELTING;
/** This machine's previous amount of energy. */ /** This machine's previous amount of energy. */
public double prevEnergy; public double prevEnergy;
@ -96,6 +96,8 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
public boolean sorting; public boolean sorting;
public IResettableSound[] sounds = new IResettableSound[RecipeType.values().length];
/** This machine's current RedstoneControl type. */ /** This machine's current RedstoneControl type. */
public RedstoneControl controlType = RedstoneControl.DISABLED; public RedstoneControl controlType = RedstoneControl.DISABLED;
@ -646,7 +648,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
super.getNetworkedData(data); super.getNetworkedData(data);
data.add(isActive); data.add(isActive);
data.add(recipeType); data.add(recipeType.ordinal());
data.add(recipeTicks); data.add(recipeTicks);
data.add(controlType.ordinal()); data.add(controlType.ordinal());
data.add(sorting); data.add(sorting);
@ -816,9 +818,18 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
} }
@Override @Override
public ResourceLocation getSoundLocation() public IResettableSound getSound()
{ {
return recipeType.getSound(); return sounds[recipeType.ordinal()];
}
@Override
public void initSounds()
{
for(RecipeType type : RecipeType.values())
{
sounds[type.ordinal()] = new TileSound(this, this, type.getSound());
}
} }
@Override @Override

View file

@ -9,7 +9,6 @@ import mekanism.client.sound.SoundHandler;
import mekanism.client.sound.TileSound; import mekanism.client.sound.TileSound;
import mekanism.common.base.IActiveState; import mekanism.common.base.IActiveState;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.ISound.AttenuationType; import net.minecraft.client.audio.ISound.AttenuationType;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@ -35,7 +34,7 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo
} }
@Override @Override
public ISound getSound() public IResettableSound getSound()
{ {
return sound; return sound;
} }
@ -93,6 +92,11 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo
{ {
super.validate(); super.validate();
initSounds();
}
public void initSounds()
{
sound = new TileSound(this, this); sound = new TileSound(this, this);
} }
@ -101,10 +105,10 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo
{ {
super.onUpdate(); super.onUpdate();
if(worldObj.isRemote && shouldPlaySound() && SoundHandler.canRestartSound(sound) && client.enableMachineSounds) if(worldObj.isRemote && shouldPlaySound() && SoundHandler.canRestartSound(getSound()) && client.enableMachineSounds)
{ {
sound.reset(); getSound().reset();
SoundHandler.playSound(sound); SoundHandler.playSound(getSound());
} }
} }
} }