diff --git a/src/main/java/cursedbread/carry/mixin/CarryMixin.java b/src/main/java/cursedbread/carry/mixin/CarryMixin.java deleted file mode 100644 index 8c197e8..0000000 --- a/src/main/java/cursedbread/carry/mixin/CarryMixin.java +++ /dev/null @@ -1,27 +0,0 @@ -package cursedbread.carry.mixin; - -import net.minecraft.core.block.BlockLogic; -import net.minecraft.core.block.entity.TileEntity; -import net.minecraft.core.block.motion.CarriedBlock; -import net.minecraft.core.entity.player.Player; -import net.minecraft.core.util.helper.Side; -import net.minecraft.core.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import static org.apache.log4j.builders.appender.SocketAppenderBuilder.LOGGER; - -@Mixin(value = BlockLogic.class, remap = false) - -public class CarryMixin { - @Inject(method = "onBlockRightClicked(Lnet/minecraft/core/world/World;IIILnet/minecraft/core/entity/player/Player;Lnet/minecraft/core/util/helper/Side;DD)Z", at = @At("HEAD"), cancellable = true) - public void onBlockRightClicked(World world, int x, int y, int z, Player player, Side side, double xHit, double yHit, CallbackInfoReturnable cir) { - if (player.getHeldItem() == null && player.isSneaking()){ - player.setHeldObject(new CarriedBlock(player, world.getBlockId(x, y, z), world.getBlockMetadata(z, y, z), null)); - world.setBlockWithNotify(x, y, z, 0); - } - } -} diff --git a/src/main/java/cursedbread/carry/mixin/PlayerControllerMixin.java b/src/main/java/cursedbread/carry/mixin/PlayerControllerMixin.java new file mode 100644 index 0000000..c257796 --- /dev/null +++ b/src/main/java/cursedbread/carry/mixin/PlayerControllerMixin.java @@ -0,0 +1,34 @@ +package cursedbread.carry.mixin; + +import net.minecraft.client.player.controller.PlayerController; +import net.minecraft.core.block.entity.TileEntity; +import net.minecraft.core.block.motion.CarriedBlock; +import net.minecraft.core.entity.player.Player; +import net.minecraft.core.item.ItemStack; +import net.minecraft.core.util.helper.Side; +import net.minecraft.core.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(value = PlayerController.class, remap = false) +public class PlayerControllerMixin { + + @Inject(method = "useOrPlaceItemStackOnTile(Lnet/minecraft/core/entity/player/Player;Lnet/minecraft/core/world/World;Lnet/minecraft/core/item/ItemStack;IIILnet/minecraft/core/util/helper/Side;DD)Z", at = @At("HEAD"), cancellable = true) + public void pickupAnything(Player player, World world, ItemStack itemstack, int blockX, int blockY, int blockZ, Side side, double xPlaced, double yPlaced, CallbackInfoReturnable cir) { + if (player.canInteract()) { + int blockId = world.getBlockId(blockX, blockY, blockZ); + if (player.getHeldObject() == null && blockId != 0) { + if (player.isSneaking() && itemstack == null) { + TileEntity tileEntity = world.getTileEntity(blockX, blockY, blockZ); + if (tileEntity == null) { + player.setHeldObject(new CarriedBlock(player, blockId, world.getBlockMetadata(blockX, blockY, blockZ), null)); + world.setBlockWithNotify(blockX, blockY, blockZ, 0); + cir.setReturnValue(true); + } + } + } + } + } +} diff --git a/src/main/java/cursedbread/carry/mixin/ServerPlayerControllerMixin.java b/src/main/java/cursedbread/carry/mixin/ServerPlayerControllerMixin.java new file mode 100644 index 0000000..fd2201a --- /dev/null +++ b/src/main/java/cursedbread/carry/mixin/ServerPlayerControllerMixin.java @@ -0,0 +1,34 @@ +package cursedbread.carry.mixin; + +import net.minecraft.core.block.entity.TileEntity; +import net.minecraft.core.block.motion.CarriedBlock; +import net.minecraft.core.entity.player.Player; +import net.minecraft.core.item.ItemStack; +import net.minecraft.core.util.helper.Side; +import net.minecraft.core.world.World; +import net.minecraft.server.world.ServerPlayerController; +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(value = ServerPlayerController.class, remap = false) +public class ServerPlayerControllerMixin { + + @Inject(method = "useOrPlaceItemStackOnTile(Lnet/minecraft/core/entity/player/Player;Lnet/minecraft/core/world/World;Lnet/minecraft/core/item/ItemStack;IIILnet/minecraft/core/util/helper/Side;DD)Z", at = @At("HEAD"), cancellable = true) + public void pickupAnything(Player player, World world, ItemStack itemstack, int blockX, int blockY, int blockZ, Side side, double xPlaced, double yPlaced, CallbackInfoReturnable cir) { + if (player.canInteract()) { + int blockId = world.getBlockId(blockX, blockY, blockZ); + if (player.getHeldObject() == null && blockId != 0) { + if (player.isSneaking() && itemstack == null) { + TileEntity tileEntity = world.getTileEntity(blockX, blockY, blockZ); + if (tileEntity == null) { + player.setHeldObject(new CarriedBlock(player, blockId, world.getBlockMetadata(blockX, blockY, blockZ), null)); + world.setBlockWithNotify(blockX, blockY, blockZ, 0); + cir.setReturnValue(true); + } + } + } + } + } +} diff --git a/src/main/resources/carry.mixins.json b/src/main/resources/carry.mixins.json index 12fa559..e9eb340 100644 --- a/src/main/resources/carry.mixins.json +++ b/src/main/resources/carry.mixins.json @@ -4,11 +4,14 @@ "package": "cursedbread.carry.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ - "CarryMixin" ], "client": [ + "PlayerControllerMixin" ], "injectors": { "defaultRequire": 1 - } + }, + "server": [ + "ServerPlayerControllerMixin" + ] }