Skip to content

Commit 6c60782

Browse files
committed
clean
1 parent 5ec9f7c commit 6c60782

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/main/java/carpet/mixins/ServerGamePacketListenerImpl_scarpetEventsMixin.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,17 @@ private void onQItem(ServerboundPlayerActionPacket playerActionC2SPacket_1, Call
7373
}
7474
}
7575

76-
@Inject(method = "handlePlayerAction", cancellable = true, at = @At(
77-
value = "INVOKE",
78-
target = "Lnet/minecraft/server/level/ServerPlayer;getItemInHand(Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/item/ItemStack;",
79-
ordinal = 0,
80-
shift = At.Shift.BEFORE
81-
))
82-
private void onHandSwap(ServerboundPlayerActionPacket playerActionC2SPacket_1, CallbackInfo ci)
83-
{
84-
if(PLAYER_SWAPS_HANDS.onPlayerEvent(player)) ci.cancel();
85-
}
76+
// Use LivingSwapItemsEvent.Hands event with NeoForge patches
77+
// @Inject(method = "handlePlayerAction", cancellable = true, at = @At(
78+
// value = "INVOKE",
79+
// target = "Lnet/minecraft/server/level/ServerPlayer;getItemInHand(Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/item/ItemStack;",
80+
// ordinal = 0,
81+
// shift = At.Shift.BEFORE
82+
// ))
83+
// private void onHandSwap(ServerboundPlayerActionPacket playerActionC2SPacket_1, CallbackInfo ci)
84+
// {
85+
// if(PLAYER_SWAPS_HANDS.onPlayerEvent(player)) ci.cancel();
86+
// }
8687

8788
@Inject(method = "handlePlayerAction", cancellable = true, at = @At(
8889
value = "INVOKE",

src/main/java/org/thinkingstudio/bedsheet/BedSheetModEvents.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
import net.neoforged.bus.api.EventPriority;
77
import net.neoforged.bus.api.IEventBus;
88
import net.neoforged.neoforge.event.RegisterCommandsEvent;
9+
import net.neoforged.neoforge.event.entity.living.LivingSwapItemsEvent;
910
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
1011
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
1112
import net.neoforged.neoforge.network.registration.PayloadRegistrar;
1213

14+
import static carpet.script.CarpetEventServer.Event.PLAYER_SWAPS_HANDS;
15+
1316
public class BedSheetModEvents {
1417
public static void registerEvents(IEventBus modEventBus, IEventBus forgeEventBus) {
1518
forgeEventBus.addListener(EventPriority.HIGHEST, RegisterCommandsEvent.class, event -> {
@@ -20,6 +23,13 @@ public static void registerEvents(IEventBus modEventBus, IEventBus forgeEventBus
2023
CarpetServer.onPlayerLoggedIn(serverPlayer);
2124
}
2225
});
26+
forgeEventBus.addListener(EventPriority.HIGHEST, LivingSwapItemsEvent.Hands.class, event -> {
27+
if (event.getEntity() instanceof ServerPlayer serverPlayer) {
28+
if (PLAYER_SWAPS_HANDS.onPlayerEvent(serverPlayer)) {
29+
event.isCanceled();
30+
}
31+
}
32+
});
2333

2434
modEventBus.addListener(EventPriority.HIGHEST, RegisterPayloadHandlersEvent.class, event -> {
2535
final PayloadRegistrar registrar = event.registrar(BedSheetModReference.MODID);

0 commit comments

Comments
 (0)