- Attempt to improve handling of toolbox storage on contraptions #6940
This commit is contained in:
simibubi 2024-10-08 15:56:13 +02:00
parent 8f5c91c195
commit a99f05d8b0
2 changed files with 16 additions and 6 deletions

View file

@ -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");

View file

@ -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();
}
}