Skip to content

Commit a55c17c

Browse files
committed
fix pure daisy pendant drop logs bug
1 parent 0a81490 commit a55c17c

5 files changed

Lines changed: 87 additions & 2 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.github.lounode.extrabotany.fabric.mixin;
2+
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.server.level.ServerPlayerGameMode;
5+
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.injection.At;
8+
import org.spongepowered.asm.mixin.injection.Inject;
9+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
10+
11+
import io.github.lounode.extrabotany.common.util.PlayerUtil;
12+
13+
@Mixin(ServerPlayerGameMode.class)
14+
public class SimulateDestroyMixinFabric {
15+
16+
@Inject(
17+
method = "destroyBlock",
18+
at = @At(
19+
value = "INVOKE",
20+
target = "Lnet/minecraft/world/level/block/Block;playerWillDestroy(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/entity/player/Player;)V"
21+
),
22+
cancellable = true
23+
)
24+
private void onDestroyBlock(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
25+
if (pos instanceof PlayerUtil.SimulateDestroyBlockPos) {
26+
cir.setReturnValue(true);
27+
}
28+
}
29+
}

Fabric/src/main/resources/extrabotany_fabric.mixins.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"compatibilityLevel": "JAVA_17",
66
"mixins": [
77
"GetBlockEnchantLevelMixin",
8-
"ServerPlayerGameModeFabricMixin"
8+
"ServerPlayerGameModeFabricMixin",
9+
"SimulateDestroyMixinFabric"
910
],
1011
"injectors": {
1112
"defaultRequire": 1
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package io.github.lounode.extrabotany.forge.mixin;
2+
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.server.level.ServerPlayerGameMode;
5+
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.injection.At;
8+
import org.spongepowered.asm.mixin.injection.Inject;
9+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
10+
11+
import io.github.lounode.extrabotany.common.util.PlayerUtil;
12+
13+
@Mixin(ServerPlayerGameMode.class)
14+
public class SimulateDestroyMixinForge {
15+
16+
@Inject(
17+
method = "destroyBlock",
18+
at = @At(
19+
value = "INVOKE",
20+
target = "Lnet/minecraft/world/item/ItemStack;mineBlock(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/player/Player;)V"
21+
),
22+
cancellable = true
23+
)
24+
private void onDestroyBlock(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
25+
if (pos instanceof PlayerUtil.SimulateDestroyBlockPos) {
26+
cir.setReturnValue(true);
27+
}
28+
}
29+
30+
@Inject(
31+
method = "destroyBlock",
32+
at = @At(
33+
value = "INVOKE",
34+
target = "Lnet/minecraft/server/level/ServerPlayerGameMode;removeBlock(Lnet/minecraft/core/BlockPos;Z)Z",
35+
ordinal = 0
36+
),
37+
cancellable = true
38+
)
39+
private void onCreativeDestroyBlock(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
40+
if (pos instanceof PlayerUtil.SimulateDestroyBlockPos) {
41+
cir.setReturnValue(true);
42+
}
43+
}
44+
}

Forge/src/main/resources/extrabotany_forge.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"package": "io.github.lounode.extrabotany.forge.mixin",
55
"compatibilityLevel": "JAVA_17",
66
"mixins": [
7+
"SimulateDestroyMixinForge",
78
"client.ItemStarryIdolArmorForgeMixin"
89
],
910
"client": [

Xplat/src/main/java/io/github/lounode/extrabotany/common/util/PlayerUtil.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,22 @@ public static boolean tryBreakBlock(Player player, ItemStack stack, Level world,
4141
}
4242
ItemStack save = player.getMainHandItem();
4343
player.setItemInHand(InteractionHand.MAIN_HAND, stack);
44-
boolean result = ((ServerPlayer) player).gameMode.destroyBlock(pos);
44+
45+
SimulateDestroyBlockPos simulatePos = new SimulateDestroyBlockPos(pos.getX(), pos.getY(), pos.getZ());
46+
47+
boolean result = ((ServerPlayer) player).gameMode.destroyBlock(simulatePos);
4548
if (result) {
4649
((ServerPlayer) player).connection.send(
4750
new ClientboundLevelEventPacket(LevelEvent.PARTICLES_DESTROY_BLOCK, pos, Block.getId(blockstate), false));
4851
}
4952
player.setItemInHand(InteractionHand.MAIN_HAND, save);
5053
return result;
5154
}
55+
56+
public static class SimulateDestroyBlockPos extends BlockPos {
57+
58+
public SimulateDestroyBlockPos(int x, int y, int z) {
59+
super(x, y, z);
60+
}
61+
}
5262
}

0 commit comments

Comments
 (0)