From 1d8c4de0d040f0d3d0a6074a42635459419add53 Mon Sep 17 00:00:00 2001 From: tyrannus00 Date: Thu, 25 Apr 2024 18:46:44 +0200 Subject: [PATCH] Fixed NoGhostBlocks playing wrong sound when placing option is enabled --- .../meteorclient/mixin/BlockItemMixin.java | 31 +++++++++++++++++-- .../systems/modules/world/NoGhostBlocks.java | 2 +- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BlockItemMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BlockItemMixin.java index f3f4657ddf..6386182ebf 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BlockItemMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BlockItemMixin.java @@ -7,20 +7,47 @@ import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.events.entity.player.PlaceBlockEvent; +import meteordevelopment.meteorclient.systems.modules.Modules; +import meteordevelopment.meteorclient.systems.modules.world.NoGhostBlocks; import net.minecraft.block.BlockState; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemPlacementContext; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(BlockItem.class) -public class BlockItemMixin { +public abstract class BlockItemMixin { + @Shadow + protected abstract BlockState getPlacementState(ItemPlacementContext context); + @Inject(method = "place(Lnet/minecraft/item/ItemPlacementContext;Lnet/minecraft/block/BlockState;)Z", at = @At("HEAD"), cancellable = true) private void onPlace(ItemPlacementContext context, BlockState state, CallbackInfoReturnable info) { if (!context.getWorld().isClient) return; - if (MeteorClient.EVENT_BUS.post(PlaceBlockEvent.get(context.getBlockPos(), state.getBlock())).isCancelled()) info.setReturnValue(true); + if (MeteorClient.EVENT_BUS.post(PlaceBlockEvent.get(context.getBlockPos(), state.getBlock())).isCancelled()) { + info.setReturnValue(true); + } + } + + @ModifyVariable( + method = "place(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/util/ActionResult;", + ordinal = 1, + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/block/BlockState;isOf(Lnet/minecraft/block/Block;)Z" + ) + ) + private BlockState modifyState(BlockState state, ItemPlacementContext context) { + var noGhostBlocks = Modules.get().get(NoGhostBlocks.class); + + if (noGhostBlocks.isActive() && noGhostBlocks.placing.get()) { + return getPlacementState(context); + } + + return state; } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/NoGhostBlocks.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/NoGhostBlocks.java index d01cf1cd4f..e05462d3ae 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/NoGhostBlocks.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/NoGhostBlocks.java @@ -25,7 +25,7 @@ public class NoGhostBlocks extends Module { .build() ); - private final Setting placing = sgGeneral.add(new BoolSetting.Builder() + public final Setting placing = sgGeneral.add(new BoolSetting.Builder() .name("placing") .description("Whether to apply for block placement actions.") .defaultValue(true)