From 41be14fad4d3d794d5637fd7d78f3520f659e818 Mon Sep 17 00:00:00 2001 From: Ben Spiers Date: Wed, 27 Aug 2014 20:15:33 +0100 Subject: [PATCH] Start to re-implement sound system in vanilla sounds. This will make us compatible with XU mufflers (when they're) fixed and reduce unneccesary reinvention of wheels. --- .../java/mekanism/client/sound/TestSound.java | 38 +++++++++++++++ .../java/mekanism/client/sound/TileSound.java | 4 +- .../common/tile/TileEntityCrusher.java | 48 ++++++++++++------- .../resources/assets/mekanism/sounds.json | 3 +- 4 files changed, 73 insertions(+), 20 deletions(-) create mode 100644 src/main/java/mekanism/client/sound/TestSound.java diff --git a/src/main/java/mekanism/client/sound/TestSound.java b/src/main/java/mekanism/client/sound/TestSound.java new file mode 100644 index 000000000..19de5f25e --- /dev/null +++ b/src/main/java/mekanism/client/sound/TestSound.java @@ -0,0 +1,38 @@ +package mekanism.client.sound; + +import net.minecraft.client.audio.ITickableSound; +import net.minecraft.client.audio.PositionedSound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class TestSound extends PositionedSound implements ITickableSound +{ + public boolean finished = true; + + public TestSound(ResourceLocation location, TileEntity tile) + { + super(location); + this.volume = 1.0f; + this.field_147663_c = 1.0f; + this.xPosF = tile.xCoord; + this.yPosF = tile.yCoord; + this.zPosF = tile.zCoord; + this.repeat = true; + this.field_147665_h = 0; + this.field_147666_i = AttenuationType.LINEAR; + } + + @Override + public boolean isDonePlaying() + { + return finished; + } + + @Override + public void update() + { + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/sound/TileSound.java b/src/main/java/mekanism/client/sound/TileSound.java index 24e5420ef..0b9996af0 100644 --- a/src/main/java/mekanism/client/sound/TileSound.java +++ b/src/main/java/mekanism/client/sound/TileSound.java @@ -49,7 +49,7 @@ public class TileSound extends Sound @Override public boolean update(World world) - { + {/* if(!super.update(world)) { return false; @@ -84,7 +84,7 @@ public class TileSound extends Sound { ticksSincePlay++; } - +*/ return true; } } diff --git a/src/main/java/mekanism/common/tile/TileEntityCrusher.java b/src/main/java/mekanism/common/tile/TileEntityCrusher.java index 16b86d8d1..9adbd8cb3 100644 --- a/src/main/java/mekanism/common/tile/TileEntityCrusher.java +++ b/src/main/java/mekanism/common/tile/TileEntityCrusher.java @@ -3,12 +3,20 @@ package mekanism.common.tile; import java.util.Map; import mekanism.api.MekanismConfig.usage; +import mekanism.client.sound.TestSound; +import mekanism.common.Mekanism; import mekanism.common.block.BlockMachine.MachineType; import mekanism.common.recipe.RecipeHandler.Recipe; +import net.minecraft.client.audio.ISound.AttenuationType; +import net.minecraft.client.audio.PositionedSound; +import net.minecraft.client.audio.PositionedSoundRecord; +import net.minecraft.util.ResourceLocation; +import cpw.mods.fml.client.FMLClientHandler; + public class TileEntityCrusher extends TileEntityElectricMachine { - public float crushMatrix = 0; + public TestSound sfx; public TileEntityCrusher() { @@ -22,28 +30,20 @@ public class TileEntityCrusher extends TileEntityElectricMachine if(worldObj.isRemote) { - if(crushMatrix < 6) + if(isActive && sfx.isDonePlaying()) { - crushMatrix+=0.2F; + Mekanism.logger.info("Playing Crusher noise"); + sfx.finished = false; + FMLClientHandler.instance().getClient().getSoundHandler().playSound(sfx); } - else { - crushMatrix = 0; + else if(!(isActive || sfx.isDonePlaying())) + { + Mekanism.logger.info("Stopping Crusher noise"); + sfx.finished = true; } } } - public float getMatrix() - { - float matrix = 0; - - if(crushMatrix <= 3) - { - return crushMatrix; - } - else { - return 3 - (crushMatrix-3); - } - } @Override public Map getRecipes() @@ -56,4 +56,18 @@ public class TileEntityCrusher extends TileEntityElectricMachine { return 0.5F; } + + @Override + public void validate() + { + super.validate(); + sfx = new TestSound(new ResourceLocation("mekanism", "tile.machine.crusher"), this); + } + + @Override + public void invalidate() + { + super.invalidate(); + sfx.finished = true; + } } diff --git a/src/main/resources/assets/mekanism/sounds.json b/src/main/resources/assets/mekanism/sounds.json index 9c9964136..d4fcd0e8f 100644 --- a/src/main/resources/assets/mekanism/sounds.json +++ b/src/main/resources/assets/mekanism/sounds.json @@ -6,5 +6,6 @@ "etc.GasMask": {"category": "master","sounds": [{"name": "etc/GasMask","stream": false}]}, "etc.Hydraulic": {"category": "master","sounds": [{"name": "etc/Hydraulic","stream": false}]}, "etc.Pop": {"category": "master","sounds": [{"name": "etc/Pop","stream": false}]}, - "etc.Success": {"category": "master","sounds": [{"name": "etc/Success","stream": false}]} + "etc.Success": {"category": "master","sounds": [{"name": "etc/Success","stream": false}]}, + "tile.machine.crusher": {"category": "block", "sounds": [{"name": "Crusher","stream": false}]} } \ No newline at end of file