From a99f05d8b0da4188f4fc3da9bde6fad3ff015aac Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Tue, 8 Oct 2024 15:56:13 +0200 Subject: [PATCH] Toolbugs - Attempt to improve handling of toolbox storage on contraptions #6940 --- .../content/contraptions/MountedStorage.java | 6 ++++++ .../equipment/toolbox/ToolboxInventory.java | 16 ++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/MountedStorage.java b/src/main/java/com/simibubi/create/content/contraptions/MountedStorage.java index ad9b0c859..3b86dafc6 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/MountedStorage.java +++ b/src/main/java/com/simibubi/create/content/contraptions/MountedStorage.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions; import com.simibubi.create.AllBlockEntityTypes; import com.simibubi.create.AllTags.AllBlockTags; +import com.simibubi.create.content.equipment.toolbox.ToolboxInventory; import com.simibubi.create.content.kinetics.crafter.MechanicalCrafterBlockEntity; import com.simibubi.create.content.logistics.crate.BottomlessItemHandler; import com.simibubi.create.content.logistics.vault.ItemVaultBlockEntity; @@ -177,6 +178,8 @@ public class MountedStorage { CompoundTag tag = handler.serializeNBT(); if (noFuel) NBTHelper.putMarker(tag, "NoFuel"); + if (handler instanceof ToolboxInventory) + NBTHelper.putMarker(tag, "Toolbox"); if (!(handler instanceof BottomlessItemHandler)) return tag; @@ -191,6 +194,9 @@ public class MountedStorage { storage.handler = new ItemStackHandler(); if (nbt == null) return storage; + if (nbt.contains("Toolbox")) + storage.handler = new ToolboxInventory(null); + storage.valid = true; storage.noFuel = nbt.contains("NoFuel"); diff --git a/src/main/java/com/simibubi/create/content/equipment/toolbox/ToolboxInventory.java b/src/main/java/com/simibubi/create/content/equipment/toolbox/ToolboxInventory.java index a9d69e9ca..bb16f4feb 100644 --- a/src/main/java/com/simibubi/create/content/equipment/toolbox/ToolboxInventory.java +++ b/src/main/java/com/simibubi/create/content/equipment/toolbox/ToolboxInventory.java @@ -83,7 +83,7 @@ public class ToolboxInventory extends ItemStackHandler { } } settling = false; - blockEntity.sendData(); + notifyUpdate(); } @Override @@ -109,7 +109,7 @@ public class ToolboxInventory extends ItemStackHandler { if (!stack.isEmpty() && filters.get(compartment) .isEmpty()) { filters.set(compartment, ItemHandlerHelper.copyStackWithSize(stack, 1)); - blockEntity.sendData(); + notifyUpdate(); } } @@ -121,7 +121,7 @@ public class ToolboxInventory extends ItemStackHandler { if (!stack.isEmpty() && filters.get(compartment) .isEmpty()) { filters.set(compartment, ItemHandlerHelper.copyStackWithSize(stack, 1)); - blockEntity.sendData(); + notifyUpdate(); } } return insertItem; @@ -136,10 +136,9 @@ public class ToolboxInventory extends ItemStackHandler { @Override protected void onContentsChanged(int slot) { - if (!settling && !blockEntity.getLevel().isClientSide) + if (!settling && (blockEntity == null || !blockEntity.getLevel().isClientSide)) settle(slot / STACKS_PER_COMPARTMENT); - blockEntity.sendData(); - blockEntity.setChanged(); + notifyUpdate(); super.onContentsChanged(slot); } @@ -208,4 +207,9 @@ public class ToolboxInventory extends ItemStackHandler { return ItemHandlerHelper.canItemStacksStack(stack1, stack2); } + private void notifyUpdate() { + if (blockEntity != null) + blockEntity.notifyUpdate(); + } + }