Skip to content

Commit

Permalink
Fixed NoGhostBlocks playing wrong sound when placing option is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrannus00 committed Apr 25, 2024
1 parent bf2f9d2 commit 1d8c4de
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class NoGhostBlocks extends Module {
.build()
);

private final Setting<Boolean> placing = sgGeneral.add(new BoolSetting.Builder()
public final Setting<Boolean> placing = sgGeneral.add(new BoolSetting.Builder()
.name("placing")
.description("Whether to apply for block placement actions.")
.defaultValue(true)
Expand Down

0 comments on commit 1d8c4de

Please sign in to comment.