From 7ed53429212c118d84c6c01911773b50ff9ae31f Mon Sep 17 00:00:00 2001 From: MartinTheDragon Date: Tue, 12 Sep 2023 15:00:33 +0200 Subject: [PATCH 1/2] Make ModSoundType more versatile - Fine-grained control over block sound subtypes - Allows copying from existing sounds - Volume and pitch envelopes Also moved custom sound types into their own class. --- src/main/java/com/hbm/blocks/ModBlocks.java | 90 +++++----- .../java/com/hbm/blocks/ModSoundType.java | 158 +++++++++++++++++- .../java/com/hbm/blocks/ModSoundTypes.java | 7 + 3 files changed, 199 insertions(+), 56 deletions(-) create mode 100644 src/main/java/com/hbm/blocks/ModSoundTypes.java diff --git a/src/main/java/com/hbm/blocks/ModBlocks.java b/src/main/java/com/hbm/blocks/ModBlocks.java index 7601d719a..196925a44 100644 --- a/src/main/java/com/hbm/blocks/ModBlocks.java +++ b/src/main/java/com/hbm/blocks/ModBlocks.java @@ -1,38 +1,37 @@ package com.hbm.blocks; -import com.hbm.blocks.generic.*; -import com.hbm.blocks.generic.BlockHazard.ExtDisplayEffect; -import com.hbm.blocks.generic.BlockMotherOfAllOres.ItemRandomOreBlock; import com.hbm.blocks.BlockEnums.*; import com.hbm.blocks.bomb.*; import com.hbm.blocks.fluid.*; import com.hbm.blocks.gas.*; +import com.hbm.blocks.generic.*; +import com.hbm.blocks.generic.BlockHazard.ExtDisplayEffect; +import com.hbm.blocks.generic.BlockMotherOfAllOres.ItemRandomOreBlock; import com.hbm.blocks.machine.*; import com.hbm.blocks.machine.pile.*; import com.hbm.blocks.machine.rbmk.*; import com.hbm.blocks.network.*; -import com.hbm.blocks.rail.RailNarrowCurve; -import com.hbm.blocks.rail.RailNarrowStraight; -import com.hbm.blocks.rail.RailStandardBuffer; -import com.hbm.blocks.rail.RailStandardCurve; -import com.hbm.blocks.rail.RailStandardRamp; -import com.hbm.blocks.rail.RailStandardStraight; -import com.hbm.blocks.siege.*; +import com.hbm.blocks.rail.*; +import com.hbm.blocks.siege.SiegeCircuit; +import com.hbm.blocks.siege.SiegeHole; +import com.hbm.blocks.siege.SiegeInternal; +import com.hbm.blocks.siege.SiegeShield; import com.hbm.blocks.test.*; import com.hbm.blocks.turret.*; import com.hbm.items.block.*; -import com.hbm.items.bomb.*; +import com.hbm.items.bomb.ItemPrototypeBlock; import com.hbm.items.special.ItemOreBlock; import com.hbm.lib.ModDamageSource; import com.hbm.lib.RefStrings; import com.hbm.main.MainRegistry; import com.hbm.tileentity.DoorDecl; import com.hbm.tileentity.machine.storage.TileEntityFileCabinet; - import cpw.mods.fml.common.registry.GameRegistry; import net.minecraft.block.Block; import net.minecraft.block.BlockFalling; -import net.minecraft.block.material.*; +import net.minecraft.block.material.MapColor; +import net.minecraft.block.material.Material; +import net.minecraft.block.material.MaterialLiquid; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.ItemBlock; import net.minecraftforge.fluids.Fluid; @@ -1263,19 +1262,6 @@ public class ModBlocks { public static Material materialGas = new MaterialGas(); - public static Block.SoundType soundTypeGrate = new ModSoundType("metalBlock", 0.5F, 1.0F) { - - @Override - public String func_150496_b() { - return Block.soundTypeMetal.func_150496_b(); - } - - @Override - public String getBreakSound() { - return "dig.stone"; - } - }; - private static void initializeBlock() { test_render = new TestRender(Material.rock).setBlockName("test_render").setCreativeTab(null); @@ -1676,33 +1662,33 @@ public class ModBlocks { steel_roof = new DecoBlock(Material.iron).setBlockName("steel_roof").setCreativeTab(MainRegistry.blockTab).setHardness(5.0F).setResistance(15.0F).setBlockTextureName(RefStrings.MODID + ":steel_roof"); steel_beam = new DecoBlock(Material.iron).setBlockName("steel_beam").setCreativeTab(MainRegistry.blockTab).setHardness(5.0F).setResistance(15.0F).setBlockTextureName(RefStrings.MODID + ":steel_beam"); steel_scaffold = new BlockScaffold().setBlockName("steel_scaffold").setCreativeTab(MainRegistry.blockTab).setHardness(5.0F).setResistance(15.0F).setBlockTextureName(RefStrings.MODID + ":deco_steel_orig"); - steel_grate = new BlockGrate(Material.iron).setBlockName("steel_grate").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F); - steel_grate_wide = new BlockGrate(Material.iron).setBlockName("steel_grate_wide").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F); + steel_grate = new BlockGrate(Material.iron).setBlockName("steel_grate").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F); + steel_grate_wide = new BlockGrate(Material.iron).setBlockName("steel_grate_wide").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F); - deco_pipe = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side", 0).setBlockName("deco_pipe").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top"); - deco_pipe_rusted = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_rusty", 0).setBlockName("deco_pipe_rusted").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_rusty"); - deco_pipe_green = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_green", 0).setBlockName("deco_pipe_green").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_green"); - deco_pipe_green_rusted = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_green_rusty", 0).setBlockName("deco_pipe_green_rusted").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_green_rusty"); - deco_pipe_red = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_red", 0).setBlockName("deco_pipe_red").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_red"); - deco_pipe_marked = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_marked", 0).setBlockName("deco_pipe_marked").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_marked"); - deco_pipe_rim = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side", 1).setBlockName("deco_pipe_rim").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top"); - deco_pipe_rim_rusted = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_rusty", 1).setBlockName("deco_pipe_rim_rusted").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_rusty"); - deco_pipe_rim_green = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_green", 1).setBlockName("deco_pipe_rim_green").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_green"); - deco_pipe_rim_green_rusted = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_green_rusty", 1).setBlockName("deco_pipe_rim_green_rusted").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_green_rusty"); - deco_pipe_rim_red = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_red", 1).setBlockName("deco_pipe_rim_red").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_red"); - deco_pipe_rim_marked = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_marked", 1).setBlockName("deco_pipe_rim_marked").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_marked"); - deco_pipe_framed = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side", 3).setBlockName("deco_pipe_framed").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top"); - deco_pipe_framed_rusted = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_rusty", 3).setBlockName("deco_pipe_framed_rusted").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_rusty"); - deco_pipe_framed_green = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_green", 3).setBlockName("deco_pipe_framed_green").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_green"); - deco_pipe_framed_green_rusted = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_green_rusty", 3).setBlockName("deco_pipe_framed_green_rusted").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_green_rusty"); - deco_pipe_framed_red = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_red", 3).setBlockName("deco_pipe_framed_red").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_red"); - deco_pipe_framed_marked = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_marked", 3).setBlockName("deco_pipe_framed_marked").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_marked"); - deco_pipe_quad = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side", 2).setBlockName("deco_pipe_quad").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top"); - deco_pipe_quad_rusted = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_rusty", 2).setBlockName("deco_pipe_quad_rusted").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_rusty"); - deco_pipe_quad_green = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_green", 2).setBlockName("deco_pipe_quad_green").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_green"); - deco_pipe_quad_green_rusted = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_green_rusty", 2).setBlockName("deco_pipe_quad_green_rusted").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_green_rusty"); - deco_pipe_quad_red = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_red", 2).setBlockName("deco_pipe_quad_red").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_red"); - deco_pipe_quad_marked = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_marked", 2).setBlockName("deco_pipe_quad_marked").setStepSound(soundTypeGrate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_marked"); + deco_pipe = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side", 0).setBlockName("deco_pipe").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top"); + deco_pipe_rusted = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_rusty", 0).setBlockName("deco_pipe_rusted").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_rusty"); + deco_pipe_green = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_green", 0).setBlockName("deco_pipe_green").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_green"); + deco_pipe_green_rusted = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_green_rusty", 0).setBlockName("deco_pipe_green_rusted").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_green_rusty"); + deco_pipe_red = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_red", 0).setBlockName("deco_pipe_red").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_red"); + deco_pipe_marked = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_marked", 0).setBlockName("deco_pipe_marked").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_marked"); + deco_pipe_rim = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side", 1).setBlockName("deco_pipe_rim").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top"); + deco_pipe_rim_rusted = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_rusty", 1).setBlockName("deco_pipe_rim_rusted").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_rusty"); + deco_pipe_rim_green = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_green", 1).setBlockName("deco_pipe_rim_green").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_green"); + deco_pipe_rim_green_rusted = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_green_rusty", 1).setBlockName("deco_pipe_rim_green_rusted").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_green_rusty"); + deco_pipe_rim_red = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_red", 1).setBlockName("deco_pipe_rim_red").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_red"); + deco_pipe_rim_marked = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_marked", 1).setBlockName("deco_pipe_rim_marked").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_marked"); + deco_pipe_framed = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side", 3).setBlockName("deco_pipe_framed").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top"); + deco_pipe_framed_rusted = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_rusty", 3).setBlockName("deco_pipe_framed_rusted").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_rusty"); + deco_pipe_framed_green = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_green", 3).setBlockName("deco_pipe_framed_green").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_green"); + deco_pipe_framed_green_rusted = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_green_rusty", 3).setBlockName("deco_pipe_framed_green_rusted").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_green_rusty"); + deco_pipe_framed_red = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_red", 3).setBlockName("deco_pipe_framed_red").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_red"); + deco_pipe_framed_marked = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_marked", 3).setBlockName("deco_pipe_framed_marked").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_marked"); + deco_pipe_quad = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side", 2).setBlockName("deco_pipe_quad").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top"); + deco_pipe_quad_rusted = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_rusty", 2).setBlockName("deco_pipe_quad_rusted").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_rusty"); + deco_pipe_quad_green = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_green", 2).setBlockName("deco_pipe_quad_green").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_green"); + deco_pipe_quad_green_rusted = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_green_rusty", 2).setBlockName("deco_pipe_quad_green_rusted").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_green_rusty"); + deco_pipe_quad_red = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_red", 2).setBlockName("deco_pipe_quad_red").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_red"); + deco_pipe_quad_marked = new BlockPipe(Material.iron, RefStrings.MODID + ":pipe_side_marked", 2).setBlockName("deco_pipe_quad_marked").setStepSound(ModSoundTypes.grate).setCreativeTab(MainRegistry.blockTab).setHardness(2.0F).setResistance(5.0F).setBlockTextureName(RefStrings.MODID + ":pipe_top_marked"); broadcaster_pc = new PinkCloudBroadcaster(Material.iron).setBlockName("broadcaster_pc").setCreativeTab(MainRegistry.machineTab).setHardness(5.0F).setResistance(15.0F).setBlockTextureName(RefStrings.MODID + ":broadcaster_pc"); geiger = new GeigerCounter(Material.iron).setBlockName("geiger").setCreativeTab(MainRegistry.machineTab).setHardness(15.0F).setResistance(0.25F).setBlockTextureName(RefStrings.MODID + ":geiger"); diff --git a/src/main/java/com/hbm/blocks/ModSoundType.java b/src/main/java/com/hbm/blocks/ModSoundType.java index 331a7e27a..0bd8e8a46 100644 --- a/src/main/java/com/hbm/blocks/ModSoundType.java +++ b/src/main/java/com/hbm/blocks/ModSoundType.java @@ -2,18 +2,168 @@ package com.hbm.blocks; import net.minecraft.block.Block; +import java.util.Random; + public class ModSoundType extends Block.SoundType { + protected final String placeSound; + protected final String breakSound; + protected final String stepSound; - public ModSoundType(String name, float volume, float pitch) { - super(name, volume, pitch); + protected ModSoundType(String placeSound, String breakSound, String stepSound, float volume, float pitch) { + super("", volume, pitch); + this.placeSound = placeSound; + this.breakSound = breakSound; + this.stepSound = stepSound; } + public ModEnvelopedSoundType enveloped() { + return new ModEnvelopedSoundType(placeSound, breakSound, stepSound, volume, frequency); + } + + public ModEnvelopedSoundType enveloped(Random random) { + return new ModEnvelopedSoundType(placeSound, breakSound, stepSound, volume, frequency, random); + } + + @Override + public String func_150496_b() { + return placeSound; + } + + @Override public String getBreakSound() { - return "hbm:" + super.getBreakSound(); + return breakSound; } + @Override public String getStepResourcePath() { - return "hbm:" + super.getStepResourcePath(); + return stepSound; } + // creates a sound type with vanilla-like sound strings name-spaced to the mod + public static ModSoundType mod(String soundName, float volume, float pitch) { + return new ModSoundType(modDig(soundName), modDig(soundName), modStep(soundName), volume, pitch); + } + + // these permutations allow creating a sound type with one of the three sounds being custom + // and the other ones defaulting to vanilla-like sound strings name-spaced to the mod + + public static ModSoundType customPlace(String soundName, String placeSound, float volume, float pitch) { + return new ModSoundType(placeSound, modDig(soundName), modStep(soundName), volume, pitch); + } + + public static ModSoundType customBreak(String soundName, String breakSound, float volume, float pitch) { + return new ModSoundType(modDig(soundName), breakSound, modStep(soundName), volume, pitch); + } + + public static ModSoundType customStep(String soundName, String stepSound, float volume, float pitch) { + return new ModSoundType(modDig(soundName), modDig(soundName), stepSound, volume, pitch); + } + + public static ModSoundType customDig(String soundName, String digSound, float volume, float pitch) { + return new ModSoundType(digSound, digSound, modStep(soundName), volume, pitch); + } + + // these permutations copy sounds from an existing sound type and modify one of the sounds, + // but with a manual path for the custom sound + + public static ModSoundType customPlace(Block.SoundType from, String placeSound, float volume, float pitch) { + return new ModSoundType(placeSound, from.getBreakSound(), from.getStepResourcePath(), volume, pitch); + } + + public static ModSoundType customBreak(Block.SoundType from, String breakSound, float volume, float pitch) { + return new ModSoundType(from.func_150496_b(), breakSound, from.getStepResourcePath(), volume, pitch); + } + + public static ModSoundType customStep(Block.SoundType from, String stepSound, float volume, float pitch) { + return new ModSoundType(from.func_150496_b(), from.getBreakSound(), stepSound, volume, pitch); + } + + public static ModSoundType customDig(Block.SoundType from, String dig, float volume, float pitch) { + return new ModSoundType(dig, dig, from.getStepResourcePath(), volume, pitch); + } + + // customizes all sounds + public static ModSoundType placeBreakStep(String placeSound, String breakSound, String stepSound, float volume, float pitch) { + return new ModSoundType(placeSound, breakSound, stepSound, volume, pitch); + } + + private static String modDig(String soundName) { + return "hbm:dig." + soundName; + } + + private static String modStep(String soundName) { + return "hbm:step." + soundName; + } + + public static class ModEnvelopedSoundType extends ModSoundType { + private final Random random; + + ModEnvelopedSoundType(String placeSound, String breakSound, String stepSound, float volume, float pitch, Random random) { + super(placeSound, breakSound, stepSound, volume, pitch); + this.random = random; + } + + ModEnvelopedSoundType(String placeSound, String breakSound, String stepSound, float volume, float pitch) { + this(placeSound, breakSound, stepSound, volume, pitch, new Random()); + } + + // a bit of a hack, but most of the time, playSound is called with the sound path queried first, and then volume and pitch + private SubType probableSubType = SubType.PLACE; + + @Override + public String func_150496_b() { + probableSubType = SubType.PLACE; + return super.func_150496_b(); + } + + @Override + public String getBreakSound() { + probableSubType = SubType.BREAK; + return super.getBreakSound(); + } + + @Override + public String getStepResourcePath() { + probableSubType = SubType.STEP; + return super.getStepResourcePath(); + } + + private Envelope volumeEnvelope = null; + private Envelope pitchEnvelope = null; + + public ModEnvelopedSoundType volumeFunction(Envelope volumeEnvelope) { + this.volumeEnvelope = volumeEnvelope; + return this; + } + + public ModEnvelopedSoundType pitchFunction(Envelope pitchEnvelope) { + this.pitchEnvelope = pitchEnvelope; + return this; + } + + @Override + public float getVolume() { + if (volumeEnvelope == null) + return super.getVolume(); + else + return volumeEnvelope.compute(super.getVolume(), random, probableSubType); + } + + @Override + public float getPitch() { + if (pitchEnvelope == null) + return super.getPitch(); + else + return pitchEnvelope.compute(super.getPitch(), random, probableSubType); + } + + @FunctionalInterface + public interface Envelope { + float compute(float in, Random rand, SubType type); + } + } + + public enum SubType { + PLACE, BREAK, STEP + } } diff --git a/src/main/java/com/hbm/blocks/ModSoundTypes.java b/src/main/java/com/hbm/blocks/ModSoundTypes.java new file mode 100644 index 000000000..2b4213cd4 --- /dev/null +++ b/src/main/java/com/hbm/blocks/ModSoundTypes.java @@ -0,0 +1,7 @@ +package com.hbm.blocks; + +import net.minecraft.block.Block; + +class ModSoundTypes { + static final ModSoundType grate = ModSoundType.customStep(Block.soundTypeStone, "hbm:step.metalBlock", 0.5F, 1.0F); +} From 283569d28f985897dc237018f2b53aa39121dd70 Mon Sep 17 00:00:00 2001 From: MartinTheDragon Date: Tue, 12 Sep 2023 15:25:13 +0200 Subject: [PATCH 2/2] Play pipe sound when placing default ducts --- src/main/java/com/hbm/blocks/ModBlocks.java | 2 +- .../java/com/hbm/blocks/ModSoundTypes.java | 2 + .../com/hbm/items/machine/ItemFluidDuct.java | 7 +- src/main/java/com/hbm/main/MainRegistry.java | 140 +++++++++--------- 4 files changed, 73 insertions(+), 78 deletions(-) diff --git a/src/main/java/com/hbm/blocks/ModBlocks.java b/src/main/java/com/hbm/blocks/ModBlocks.java index 196925a44..868165597 100644 --- a/src/main/java/com/hbm/blocks/ModBlocks.java +++ b/src/main/java/com/hbm/blocks/ModBlocks.java @@ -1958,7 +1958,7 @@ public class ModBlocks { machine_detector = new PowerDetector(Material.iron).setBlockName("machine_detector").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":machine_detector_off"); fluid_duct = new BlockFluidDuct(Material.iron).setBlockName("fluid_duct").setHardness(5.0F).setResistance(10.0F).setCreativeTab(null).setBlockTextureName(RefStrings.MODID + ":fluid_duct_icon"); fluid_duct_solid = new BlockFluidDuctSolid(Material.iron).setBlockName("fluid_duct_solid").setHardness(5.0F).setResistance(10.0F).setCreativeTab(null).setBlockTextureName(RefStrings.MODID + ":fluid_duct_solid"); - fluid_duct_neo = new FluidDuctStandard(Material.iron).setBlockName("fluid_duct_neo").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":pipe_neo"); + fluid_duct_neo = new FluidDuctStandard(Material.iron).setBlockName("fluid_duct_neo").setStepSound(ModSoundTypes.pipe).setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":pipe_neo"); fluid_duct_box = new FluidDuctBox(Material.iron).setBlockName("fluid_duct_box").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":fluid_duct_box"); fluid_duct_exhaust = new FluidDuctBoxExhaust(Material.iron).setBlockName("fluid_duct_exhaust").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":fluid_duct_box"); fluid_duct_paintable = new FluidDuctPaintable().setBlockName("fluid_duct_paintable").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab); diff --git a/src/main/java/com/hbm/blocks/ModSoundTypes.java b/src/main/java/com/hbm/blocks/ModSoundTypes.java index 2b4213cd4..544f70c1e 100644 --- a/src/main/java/com/hbm/blocks/ModSoundTypes.java +++ b/src/main/java/com/hbm/blocks/ModSoundTypes.java @@ -1,7 +1,9 @@ package com.hbm.blocks; +import com.hbm.main.MainRegistry; import net.minecraft.block.Block; class ModSoundTypes { static final ModSoundType grate = ModSoundType.customStep(Block.soundTypeStone, "hbm:step.metalBlock", 0.5F, 1.0F); + static final ModSoundType pipe = ModSoundType.customDig(Block.soundTypeMetal, "hbm:block.pipePlaced", 0.85F, 0.65F).enveloped(MainRegistry.instance.rand).pitchFunction((in, rand, type) -> { if (type == ModSoundType.SubType.BREAK) in -= 0.15F; return type == ModSoundType.SubType.STEP ? in : in + rand.nextFloat() * 0.2F; }); } diff --git a/src/main/java/com/hbm/items/machine/ItemFluidDuct.java b/src/main/java/com/hbm/items/machine/ItemFluidDuct.java index b366e39ea..93413ee62 100644 --- a/src/main/java/com/hbm/items/machine/ItemFluidDuct.java +++ b/src/main/java/com/hbm/items/machine/ItemFluidDuct.java @@ -1,12 +1,9 @@ package com.hbm.items.machine; -import java.util.List; - import com.hbm.blocks.ModBlocks; import com.hbm.inventory.fluid.FluidType; import com.hbm.inventory.fluid.Fluids; import com.hbm.tileentity.network.TileEntityPipeBaseNT; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.texture.IIconRegister; @@ -19,6 +16,8 @@ import net.minecraft.util.IIcon; import net.minecraft.util.StatCollector; import net.minecraft.world.World; +import java.util.List; + public class ItemFluidDuct extends Item { IIcon overlayIcon; @@ -126,8 +125,6 @@ public class ItemFluidDuct extends Item { ((TileEntityPipeBaseNT) world.getTileEntity(x, y, z)).setType(Fluids.fromID(stack.getItemDamage())); } - world.playSoundEffect(x, y, z, "hbm:block.pipePlaced", 1.0F, 0.65F + world.rand.nextFloat() * 0.2F); - return true; } } diff --git a/src/main/java/com/hbm/main/MainRegistry.java b/src/main/java/com/hbm/main/MainRegistry.java index 7c3542ec2..44e8ebca1 100644 --- a/src/main/java/com/hbm/main/MainRegistry.java +++ b/src/main/java/com/hbm/main/MainRegistry.java @@ -1,6 +1,71 @@ package com.hbm.main; +import com.google.common.collect.ImmutableList; +import com.hbm.blocks.BlockEnums.EnumStoneType; +import com.hbm.blocks.ModBlocks; +import com.hbm.blocks.generic.BlockMotherOfAllOres; +import com.hbm.blocks.generic.BlockToolConversion; +import com.hbm.commands.CommandDebugChunkLoad; +import com.hbm.commands.CommandReloadRecipes; import com.hbm.commands.CommandSatellites; +import com.hbm.config.*; +import com.hbm.crafting.RodRecipes; +import com.hbm.creativetabs.*; +import com.hbm.entity.EntityMappings; +import com.hbm.entity.grenade.*; +import com.hbm.entity.logic.IChunkLoader; +import com.hbm.entity.mob.siege.SiegeTier; +import com.hbm.handler.*; +import com.hbm.handler.imc.IMCBlastFurnace; +import com.hbm.handler.imc.IMCCentrifuge; +import com.hbm.handler.imc.IMCCrystallizer; +import com.hbm.handler.imc.IMCHandler; +import com.hbm.handler.pollution.PollutionHandler; +import com.hbm.handler.radiation.ChunkRadiationManager; +import com.hbm.hazard.HazardRegistry; +import com.hbm.inventory.FluidContainerRegistry; +import com.hbm.inventory.OreDictManager; +import com.hbm.inventory.OreDictManager.DictFrame; +import com.hbm.inventory.fluid.Fluids; +import com.hbm.inventory.recipes.*; +import com.hbm.inventory.recipes.anvil.AnvilRecipes; +import com.hbm.inventory.recipes.loader.SerializableRecipe; +import com.hbm.items.ItemAmmoEnums.Ammo4Gauge; +import com.hbm.items.ItemEnums.EnumAchievementType; +import com.hbm.items.ModItems; +import com.hbm.items.tool.ItemFertilizer; +import com.hbm.items.weapon.ItemGenericGrenade; +import com.hbm.lib.HbmWorld; +import com.hbm.lib.Library; +import com.hbm.lib.RefStrings; +import com.hbm.packet.PacketDispatcher; +import com.hbm.potion.HbmPotion; +import com.hbm.saveddata.satellites.Satellite; +import com.hbm.tileentity.TileMappings; +import com.hbm.tileentity.bomb.TileEntityNukeCustom; +import com.hbm.tileentity.machine.TileEntityMachineReactorLarge; +import com.hbm.tileentity.machine.TileEntityNukeFurnace; +import com.hbm.tileentity.machine.rbmk.RBMKDials; +import com.hbm.util.*; +import com.hbm.world.feature.BedrockOre; +import com.hbm.world.feature.OreCave; +import com.hbm.world.feature.OreLayer3D; +import com.hbm.world.feature.SchistStratum; +import com.hbm.world.generator.CellularDungeonFactory; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.Mod.EventHandler; +import cpw.mods.fml.common.Mod.Instance; +import cpw.mods.fml.common.Mod.Metadata; +import cpw.mods.fml.common.ModMetadata; +import cpw.mods.fml.common.SidedProxy; +import cpw.mods.fml.common.event.*; +import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent; +import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage; +import cpw.mods.fml.common.event.FMLMissingMappingsEvent.MissingMapping; +import cpw.mods.fml.common.network.NetworkRegistry; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; import net.minecraft.block.BlockDispenser; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.dispenser.BehaviorDefaultDispenseItem; @@ -26,12 +91,8 @@ import net.minecraftforge.common.ForgeChunkManager.Ticket; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.util.EnumHelper; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.Mod; -import cpw.mods.fml.common.Mod.EventHandler; -import cpw.mods.fml.common.Mod.Instance; -import cpw.mods.fml.common.Mod.Metadata; -import cpw.mods.fml.common.ModMetadata; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.File; import java.util.HashMap; @@ -40,71 +101,6 @@ import java.util.List; import java.util.Map.Entry; import java.util.Random; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import com.google.common.collect.ImmutableList; -import com.hbm.blocks.BlockEnums.EnumStoneType; -import com.hbm.blocks.ModBlocks; -import com.hbm.blocks.generic.BlockMotherOfAllOres; -import com.hbm.blocks.generic.BlockToolConversion; -import com.hbm.commands.CommandDebugChunkLoad; -import com.hbm.commands.CommandReloadRecipes; -import com.hbm.config.*; -import com.hbm.crafting.RodRecipes; -import com.hbm.creativetabs.*; -import com.hbm.entity.EntityMappings; -import com.hbm.entity.grenade.*; -import com.hbm.entity.logic.*; -import com.hbm.entity.mob.siege.*; -import com.hbm.handler.*; -import com.hbm.handler.imc.*; -import com.hbm.handler.pollution.PollutionHandler; -import com.hbm.handler.radiation.ChunkRadiationManager; -import com.hbm.hazard.HazardRegistry; -import com.hbm.inventory.*; -import com.hbm.inventory.OreDictManager.DictFrame; -import com.hbm.inventory.fluid.Fluids; -import com.hbm.inventory.recipes.*; -import com.hbm.inventory.recipes.anvil.AnvilRecipes; -import com.hbm.inventory.recipes.loader.SerializableRecipe; -import com.hbm.items.ModItems; -import com.hbm.items.tool.ItemFertilizer; -import com.hbm.items.weapon.ItemGenericGrenade; -import com.hbm.items.ItemAmmoEnums.Ammo4Gauge; -import com.hbm.items.ItemEnums.EnumAchievementType; -import com.hbm.lib.HbmWorld; -import com.hbm.lib.Library; -import com.hbm.lib.RefStrings; -import com.hbm.packet.PacketDispatcher; -import com.hbm.potion.HbmPotion; -import com.hbm.saveddata.satellites.Satellite; -import com.hbm.tileentity.TileMappings; -import com.hbm.tileentity.bomb.TileEntityNukeCustom; -import com.hbm.tileentity.machine.*; -import com.hbm.tileentity.machine.rbmk.RBMKDials; -import com.hbm.util.AchievementHandler; -import com.hbm.util.ArmorUtil; -import com.hbm.util.Compat; -import com.hbm.util.StatHelper; -import com.hbm.util.SuicideThreadDump; -import com.hbm.world.feature.*; -import com.hbm.world.generator.CellularDungeonFactory; - -import cpw.mods.fml.common.SidedProxy; -import cpw.mods.fml.common.event.FMLInitializationEvent; -import cpw.mods.fml.common.event.FMLMissingMappingsEvent; -import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent; -import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage; -import cpw.mods.fml.common.event.FMLMissingMappingsEvent.MissingMapping; -import cpw.mods.fml.common.event.FMLPostInitializationEvent; -import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import cpw.mods.fml.common.event.FMLServerStartedEvent; -import cpw.mods.fml.common.event.FMLServerStartingEvent; -import cpw.mods.fml.common.network.NetworkRegistry; -import cpw.mods.fml.common.registry.GameRegistry; -import cpw.mods.fml.relauncher.Side; - @Mod(modid = RefStrings.MODID, name = RefStrings.NAME, version = RefStrings.VERSION) public class MainRegistry { @@ -249,7 +245,7 @@ public class MainRegistry { public static File configDir; public static File configHbmDir; - Random rand = new Random(); + public Random rand = new Random(); @EventHandler public void PreLoad(FMLPreInitializationEvent PreEvent) {