From caaa5a3e7f0e3d7872e54d946db985bd5da2f083 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 8 May 2016 11:42:59 +0100 Subject: [PATCH] Fix sounds --- .../techreborn/blocks/BlockRubberLog.java | 8 ++++--- src/main/java/techreborn/init/ModSounds.java | 9 ++++++-- .../techreborn/items/tools/ItemHammer.java | 22 ++++++++++++------- .../techreborn/items/tools/ItemWrench.java | 9 ++++---- .../java/techreborn/parts/CableMultipart.java | 11 ++++------ .../java/techreborn/proxies/ClientProxy.java | 3 +-- 6 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/main/java/techreborn/blocks/BlockRubberLog.java b/src/main/java/techreborn/blocks/BlockRubberLog.java index 916650e30..bb7138ab0 100644 --- a/src/main/java/techreborn/blocks/BlockRubberLog.java +++ b/src/main/java/techreborn/blocks/BlockRubberLog.java @@ -16,11 +16,13 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; +import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import reborncore.RebornCore; import techreborn.client.TechRebornCreativeTabMisc; +import techreborn.init.ModSounds; import techreborn.items.ItemParts; import techreborn.items.tools.ItemTreeTap; @@ -173,9 +175,9 @@ public class BlockRubberLog extends Block implements ITexturedBlock { worldIn.setBlockState(pos, state.withProperty(HAS_SAP, false).withProperty(SAP_SIDE, EnumFacing.getHorizontal(0))); - // TODO 1.9 sounds - // worldIn.playSoundAtEntity(playerIn, - // "techreborn:sap_extract", 0.8F, 1F); + worldIn.playSound(null, pos.getX(), pos.getY(), + pos.getZ(), ModSounds.extract, + SoundCategory.BLOCKS, 0.6F, 1F); if (!worldIn.isRemote) { Random rand = new Random(); diff --git a/src/main/java/techreborn/init/ModSounds.java b/src/main/java/techreborn/init/ModSounds.java index 5ceb2ecba..2158d3f83 100644 --- a/src/main/java/techreborn/init/ModSounds.java +++ b/src/main/java/techreborn/init/ModSounds.java @@ -2,6 +2,7 @@ package techreborn.init; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundEvent; +import net.minecraftforge.fml.common.registry.GameRegistry; /** * Created by Mark on 20/03/2016. @@ -10,16 +11,20 @@ public class ModSounds { public static SoundEvent shock; + public static SoundEvent dismantle; + public static SoundEvent extract; public static void init() { shock = getSound("cable_shock"); + dismantle = getSound("block_dismantle"); + extract = getSound("sap_extract"); } private static SoundEvent getSound(String str) { - SoundEvent soundEvent = SoundEvent.REGISTRY.getObject(new ResourceLocation("techreborn" + str)); - return soundEvent; + ResourceLocation resourceLocation = new ResourceLocation("techreborn" , str); + return GameRegistry.register(new SoundEvent(resourceLocation).setRegistryName(resourceLocation)); } } diff --git a/src/main/java/techreborn/items/tools/ItemHammer.java b/src/main/java/techreborn/items/tools/ItemHammer.java index 1eaeb0c0a..4d3e9ec9c 100644 --- a/src/main/java/techreborn/items/tools/ItemHammer.java +++ b/src/main/java/techreborn/items/tools/ItemHammer.java @@ -5,8 +5,15 @@ import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import techreborn.init.ModSounds; import techreborn.items.ItemTR; import techreborn.lib.ModInfo; @@ -20,14 +27,13 @@ public class ItemHammer extends ItemTR implements ITexturedItem setMaxDamage(MaxDamage); } - // @Override - // public boolean onItemUse(ItemStack stack, EntityPlayer player, World - // world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) - // { - // world.playSoundAtEntity(player, "techreborn:block_dismantle", 0.8F, - // 0.4F); - // return true; - // } + @Override + public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { + world.playSound(player, player.posX, player.posY, + player.posZ, ModSounds.dismantle, + SoundCategory.BLOCKS, 0.6F, 1F); + return EnumActionResult.SUCCESS; + } @Override public Item setUnlocalizedName(String par1Str) diff --git a/src/main/java/techreborn/items/tools/ItemWrench.java b/src/main/java/techreborn/items/tools/ItemWrench.java index 99058be39..6cbe6b3f2 100644 --- a/src/main/java/techreborn/items/tools/ItemWrench.java +++ b/src/main/java/techreborn/items/tools/ItemWrench.java @@ -16,6 +16,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; +import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; @@ -24,6 +25,7 @@ import reborncore.common.tile.TileMachineBase; import techreborn.blocks.fluid.BlockFluidBase; import techreborn.blocks.storage.BlockBatBox; import techreborn.client.TechRebornCreativeTabMisc; +import techreborn.init.ModSounds; import techreborn.items.ItemTR; import techreborn.lib.ModInfo; import techreborn.tiles.storage.TileEnergyStorage; @@ -152,10 +154,9 @@ public class ItemWrench extends ItemTR implements ITexturedItem } } } - - // TODO 1.9 sounds - // world.playSoundAtEntity(player, "techreborn:block_dismantle", - // 0.8F, 1F); + world.playSound(null, player.posX, player.posY, + player.posZ, ModSounds.dismantle, + SoundCategory.BLOCKS, 0.6F, 1F); if (!world.isRemote) { world.setBlockState(pos, Blocks.AIR.getDefaultState(), 2); diff --git a/src/main/java/techreborn/parts/CableMultipart.java b/src/main/java/techreborn/parts/CableMultipart.java index be497a1ec..deede2248 100644 --- a/src/main/java/techreborn/parts/CableMultipart.java +++ b/src/main/java/techreborn/parts/CableMultipart.java @@ -30,6 +30,7 @@ import reborncore.common.misc.Functions; import reborncore.common.misc.vecmath.Vecs3dCube; import reborncore.common.util.WorldUtils; import techreborn.config.ConfigTechReborn; +import techreborn.init.ModSounds; import techreborn.parts.walia.IPartWaliaProvider; import techreborn.power.TRPowerNet; import techreborn.utils.damageSources.ElectrialShockSource; @@ -305,9 +306,6 @@ public abstract class CableMultipart extends Multipart @Override public void onEntityCollided(Entity entity) { if (getCableType().canKill && entity instanceof EntityLivingBase) { - if (entity instanceof EntityPlayer && ((EntityPlayer) entity).capabilities.isCreativeMode) { - - } else { if (network != null) { if (network.getEnergy() != 0) { if (ConfigTechReborn.UninsulatedElectocutionDamage) { @@ -318,9 +316,9 @@ public abstract class CableMultipart extends Multipart entity.attackEntityFrom(new ElectrialShockSource(), 1F); } if (ConfigTechReborn.UninsulatedElectocutionSound) { - // getWorld().playSound(entity.posX, entity.posY, - // entity.posZ, ModSounds.shock, - // SoundCategory.BLOCKS, 0.6F, 1F, false); + getWorld().playSound(null, entity.posX, entity.posY, + entity.posZ, ModSounds.shock, + SoundCategory.BLOCKS, 0.6F, 1F); } if (ConfigTechReborn.UninsulatedElectocutionParticle) { getWorld().spawnParticle(EnumParticleTypes.CRIT, entity.posX, entity.posY, entity.posZ, 0, @@ -328,7 +326,6 @@ public abstract class CableMultipart extends Multipart } } } - } } } diff --git a/src/main/java/techreborn/proxies/ClientProxy.java b/src/main/java/techreborn/proxies/ClientProxy.java index a6a30a924..bd33e804b 100644 --- a/src/main/java/techreborn/proxies/ClientProxy.java +++ b/src/main/java/techreborn/proxies/ClientProxy.java @@ -28,6 +28,7 @@ import techreborn.client.hud.ChargeHud; import techreborn.client.keybindings.KeyBindings; import techreborn.client.render.entitys.RenderNukePrimed; import techreborn.entitys.EntityNukePrimed; +import techreborn.init.ModSounds; import techreborn.manual.loader.ManualLoader; import java.io.File; @@ -77,8 +78,6 @@ public class ClientProxy extends CommonProxy // TODO FIX ME ClientRegistry.registerKeyBinding(KeyBindings.config); ClientMultiBlocks.init(); - - } protected void registerItemModel(ItemStack item, String name) {