Skip to content

Commit bb04f5c

Browse files
Merge pull request #2 from UselessBullets/m-carryall
Changed implementation to work on all blocks
2 parents 252e41c + e448bab commit bb04f5c

4 files changed

Lines changed: 73 additions & 30 deletions

File tree

src/main/java/cursedbread/carry/mixin/CarryMixin.java

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package cursedbread.carry.mixin;
2+
3+
import net.minecraft.client.player.controller.PlayerController;
4+
import net.minecraft.core.block.entity.TileEntity;
5+
import net.minecraft.core.block.motion.CarriedBlock;
6+
import net.minecraft.core.entity.player.Player;
7+
import net.minecraft.core.item.ItemStack;
8+
import net.minecraft.core.util.helper.Side;
9+
import net.minecraft.core.world.World;
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 = PlayerController.class, remap = false)
16+
public class PlayerControllerMixin {
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+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

src/main/resources/carry.mixins.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
"package": "cursedbread.carry.mixin",
55
"compatibilityLevel": "JAVA_8",
66
"mixins": [
7-
"CarryMixin"
87
],
98
"client": [
9+
"PlayerControllerMixin"
1010
],
1111
"injectors": {
1212
"defaultRequire": 1
13-
}
13+
},
14+
"server": [
15+
"ServerPlayerControllerMixin"
16+
]
1417
}

0 commit comments

Comments
 (0)