From c092414565c7bb3611eb26edffeb6389c6834bf6 Mon Sep 17 00:00:00 2001 From: Wynd Date: Tue, 24 Dec 2024 19:21:10 +0200 Subject: [PATCH] Added random sfx for lava pools and furnaces while they're cookin --- .../xyz/pixelatedw/finalbeta/WyHelper.java | 2 +- .../finalbeta/mixin/FurnaceEntityMixin.java | 16 ++++++++++- .../finalbeta/mixin/StillFluidTileMixin.java | 27 +++++++++++++++++++ src/main/resources/finalbeta.mixins.json | 3 ++- 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 src/main/java/xyz/pixelatedw/finalbeta/mixin/StillFluidTileMixin.java diff --git a/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java b/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java index e7cd69a..cc4bcfd 100644 --- a/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java +++ b/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java @@ -115,7 +115,7 @@ public class WyHelper { // player.dropItem(new ItemInstance(Tile.SLAB, 64)); // player.dropItem(new ItemInstance(ItemType.minecart, 1)); // player.dropItem(new ItemInstance(ItemType.minecartFurnace, 1)); - player.dropItem(new ItemInstance(ItemType.flintAndSteel, 1)); + player.dropItem(new ItemInstance(ItemType.bucket, 1)); // player.dropItem(new ItemInstance(Tile.GOLDEN_RAIL, 64)); // player.dropItem(new ItemInstance(Tile.COBBLESTONE, 64)); diff --git a/src/main/java/xyz/pixelatedw/finalbeta/mixin/FurnaceEntityMixin.java b/src/main/java/xyz/pixelatedw/finalbeta/mixin/FurnaceEntityMixin.java index 7f609b4..2765b2d 100644 --- a/src/main/java/xyz/pixelatedw/finalbeta/mixin/FurnaceEntityMixin.java +++ b/src/main/java/xyz/pixelatedw/finalbeta/mixin/FurnaceEntityMixin.java @@ -23,8 +23,22 @@ public class FurnaceEntityMixin { @Shadow private ItemInstance[] contents; + private int nextRandomTick = 20; + + @Inject(method = "tick", at = @At("HEAD")) + public void tickHead(CallbackInfo ci) { + FurnaceEntity tileEntity = ((FurnaceEntity)(Object)this); + if (ModConfig.ADD_MORE_SOUNDS.get() && tileEntity.cookTime > 0) { + if (tileEntity.level.getLevelTime() % this.nextRandomTick == 0) { + float pitch = 0.5f + tileEntity.level.rand.nextFloat() / 1.5f; + tileEntity.level.playSound(tileEntity.x, tileEntity.y, tileEntity.z, "sound3.liquid.lavapop", 0.4f, pitch); + this.nextRandomTick = 20 + tileEntity.level.rand.nextInt(20); + } + } + } + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/FurnaceEntity;getFuelTime(Lnet/minecraft/item/ItemInstance;)I", shift = At.Shift.BY, by = 5), cancellable = true) - public void tick(CallbackInfo ci) { + public void tick(CallbackInfo ci) { if(ModConfig.FIX_FURNACE_LAVA_BUCKET.get()) { if(this.contents[1] != null && this.contents[1].itemId == ItemType.bucketLava.id) { ci.cancel(); diff --git a/src/main/java/xyz/pixelatedw/finalbeta/mixin/StillFluidTileMixin.java b/src/main/java/xyz/pixelatedw/finalbeta/mixin/StillFluidTileMixin.java new file mode 100644 index 0000000..f72d50a --- /dev/null +++ b/src/main/java/xyz/pixelatedw/finalbeta/mixin/StillFluidTileMixin.java @@ -0,0 +1,27 @@ +package xyz.pixelatedw.finalbeta.mixin; + +import java.util.Random; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.level.Level; +import net.minecraft.tile.StillFluidTile; +import net.minecraft.tile.material.Material; + +@Mixin(StillFluidTile.class) +public class StillFluidTileMixin { + @Inject(method = "onScheduledTick", at = @At("HEAD")) + public void onScheduledTick(Level level, int x, int y, int z, Random random, CallbackInfo ci) { + StillFluidTile tile = ((StillFluidTile) (Object) this); + if (tile.material == Material.LAVA) { + if (level.rand.nextBoolean()) { + level.playSound(x, y, z, "sound3.liquid.lava", 0.5f, 1.0f); + } else { + level.playSound(x, y, z, "sound3.liquid.lavapop", 0.5f, 1.0f); + } + } + } +} diff --git a/src/main/resources/finalbeta.mixins.json b/src/main/resources/finalbeta.mixins.json index a6af6fc..f295b9f 100644 --- a/src/main/resources/finalbeta.mixins.json +++ b/src/main/resources/finalbeta.mixins.json @@ -48,7 +48,8 @@ "FoodItemMixin", "ItemTypeAccessor", "PressurePlateTileMixin", - "LeavesTileMixin" + "LeavesTileMixin", + "StillFluidTileMixin" ], "injectors": { "defaultRequire": -1