From ff77e2b57613db58f413d26e94012736a6e0977e Mon Sep 17 00:00:00 2001 From: moonleay Date: Thu, 25 Apr 2024 02:12:27 +0200 Subject: [PATCH] WIP: started working on ForcePlace --- .../gimble/mixin/AlwaysAllowBlock.java | 19 ++++++++++++++++ .../gimble/mixin/ForcePlaceMixin.java | 22 +++++++++++++++++++ .../gimble/mixin/WorldSetBlockStateMixin.java | 18 +++++++++++++++ src/main/resources/gimble.mixins.json | 5 ++++- 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/moonleay/gimble/mixin/AlwaysAllowBlock.java create mode 100644 src/main/java/net/moonleay/gimble/mixin/ForcePlaceMixin.java create mode 100644 src/main/java/net/moonleay/gimble/mixin/WorldSetBlockStateMixin.java diff --git a/src/main/java/net/moonleay/gimble/mixin/AlwaysAllowBlock.java b/src/main/java/net/moonleay/gimble/mixin/AlwaysAllowBlock.java new file mode 100644 index 0000000..2c64831 --- /dev/null +++ b/src/main/java/net/moonleay/gimble/mixin/AlwaysAllowBlock.java @@ -0,0 +1,19 @@ +package net.moonleay.gimble.mixin; + +import net.minecraft.block.Block; +import net.minecraft.block.pattern.CachedBlockPosition; +import net.minecraft.item.ItemStack; +import net.minecraft.util.registry.Registry; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(ItemStack.class) +public class AlwaysAllowBlock { + + @Redirect(method = "useOnBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;canPlaceOn(Lnet/minecraft/util/registry/Registry;Lnet/minecraft/block/pattern/CachedBlockPosition;)Z")) + private boolean func(ItemStack instance, Registry blockRegistry, CachedBlockPosition pos) { + + return true; + } +} diff --git a/src/main/java/net/moonleay/gimble/mixin/ForcePlaceMixin.java b/src/main/java/net/moonleay/gimble/mixin/ForcePlaceMixin.java new file mode 100644 index 0000000..5a21038 --- /dev/null +++ b/src/main/java/net/moonleay/gimble/mixin/ForcePlaceMixin.java @@ -0,0 +1,22 @@ +package net.moonleay.gimble.mixin; + +import net.minecraft.item.ItemStack; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.network.ServerPlayerInteractionManager; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.world.World; +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.CallbackInfoReturnable; + +@Mixin(ServerPlayerInteractionManager.class) +public class ForcePlaceMixin { + + @Inject(method = "interactBlock", at = @At("HEAD")) + private void func(ServerPlayerEntity player, World world, ItemStack stack, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable cir) { + + } +} diff --git a/src/main/java/net/moonleay/gimble/mixin/WorldSetBlockStateMixin.java b/src/main/java/net/moonleay/gimble/mixin/WorldSetBlockStateMixin.java new file mode 100644 index 0000000..3ad9a4d --- /dev/null +++ b/src/main/java/net/moonleay/gimble/mixin/WorldSetBlockStateMixin.java @@ -0,0 +1,18 @@ +package net.moonleay.gimble.mixin; + +import net.minecraft.block.BlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +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.CallbackInfoReturnable; + +@Mixin(World.class) +public class WorldSetBlockStateMixin { + + @Inject(method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;II)Z", at = @At("HEAD")) + private void func(BlockPos pos, BlockState state, int flags, int maxUpdateDepth, CallbackInfoReturnable cir) { + System.out.println("setBlockState was run"); + } +} diff --git a/src/main/resources/gimble.mixins.json b/src/main/resources/gimble.mixins.json index 1a39739..ee75399 100644 --- a/src/main/resources/gimble.mixins.json +++ b/src/main/resources/gimble.mixins.json @@ -4,7 +4,10 @@ "package": "net.moonleay.gimble.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "NoClipMixin" + "AlwaysAllowBlock", + "ForcePlaceMixin", + "NoClipMixin", + "WorldSetBlockStateMixin" ], "client": [ "HudMixin",