diff --git a/src/main/java/vazkii/botania/common/core/handler/MethodHandles.java b/src/main/java/vazkii/botania/common/core/handler/MethodHandles.java index 9f76d1f96..e3a33192d 100644 --- a/src/main/java/vazkii/botania/common/core/handler/MethodHandles.java +++ b/src/main/java/vazkii/botania/common/core/handler/MethodHandles.java @@ -1,6 +1,7 @@ package vazkii.botania.common.core.handler; import com.google.common.base.Throwables; +import net.minecraft.block.SoundType; import net.minecraft.entity.item.EntityItem; import net.minecraft.tileentity.MobSpawnerBaseLogic; import net.minecraftforge.fml.common.FMLLog; @@ -22,7 +23,8 @@ public final class MethodHandles { spawnRange_getter, spawnCount_getter, maxNearbyEntities_getter, maxSpawnDelay_getter, minSpawnDelay_getter, spawnDelay_getter, spawnDelay_setter, prevMobRotation_setter, mobRotation_setter, potentialSpawns_getter, - randomEntity_getter, isActivated; // MobSpawnerBaseLogic + randomEntity_getter, isActivated, // MobSpawnerBaseLogic + breakSound_getter; // SoundType static { try { @@ -79,6 +81,10 @@ public final class MethodHandles { f.setAccessible(true); randomEntity_getter = publicLookup().unreflectGetter(f); + f = ReflectionHelper.findField(SoundType.class, LibObfuscation.BREAK_SOUND); + f.setAccessible(true); + breakSound_getter = publicLookup().unreflectGetter(f); + Method m = ReflectionHelper.findMethod(MobSpawnerBaseLogic.class, null, LibObfuscation.IS_ACTIVATED); m.setAccessible(true); isActivated = publicLookup().unreflect(m); diff --git a/src/main/java/vazkii/botania/common/lib/LibObfuscation.java b/src/main/java/vazkii/botania/common/lib/LibObfuscation.java index 832c6ea22..4bbc37e2c 100644 --- a/src/main/java/vazkii/botania/common/lib/LibObfuscation.java +++ b/src/main/java/vazkii/botania/common/lib/LibObfuscation.java @@ -102,4 +102,7 @@ public final class LibObfuscation { public static final String[] PREV_EQUIPPED_PROGRESS = { "prevEquippedProgress", "field_78451_d", "f" }; public static final String[] EQUIPPED_PROGRESS = { "equippedProgress", "field_78454_c", "e" }; + // SoundType + public static final String[] BREAK_SOUND = { "breakSound", "field_185862_o", "o" }; + } diff --git a/src/main/java/vazkii/botania/common/world/SkyblockWorldEvents.java b/src/main/java/vazkii/botania/common/world/SkyblockWorldEvents.java index a9ce3ce25..a24ff8656 100644 --- a/src/main/java/vazkii/botania/common/world/SkyblockWorldEvents.java +++ b/src/main/java/vazkii/botania/common/world/SkyblockWorldEvents.java @@ -19,6 +19,7 @@ import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.SoundCategory; +import net.minecraft.util.SoundEvent; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; @@ -28,6 +29,7 @@ import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import vazkii.botania.common.block.ModBlocks; import vazkii.botania.common.block.tile.TileManaFlame; +import vazkii.botania.common.core.handler.MethodHandles; import vazkii.botania.common.item.ModItems; import vazkii.botania.common.item.equipment.tool.ToolCommons; @@ -74,7 +76,11 @@ public final class SkyblockWorldEvents { if(event.getWorld().isRemote) event.getEntityPlayer().swingArm(event.getHand()); else { - event.getWorld().playSound(null, event.getPos(), block.getSoundType().getBreakSound(), SoundCategory.BLOCKS, block.getSoundType().getVolume() * 0.4F, block.getSoundType().getPitch() + (float) (Math.random() * 0.2 - 0.1)); + try { + SoundEvent breakSound = (SoundEvent) MethodHandles.breakSound_getter.invokeExact(block.getSoundType()); + event.getWorld().playSound(null, event.getPos(), breakSound, SoundCategory.BLOCKS, block.getSoundType().getVolume() * 0.4F, block.getSoundType().getPitch() + (float) (Math.random() * 0.2 - 0.1)); + } catch (Throwable ignore) {} + if(Math.random() < 0.8) event.getEntityPlayer().dropPlayerItemWithRandomChoice(new ItemStack(ModItems.manaResource, 1, 21), false); }