Skip to content

Commit

Permalink
fix: Fix trash slot being accessible in spectator mode #126
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Sep 13, 2023
1 parent 5ae66bc commit 6778692
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ private static void onScreenInit(ScreenInitEvent.Post event) {
return;
}

Player player = Minecraft.getInstance().player;
if (player != null && player.isSpectator()) {
return;
}

if (event.getScreen() instanceof CreativeModeInventoryScreen) {
currentContainerSettings = ContainerSettings.NONE;
trashSlotComponent = null;
Expand All @@ -70,7 +75,7 @@ private static void onScreenInit(ScreenInitEvent.Post event) {
}

// For some reason this event gets fired with GuiInventory right after opening the creative menu, AFTER it got fired for GuiContainerCreative
if (screen instanceof InventoryScreen && Minecraft.getInstance().player.getAbilities().instabuild) {
if (screen instanceof InventoryScreen && player != null && player.getAbilities().instabuild) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public static MessageDeleteFromSlot decode(final FriendlyByteBuf buf) {
}

public static void handle(ServerPlayer player, MessageDeleteFromSlot message) {
if (player.isSpectator()) {
return;
}

if (message.slotNumber == -1) {
TrashHelper.setTrashItem(player, ItemStack.EMPTY);
Balm.getNetworking().reply(new MessageTrashSlotContent(ItemStack.EMPTY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public static MessageTrashSlotClick decode(FriendlyByteBuf buf) {
}

public static void handle(ServerPlayer player, MessageTrashSlotClick message) {
if (player.isSpectator()) {
return;
}

ItemStack actualMouseItem = player.containerMenu.getCarried();
if (ItemStack.matches(actualMouseItem, message.itemStack)) {
if (actualMouseItem.isEmpty()) {
Expand Down

0 comments on commit 6778692

Please sign in to comment.