From 3c547fa0aafb98244ba1868a0901ec9130eceff9 Mon Sep 17 00:00:00 2001 From: Ben Spiers Date: Fri, 5 Sep 2014 18:31:10 +0100 Subject: [PATCH] Fix factories and smelting. --- .../java/mekanism/api/util/StackUtils.java | 3 ++- .../java/mekanism/client/sound/TileSound.java | 9 +++++-- src/main/java/mekanism/common/Mekanism.java | 10 +++++--- .../java/mekanism/common/base/IFactory.java | 17 +++---------- .../mekanism/common/recipe/RecipeHandler.java | 3 ++- .../recipe/machines/SmeltingRecipe.java | 25 +++++++++++++++++++ .../tile/TileEntityEnergizedSmelter.java | 14 +++++------ .../common/tile/TileEntityFactory.java | 23 ++++++++++++----- .../tile/TileEntityNoisyElectricBlock.java | 16 +++++++----- 9 files changed, 80 insertions(+), 40 deletions(-) create mode 100644 src/main/java/mekanism/common/recipe/machines/SmeltingRecipe.java diff --git a/src/main/java/mekanism/api/util/StackUtils.java b/src/main/java/mekanism/api/util/StackUtils.java index a215038a1..d15c4fb1d 100644 --- a/src/main/java/mekanism/api/util/StackUtils.java +++ b/src/main/java/mekanism/api/util/StackUtils.java @@ -242,6 +242,7 @@ public final class StackUtils 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(); } } diff --git a/src/main/java/mekanism/client/sound/TileSound.java b/src/main/java/mekanism/client/sound/TileSound.java index 67472a9e4..32802e44f 100644 --- a/src/main/java/mekanism/client/sound/TileSound.java +++ b/src/main/java/mekanism/client/sound/TileSound.java @@ -23,7 +23,12 @@ 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); } - public TileSound(IHasSound source, String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) + 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) { this(source, sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR); } @@ -80,7 +85,7 @@ public class TileSound extends Sound implements IResettableSound { ticks++; } - if(!source.shouldPlaySound()) + if(!(source.shouldPlaySound() && source.getSound() == this)) { beginFadeOut = true; ticks = 0; diff --git a/src/main/java/mekanism/common/Mekanism.java b/src/main/java/mekanism/common/Mekanism.java index b9be33676..a393fb10e 100644 --- a/src/main/java/mekanism/common/Mekanism.java +++ b/src/main/java/mekanism/common/Mekanism.java @@ -57,11 +57,14 @@ import mekanism.common.network.PacketTransmitterUpdate.TransmitterUpdateMessage; import mekanism.common.recipe.BinRecipe; import mekanism.common.recipe.MekanismRecipe; 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.TileEntityBoundingBlock; import mekanism.common.tile.TileEntityCardboardBox; import mekanism.common.tile.TileEntityElectricBlock; -import mekanism.common.tile.TileEntityEnergizedSmelter; import mekanism.common.tile.TileEntityEntangledBlock; import mekanism.common.tile.TileEntitySalinationBlock; import mekanism.common.tile.TileEntitySalinationValve; @@ -960,12 +963,13 @@ public class Mekanism } //Load cached furnace recipes - TileEntityEnergizedSmelter.furnaceRecipes.clear(); + Recipe.ENERGIZED_SMELTER.get().clear(); for(Object obj : FurnaceRecipes.smelting().getSmeltingList().entrySet()) { Map.Entry entry = (Map.Entry)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()); diff --git a/src/main/java/mekanism/common/base/IFactory.java b/src/main/java/mekanism/common/base/IFactory.java index 454eda524..4f66f596f 100644 --- a/src/main/java/mekanism/common/base/IFactory.java +++ b/src/main/java/mekanism/common/base/IFactory.java @@ -4,24 +4,20 @@ import java.util.Map; import mekanism.api.gas.Gas; import mekanism.api.gas.GasStack; -import mekanism.common.recipe.inputs.AdvancedMachineInput; import mekanism.api.util.StackUtils; import mekanism.common.block.BlockMachine.MachineType; import mekanism.common.recipe.RecipeHandler; import mekanism.common.recipe.RecipeHandler.Recipe; +import mekanism.common.recipe.inputs.AdvancedMachineInput; import mekanism.common.recipe.inputs.ItemStackInput; -import mekanism.common.recipe.inputs.MachineInput; import mekanism.common.recipe.machines.AdvancedMachineRecipe; import mekanism.common.recipe.machines.BasicMachineRecipe; 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.util.MekanismUtils; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.util.ForgeDirection; @@ -48,7 +44,7 @@ public interface IFactory 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), CRUSHING("crushing", "crusher", MachineType.CRUSHER.getStack(), false, Recipe.CRUSHER), COMPRESSING("compressing", "compressor", MachineType.OSMIUM_COMPRESSOR.getStack(), true, Recipe.OSMIUM_COMPRESSOR), @@ -65,11 +61,6 @@ public interface IFactory public BasicMachineRecipe getRecipe(ItemStackInput input) { - if(this == SMELTING) - { - return null; - } - return RecipeHandler.getRecipe(input, recipe.get()); } @@ -80,7 +71,7 @@ public interface IFactory public AdvancedMachineRecipe getRecipe(AdvancedMachineInput input) { - return RecipeHandler.getRecipe(input, recipe.get()); + return RecipeHandler.getRecipe(input, recipe.get()); } public AdvancedMachineRecipe getRecipe(ItemStack input, Gas gas) @@ -211,7 +202,7 @@ public interface IFactory private RecipeType(String s, String s1, ItemStack is, boolean b, Recipe r) { name = s; - sound = new ResourceLocation("mekanism", s1); + sound = new ResourceLocation("mekanism", "tile.machine." + s1); stack = is; usesFuel = b; recipe = r; diff --git a/src/main/java/mekanism/common/recipe/RecipeHandler.java b/src/main/java/mekanism/common/recipe/RecipeHandler.java index 2e3414675..40ec37b36 100644 --- a/src/main/java/mekanism/common/recipe/RecipeHandler.java +++ b/src/main/java/mekanism/common/recipe/RecipeHandler.java @@ -5,7 +5,6 @@ import java.util.Map; import java.util.Set; import mekanism.api.gas.GasStack; -import mekanism.api.gas.GasTank; import mekanism.api.infuse.InfuseType; import mekanism.api.util.StackUtils; 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.SawmillRecipe; import mekanism.common.recipe.machines.SeparatorRecipe; +import mekanism.common.recipe.machines.SmeltingRecipe; import mekanism.common.recipe.machines.WasherRecipe; import net.minecraft.item.ItemStack; @@ -483,6 +483,7 @@ public final class RecipeHandler public static enum Recipe { + ENERGIZED_SMELTER(new HashMap()), ENRICHMENT_CHAMBER(new HashMap()), OSMIUM_COMPRESSOR(new HashMap()), COMBINER(new HashMap()), diff --git a/src/main/java/mekanism/common/recipe/machines/SmeltingRecipe.java b/src/main/java/mekanism/common/recipe/machines/SmeltingRecipe.java new file mode 100644 index 000000000..c762e9ce8 --- /dev/null +++ b/src/main/java/mekanism/common/recipe/machines/SmeltingRecipe.java @@ -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 +{ + 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()); + } +} diff --git a/src/main/java/mekanism/common/tile/TileEntityEnergizedSmelter.java b/src/main/java/mekanism/common/tile/TileEntityEnergizedSmelter.java index 2866ac577..90e4c6468 100644 --- a/src/main/java/mekanism/common/tile/TileEntityEnergizedSmelter.java +++ b/src/main/java/mekanism/common/tile/TileEntityEnergizedSmelter.java @@ -1,25 +1,23 @@ package mekanism.common.tile; -import java.util.HashMap; import java.util.Map; import mekanism.api.MekanismConfig.usage; 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 +public class TileEntityEnergizedSmelter extends TileEntityElectricMachine { - public static Map furnaceRecipes = new HashMap(); - public TileEntityEnergizedSmelter() { super("smelter", "EnergizedSmelter", usage.energizedSmelterUsage, 200, MachineType.ENERGIZED_SMELTER.baseEnergy); } @Override - public Map getRecipes() + public Map getRecipes() { - return furnaceRecipes; + return Recipe.ENERGIZED_SMELTER.get(); } } diff --git a/src/main/java/mekanism/common/tile/TileEntityFactory.java b/src/main/java/mekanism/common/tile/TileEntityFactory.java index 4c4c64567..59ee52844 100644 --- a/src/main/java/mekanism/common/tile/TileEntityFactory.java +++ b/src/main/java/mekanism/common/tile/TileEntityFactory.java @@ -16,6 +16,8 @@ import mekanism.api.gas.IGasHandler; import mekanism.api.gas.IGasItem; import mekanism.api.gas.ITubeConnection; import mekanism.api.util.StackUtils; +import mekanism.client.sound.IResettableSound; +import mekanism.client.sound.TileSound; import mekanism.common.Mekanism; import mekanism.common.MekanismItems; import mekanism.common.SideData; @@ -29,7 +31,6 @@ import mekanism.common.block.BlockMachine.MachineType; import mekanism.common.network.PacketTileEntity.TileEntityMessage; import mekanism.common.recipe.machines.AdvancedMachineRecipe; import mekanism.common.recipe.machines.BasicMachineRecipe; -import mekanism.common.recipe.machines.MachineRecipe; import mekanism.common.tile.component.TileComponentEjector; import mekanism.common.tile.component.TileComponentUpgrade; import mekanism.common.util.ChargeUtils; @@ -39,7 +40,6 @@ import mekanism.common.util.MekanismUtils; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.util.ForgeDirection; import cpw.mods.fml.common.Optional.Interface; import cpw.mods.fml.common.Optional.Method; @@ -87,7 +87,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I public int updateDelay; /** This machine's recipe type. */ - public RecipeType recipeType; + public RecipeType recipeType = RecipeType.SMELTING; /** This machine's previous amount of energy. */ public double prevEnergy; @@ -96,6 +96,8 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I public boolean sorting; + public IResettableSound[] sounds = new IResettableSound[RecipeType.values().length]; + /** This machine's current RedstoneControl type. */ public RedstoneControl controlType = RedstoneControl.DISABLED; @@ -646,7 +648,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I super.getNetworkedData(data); data.add(isActive); - data.add(recipeType); + data.add(recipeType.ordinal()); data.add(recipeTicks); data.add(controlType.ordinal()); data.add(sorting); @@ -816,9 +818,18 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I } @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 diff --git a/src/main/java/mekanism/common/tile/TileEntityNoisyElectricBlock.java b/src/main/java/mekanism/common/tile/TileEntityNoisyElectricBlock.java index dd0febe3c..35b6fb2e6 100644 --- a/src/main/java/mekanism/common/tile/TileEntityNoisyElectricBlock.java +++ b/src/main/java/mekanism/common/tile/TileEntityNoisyElectricBlock.java @@ -9,7 +9,6 @@ import mekanism.client.sound.SoundHandler; import mekanism.client.sound.TileSound; import mekanism.common.base.IActiveState; -import net.minecraft.client.audio.ISound; import net.minecraft.client.audio.ISound.AttenuationType; import net.minecraft.util.ResourceLocation; @@ -35,7 +34,7 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo } @Override - public ISound getSound() + public IResettableSound getSound() { return sound; } @@ -92,7 +91,12 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo public void validate() { super.validate(); - + + initSounds(); + } + + public void initSounds() + { sound = new TileSound(this, this); } @@ -101,10 +105,10 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo { super.onUpdate(); - if(worldObj.isRemote && shouldPlaySound() && SoundHandler.canRestartSound(sound) && client.enableMachineSounds) + if(worldObj.isRemote && shouldPlaySound() && SoundHandler.canRestartSound(getSound()) && client.enableMachineSounds) { - sound.reset(); - SoundHandler.playSound(sound); + getSound().reset(); + SoundHandler.playSound(getSound()); } } }