|
| 1 | +package cursedbread.carry.mixin; |
| 2 | + |
| 3 | +import net.minecraft.core.block.entity.TileEntity; |
| 4 | +import net.minecraft.core.block.motion.CarriedBlock; |
| 5 | +import net.minecraft.core.entity.player.Player; |
| 6 | +import net.minecraft.core.item.ItemStack; |
| 7 | +import net.minecraft.core.util.helper.Side; |
| 8 | +import net.minecraft.core.world.World; |
| 9 | +import net.minecraft.server.world.ServerPlayerController; |
| 10 | +import org.spongepowered.asm.mixin.Mixin; |
| 11 | +import org.spongepowered.asm.mixin.injection.At; |
| 12 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 13 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
| 14 | + |
| 15 | +@Mixin(value = ServerPlayerController.class, remap = false) |
| 16 | +public class ServerPlayerControllerMixin { |
| 17 | + |
| 18 | + @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) |
| 19 | + public void pickupAnything(Player player, World world, ItemStack itemstack, int blockX, int blockY, int blockZ, Side side, double xPlaced, double yPlaced, CallbackInfoReturnable<Boolean> cir) { |
| 20 | + if (player.canInteract()) { |
| 21 | + int blockId = world.getBlockId(blockX, blockY, blockZ); |
| 22 | + if (player.getHeldObject() == null && blockId != 0) { |
| 23 | + if (player.isSneaking() && itemstack == null) { |
| 24 | + TileEntity tileEntity = world.getTileEntity(blockX, blockY, blockZ); |
| 25 | + if (tileEntity == null) { |
| 26 | + player.setHeldObject(new CarriedBlock(player, blockId, world.getBlockMetadata(blockX, blockY, blockZ), null)); |
| 27 | + world.setBlockWithNotify(blockX, blockY, blockZ, 0); |
| 28 | + cir.setReturnValue(true); |
| 29 | + } |
| 30 | + } |
| 31 | + } |
| 32 | + } |
| 33 | + } |
| 34 | +} |
0 commit comments