From f06e1a8673d0d650dd41b6dabfbaa06ceb73ae8f Mon Sep 17 00:00:00 2001 From: drcrazy Date: Fri, 26 Jul 2019 11:45:30 +0300 Subject: [PATCH] ModSounds refactored to follow items, blocks and fluids --- src/main/java/techreborn/TechReborn.java | 6 ++--- .../java/techreborn/events/ModRegistry.java | 14 ++++++++++ src/main/java/techreborn/init/ModSounds.java | 27 +------------------ src/main/java/techreborn/utils/InitUtils.java | 7 +++++ 4 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/main/java/techreborn/TechReborn.java b/src/main/java/techreborn/TechReborn.java index bbd5bf6c8..3cc30f588 100644 --- a/src/main/java/techreborn/TechReborn.java +++ b/src/main/java/techreborn/TechReborn.java @@ -33,6 +33,7 @@ import net.minecraft.util.Identifier; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import reborncore.common.recipes.RecipeCrafter; import reborncore.common.registration.RegistrationManager; import reborncore.common.util.Torus; import techreborn.client.GuiHandler; @@ -63,7 +64,6 @@ public class TechReborn implements ModInitializer { INSTANCE = this; @SuppressWarnings("unused") RegistrationManager registrationManager = new RegistrationManager("techreborn", getClass()); -// TechRebornAPI.subItemRetriever = new SubItemRetriever(); // Done to force the class to load ModRecipes.GRINDER.getName(); @@ -72,15 +72,13 @@ public class TechReborn implements ModInitializer { ServerboundPackets.init(); ModRegistry.setupShit(); + RecipeCrafter.soundHanlder = new ModSounds.SoundHandler(); proxy.preInit(); // Registers Chest Loot ModLoot.init(); // MinecraftForge.EVENT_BUS.register(new ModLoot()); - // Sounds - // TODO 1.13 registry events - ModSounds.init(); // Client only init, needs to be done before parts system proxy.init(); diff --git a/src/main/java/techreborn/events/ModRegistry.java b/src/main/java/techreborn/events/ModRegistry.java index df07f37a1..9117fb189 100644 --- a/src/main/java/techreborn/events/ModRegistry.java +++ b/src/main/java/techreborn/events/ModRegistry.java @@ -41,6 +41,7 @@ import techreborn.blocks.misc.BlockRubberPlankStair; import techreborn.blocks.misc.BlockRubberSapling; import techreborn.config.ConfigTechReborn; import techreborn.init.ModFluids; +import techreborn.init.ModSounds; import techreborn.init.TRArmorMaterial; import techreborn.init.TRContent; import techreborn.init.TRContent.*; @@ -82,6 +83,7 @@ public class ModRegistry { registerBlocks(); registerItems(); registerFluids(); + registerSounds(); } public static void registerBlocks() { @@ -214,4 +216,16 @@ public class ModRegistry { public static void registerFluids() { Arrays.stream(ModFluids.values()).forEach(ModFluids::register); } + + public static void registerSounds() { + ModSounds.ALARM = InitUtils.setup("alarm"); + ModSounds.ALARM_2 = InitUtils.setup("alarm_2"); + ModSounds.ALARM_3 = InitUtils.setup("alarm_3"); + ModSounds.AUTO_CRAFTING = InitUtils.setup("auto_crafting"); + ModSounds.BLOCK_DISMANTLE = InitUtils.setup("block_dismantle"); + ModSounds.CABLE_SHOCK = InitUtils.setup("cable_shock"); + ModSounds.MACHINE_RUN = InitUtils.setup("machine_run"); + ModSounds.MACHINE_START = InitUtils.setup("machine_start"); + ModSounds.SAP_EXTRACT = InitUtils.setup("sap_extract"); + } } diff --git a/src/main/java/techreborn/init/ModSounds.java b/src/main/java/techreborn/init/ModSounds.java index 94ac490b2..5b89f8c0b 100644 --- a/src/main/java/techreborn/init/ModSounds.java +++ b/src/main/java/techreborn/init/ModSounds.java @@ -27,10 +27,7 @@ package techreborn.init; import net.minecraft.block.entity.BlockEntity; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvent; -import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; import reborncore.common.recipes.ICrafterSoundHanlder; -import reborncore.common.recipes.RecipeCrafter; /** * Created by Mark on 20/03/2016. @@ -47,34 +44,12 @@ public class ModSounds { public static SoundEvent ALARM_2; public static SoundEvent ALARM_3; - public static void init() { - CABLE_SHOCK = getSound("cable_shock"); - BLOCK_DISMANTLE = getSound("block_dismantle"); - SAP_EXTRACT = getSound("sap_extract"); - AUTO_CRAFTING = getSound("auto_crafting"); - MACHINE_RUN = getSound("machine_run"); - MACHINE_START = getSound("machine_start"); - ALARM = getSound("alarm"); - ALARM_2 = getSound("alarm_2"); - ALARM_3 = getSound("alarm_3"); - - RecipeCrafter.soundHanlder = new SoundHandler(); - } - - private static SoundEvent getSound(String str) { - Identifier identifier = new Identifier("techreborn", str); - SoundEvent soundEvent = new SoundEvent(identifier); - return Registry.register(Registry.SOUND_EVENT, identifier, soundEvent); - } - public static class SoundHandler implements ICrafterSoundHanlder { @Override public void playSound(boolean firstRun, BlockEntity blockEntity) { blockEntity.getWorld().playSound(null, blockEntity.getPos().getX(), blockEntity.getPos().getY(), - blockEntity.getPos().getZ(), ModSounds.MACHINE_RUN, - SoundCategory.BLOCKS, 0.1F, 1F); + blockEntity.getPos().getZ(), ModSounds.MACHINE_RUN, SoundCategory.BLOCKS, 0.1F, 1F); } } - } diff --git a/src/main/java/techreborn/utils/InitUtils.java b/src/main/java/techreborn/utils/InitUtils.java index c8908c055..0942da619 100644 --- a/src/main/java/techreborn/utils/InitUtils.java +++ b/src/main/java/techreborn/utils/InitUtils.java @@ -26,7 +26,9 @@ package techreborn.utils; import net.minecraft.block.Block; import net.minecraft.item.Item; +import net.minecraft.sound.SoundEvent; import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; import reborncore.RebornRegistry; import techreborn.TechReborn; @@ -40,4 +42,9 @@ public class InitUtils { RebornRegistry.registerIdent(block, new Identifier(TechReborn.MOD_ID, name)); return block; } + + public static SoundEvent setup(String name) { + Identifier identifier = new Identifier(TechReborn.MOD_ID, name); + return Registry.register(Registry.SOUND_EVENT, identifier, new SoundEvent(identifier)); + } }