diff --git a/src/main/java/com/simibubi/create/content/logistics/factoryBoard/FactoryPanelBlock.java b/src/main/java/com/simibubi/create/content/logistics/factoryBoard/FactoryPanelBlock.java index dbcd2f78d7..a88149fe68 100644 --- a/src/main/java/com/simibubi/create/content/logistics/factoryBoard/FactoryPanelBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/factoryBoard/FactoryPanelBlock.java @@ -122,16 +122,16 @@ public class FactoryPanelBlock extends FaceAttachedHorizontalDirectionalBlock if (blockState.is(this) && location != null && fpbe != null) { if (!level.isClientSide()) { PanelSlot targetedSlot = getTargetedSlot(pos, blockState, location); - UUID networkFromStack = LogisticallyLinkedBlockItem.networkFromStack(pContext.getItemInHand()); + ItemStack panelItem = FactoryPanelBlockItem.fixCtrlCopiedStack(pContext.getItemInHand()); + UUID networkFromStack = LogisticallyLinkedBlockItem.networkFromStack(panelItem); Player pPlayer = pContext.getPlayer(); if (fpbe.addPanel(targetedSlot, networkFromStack) && pPlayer != null) { pPlayer.displayClientMessage(CreateLang.translateDirect("logistically_linked.connected"), true); if (!pPlayer.isCreative()) { - ItemStack item = pContext.getItemInHand(); - item.shrink(1); - if (item.isEmpty()) + panelItem.shrink(1); + if (panelItem.isEmpty()) pPlayer.setItemInHand(pContext.getHand(), ItemStack.EMPTY); } } @@ -217,7 +217,7 @@ public class FactoryPanelBlock extends FaceAttachedHorizontalDirectionalBlock PanelSlot newSlot = getTargetedSlot(pPos, pState, location); withBlockEntityDo(pLevel, pPos, fpbe -> { - if (!fpbe.addPanel(newSlot, LogisticallyLinkedBlockItem.networkFromStack(item))) + if (!fpbe.addPanel(newSlot, LogisticallyLinkedBlockItem.networkFromStack(FactoryPanelBlockItem.fixCtrlCopiedStack(item)))) return; pPlayer.displayClientMessage(CreateLang.translateDirect("logistically_linked.connected"), true); pLevel.playSound(null, pPos, soundType.getPlaceSound(), SoundSource.BLOCKS); diff --git a/src/main/java/com/simibubi/create/content/logistics/factoryBoard/FactoryPanelBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/factoryBoard/FactoryPanelBlockEntity.java index 64a5249ac8..104ca18fd2 100644 --- a/src/main/java/com/simibubi/create/content/logistics/factoryBoard/FactoryPanelBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/factoryBoard/FactoryPanelBlockEntity.java @@ -133,7 +133,8 @@ public class FactoryPanelBlockEntity extends SmartBlockEntity { FactoryPanelBehaviour behaviour = panels.get(slot); if (behaviour != null && !behaviour.isActive()) { behaviour.enable(); - behaviour.setNetwork(frequency); + if (frequency != null) + behaviour.setNetwork(frequency); redraw = true; lastShape = null; diff --git a/src/main/java/com/simibubi/create/content/logistics/factoryBoard/FactoryPanelBlockItem.java b/src/main/java/com/simibubi/create/content/logistics/factoryBoard/FactoryPanelBlockItem.java index 83277f542a..105a6f57ec 100644 --- a/src/main/java/com/simibubi/create/content/logistics/factoryBoard/FactoryPanelBlockItem.java +++ b/src/main/java/com/simibubi/create/content/logistics/factoryBoard/FactoryPanelBlockItem.java @@ -1,13 +1,21 @@ package com.simibubi.create.content.logistics.factoryBoard; +import java.util.UUID; + import com.simibubi.create.AllSoundEvents; +import com.simibubi.create.content.logistics.factoryBoard.FactoryPanelBlock.PanelSlot; import com.simibubi.create.content.logistics.packagerLink.LogisticallyLinkedBlockItem; import com.simibubi.create.foundation.utility.CreateLang; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; public class FactoryPanelBlockItem extends LogisticallyLinkedBlockItem { @@ -29,5 +37,31 @@ public class FactoryPanelBlockItem extends LogisticallyLinkedBlockItem { return super.place(pContext); } + + @Override + protected boolean updateCustomBlockEntityTag(BlockPos pos, Level level, Player player, ItemStack stack, + BlockState state) { + return super.updateCustomBlockEntityTag(pos, level, player, fixCtrlCopiedStack(stack), state); + } + + public static ItemStack fixCtrlCopiedStack(ItemStack stack) { + // Salvage frequency data from one of the panel slots + if (isTuned(stack) && networkFromStack(stack) == null) { + CompoundTag bet = stack.getTagElement(BLOCK_ENTITY_TAG); + UUID frequency = UUID.randomUUID(); + + for (PanelSlot slot : PanelSlot.values()) { + CompoundTag panelTag = bet.getCompound(CreateLang.asId(slot.name())); + if (panelTag.hasUUID("Freq")) + frequency = panelTag.getUUID("Freq"); + } + + bet = new CompoundTag(); + bet.putUUID("Freq", frequency); + stack.getTag().put(BLOCK_ENTITY_TAG, bet); + } + + return stack; + } } diff --git a/src/main/java/com/simibubi/create/content/logistics/packager/PackageDefragmenter.java b/src/main/java/com/simibubi/create/content/logistics/packager/PackageDefragmenter.java index 77fc51f258..1ada09e81f 100644 --- a/src/main/java/com/simibubi/create/content/logistics/packager/PackageDefragmenter.java +++ b/src/main/java/com/simibubi/create/content/logistics/packager/PackageDefragmenter.java @@ -113,7 +113,8 @@ public class PackageDefragmenter { ItemStack output = ItemHandlerHelper.copyStackWithSize(entry.stack, removedAmount); targetAmount -= removedAmount; - targetedEntry.count = targetAmount; + if (targetedEntry != null) + targetedEntry.count = targetAmount; entry.count -= removedAmount; outputSlots.add(output); } diff --git a/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockKeeperRequestScreen.java b/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockKeeperRequestScreen.java index 18ff2d66b1..7adc2d71b2 100644 --- a/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockKeeperRequestScreen.java +++ b/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockKeeperRequestScreen.java @@ -38,6 +38,7 @@ import com.simibubi.create.content.trains.station.NoShadowFontWrapper; import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.ScreenWithStencils; import com.simibubi.create.foundation.gui.menu.AbstractSimiContainerScreen; +import com.simibubi.create.foundation.gui.widget.ScrollInput; import com.simibubi.create.foundation.utility.CreateLang; import dev.engine_room.flywheel.lib.model.baked.PartialModel; @@ -489,9 +490,12 @@ public class StockKeeperRequestScreen extends AbstractSimiContainerScreen