From 90dbcbe6965b97ff6f962242727c0e351481e726 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Sun, 2 Mar 2025 23:55:28 +0100 Subject: [PATCH 01/48] cherry-pick 1 --- .../implementation/ComputerBehaviour.java | 8 + .../peripherals/PackagerPeripheral.java | 103 +++++++ .../peripherals/StockTickerPeripheral.java | 259 ++++++++++++++++++ .../packager/PackagerBlockEntity.java | 31 ++- .../stockTicker/StockTickerBlockEntity.java | 28 ++ 5 files changed, 428 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java create mode 100644 src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java index d0e4e9e90d..1da46dbb3d 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java @@ -7,6 +7,10 @@ import com.simibubi.create.compat.computercraft.implementation.peripherals.SpeedGaugePeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.StationPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.StressGaugePeripheral; +import com.simibubi.create.compat.computercraft.implementation.peripherals.StockTickerPeripheral; +import com.simibubi.create.compat.computercraft.implementation.peripherals.PackagerPeripheral; +import com.simibubi.create.content.logistics.packager.PackagerBlockEntity; +import com.simibubi.create.content.logistics.stockTicker.StockTickerBlockEntity; import com.simibubi.create.content.kinetics.gauge.SpeedGaugeBlockEntity; import com.simibubi.create.content.kinetics.gauge.StressGaugeBlockEntity; import com.simibubi.create.content.kinetics.speedController.SpeedControllerBlockEntity; @@ -47,6 +51,10 @@ public static NonNullSupplier getPeripheralFor(SmartBlockEntity be) return () -> new SpeedGaugePeripheral(sgbe); if (be instanceof StressGaugeBlockEntity sgbe) return () -> new StressGaugePeripheral(sgbe); + if (be instanceof StockTickerBlockEntity sgbe) + return () -> new StockTickerPeripheral(sgbe); + if (be instanceof PackagerBlockEntity pgbe) + return () -> new PackagerPeripheral(pgbe); if (be instanceof StationBlockEntity sbe) return () -> new StationPeripheral(sbe); diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java new file mode 100644 index 0000000000..4c9be62d77 --- /dev/null +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java @@ -0,0 +1,103 @@ +package com.simibubi.create.compat.computercraft.implementation.peripherals; + +import org.jetbrains.annotations.NotNull; + +import com.simibubi.create.content.logistics.packager.PackagerBlockEntity; + +import com.simibubi.create.content.logistics.BigItemStack; +import java.util.HashMap; +import java.util.Map; + +import dan200.computercraft.api.lua.LuaFunction; +import dan200.computercraft.api.lua.IArguments; +import dan200.computercraft.api.lua.LuaException; +import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.items.ItemStackHandler; +import com.simibubi.create.content.logistics.box.PackageItem; +import dan200.computercraft.api.detail.VanillaDetailRegistries; + +public class PackagerPeripheral extends SyncedPeripheral { + + public PackagerPeripheral(PackagerBlockEntity blockEntity) { + super(blockEntity); + } + + @LuaFunction(mainThread = true) + public final float makePackage() { + blockEntity.activate(); + return 1; + } + + @LuaFunction(mainThread = true) + public final Map> list() { + Map> result = new HashMap<>(); + int i = 0; + for (BigItemStack entry : blockEntity.getAvailableItems().getStacks()) { + i++; + Map details = new HashMap<>( + VanillaDetailRegistries.ITEM_STACK.getBasicDetails(entry.stack)); + details.put("count", entry.count); + result.put(i, details); + } + return result; + } + + @LuaFunction(mainThread = true) + public final String setAddress(IArguments arguments) throws LuaException { + Object argument = arguments.get(0); + if (argument instanceof String) { + blockEntity.CustomComputerAddress = (String) argument; + blockEntity.hasCustomComputerAddress = true; + return blockEntity.CustomComputerAddress; + } else if (argument instanceof Double) { + if ((Double) argument == ((Double) argument).intValue()) // to get rid of the floating point + blockEntity.CustomComputerAddress = String.valueOf(((Double) argument).intValue()); + else + blockEntity.CustomComputerAddress = String.valueOf((Double) argument); + blockEntity.hasCustomComputerAddress = true; + return blockEntity.CustomComputerAddress; + } else { + blockEntity.hasCustomComputerAddress = false; + return null; + } + } + + @LuaFunction(mainThread = true) + public final Map> listDetailed() { + Map> result = new HashMap<>(); + int i = 0; + for (BigItemStack entry : blockEntity.getAvailableItems().getStacks()) { + i++; + Map details = new HashMap<>( + VanillaDetailRegistries.ITEM_STACK.getDetails(entry.stack)); + details.put("count", entry.count); + result.put(i, details); + } + return result; + } + + @LuaFunction(mainThread = true) + public final Map> checkPackage() throws LuaException { + ItemStack box = blockEntity.heldBox; + if (box.isEmpty() && !PackageItem.isPackage(box)) + return null; + ItemStackHandler results = PackageItem.getContents(box); + Map> result = new HashMap<>(); + for (int i = 0; i < results.getSlots(); i++) { + ItemStack stack = results.getStackInSlot(i); + if (!stack.isEmpty()) { + Map details = new HashMap<>( + VanillaDetailRegistries.ITEM_STACK.getDetails(stack)); + result.put(i + 1, details); // +1 because lua + } + } + return result; + } + + @NotNull + @Override + public String getType() { + return "Create_Packager"; + } + +} diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java new file mode 100644 index 0000000000..407f4cef7f --- /dev/null +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java @@ -0,0 +1,259 @@ +package com.simibubi.create.compat.computercraft.implementation.peripherals; + +import org.jetbrains.annotations.NotNull; + +import com.simibubi.create.content.logistics.stockTicker.StockTickerBlockEntity; +import com.simibubi.create.content.logistics.BigItemStack; +import com.simibubi.create.content.logistics.packagerLink.LogisticallyLinkedBehaviour.RequestType; +import com.simibubi.create.content.logistics.stockTicker.PackageOrder; +import java.util.HashMap; +import java.util.Map; +import java.util.List; +import java.util.ArrayList; + +import dan200.computercraft.api.lua.LuaFunction; +import dan200.computercraft.api.lua.IArguments; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.detail.VanillaDetailRegistries; + +public class StockTickerPeripheral extends SyncedPeripheral { + + // private final ScrollValueBehaviour targetSpeed; + + public StockTickerPeripheral(StockTickerBlockEntity blockEntity) { + super(blockEntity); + // this.targetSpeed = targetSpeed; + } + + // tldr: the computercraft api lets you parse items into lua-like-tables that cc + // uses for all it's items. to keep consistency with the rest of the inventory + // api in other parts of the mod i must do this terribleness. i am sorry. + private int checkFilter(BigItemStack entry, Map filter) throws LuaException { + Map details = new HashMap<>( + VanillaDetailRegistries.ITEM_STACK.getDetails(entry.stack)); + details.put("count", entry.count); + if (filter.containsKey("name")) + if (filter.get("name") instanceof String) { + String filterName = (String) filter.get("name"); + if (!filterName.contains(":")) + filterName = "minecraft:" + filterName; + if (!filterName.equals(details.get("name"))) + return 0; + } else { + throw new LuaException("Name must be a string"); + } + // check the easy types + Map> expectedTypes = new HashMap<>(); + expectedTypes.put("displayName", String.class); + expectedTypes.put("nbt", String.class); + expectedTypes.put("damage", Double.class); + expectedTypes.put("durability", Double.class); + expectedTypes.put("maxDamage", Double.class); + expectedTypes.put("maxCount", Double.class); + for (String key : expectedTypes.keySet()) { + if (filter.containsKey(key)) { + Object filterValue = filter.get(key); + Class expectedType = expectedTypes.get(key); + if (expectedType.isInstance(filterValue)) { + Object detailsValue = details.get(key); + // some of these values are ints sometimes :tf: + if (expectedType == Double.class && detailsValue instanceof Number) { + detailsValue = ((Number) detailsValue).doubleValue(); + } + if (!details.containsKey(key) || !filterValue.equals(detailsValue)) { + return 0; + } + } else { + throw new LuaException(key + " must be a " + expectedType.getSimpleName()); + } + } + } + // java types dont mix well with lua tables at all + if (filter.containsKey("tags")) { + Object filterTagsObject = filter.get("tags"); + Object itemTagsObject = details.get("tags"); + if (filterTagsObject instanceof Map && itemTagsObject instanceof Map) { + @SuppressWarnings("unchecked") + Map filterTags = (Map) filterTagsObject; + @SuppressWarnings("unchecked") + Map itemTags = (Map) itemTagsObject; + for (Map.Entry filterTagEntry : filterTags.entrySet()) { + if (!(filterTagEntry.getValue() instanceof Boolean)) { + throw new LuaException( + "Tags filter must be a table of tags like: \n{tags = { \n [\"minecraft:logs\"] = true} \n {diamonds = true}\n}}"); + } + int filterMatches = 0; + for (Map.Entry itemTagEntry : itemTags.entrySet()) { + if (itemTagEntry.getKey().equals(filterTagEntry.getKey())) { + filterMatches++; + } + } + if (filterMatches == 0) { + return 0; + } + } + } else { + return 0; + } + } + // avert your eyes, it only gets worse. When the computercraft api fetches + // enchants of an item, it's an array list. when you submit a table from within + // computercraft as an argument, it's always a hash map. Handling the mix of + // both instead of converting because i felt like it's a good idea + if (filter.containsKey("enchantments")) { + Object filterEnchantmentsObject = filter.get("enchantments"); // HashMap + Object itemEnchantmentsObject = details.get("enchantments"); // ArrayList + // i might be doing a major skill issue here, idk i mainly do development in lua + if (filterEnchantmentsObject instanceof Map && itemEnchantmentsObject instanceof ArrayList) { + @SuppressWarnings("unchecked") + Map> filterEnchantments = (Map>) filterEnchantmentsObject; + @SuppressWarnings("unchecked") + ArrayList> itemEnchantments = (ArrayList>) itemEnchantmentsObject; + for (Map.Entry filterEnchantmentNode : filterEnchantments.entrySet()) { + int filterMatches = 0; + if (!(filterEnchantmentNode.getValue() instanceof Map)) { + throw new LuaException( + "Enchantments filter must be a table of enchant information like: \n{enchantments = { \n {name = \"minecraft:sharpness\"} \n {name = \"minecraft:protection\" \n level = 1\n }\n}}"); + } + @SuppressWarnings("unchecked") + Map filterEnchantmentEntry = (Map) (filterEnchantmentNode.getValue()); + String filterEnchantmentName = (String) (filterEnchantmentEntry.get("name")); + Double filterEnchantmentLevel = 0.0; + boolean CheckEnchantmentLevel = false; + if (filterEnchantmentEntry.get("level") instanceof Double) { + filterEnchantmentLevel = (Double) (filterEnchantmentEntry.get("level")); + CheckEnchantmentLevel = true; + } + for (HashMap itemEnchantmentEntry : itemEnchantments) { + String itemEnchantmentName = (String) itemEnchantmentEntry.get("name"); + Integer itemEnchantmentLevel = (Integer) (itemEnchantmentEntry.get("level")); + + if (itemEnchantmentName.equals(filterEnchantmentName) + && (!CheckEnchantmentLevel + || (itemEnchantmentLevel.doubleValue()) == filterEnchantmentLevel)) { + filterMatches++; + } + } + if (filterMatches == 0) { + return 0; + } + } + } else { + return 0; + } + } + return entry.count; + } + + @LuaFunction(mainThread = true) + public final int getItemCount() { + return blockEntity.getAccurateSummary().getTotalCount(); + // this.targetSpeed.setValue(speed); + } + + @LuaFunction(mainThread = true) + public final Map> list() { + Map> result = new HashMap<>(); + int i = 0; + for (BigItemStack entry : blockEntity.getAccurateSummary().getStacks()) { + i++; + Map details = new HashMap<>( + VanillaDetailRegistries.ITEM_STACK.getBasicDetails(entry.stack)); + details.put("count", entry.count); + result.put(i, details); + } + return result; + // return this.targetSpeed.getValue(); + } + + @LuaFunction(mainThread = true) + public final Map> listDetailed() { + Map> result = new HashMap<>(); + int i = 0; + for (BigItemStack entry : blockEntity.getAccurateSummary().getStacks()) { + i++; + Map details = new HashMap<>( + VanillaDetailRegistries.ITEM_STACK.getDetails(entry.stack)); + details.put("count", entry.count); + result.put(i, details); + } + return result; + // return this.targetSpeed.getValue();C + } + + /* + * for every item in the netowrk, this will compare that item to the CC args + * filter, a table that looks something like this: + * { + * name = "minecraft:jungle_log", + * tags = { + * ["minecraft:logs"] = true + * }, + * count = 5 + * }, + * and the second optional String arg which is the address: + * "home_address" + * (default value "") + * + * It then adds items that match the name if provided, nbt if provided, have all + * of the tags if provided, excluisvely match all the enchants if provided and + * stops looking after adding items equal to count or finishing + * going through the summary. + * filter of {} requests all items from the network trollface.jpeg + */ + @LuaFunction(mainThread = true) + public final String request(IArguments arguments) throws LuaException { + if (!(arguments.get(0) instanceof Map)) + return "false"; + Map filter = (Map) arguments.get(0); + String address; + // Computercraft has forced my hand to make this dollar store filter algo + List validItems = new ArrayList<>(); + int totalItemCount = 0; + for (BigItemStack entry : blockEntity.getAccurateSummary().getStacks()) { + if (checkFilter(entry, filter) > 0) { + // limit the number of items pulled from the system equals to the requested + // count parameter + if (filter.containsKey("count")) { + Object count = filter.get("count"); + if (count instanceof Double) { + int maxCount = ((Double) count).intValue(); + int remainingCount = maxCount - totalItemCount; + + if (remainingCount > 0) { + int itemsToAdd = Math.min(remainingCount, entry.count); + entry.count = itemsToAdd; + totalItemCount += itemsToAdd; + } else + break; + } + } else { + totalItemCount += entry.count; + } + validItems.add(entry); + } + } + if (arguments.get(1) instanceof String) + address = arguments.getString(1); + else + address = ""; + + PackageOrder order = new PackageOrder(validItems); + blockEntity.broadcastPackageRequest(RequestType.RESTOCK, order, null, address); + + /* + * CatnipServices.NETWORK + * .sendToServer(new PackageOrderRequestPacket(blockEntity.getBlockPos(), new + * PackageOrder(itemsToOrder), + * address, false, new PackageOrder(stacks); + */ + return "Requested " + String.valueOf(totalItemCount) + " item(s)"; + } + + @NotNull + @Override + public String getType() { + return "Create_StockTicker"; + } + +} diff --git a/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java index 6d77e6be26..0a24d488e0 100644 --- a/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java @@ -6,9 +6,13 @@ import java.util.Set; import java.util.UUID; +import com.simibubi.create.AllBlockEntityTypes; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllSoundEvents; import com.simibubi.create.Create; +import com.simibubi.create.compat.Mods; +import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; +import com.simibubi.create.compat.computercraft.ComputerCraftProxy; import com.simibubi.create.content.contraptions.actors.psi.PortableStorageInterfaceBlockEntity; import com.simibubi.create.content.kinetics.crafter.MechanicalCrafterBlockEntity; import com.simibubi.create.content.logistics.BigItemStack; @@ -34,10 +38,13 @@ import com.simibubi.create.foundation.blockEntity.behaviour.inventory.VersionedInventoryTrackerBehaviour; import com.simibubi.create.foundation.item.ItemHelper; +import dan200.computercraft.api.peripheral.PeripheralCapability; +import net.createmod.catnip.codecs.CatnipCodecUtils; import net.createmod.catnip.data.Iterate; import net.createmod.catnip.nbt.NBTHelper; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; @@ -77,6 +84,10 @@ public class PackagerBlockEntity extends SmartBlockEntity { public int animationTicks; public boolean animationInward; + public AbstractComputerBehaviour computerBehaviour; + public Boolean hasCustomComputerAddress = false; + public String CustomComputerAddress = ""; + private InventorySummary availableItems; private VersionedInventoryTrackerBehaviour invVersionTracker; @@ -99,12 +110,27 @@ public PackagerBlockEntity(BlockEntityType typeIn, BlockPos pos, BlockState s buttonCooldown = 0; } + public static void registerCapabilities(RegisterCapabilitiesEvent event) { + event.registerBlockEntity( + Capabilities.ItemHandler.BLOCK, + AllBlockEntityTypes.PACKAGER.get(), + (be, context) -> be.inventory + ); + if (Mods.COMPUTERCRAFT.isLoaded()) { + event.registerBlockEntity( + PeripheralCapability.get(), + AllBlockEntityTypes.PACKAGER.get(), + (be, context) -> be.computerBehaviour.getPeripheralCapability()); + } + } + @Override public void addBehaviours(List behaviours) { behaviours.add(targetInventory = new InvManipulationBehaviour(this, InterfaceProvider.oppositeOfBlockFacing()) .withFilter(this::supportsBlockEntity)); behaviours.add(invVersionTracker = new VersionedInventoryTrackerBehaviour(this)); behaviours.add(advancements = new AdvancementBehaviour(this, AllAdvancements.PACKAGER)); + behaviours.add(computerBehaviour = ComputerCraftProxy.behaviour(this)); } private boolean supportsBlockEntity(BlockEntity target) { @@ -160,7 +186,7 @@ public void triggerStockCheck() { public InventorySummary getAvailableItems() { return getAvailableItems(false); } - + public InventorySummary getAvailableItems(boolean scanInputSlots) { if (availableItems != null && invVersionTracker.stillWaiting(targetInventory.getInventory())) return availableItems; @@ -572,6 +598,9 @@ protected void updateSignAddress() { continue; signBasedAddress = address; } + if (computerBehaviour.hasAttachedComputer() && hasCustomComputerAddress) { + signBasedAddress = CustomComputerAddress; + } } protected String getSign(Direction side) { diff --git a/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockTickerBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockTickerBlockEntity.java index c106713650..b586329123 100644 --- a/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockTickerBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockTickerBlockEntity.java @@ -13,6 +13,9 @@ import com.simibubi.create.AllBlockEntityTypes; import com.simibubi.create.AllPackets; +import com.simibubi.create.compat.Mods; +import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; +import com.simibubi.create.compat.computercraft.ComputerCraftProxy; import com.simibubi.create.AllSoundEvents; import com.simibubi.create.api.equipment.goggles.IHaveHoveringInformation; import com.simibubi.create.content.contraptions.actors.seat.SeatEntity; @@ -25,7 +28,9 @@ import com.simibubi.create.foundation.item.ItemHelper; import com.simibubi.create.foundation.item.SmartInventory; import com.simibubi.create.foundation.utility.CreateLang; +import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; +import dan200.computercraft.api.peripheral.PeripheralCapability; import net.createmod.catnip.data.Iterate; import net.createmod.catnip.nbt.NBTHelper; import net.minecraft.ChatFormatting; @@ -54,6 +59,14 @@ public class StockTickerBlockEntity extends StockCheckingBlockEntity implements IHaveHoveringInformation { + public AbstractComputerBehaviour computerBehaviour; + + @Override + public void addBehaviours(List behaviours) { + super.addBehaviours(behaviours); + behaviours.add(computerBehaviour = ComputerCraftProxy.behaviour(this)); + } + // Player-interface Feature protected List> lastClientsideStockSnapshot; protected InventorySummary lastClientsideStockSnapshotAsSummary; @@ -77,6 +90,21 @@ public StockTickerBlockEntity(BlockEntityType type, BlockPos pos, BlockState hiddenCategoriesByPlayer = new HashMap<>(); } + public static void registerCapabilities(RegisterCapabilitiesEvent event) { + event.registerBlockEntity( + Capabilities.ItemHandler.BLOCK, + AllBlockEntityTypes.STOCK_TICKER.get(), + (be, context) -> be.receivedPayments + ); + + if (Mods.COMPUTERCRAFT.isLoaded()) { + event.registerBlockEntity( + PeripheralCapability.get(), + AllBlockEntityTypes.STOCK_TICKER.get(), + (be, context) -> be.computerBehaviour.getPeripheralCapability()); + } + } + public void refreshClientStockSnapshot() { ticksSinceLastUpdate = 0; AllPackets.getChannel() From ac5a05b794b33645910e67065ff0749cc0dce890 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Mon, 3 Mar 2025 19:29:53 +0100 Subject: [PATCH 02/48] walking around packager's actiavte() since it doesn't return a variable. seems to work flawlessly. --- .../peripherals/PackagerPeripheral.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java index 4c9be62d77..5cfc5ee292 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java @@ -23,9 +23,13 @@ public PackagerPeripheral(PackagerBlockEntity blockEntity) { } @LuaFunction(mainThread = true) - public final float makePackage() { - blockEntity.activate(); - return 1; + public final boolean makePackage() { + if (!blockEntity.heldBox.isEmpty()) + return false; + blockEntity.activate(); // activate() doesn't return a value so i'm walking around it + if (blockEntity.heldBox.isEmpty()) + return false; + return true; } @LuaFunction(mainThread = true) @@ -42,6 +46,7 @@ public final float makePackage() { return result; } + // sets the packagaer's address. Clears once it gets reloaded for safety @LuaFunction(mainThread = true) public final String setAddress(IArguments arguments) throws LuaException { Object argument = arguments.get(0); From 449b6346f08f62eafd64ead60ab5135bcf5a682e Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Mon, 3 Mar 2025 20:23:12 +0100 Subject: [PATCH 03/48] i forgor to make StockTicker's .request() return an int --- .../implementation/peripherals/StockTickerPeripheral.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java index 407f4cef7f..767b4e767d 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java @@ -202,9 +202,9 @@ public final int getItemCount() { * filter of {} requests all items from the network trollface.jpeg */ @LuaFunction(mainThread = true) - public final String request(IArguments arguments) throws LuaException { + public final int request(IArguments arguments) throws LuaException { if (!(arguments.get(0) instanceof Map)) - return "false"; + return 0; Map filter = (Map) arguments.get(0); String address; // Computercraft has forced my hand to make this dollar store filter algo @@ -247,7 +247,7 @@ public final String request(IArguments arguments) throws LuaException { * PackageOrder(itemsToOrder), * address, false, new PackageOrder(stacks); */ - return "Requested " + String.valueOf(totalItemCount) + " item(s)"; + return totalItemCount; } @NotNull From 60103239fa797653ff6d9c7921e2f69041939e44 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Mon, 3 Mar 2025 21:17:35 +0100 Subject: [PATCH 04/48] Made it so names in the enchant filter are optional --- .../peripherals/StockTickerPeripheral.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java index 767b4e767d..bb8bcffe26 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java @@ -120,15 +120,20 @@ private int checkFilter(BigItemStack entry, Map filter) throws LuaExceptio String filterEnchantmentName = (String) (filterEnchantmentEntry.get("name")); Double filterEnchantmentLevel = 0.0; boolean CheckEnchantmentLevel = false; + boolean CheckEnchantmentName = false; if (filterEnchantmentEntry.get("level") instanceof Double) { filterEnchantmentLevel = (Double) (filterEnchantmentEntry.get("level")); CheckEnchantmentLevel = true; } + if (filterEnchantmentEntry.get("name") instanceof String) { + filterEnchantmentName = (String) (filterEnchantmentEntry.get("name")); + CheckEnchantmentName = true; + } for (HashMap itemEnchantmentEntry : itemEnchantments) { String itemEnchantmentName = (String) itemEnchantmentEntry.get("name"); Integer itemEnchantmentLevel = (Integer) (itemEnchantmentEntry.get("level")); - if (itemEnchantmentName.equals(filterEnchantmentName) + if ((!CheckEnchantmentName || itemEnchantmentName.equals(filterEnchantmentName)) && (!CheckEnchantmentLevel || (itemEnchantmentLevel.doubleValue()) == filterEnchantmentLevel)) { filterMatches++; @@ -196,7 +201,7 @@ public final int getItemCount() { * (default value "") * * It then adds items that match the name if provided, nbt if provided, have all - * of the tags if provided, excluisvely match all the enchants if provided and + * of the tags if provided, has all the enchants if provided and * stops looking after adding items equal to count or finishing * going through the summary. * filter of {} requests all items from the network trollface.jpeg From df88af81e55dfce2d64530d81e3962d64efcd5b9 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Mon, 3 Mar 2025 21:50:23 +0100 Subject: [PATCH 05/48] Made it so you can check enchantments by displayName (why not), made enchantment checks exclusive, (one enchant per one set of enchant traits), made it so the number of enchants in the filter and items have to match. Will give a good example of it in the documentation linked in the pr --- .../peripherals/StockTickerPeripheral.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java index bb8bcffe26..3045fae5f3 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java @@ -7,6 +7,8 @@ import com.simibubi.create.content.logistics.packagerLink.LogisticallyLinkedBehaviour.RequestType; import com.simibubi.create.content.logistics.stockTicker.PackageOrder; import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; import java.util.Map; import java.util.List; import java.util.ArrayList; @@ -109,6 +111,9 @@ private int checkFilter(BigItemStack entry, Map filter) throws LuaExceptio Map> filterEnchantments = (Map>) filterEnchantmentsObject; @SuppressWarnings("unchecked") ArrayList> itemEnchantments = (ArrayList>) itemEnchantmentsObject; + if (filterEnchantments.size() != itemEnchantments.size()) + return 0; + Set> matchedItemEnchantments = new HashSet<>(); for (Map.Entry filterEnchantmentNode : filterEnchantments.entrySet()) { int filterMatches = 0; if (!(filterEnchantmentNode.getValue() instanceof Map)) { @@ -118,9 +123,11 @@ private int checkFilter(BigItemStack entry, Map filter) throws LuaExceptio @SuppressWarnings("unchecked") Map filterEnchantmentEntry = (Map) (filterEnchantmentNode.getValue()); String filterEnchantmentName = (String) (filterEnchantmentEntry.get("name")); + String filterEnchantmentDisplayName = (String) (filterEnchantmentEntry.get("displayName")); Double filterEnchantmentLevel = 0.0; - boolean CheckEnchantmentLevel = false; boolean CheckEnchantmentName = false; + boolean CheckEnchantmentDisplayName = false; + boolean CheckEnchantmentLevel = false; if (filterEnchantmentEntry.get("level") instanceof Double) { filterEnchantmentLevel = (Double) (filterEnchantmentEntry.get("level")); CheckEnchantmentLevel = true; @@ -129,13 +136,23 @@ private int checkFilter(BigItemStack entry, Map filter) throws LuaExceptio filterEnchantmentName = (String) (filterEnchantmentEntry.get("name")); CheckEnchantmentName = true; } + if (filterEnchantmentEntry.get("displayName") instanceof String) { + filterEnchantmentDisplayName = (String) (filterEnchantmentEntry.get("displayName")); + CheckEnchantmentDisplayName = true; + } for (HashMap itemEnchantmentEntry : itemEnchantments) { String itemEnchantmentName = (String) itemEnchantmentEntry.get("name"); + String itemEnchantmentDisplayName = (String) (itemEnchantmentEntry.get("displayName")); Integer itemEnchantmentLevel = (Integer) (itemEnchantmentEntry.get("level")); - if ((!CheckEnchantmentName || itemEnchantmentName.equals(filterEnchantmentName)) + if (!matchedItemEnchantments.contains(itemEnchantmentEntry) + && (!CheckEnchantmentName || itemEnchantmentName.equals(filterEnchantmentName)) + && (!CheckEnchantmentDisplayName + || (itemEnchantmentDisplayName.equals(filterEnchantmentDisplayName))) && (!CheckEnchantmentLevel - || (itemEnchantmentLevel.doubleValue()) == filterEnchantmentLevel)) { + || (itemEnchantmentLevel + .doubleValue()) == filterEnchantmentLevel)) { + matchedItemEnchantments.add(itemEnchantmentEntry); // one itemenchant per filter filterMatches++; } } From a192be4884c1baae25b0cfeb281df19faf2076b2 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Tue, 4 Mar 2025 02:22:46 +0100 Subject: [PATCH 06/48] Packager now can get the num of items in attached storage --- .../implementation/peripherals/PackagerPeripheral.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java index 5cfc5ee292..d6623bf51b 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java @@ -22,6 +22,11 @@ public PackagerPeripheral(PackagerBlockEntity blockEntity) { super(blockEntity); } + @LuaFunction(mainThread = true) + public final int getItemCount() { + return blockEntity.getAvailableItems().getTotalCount(); + } + @LuaFunction(mainThread = true) public final boolean makePackage() { if (!blockEntity.heldBox.isEmpty()) From 1e5c4f70515f2f89c42d95c9ab77523dd192417e Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Tue, 4 Mar 2025 03:22:21 +0100 Subject: [PATCH 07/48] remove old comments because i'm silly --- .../implementation/peripherals/StockTickerPeripheral.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java index 3045fae5f3..6e241c81d2 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java @@ -170,7 +170,6 @@ private int checkFilter(BigItemStack entry, Map filter) throws LuaExceptio @LuaFunction(mainThread = true) public final int getItemCount() { return blockEntity.getAccurateSummary().getTotalCount(); - // this.targetSpeed.setValue(speed); } @LuaFunction(mainThread = true) @@ -185,7 +184,6 @@ public final int getItemCount() { result.put(i, details); } return result; - // return this.targetSpeed.getValue(); } @LuaFunction(mainThread = true) @@ -200,7 +198,6 @@ public final int getItemCount() { result.put(i, details); } return result; - // return this.targetSpeed.getValue();C } /* From d246b118d49600f4624eee5204157f71ea03e3e1 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Thu, 6 Mar 2025 15:44:19 +0100 Subject: [PATCH 08/48] cherry-pick 2 --- .../packager/PackagerBlockEntity.java | 82 ++++++++++--------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java index 0a24d488e0..0d738b0557 100644 --- a/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java @@ -98,7 +98,7 @@ public class PackagerBlockEntity extends SmartBlockEntity { public PackagerBlockEntity(BlockEntityType typeIn, BlockPos pos, BlockState state) { super(typeIn, pos, state); redstonePowered = state.getOptionalValue(PackagerBlock.POWERED) - .orElse(false); + .orElse(false); heldBox = ItemStack.EMPTY; previouslyUnwrapped = ItemStack.EMPTY; inventory = new PackagerItemHandler(this); @@ -112,22 +112,21 @@ public PackagerBlockEntity(BlockEntityType typeIn, BlockPos pos, BlockState s public static void registerCapabilities(RegisterCapabilitiesEvent event) { event.registerBlockEntity( - Capabilities.ItemHandler.BLOCK, - AllBlockEntityTypes.PACKAGER.get(), - (be, context) -> be.inventory - ); + Capabilities.ItemHandler.BLOCK, + AllBlockEntityTypes.PACKAGER.get(), + (be, context) -> be.inventory); if (Mods.COMPUTERCRAFT.isLoaded()) { event.registerBlockEntity( - PeripheralCapability.get(), - AllBlockEntityTypes.PACKAGER.get(), - (be, context) -> be.computerBehaviour.getPeripheralCapability()); + PeripheralCapability.get(), + AllBlockEntityTypes.PACKAGER.get(), + (be, context) -> be.computerBehaviour.getPeripheralCapability()); } } @Override public void addBehaviours(List behaviours) { behaviours.add(targetInventory = new InvManipulationBehaviour(this, InterfaceProvider.oppositeOfBlockFacing()) - .withFilter(this::supportsBlockEntity)); + .withFilter(this::supportsBlockEntity)); behaviours.add(invVersionTracker = new VersionedInventoryTrackerBehaviour(this)); behaviours.add(advancements = new AdvancementBehaviour(this, AllAdvancements.PACKAGER)); behaviours.add(computerBehaviour = ComputerCraftProxy.behaviour(this)); @@ -168,7 +167,7 @@ public void tick() { AllSoundEvents.PACKAGER.playAt(level, worldPosition, 1, 1, true); if (animationTicks == (animationInward ? 1 : 5)) level.playLocalSound(worldPosition, SoundEvents.IRON_TRAPDOOR_CLOSE, SoundSource.BLOCKS, 0.25f, 0.75f, - true); + true); } animationTicks--; @@ -207,7 +206,8 @@ public InventorySummary getAvailableItems(boolean scanInputSlots) { for (int slot = 0; slot < targetInv.getSlots(); slot++) { int slotLimit = targetInv.getSlotLimit(slot); - availableItems.add(scanInputSlots ? targetInv.getStackInSlot(slot) : targetInv.extractItem(slot, slotLimit, true)); + availableItems.add( + scanInputSlots ? targetInv.getStackInSlot(slot) : targetInv.extractItem(slot, slotLimit, true)); } invVersionTracker.awaitNewVersion(targetInventory.getInventory()); @@ -273,7 +273,7 @@ public void lazyTick() { if (!redstonePowered) return; redstonePowered = getBlockState().getOptionalValue(PackagerBlock.POWERED) - .orElse(false); + .orElse(false); if (!redstoneModeActive()) return; updateSignAddress(); @@ -295,7 +295,7 @@ public void recheckIfLinksPresent() { public boolean redstoneModeActive() { return !getBlockState().getOptionalValue(PackagerBlock.LINKED) - .orElse(false); + .orElse(false); } private BlockPos getLinkPos() { @@ -325,9 +325,9 @@ public void flashLink() { public boolean isTooBusyFor(RequestType type) { int queue = queuedExitingPackages.size(); return queue >= switch (type) { - case PLAYER -> 50; - case REDSTONE -> 20; - case RESTOCK -> 10; + case PLAYER -> 50; + case REDSTONE -> 20; + case RESTOCK -> 10; }; } @@ -353,10 +353,10 @@ public boolean unwrapBox(ItemStack box, boolean simulate) { ItemStackHandler contents = PackageItem.getContents(box); PackageOrder orderContext = PackageItem.getOrderContext(box); IItemHandler targetInv = targetInventory.getInventory(); - BlockEntity targetBE = - level.getBlockEntity(worldPosition.relative(getBlockState().getOptionalValue(PackagerBlock.FACING) - .orElse(Direction.UP) - .getOpposite())); + BlockEntity targetBE = level + .getBlockEntity(worldPosition.relative(getBlockState().getOptionalValue(PackagerBlock.FACING) + .orElse(Direction.UP) + .getOpposite())); if (targetInv == null) return false; @@ -381,9 +381,9 @@ public boolean unwrapBox(ItemStack box, boolean simulate) { // Follow crafting arrangement if (targetIsCrafter && orderContext != null && orderContext.stacks() - .size() > slot) { + .size() > slot) { BigItemStack targetStack = orderContext.stacks() - .get(slot); + .get(slot); if (targetStack.stack.isEmpty()) break; if (!ItemHandlerHelper.canItemStacksStack(toInsert, targetStack.stack)) @@ -391,7 +391,7 @@ public boolean unwrapBox(ItemStack box, boolean simulate) { } if (targetInv.insertItem(slot, toInsert, true) - .getCount() == toInsert.getCount()) + .getCount() == toInsert.getCount()) continue; if (itemInSlot.isEmpty()) { @@ -414,17 +414,17 @@ public boolean unwrapBox(ItemStack box, boolean simulate) { continue; int insertedAmount = toInsert.getCount() - targetInv.insertItem(slot, toInsert, simulate) - .getCount(); + .getCount(); int slotLimit = (int) ((targetInv.getStackInSlot(slot) - .isEmpty() ? itemInSlot.getMaxStackSize() / 64f : 1) * targetInv.getSlotLimit(slot)); - int insertableAmountWithPreviousItems = - Math.min(toInsert.getCount(), slotLimit - itemInSlot.getCount() - itemsAddedToSlot); + .isEmpty() ? itemInSlot.getMaxStackSize() / 64f : 1) * targetInv.getSlotLimit(slot)); + int insertableAmountWithPreviousItems = Math.min(toInsert.getCount(), + slotLimit - itemInSlot.getCount() - itemsAddedToSlot); int added = Math.min(insertedAmount, Math.max(0, insertableAmountWithPreviousItems)); itemsAddedToSlot += added; contents.setStackInSlot(boxSlot, - ItemHandlerHelper.copyStackWithSize(toInsert, toInsert.getCount() - added)); + ItemHandlerHelper.copyStackWithSize(toInsert, toInsert.getCount() - added)); } } @@ -434,7 +434,7 @@ public boolean unwrapBox(ItemStack box, boolean simulate) { if (!targetIsCreativeCrate) for (int boxSlot = 0; boxSlot < contents.getSlots(); boxSlot++) if (!contents.getStackInSlot(boxSlot) - .isEmpty()) + .isEmpty()) return false; if (simulate) @@ -479,9 +479,9 @@ public void attemptToSend(List queuedRequests) { fixedOrderId = nextRequest.orderId(); linkIndexInOrder = nextRequest.linkIndex(); finalLinkInOrder = nextRequest.finalLink() - .booleanValue(); + .booleanValue(); packageIndexAtLink = nextRequest.packageCounter() - .getAndIncrement(); + .getAndIncrement(); orderContext = nextRequest.context(); } @@ -500,13 +500,13 @@ public void attemptToSend(List queuedRequests) { continue; boolean bulky = !extracted.getItem() - .canFitInsideContainerItems(); + .canFitInsideContainerItems(); if (bulky && anyItemPresent) continue; anyItemPresent = true; int leftovers = ItemHandlerHelper.insertItemStacked(extractedItems, extracted.copy(), false) - .getCount(); + .getCount(); int transferred = extracted.getCount() - leftovers; targetInv.extractItem(slot, transferred, false); @@ -532,7 +532,7 @@ public void attemptToSend(List queuedRequests) { if (queuedRequests.isEmpty()) break Outer; int previousCount = nextRequest.packageCounter() - .intValue(); + .intValue(); nextRequest = queuedRequests.get(0); if (!fixedAddress.equals(nextRequest.address())) break Outer; @@ -540,7 +540,7 @@ public void attemptToSend(List queuedRequests) { break Outer; nextRequest.packageCounter() - .setValue(previousCount); + .setValue(previousCount); finalPackageAtLink = false; continuePacking = true; if (nextRequest.context() != null) @@ -559,21 +559,21 @@ public void attemptToSend(List queuedRequests) { return; } - ItemStack createdBox = - extractedPackageItem.isEmpty() ? PackageItem.containing(extractedItems) : extractedPackageItem.copy(); + ItemStack createdBox = extractedPackageItem.isEmpty() ? PackageItem.containing(extractedItems) + : extractedPackageItem.copy(); PackageItem.clearAddress(createdBox); if (fixedAddress != null) PackageItem.addAddress(createdBox, fixedAddress); if (requestQueue) PackageItem.setOrder(createdBox, fixedOrderId, linkIndexInOrder, finalLinkInOrder, packageIndexAtLink, - finalPackageAtLink, orderContext); + finalPackageAtLink, orderContext); if (!requestQueue && !signBasedAddress.isBlank()) PackageItem.addAddress(createdBox, signBasedAddress); BlockPos linkPos = getLinkPos(); if (extractedPackageItem.isEmpty() && linkPos != null - && level.getBlockEntity(linkPos) instanceof PackagerLinkBlockEntity plbe) + && level.getBlockEntity(linkPos) instanceof PackagerLinkBlockEntity plbe) plbe.behaviour.deductFromAccurateSummary(extractedItems); if (!heldBox.isEmpty() || animationTicks != 0) { @@ -600,6 +600,8 @@ protected void updateSignAddress() { } if (computerBehaviour.hasAttachedComputer() && hasCustomComputerAddress) { signBasedAddress = CustomComputerAddress; + } else { + hasCustomComputerAddress = false; } } @@ -666,7 +668,7 @@ public void destroy() { super.destroy(); ItemHelper.dropContents(level, worldPosition, inventory); queuedExitingPackages.forEach(stack -> Containers.dropItemStack(level, worldPosition.getX(), - worldPosition.getY(), worldPosition.getZ(), stack)); + worldPosition.getY(), worldPosition.getZ(), stack)); queuedExitingPackages.clear(); } From 455c776cc3442c14ee8061d70544756ede3bad5d Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Thu, 6 Mar 2025 16:14:48 +0100 Subject: [PATCH 09/48] cherry-pick 3 --- .../packager/PackagerBlockEntity.java | 87 +++++++++---------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java index 0d738b0557..9b0b59b7f3 100644 --- a/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java @@ -98,7 +98,7 @@ public class PackagerBlockEntity extends SmartBlockEntity { public PackagerBlockEntity(BlockEntityType typeIn, BlockPos pos, BlockState state) { super(typeIn, pos, state); redstonePowered = state.getOptionalValue(PackagerBlock.POWERED) - .orElse(false); + .orElse(false); heldBox = ItemStack.EMPTY; previouslyUnwrapped = ItemStack.EMPTY; inventory = new PackagerItemHandler(this); @@ -112,21 +112,22 @@ public PackagerBlockEntity(BlockEntityType typeIn, BlockPos pos, BlockState s public static void registerCapabilities(RegisterCapabilitiesEvent event) { event.registerBlockEntity( - Capabilities.ItemHandler.BLOCK, - AllBlockEntityTypes.PACKAGER.get(), - (be, context) -> be.inventory); + Capabilities.ItemHandler.BLOCK, + AllBlockEntityTypes.PACKAGER.get(), + (be, context) -> be.inventory + ); if (Mods.COMPUTERCRAFT.isLoaded()) { event.registerBlockEntity( - PeripheralCapability.get(), - AllBlockEntityTypes.PACKAGER.get(), - (be, context) -> be.computerBehaviour.getPeripheralCapability()); + PeripheralCapability.get(), + AllBlockEntityTypes.PACKAGER.get(), + (be, context) -> be.computerBehaviour.getPeripheralCapability()); } } @Override public void addBehaviours(List behaviours) { behaviours.add(targetInventory = new InvManipulationBehaviour(this, InterfaceProvider.oppositeOfBlockFacing()) - .withFilter(this::supportsBlockEntity)); + .withFilter(this::supportsBlockEntity)); behaviours.add(invVersionTracker = new VersionedInventoryTrackerBehaviour(this)); behaviours.add(advancements = new AdvancementBehaviour(this, AllAdvancements.PACKAGER)); behaviours.add(computerBehaviour = ComputerCraftProxy.behaviour(this)); @@ -167,7 +168,7 @@ public void tick() { AllSoundEvents.PACKAGER.playAt(level, worldPosition, 1, 1, true); if (animationTicks == (animationInward ? 1 : 5)) level.playLocalSound(worldPosition, SoundEvents.IRON_TRAPDOOR_CLOSE, SoundSource.BLOCKS, 0.25f, 0.75f, - true); + true); } animationTicks--; @@ -206,8 +207,7 @@ public InventorySummary getAvailableItems(boolean scanInputSlots) { for (int slot = 0; slot < targetInv.getSlots(); slot++) { int slotLimit = targetInv.getSlotLimit(slot); - availableItems.add( - scanInputSlots ? targetInv.getStackInSlot(slot) : targetInv.extractItem(slot, slotLimit, true)); + availableItems.add(scanInputSlots ? targetInv.getStackInSlot(slot) : targetInv.extractItem(slot, slotLimit, true)); } invVersionTracker.awaitNewVersion(targetInventory.getInventory()); @@ -273,7 +273,7 @@ public void lazyTick() { if (!redstonePowered) return; redstonePowered = getBlockState().getOptionalValue(PackagerBlock.POWERED) - .orElse(false); + .orElse(false); if (!redstoneModeActive()) return; updateSignAddress(); @@ -295,7 +295,7 @@ public void recheckIfLinksPresent() { public boolean redstoneModeActive() { return !getBlockState().getOptionalValue(PackagerBlock.LINKED) - .orElse(false); + .orElse(false); } private BlockPos getLinkPos() { @@ -325,9 +325,9 @@ public void flashLink() { public boolean isTooBusyFor(RequestType type) { int queue = queuedExitingPackages.size(); return queue >= switch (type) { - case PLAYER -> 50; - case REDSTONE -> 20; - case RESTOCK -> 10; + case PLAYER -> 50; + case REDSTONE -> 20; + case RESTOCK -> 10; }; } @@ -353,10 +353,10 @@ public boolean unwrapBox(ItemStack box, boolean simulate) { ItemStackHandler contents = PackageItem.getContents(box); PackageOrder orderContext = PackageItem.getOrderContext(box); IItemHandler targetInv = targetInventory.getInventory(); - BlockEntity targetBE = level - .getBlockEntity(worldPosition.relative(getBlockState().getOptionalValue(PackagerBlock.FACING) - .orElse(Direction.UP) - .getOpposite())); + BlockEntity targetBE = + level.getBlockEntity(worldPosition.relative(getBlockState().getOptionalValue(PackagerBlock.FACING) + .orElse(Direction.UP) + .getOpposite())); if (targetInv == null) return false; @@ -381,9 +381,9 @@ public boolean unwrapBox(ItemStack box, boolean simulate) { // Follow crafting arrangement if (targetIsCrafter && orderContext != null && orderContext.stacks() - .size() > slot) { + .size() > slot) { BigItemStack targetStack = orderContext.stacks() - .get(slot); + .get(slot); if (targetStack.stack.isEmpty()) break; if (!ItemHandlerHelper.canItemStacksStack(toInsert, targetStack.stack)) @@ -391,18 +391,17 @@ public boolean unwrapBox(ItemStack box, boolean simulate) { } if (targetInv.insertItem(slot, toInsert, true) - .getCount() == toInsert.getCount()) + .getCount() == toInsert.getCount()) continue; if (itemInSlot.isEmpty()) { int maxStackSize = targetInv.getSlotLimit(slot); if (maxStackSize < toInsert.getCount()) { toInsert.shrink(maxStackSize); - toInsert = ItemHandlerHelper.copyStackWithSize(toInsert, maxStackSize); - } else - contents.setStackInSlot(boxSlot, ItemStack.EMPTY); - - itemInSlot = toInsert; + toInsert = toInsert.copyWithCount(maxStackSize); + } else + contents.setStackInSlot(boxSlot, ItemStack.EMPTY); + itemInSlot = toInsert; if (!simulate) itemInSlot = itemInSlot.copy(); @@ -414,11 +413,11 @@ public boolean unwrapBox(ItemStack box, boolean simulate) { continue; int insertedAmount = toInsert.getCount() - targetInv.insertItem(slot, toInsert, simulate) - .getCount(); + .getCount(); int slotLimit = (int) ((targetInv.getStackInSlot(slot) - .isEmpty() ? itemInSlot.getMaxStackSize() / 64f : 1) * targetInv.getSlotLimit(slot)); - int insertableAmountWithPreviousItems = Math.min(toInsert.getCount(), - slotLimit - itemInSlot.getCount() - itemsAddedToSlot); + .isEmpty() ? itemInSlot.getMaxStackSize() / 64f : 1) * targetInv.getSlotLimit(slot)); + int insertableAmountWithPreviousItems = + Math.min(toInsert.getCount(), slotLimit - itemInSlot.getCount() - itemsAddedToSlot); int added = Math.min(insertedAmount, Math.max(0, insertableAmountWithPreviousItems)); itemsAddedToSlot += added; @@ -434,7 +433,7 @@ public boolean unwrapBox(ItemStack box, boolean simulate) { if (!targetIsCreativeCrate) for (int boxSlot = 0; boxSlot < contents.getSlots(); boxSlot++) if (!contents.getStackInSlot(boxSlot) - .isEmpty()) + .isEmpty()) return false; if (simulate) @@ -479,9 +478,9 @@ public void attemptToSend(List queuedRequests) { fixedOrderId = nextRequest.orderId(); linkIndexInOrder = nextRequest.linkIndex(); finalLinkInOrder = nextRequest.finalLink() - .booleanValue(); + .booleanValue(); packageIndexAtLink = nextRequest.packageCounter() - .getAndIncrement(); + .getAndIncrement(); orderContext = nextRequest.context(); } @@ -500,13 +499,13 @@ public void attemptToSend(List queuedRequests) { continue; boolean bulky = !extracted.getItem() - .canFitInsideContainerItems(); + .canFitInsideContainerItems(); if (bulky && anyItemPresent) continue; anyItemPresent = true; int leftovers = ItemHandlerHelper.insertItemStacked(extractedItems, extracted.copy(), false) - .getCount(); + .getCount(); int transferred = extracted.getCount() - leftovers; targetInv.extractItem(slot, transferred, false); @@ -532,7 +531,7 @@ public void attemptToSend(List queuedRequests) { if (queuedRequests.isEmpty()) break Outer; int previousCount = nextRequest.packageCounter() - .intValue(); + .intValue(); nextRequest = queuedRequests.get(0); if (!fixedAddress.equals(nextRequest.address())) break Outer; @@ -540,7 +539,7 @@ public void attemptToSend(List queuedRequests) { break Outer; nextRequest.packageCounter() - .setValue(previousCount); + .setValue(previousCount); finalPackageAtLink = false; continuePacking = true; if (nextRequest.context() != null) @@ -559,21 +558,21 @@ public void attemptToSend(List queuedRequests) { return; } - ItemStack createdBox = extractedPackageItem.isEmpty() ? PackageItem.containing(extractedItems) - : extractedPackageItem.copy(); + ItemStack createdBox = + extractedPackageItem.isEmpty() ? PackageItem.containing(extractedItems) : extractedPackageItem.copy(); PackageItem.clearAddress(createdBox); if (fixedAddress != null) PackageItem.addAddress(createdBox, fixedAddress); if (requestQueue) PackageItem.setOrder(createdBox, fixedOrderId, linkIndexInOrder, finalLinkInOrder, packageIndexAtLink, - finalPackageAtLink, orderContext); + finalPackageAtLink, orderContext); if (!requestQueue && !signBasedAddress.isBlank()) PackageItem.addAddress(createdBox, signBasedAddress); BlockPos linkPos = getLinkPos(); if (extractedPackageItem.isEmpty() && linkPos != null - && level.getBlockEntity(linkPos) instanceof PackagerLinkBlockEntity plbe) + && level.getBlockEntity(linkPos) instanceof PackagerLinkBlockEntity plbe) plbe.behaviour.deductFromAccurateSummary(extractedItems); if (!heldBox.isEmpty() || animationTicks != 0) { @@ -668,7 +667,7 @@ public void destroy() { super.destroy(); ItemHelper.dropContents(level, worldPosition, inventory); queuedExitingPackages.forEach(stack -> Containers.dropItemStack(level, worldPosition.getX(), - worldPosition.getY(), worldPosition.getZ(), stack)); + worldPosition.getY(), worldPosition.getZ(), stack)); queuedExitingPackages.clear(); } From 994420517dfef06375c490fef207ddcb10b733f2 Mon Sep 17 00:00:00 2001 From: Karotte128 Date: Thu, 6 Mar 2025 18:26:56 +0100 Subject: [PATCH 10/48] cherry-pick 4 --- .../implementation/ComputerBehaviour.java | 4 ++ .../peripherals/FrogportPeripheral.java | 41 +++++++++++++++++++ .../frogport/FrogportBlockEntity.java | 37 +++++++++++++++-- 3 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/FrogportPeripheral.java diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java index 1da46dbb3d..9427b0b25a 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java @@ -2,6 +2,7 @@ import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; import com.simibubi.create.compat.computercraft.implementation.peripherals.DisplayLinkPeripheral; +import com.simibubi.create.compat.computercraft.implementation.peripherals.FrogportPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.SequencedGearshiftPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.SpeedControllerPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.SpeedGaugePeripheral; @@ -9,6 +10,7 @@ import com.simibubi.create.compat.computercraft.implementation.peripherals.StressGaugePeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.StockTickerPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.PackagerPeripheral; +import com.simibubi.create.content.logistics.packagePort.frogport.FrogportBlockEntity; import com.simibubi.create.content.logistics.packager.PackagerBlockEntity; import com.simibubi.create.content.logistics.stockTicker.StockTickerBlockEntity; import com.simibubi.create.content.kinetics.gauge.SpeedGaugeBlockEntity; @@ -45,6 +47,8 @@ public static NonNullSupplier getPeripheralFor(SmartBlockEntity be) return () -> new SpeedControllerPeripheral(scbe, scbe.targetSpeed); if (be instanceof DisplayLinkBlockEntity dlbe) return () -> new DisplayLinkPeripheral(dlbe); + if (be instanceof FrogportBlockEntity fpbe) + return () -> new FrogportPeripheral(fpbe); if (be instanceof SequencedGearshiftBlockEntity sgbe) return () -> new SequencedGearshiftPeripheral(sgbe); if (be instanceof SpeedGaugeBlockEntity sgbe) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/FrogportPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/FrogportPeripheral.java new file mode 100644 index 0000000000..21818b6399 --- /dev/null +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/FrogportPeripheral.java @@ -0,0 +1,41 @@ +package com.simibubi.create.compat.computercraft.implementation.peripherals; + +import com.simibubi.create.content.logistics.packagePort.frogport.FrogportBlockEntity; + +import dan200.computercraft.api.lua.IArguments; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.lua.LuaFunction; + +import org.jetbrains.annotations.NotNull; + +public class FrogportPeripheral extends SyncedPeripheral { + + public FrogportPeripheral(FrogportBlockEntity blockEntity) { + super(blockEntity); + } + + @LuaFunction(mainThread = true) + public final String setAddress(IArguments arguments) throws LuaException { + Object argument = arguments.get(0); + if (argument instanceof String) { + blockEntity.addressFilter = (String) argument; + blockEntity.filterChanged(); + blockEntity.notifyUpdate(); + return blockEntity.addressFilter; + } else { + return null; + } + } + + @LuaFunction(mainThread = true) + public final String getAddress() throws LuaException { + return blockEntity.addressFilter; + } + + @NotNull + @Override + public String getType() { + return "Create_Frogport"; + } + +} diff --git a/src/main/java/com/simibubi/create/content/logistics/packagePort/frogport/FrogportBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/packagePort/frogport/FrogportBlockEntity.java index 7d791f42fa..16ae6977f8 100644 --- a/src/main/java/com/simibubi/create/content/logistics/packagePort/frogport/FrogportBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/packagePort/frogport/FrogportBlockEntity.java @@ -5,6 +5,9 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; import com.simibubi.create.api.equipment.goggles.IHaveHoveringInformation; +import com.simibubi.create.compat.Mods; +import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; +import com.simibubi.create.compat.computercraft.ComputerCraftProxy; import com.simibubi.create.content.logistics.box.PackageItem; import com.simibubi.create.content.logistics.box.PackageStyles; import com.simibubi.create.content.logistics.packagePort.PackagePortBlockEntity; @@ -15,6 +18,7 @@ import com.simibubi.create.foundation.item.ItemHelper; import com.simibubi.create.foundation.item.TooltipHelper; +import dan200.computercraft.api.peripheral.PeripheralCapability; import net.createmod.catnip.animation.LerpedFloat; import net.createmod.catnip.animation.LerpedFloat.Chaser; import net.createmod.catnip.data.Iterate; @@ -56,12 +60,14 @@ public class FrogportBlockEntity extends PackagePortBlockEntity implements IHave private boolean failedLastExport; private FrogportSounds sounds; - + private ItemStack deferAnimationStart; private boolean deferAnimationInward; private AdvancementBehaviour advancements; + public AbstractComputerBehaviour computerBehaviour; + public FrogportBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); sounds = new FrogportSounds(); @@ -73,9 +79,26 @@ public FrogportBlockEntity(BlockEntityType type, BlockPos pos, BlockState sta goggles = false; } + public static void registerCapabilities(RegisterCapabilitiesEvent event) { + event.registerBlockEntity( + Capabilities.ItemHandler.BLOCK, + AllBlockEntityTypes.PACKAGE_FROGPORT.get(), + (be, context) -> be.itemHandler + ); + + if (Mods.COMPUTERCRAFT.isLoaded()) { + event.registerBlockEntity( + PeripheralCapability.get(), + AllBlockEntityTypes.PACKAGE_FROGPORT.get(), + (be, context) -> be.computerBehaviour.getPeripheralCapability() + ); + } + } + @Override public void addBehaviours(List behaviours) { behaviours.add(advancements = new AdvancementBehaviour(this, AllAdvancements.FROGPORT)); + behaviours.add(computerBehaviour = ComputerCraftProxy.behaviour(this)); super.addBehaviours(behaviours); } @@ -125,7 +148,7 @@ public void anticipate() { @Override public void tick() { super.tick(); - + if (deferAnimationStart != null) { startAnimation(deferAnimationStart, deferAnimationInward); deferAnimationStart = null; @@ -358,7 +381,7 @@ protected void onOpenedManually() { if (level.isClientSide()) sounds.open(level, worldPosition); } - + @Override public InteractionResult use(Player player) { if (player == null) @@ -373,8 +396,14 @@ public InteractionResult use(Player player) { } return InteractionResult.SUCCESS; } - + return super.use(player); } + @Override + public void invalidate() { + super.invalidate(); + computerBehaviour.removePeripheral(); + } + } From b4a06dee74bb1e30a84ad528ef316e04700892cf Mon Sep 17 00:00:00 2001 From: Karotte128 Date: Thu, 6 Mar 2025 19:11:15 +0100 Subject: [PATCH 11/48] cherry-pick 5 --- .../implementation/ComputerBehaviour.java | 4 ++ .../peripherals/PostboxPeripheral.java | 43 +++++++++++++++++++ .../postbox/PostboxBlockEntity.java | 38 ++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PostboxPeripheral.java diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java index 9427b0b25a..3ef30829e2 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java @@ -3,6 +3,7 @@ import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; import com.simibubi.create.compat.computercraft.implementation.peripherals.DisplayLinkPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.FrogportPeripheral; +import com.simibubi.create.compat.computercraft.implementation.peripherals.PostboxPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.SequencedGearshiftPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.SpeedControllerPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.SpeedGaugePeripheral; @@ -11,6 +12,7 @@ import com.simibubi.create.compat.computercraft.implementation.peripherals.StockTickerPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.PackagerPeripheral; import com.simibubi.create.content.logistics.packagePort.frogport.FrogportBlockEntity; +import com.simibubi.create.content.logistics.packagePort.postbox.PostboxBlockEntity; import com.simibubi.create.content.logistics.packager.PackagerBlockEntity; import com.simibubi.create.content.logistics.stockTicker.StockTickerBlockEntity; import com.simibubi.create.content.kinetics.gauge.SpeedGaugeBlockEntity; @@ -49,6 +51,8 @@ public static NonNullSupplier getPeripheralFor(SmartBlockEntity be) return () -> new DisplayLinkPeripheral(dlbe); if (be instanceof FrogportBlockEntity fpbe) return () -> new FrogportPeripheral(fpbe); + if (be instanceof PostboxBlockEntity pbbe) + return () -> new PostboxPeripheral(pbbe); if (be instanceof SequencedGearshiftBlockEntity sgbe) return () -> new SequencedGearshiftPeripheral(sgbe); if (be instanceof SpeedGaugeBlockEntity sgbe) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PostboxPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PostboxPeripheral.java new file mode 100644 index 0000000000..aa35c7abce --- /dev/null +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PostboxPeripheral.java @@ -0,0 +1,43 @@ +package com.simibubi.create.compat.computercraft.implementation.peripherals; + +import com.simibubi.create.content.logistics.packagePort.frogport.FrogportBlockEntity; + +import com.simibubi.create.content.logistics.packagePort.postbox.PostboxBlockEntity; + +import dan200.computercraft.api.lua.IArguments; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.lua.LuaFunction; + +import org.jetbrains.annotations.NotNull; + +public class PostboxPeripheral extends SyncedPeripheral { + + public PostboxPeripheral(PostboxBlockEntity blockEntity) { + super(blockEntity); + } + + @LuaFunction(mainThread = true) + public final String setAddress(IArguments arguments) throws LuaException { + Object argument = arguments.get(0); + if (argument instanceof String) { + blockEntity.addressFilter = (String) argument; + blockEntity.filterChanged(); + blockEntity.notifyUpdate(); + return blockEntity.addressFilter; + } else { + return null; + } + } + + @LuaFunction(mainThread = true) + public final String getAddress() throws LuaException { + return blockEntity.addressFilter; + } + + @NotNull + @Override + public String getType() { + return "Create_Postbox"; + } + +} diff --git a/src/main/java/com/simibubi/create/content/logistics/packagePort/postbox/PostboxBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/packagePort/postbox/PostboxBlockEntity.java index 1e91d1a753..92cf64a92a 100644 --- a/src/main/java/com/simibubi/create/content/logistics/packagePort/postbox/PostboxBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/packagePort/postbox/PostboxBlockEntity.java @@ -1,13 +1,21 @@ package com.simibubi.create.content.logistics.packagePort.postbox; import java.lang.ref.WeakReference; +import java.util.List; import com.simibubi.create.AllSoundEvents; import com.simibubi.create.Create; +import com.simibubi.create.compat.Mods; +import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; +import com.simibubi.create.compat.computercraft.ComputerCraftProxy; import com.simibubi.create.content.logistics.packagePort.PackagePortBlockEntity; import com.simibubi.create.content.trains.station.GlobalStation; import com.simibubi.create.content.trains.station.GlobalStation.GlobalPackagePort; +import com.simibubi.create.foundation.advancement.AdvancementBehaviour; +import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; + +import dan200.computercraft.api.peripheral.PeripheralCapability; import net.createmod.catnip.animation.LerpedFloat; import net.createmod.catnip.animation.LerpedFloat.Chaser; import net.createmod.catnip.nbt.NBTHelper; @@ -29,6 +37,8 @@ public class PostboxBlockEntity extends PackagePortBlockEntity { private boolean sendParticles; + public AbstractComputerBehaviour computerBehaviour; + public PostboxBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); trackedGlobalStation = new WeakReference<>(null); @@ -36,6 +46,28 @@ public PostboxBlockEntity(BlockEntityType type, BlockPos pos, BlockState stat .startWithValue(0); } + public static void registerCapabilities(RegisterCapabilitiesEvent event) { + event.registerBlockEntity( + Capabilities.ItemHandler.BLOCK, + AllBlockEntityTypes.PACKAGE_POSTBOX.get(), + (be, context) -> be.itemHandler + ); + + if (Mods.COMPUTERCRAFT.isLoaded()) { + event.registerBlockEntity( + PeripheralCapability.get(), + AllBlockEntityTypes.PACKAGE_POSTBOX.get(), + (be, context) -> be.computerBehaviour.getPeripheralCapability() + ); + } + } + + @Override + public void addBehaviours(List behaviours) { + behaviours.add(computerBehaviour = ComputerCraftProxy.behaviour(this)); + super.addBehaviours(behaviours); + } + @Override public void tick() { super.tick(); @@ -110,4 +142,10 @@ public void onChunkUnloaded() { super.onChunkUnloaded(); } + @Override + public void invalidate() { + super.invalidate(); + computerBehaviour.removePeripheral(); + } + } From 06eda4f62f46925756bf73ef95e2098e07e77439 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Thu, 6 Mar 2025 18:59:21 +0100 Subject: [PATCH 12/48] cherry-pick 6 --- .../implementation/ComputerBehaviour.java | 4 + .../computercraft/implementation/LuaUtil.java | 156 ++++++++++++++++++ .../RedstoneRequesterPeripheral.java | 102 ++++++++++++ .../peripherals/StockTickerPeripheral.java | 145 +--------------- .../RedstoneRequesterBlockEntity.java | 29 +++- .../foundation/events/CommonEvents.java | 66 ++++++++ 6 files changed, 358 insertions(+), 144 deletions(-) create mode 100644 src/main/java/com/simibubi/create/compat/computercraft/implementation/LuaUtil.java create mode 100644 src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java index 3ef30829e2..723763641a 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java @@ -13,6 +13,8 @@ import com.simibubi.create.compat.computercraft.implementation.peripherals.PackagerPeripheral; import com.simibubi.create.content.logistics.packagePort.frogport.FrogportBlockEntity; import com.simibubi.create.content.logistics.packagePort.postbox.PostboxBlockEntity; +import com.simibubi.create.compat.computercraft.implementation.peripherals.RedstoneRequesterPeripheral; +import com.simibubi.create.content.logistics.redstoneRequester.RedstoneRequesterBlockEntity; import com.simibubi.create.content.logistics.packager.PackagerBlockEntity; import com.simibubi.create.content.logistics.stockTicker.StockTickerBlockEntity; import com.simibubi.create.content.kinetics.gauge.SpeedGaugeBlockEntity; @@ -63,6 +65,8 @@ public static NonNullSupplier getPeripheralFor(SmartBlockEntity be) return () -> new StockTickerPeripheral(sgbe); if (be instanceof PackagerBlockEntity pgbe) return () -> new PackagerPeripheral(pgbe); + if (be instanceof RedstoneRequesterBlockEntity rrbe) + return () -> new RedstoneRequesterPeripheral(rrbe); if (be instanceof StationBlockEntity sbe) return () -> new StationPeripheral(sbe); diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/LuaUtil.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/LuaUtil.java new file mode 100644 index 0000000000..438b4950ba --- /dev/null +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/LuaUtil.java @@ -0,0 +1,156 @@ +package com.simibubi.create.compat.computercraft.implementation; + +import com.simibubi.create.content.logistics.BigItemStack; +import dan200.computercraft.api.lua.LuaException; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; +import java.util.Map; +import java.util.ArrayList; + +import dan200.computercraft.api.detail.VanillaDetailRegistries; + +public class LuaUtil { + + // tldr: the computercraft api lets you parse items into lua-like-tables that cc + // uses for all it's items. to keep consistency with the rest of the inventory + // api in other parts of the mod i must do this terribleness. i am sorry. + public static int bigItemStackToLuaTableFilter(BigItemStack entry, Map filter) throws LuaException { + Map details = new HashMap<>( + VanillaDetailRegistries.ITEM_STACK.getDetails(entry.stack)); + details.put("count", entry.count); + if (filter.containsKey("name")) + if (filter.get("name") instanceof String) { + String filterName = (String) filter.get("name"); + if (!filterName.contains(":")) + filterName = "minecraft:" + filterName; + if (!filterName.equals(details.get("name"))) + return 0; + } else { + throw new LuaException("Name must be a string"); + } + // check the easy types + Map> expectedTypes = new HashMap<>(); + expectedTypes.put("displayName", String.class); + expectedTypes.put("nbt", String.class); + expectedTypes.put("damage", Double.class); + expectedTypes.put("durability", Double.class); + expectedTypes.put("maxDamage", Double.class); + expectedTypes.put("maxCount", Double.class); + for (String key : expectedTypes.keySet()) { + if (filter.containsKey(key)) { + Object filterValue = filter.get(key); + Class expectedType = expectedTypes.get(key); + if (expectedType.isInstance(filterValue)) { + Object detailsValue = details.get(key); + // some of these values are ints sometimes :tf: + if (expectedType == Double.class && detailsValue instanceof Number) { + detailsValue = ((Number) detailsValue).doubleValue(); + } + if (!details.containsKey(key) || !filterValue.equals(detailsValue)) { + return 0; + } + } else { + throw new LuaException(key + " must be a " + expectedType.getSimpleName()); + } + } + } + // java types dont mix well with lua tables at all + if (filter.containsKey("tags")) { + Object filterTagsObject = filter.get("tags"); + Object itemTagsObject = details.get("tags"); + if (filterTagsObject instanceof Map && itemTagsObject instanceof Map) { + @SuppressWarnings("unchecked") + Map filterTags = (Map) filterTagsObject; + @SuppressWarnings("unchecked") + Map itemTags = (Map) itemTagsObject; + for (Map.Entry filterTagEntry : filterTags.entrySet()) { + if (!(filterTagEntry.getValue() instanceof Boolean)) { + throw new LuaException( + "Tags filter must be a table of tags like: \n{tags = { \n [\"minecraft:logs\"] = true} \n {diamonds = true}\n}}"); + } + int filterMatches = 0; + for (Map.Entry itemTagEntry : itemTags.entrySet()) { + if (itemTagEntry.getKey().equals(filterTagEntry.getKey())) { + filterMatches++; + } + } + if (filterMatches == 0) { + return 0; + } + } + } else { + return 0; + } + } + // avert your eyes, it only gets worse. When the computercraft api fetches + // enchants of an item, it's an array list. when you submit a table from within + // computercraft as an argument, it's always a hash map. Handling the mix of + // both instead of converting because i felt like it's a good idea + if (filter.containsKey("enchantments")) { + Object filterEnchantmentsObject = filter.get("enchantments"); // HashMap + Object itemEnchantmentsObject = details.get("enchantments"); // ArrayList + // i might be doing a major skill issue here, idk i mainly do development in lua + if (filterEnchantmentsObject instanceof Map && itemEnchantmentsObject instanceof ArrayList) { + @SuppressWarnings("unchecked") + Map> filterEnchantments = (Map>) filterEnchantmentsObject; + @SuppressWarnings("unchecked") + ArrayList> itemEnchantments = (ArrayList>) itemEnchantmentsObject; + if (filterEnchantments.size() != itemEnchantments.size()) + return 0; + Set> matchedItemEnchantments = new HashSet<>(); + for (Map.Entry filterEnchantmentNode : filterEnchantments.entrySet()) { + int filterMatches = 0; + if (!(filterEnchantmentNode.getValue() instanceof Map)) { + throw new LuaException( + "Enchantments filter must be a table of enchant information like: \n{enchantments = { \n {name = \"minecraft:sharpness\"} \n {name = \"minecraft:protection\" \n level = 1\n }\n}}"); + } + @SuppressWarnings("unchecked") + Map filterEnchantmentEntry = (Map) (filterEnchantmentNode.getValue()); + String filterEnchantmentName = (String) (filterEnchantmentEntry.get("name")); + String filterEnchantmentDisplayName = (String) (filterEnchantmentEntry.get("displayName")); + Double filterEnchantmentLevel = 0.0; + boolean CheckEnchantmentName = false; + boolean CheckEnchantmentDisplayName = false; + boolean CheckEnchantmentLevel = false; + if (filterEnchantmentEntry.get("level") instanceof Double) { + filterEnchantmentLevel = (Double) (filterEnchantmentEntry.get("level")); + CheckEnchantmentLevel = true; + } + if (filterEnchantmentEntry.get("name") instanceof String) { + filterEnchantmentName = (String) (filterEnchantmentEntry.get("name")); + CheckEnchantmentName = true; + } + if (filterEnchantmentEntry.get("displayName") instanceof String) { + filterEnchantmentDisplayName = (String) (filterEnchantmentEntry.get("displayName")); + CheckEnchantmentDisplayName = true; + } + for (HashMap itemEnchantmentEntry : itemEnchantments) { + String itemEnchantmentName = (String) itemEnchantmentEntry.get("name"); + String itemEnchantmentDisplayName = (String) (itemEnchantmentEntry.get("displayName")); + Integer itemEnchantmentLevel = (Integer) (itemEnchantmentEntry.get("level")); + + if (!matchedItemEnchantments.contains(itemEnchantmentEntry) + && (!CheckEnchantmentName || itemEnchantmentName.equals(filterEnchantmentName)) + && (!CheckEnchantmentDisplayName + || (itemEnchantmentDisplayName.equals(filterEnchantmentDisplayName))) + && (!CheckEnchantmentLevel + || (itemEnchantmentLevel + .doubleValue()) == filterEnchantmentLevel)) { + matchedItemEnchantments.add(itemEnchantmentEntry); // one itemenchant per filter + filterMatches++; + } + } + if (filterMatches == 0) { + return 0; + } + } + } else { + return 0; + } + } + return entry.count; + + } +} diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java new file mode 100644 index 0000000000..7569fbcb0c --- /dev/null +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java @@ -0,0 +1,102 @@ +package com.simibubi.create.compat.computercraft.implementation.peripherals; + +import org.jetbrains.annotations.NotNull; + +import com.simibubi.create.content.logistics.redstoneRequester.RedstoneRequesterBlockEntity; +import com.simibubi.create.content.logistics.BigItemStack; +import com.simibubi.create.compat.computercraft.implementation.LuaUtil; +import com.simibubi.create.content.logistics.packagerLink.LogisticallyLinkedBehaviour.RequestType; +import com.simibubi.create.content.logistics.stockTicker.PackageOrder; +import java.util.Map; +import java.util.List; +import java.util.ArrayList; + +import dan200.computercraft.api.lua.LuaFunction; +import dan200.computercraft.api.lua.IArguments; +import dan200.computercraft.api.lua.LuaException; + +public class RedstoneRequesterPeripheral extends SyncedPeripheral { + + // private final ScrollValueBehaviour targetSpeed; + + public RedstoneRequesterPeripheral(RedstoneRequesterBlockEntity blockEntity) { + super(blockEntity); + // this.targetSpeed = targetSpeed; + } + + /* + * for every item in the netowrk, this will compare that item to the CC args + * filter, a table that looks something like this: + * { + * name = "minecraft:jungle_log", + * tags = { + * ["minecraft:logs"] = true + * }, + * count = 5 + * }, + * and the second optional String arg which is the address: + * "home_address" + * (default value "") + * + * It then adds items that match the name if provided, nbt if provided, have all + * of the tags if provided, has all the enchants if provided and + * stops looking after adding items equal to count or finishing + * going through the summary. + * filter of {} requests all items from the network trollface.jpeg + */ + @LuaFunction(mainThread = true) + public final int request(IArguments arguments) throws LuaException { + if (!(arguments.get(0) instanceof Map)) + return 0; + Map filter = (Map) arguments.get(0); + String address; + // Computercraft has forced my hand to make this dollar store filter algo + List validItems = new ArrayList<>(); + int totalItemCount = 0; + for (BigItemStack entry : blockEntity.getAccurateSummary().getStacks()) { + if (LuaUtil.bigItemStackToLuaTableFilter(entry, filter) > 0) { + // limit the number of items pulled from the system equals to the requested + // count parameter + if (filter.containsKey("count")) { + Object count = filter.get("count"); + if (count instanceof Double) { + int maxCount = ((Double) count).intValue(); + int remainingCount = maxCount - totalItemCount; + + if (remainingCount > 0) { + int itemsToAdd = Math.min(remainingCount, entry.count); + entry.count = itemsToAdd; + totalItemCount += itemsToAdd; + } else + break; + } + } else { + totalItemCount += entry.count; + } + validItems.add(entry); + } + } + if (arguments.get(1) instanceof String) + address = arguments.getString(1); + else + address = ""; + + PackageOrder order = new PackageOrder(validItems); + blockEntity.broadcastPackageRequest(RequestType.RESTOCK, order, null, address); + + /* + * CatnipServices.NETWORK + * .sendToServer(new PackageOrderRequestPacket(blockEntity.getBlockPos(), new + * PackageOrder(itemsToOrder), + * address, false, new PackageOrder(stacks); + */ + return totalItemCount; + } + + @NotNull + @Override + public String getType() { + return "Create_RedstoneRequester"; + } + +} diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java index 6e241c81d2..2db037afe1 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java @@ -4,11 +4,10 @@ import com.simibubi.create.content.logistics.stockTicker.StockTickerBlockEntity; import com.simibubi.create.content.logistics.BigItemStack; +import com.simibubi.create.compat.computercraft.implementation.LuaUtil; import com.simibubi.create.content.logistics.packagerLink.LogisticallyLinkedBehaviour.RequestType; import com.simibubi.create.content.logistics.stockTicker.PackageOrder; import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; import java.util.Map; import java.util.List; import java.util.ArrayList; @@ -27,146 +26,6 @@ public StockTickerPeripheral(StockTickerBlockEntity blockEntity) { // this.targetSpeed = targetSpeed; } - // tldr: the computercraft api lets you parse items into lua-like-tables that cc - // uses for all it's items. to keep consistency with the rest of the inventory - // api in other parts of the mod i must do this terribleness. i am sorry. - private int checkFilter(BigItemStack entry, Map filter) throws LuaException { - Map details = new HashMap<>( - VanillaDetailRegistries.ITEM_STACK.getDetails(entry.stack)); - details.put("count", entry.count); - if (filter.containsKey("name")) - if (filter.get("name") instanceof String) { - String filterName = (String) filter.get("name"); - if (!filterName.contains(":")) - filterName = "minecraft:" + filterName; - if (!filterName.equals(details.get("name"))) - return 0; - } else { - throw new LuaException("Name must be a string"); - } - // check the easy types - Map> expectedTypes = new HashMap<>(); - expectedTypes.put("displayName", String.class); - expectedTypes.put("nbt", String.class); - expectedTypes.put("damage", Double.class); - expectedTypes.put("durability", Double.class); - expectedTypes.put("maxDamage", Double.class); - expectedTypes.put("maxCount", Double.class); - for (String key : expectedTypes.keySet()) { - if (filter.containsKey(key)) { - Object filterValue = filter.get(key); - Class expectedType = expectedTypes.get(key); - if (expectedType.isInstance(filterValue)) { - Object detailsValue = details.get(key); - // some of these values are ints sometimes :tf: - if (expectedType == Double.class && detailsValue instanceof Number) { - detailsValue = ((Number) detailsValue).doubleValue(); - } - if (!details.containsKey(key) || !filterValue.equals(detailsValue)) { - return 0; - } - } else { - throw new LuaException(key + " must be a " + expectedType.getSimpleName()); - } - } - } - // java types dont mix well with lua tables at all - if (filter.containsKey("tags")) { - Object filterTagsObject = filter.get("tags"); - Object itemTagsObject = details.get("tags"); - if (filterTagsObject instanceof Map && itemTagsObject instanceof Map) { - @SuppressWarnings("unchecked") - Map filterTags = (Map) filterTagsObject; - @SuppressWarnings("unchecked") - Map itemTags = (Map) itemTagsObject; - for (Map.Entry filterTagEntry : filterTags.entrySet()) { - if (!(filterTagEntry.getValue() instanceof Boolean)) { - throw new LuaException( - "Tags filter must be a table of tags like: \n{tags = { \n [\"minecraft:logs\"] = true} \n {diamonds = true}\n}}"); - } - int filterMatches = 0; - for (Map.Entry itemTagEntry : itemTags.entrySet()) { - if (itemTagEntry.getKey().equals(filterTagEntry.getKey())) { - filterMatches++; - } - } - if (filterMatches == 0) { - return 0; - } - } - } else { - return 0; - } - } - // avert your eyes, it only gets worse. When the computercraft api fetches - // enchants of an item, it's an array list. when you submit a table from within - // computercraft as an argument, it's always a hash map. Handling the mix of - // both instead of converting because i felt like it's a good idea - if (filter.containsKey("enchantments")) { - Object filterEnchantmentsObject = filter.get("enchantments"); // HashMap - Object itemEnchantmentsObject = details.get("enchantments"); // ArrayList - // i might be doing a major skill issue here, idk i mainly do development in lua - if (filterEnchantmentsObject instanceof Map && itemEnchantmentsObject instanceof ArrayList) { - @SuppressWarnings("unchecked") - Map> filterEnchantments = (Map>) filterEnchantmentsObject; - @SuppressWarnings("unchecked") - ArrayList> itemEnchantments = (ArrayList>) itemEnchantmentsObject; - if (filterEnchantments.size() != itemEnchantments.size()) - return 0; - Set> matchedItemEnchantments = new HashSet<>(); - for (Map.Entry filterEnchantmentNode : filterEnchantments.entrySet()) { - int filterMatches = 0; - if (!(filterEnchantmentNode.getValue() instanceof Map)) { - throw new LuaException( - "Enchantments filter must be a table of enchant information like: \n{enchantments = { \n {name = \"minecraft:sharpness\"} \n {name = \"minecraft:protection\" \n level = 1\n }\n}}"); - } - @SuppressWarnings("unchecked") - Map filterEnchantmentEntry = (Map) (filterEnchantmentNode.getValue()); - String filterEnchantmentName = (String) (filterEnchantmentEntry.get("name")); - String filterEnchantmentDisplayName = (String) (filterEnchantmentEntry.get("displayName")); - Double filterEnchantmentLevel = 0.0; - boolean CheckEnchantmentName = false; - boolean CheckEnchantmentDisplayName = false; - boolean CheckEnchantmentLevel = false; - if (filterEnchantmentEntry.get("level") instanceof Double) { - filterEnchantmentLevel = (Double) (filterEnchantmentEntry.get("level")); - CheckEnchantmentLevel = true; - } - if (filterEnchantmentEntry.get("name") instanceof String) { - filterEnchantmentName = (String) (filterEnchantmentEntry.get("name")); - CheckEnchantmentName = true; - } - if (filterEnchantmentEntry.get("displayName") instanceof String) { - filterEnchantmentDisplayName = (String) (filterEnchantmentEntry.get("displayName")); - CheckEnchantmentDisplayName = true; - } - for (HashMap itemEnchantmentEntry : itemEnchantments) { - String itemEnchantmentName = (String) itemEnchantmentEntry.get("name"); - String itemEnchantmentDisplayName = (String) (itemEnchantmentEntry.get("displayName")); - Integer itemEnchantmentLevel = (Integer) (itemEnchantmentEntry.get("level")); - - if (!matchedItemEnchantments.contains(itemEnchantmentEntry) - && (!CheckEnchantmentName || itemEnchantmentName.equals(filterEnchantmentName)) - && (!CheckEnchantmentDisplayName - || (itemEnchantmentDisplayName.equals(filterEnchantmentDisplayName))) - && (!CheckEnchantmentLevel - || (itemEnchantmentLevel - .doubleValue()) == filterEnchantmentLevel)) { - matchedItemEnchantments.add(itemEnchantmentEntry); // one itemenchant per filter - filterMatches++; - } - } - if (filterMatches == 0) { - return 0; - } - } - } else { - return 0; - } - } - return entry.count; - } - @LuaFunction(mainThread = true) public final int getItemCount() { return blockEntity.getAccurateSummary().getTotalCount(); @@ -230,7 +89,7 @@ public final int request(IArguments arguments) throws LuaException { List validItems = new ArrayList<>(); int totalItemCount = 0; for (BigItemStack entry : blockEntity.getAccurateSummary().getStacks()) { - if (checkFilter(entry, filter) > 0) { + if (LuaUtil.bigItemStackToLuaTableFilter(entry, filter) > 0) { // limit the number of items pulled from the system equals to the requested // count parameter if (filter.containsKey("count")) { diff --git a/src/main/java/com/simibubi/create/content/logistics/redstoneRequester/RedstoneRequesterBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/redstoneRequester/RedstoneRequesterBlockEntity.java index e5a0152fd8..dfa413f0a5 100644 --- a/src/main/java/com/simibubi/create/content/logistics/redstoneRequester/RedstoneRequesterBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/redstoneRequester/RedstoneRequesterBlockEntity.java @@ -2,13 +2,23 @@ import com.simibubi.create.AllPackets; import com.simibubi.create.AllSoundEvents; +import com.simibubi.create.AllBlockEntityTypes; import com.simibubi.create.content.logistics.BigItemStack; import com.simibubi.create.content.logistics.packager.InventorySummary; import com.simibubi.create.content.logistics.packagerLink.LogisticallyLinkedBehaviour.RequestType; import com.simibubi.create.content.logistics.packagerLink.WiFiParticle; import com.simibubi.create.content.logistics.stockTicker.PackageOrder; import com.simibubi.create.content.logistics.stockTicker.StockCheckingBlockEntity; - +import com.simibubi.create.compat.Mods; +import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; +import com.simibubi.create.compat.computercraft.ComputerCraftProxy; +import java.util.List; +import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; + +import dan200.computercraft.api.peripheral.PeripheralCapability; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; +import net.createmod.catnip.codecs.CatnipCodecUtils; +import net.createmod.catnip.platform.CatnipServices; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.nbt.CompoundTag; @@ -41,6 +51,23 @@ public RedstoneRequesterBlockEntity(BlockEntityType type, BlockPos pos, Block allowPartialRequests = false; } + public AbstractComputerBehaviour computerBehaviour; + + @Override + public void addBehaviours(List behaviours) { + super.addBehaviours(behaviours); + behaviours.add(computerBehaviour = ComputerCraftProxy.behaviour(this)); + } + + public static void registerCapabilities(RegisterCapabilitiesEvent event) { + if (Mods.COMPUTERCRAFT.isLoaded()) { + event.registerBlockEntity( + PeripheralCapability.get(), + AllBlockEntityTypes.REDSTONE_REQUESTER.get(), + (be, context) -> be.computerBehaviour.getPeripheralCapability()); + } + } + protected void onRedstonePowerChanged() { boolean hasNeighborSignal = level.hasNeighborSignal(worldPosition); if (redstonePowered == hasNeighborSignal) diff --git a/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java b/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java index 7f94e72ec1..7046785402 100644 --- a/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java +++ b/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java @@ -13,6 +13,28 @@ import com.simibubi.create.content.kinetics.belt.BeltHelper; import com.simibubi.create.content.kinetics.chainConveyor.ServerChainConveyorHandler; import com.simibubi.create.content.kinetics.drill.CobbleGenOptimisation; +import com.simibubi.create.content.kinetics.gauge.SpeedGaugeBlockEntity; +import com.simibubi.create.content.kinetics.gauge.StressGaugeBlockEntity; +import com.simibubi.create.content.kinetics.millstone.MillstoneBlockEntity; +import com.simibubi.create.content.kinetics.saw.SawBlockEntity; +import com.simibubi.create.content.kinetics.speedController.SpeedControllerBlockEntity; +import com.simibubi.create.content.kinetics.transmission.sequencer.SequencedGearshiftBlockEntity; +import com.simibubi.create.content.logistics.chute.ChuteBlockEntity; +import com.simibubi.create.content.logistics.chute.SmartChuteBlockEntity; +import com.simibubi.create.content.logistics.crate.CreativeCrateBlockEntity; +import com.simibubi.create.content.logistics.depot.DepotBlockEntity; +import com.simibubi.create.content.logistics.depot.EjectorBlockEntity; +import com.simibubi.create.content.logistics.packagePort.frogport.FrogportBlockEntity; +import com.simibubi.create.content.logistics.packagePort.postbox.PostboxBlockEntity; +import com.simibubi.create.content.logistics.packager.PackagerBlockEntity; +import com.simibubi.create.content.logistics.packager.repackager.RepackagerBlockEntity; +import com.simibubi.create.content.logistics.stockTicker.StockTickerBlockEntity; +import com.simibubi.create.content.logistics.redstoneRequester.RedstoneRequesterBlockEntity; +import com.simibubi.create.content.logistics.tunnel.BeltTunnelBlockEntity; +import com.simibubi.create.content.logistics.tunnel.BrassTunnelBlockEntity; +import com.simibubi.create.content.logistics.vault.ItemVaultBlockEntity; +import com.simibubi.create.content.processing.basin.BasinBlockEntity; +import com.simibubi.create.content.redstone.displayLink.DisplayLinkBlockEntity; import com.simibubi.create.content.redstone.link.controller.LinkedControllerServerHandler; import com.simibubi.create.content.trains.entity.CarriageEntityHandler; import com.simibubi.create.foundation.data.RuntimeDataGenerator; @@ -216,5 +238,49 @@ public static void addPackFinders(AddPackFindersEvent event) { event.addRepositorySource(new DynamicPackSource("create:dynamic_data", PackType.SERVER_DATA, Pack.Position.BOTTOM, dynamicPack)); } } + + @net.neoforged.bus.api.SubscribeEvent + public static void onRegisterMapDecorationRenderers(RegisterMapDecorationRenderersEvent event) { + event.register(AllMapDecorationTypes.STATION_MAP_DECORATION.value(), new StationMapDecorationRenderer()); + } + + @net.neoforged.bus.api.SubscribeEvent + public static void registerCapabilities(net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent event) { + ChuteBlockEntity.registerCapabilities(event); + SmartChuteBlockEntity.registerCapabilities(event); + BeltBlockEntity.registerCapabilities(event); + BasinBlockEntity.registerCapabilities(event); + BeltTunnelBlockEntity.registerCapabilities(event); + BrassTunnelBlockEntity.registerCapabilities(event); + CreativeCrateBlockEntity.registerCapabilities(event); + CrushingWheelControllerBlockEntity.registerCapabilities(event); + ToolboxBlockEntity.registerCapabilities(event); + DeployerBlockEntity.registerCapabilities(event); + DepotBlockEntity.registerCapabilities(event); + PortableFluidInterfaceBlockEntity.registerCapabilities(event); + SpoutBlockEntity.registerCapabilities(event); + PortableItemInterfaceBlockEntity.registerCapabilities(event); + SawBlockEntity.registerCapabilities(event); + EjectorBlockEntity.registerCapabilities(event); + FluidTankBlockEntity.registerCapabilities(event); + CreativeFluidTankBlockEntity.registerCapabilities(event); + HosePulleyBlockEntity.registerCapabilities(event); + ItemDrainBlockEntity.registerCapabilities(event); + ItemVaultBlockEntity.registerCapabilities(event); + MechanicalCrafterBlockEntity.registerCapabilities(event); + MillstoneBlockEntity.registerCapabilities(event); + StressGaugeBlockEntity.registerCapabilities(event); + SpeedGaugeBlockEntity.registerCapabilities(event); + StationBlockEntity.registerCapabilities(event); + SpeedControllerBlockEntity.registerCapabilities(event); + SequencedGearshiftBlockEntity.registerCapabilities(event); + DisplayLinkBlockEntity.registerCapabilities(event); + StockTickerBlockEntity.registerCapabilities(event); + RedstoneRequesterBlockEntity.registerCapabilities(event); + PackagerBlockEntity.registerCapabilities(event); + RepackagerBlockEntity.registerCapabilities(event); + PostboxBlockEntity.registerCapabilities(event); + FrogportBlockEntity.registerCapabilities(event); + } } } From 8b561e31fc4122ff2dc5b5df29ad8427f6e03c32 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Thu, 6 Mar 2025 21:19:51 +0100 Subject: [PATCH 13/48] made the getAddress and setAddress functions consistent accross packager/postbox/frogge --- .../peripherals/FrogportPeripheral.java | 11 ++++++---- .../peripherals/PackagerPeripheral.java | 21 ++++++++----------- .../peripherals/PostboxPeripheral.java | 11 ++++++---- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/FrogportPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/FrogportPeripheral.java index 21818b6399..fda68a4ea1 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/FrogportPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/FrogportPeripheral.java @@ -15,21 +15,24 @@ public FrogportPeripheral(FrogportBlockEntity blockEntity) { } @LuaFunction(mainThread = true) - public final String setAddress(IArguments arguments) throws LuaException { + public final void setAddress(IArguments arguments) throws LuaException { Object argument = arguments.get(0); if (argument instanceof String) { blockEntity.addressFilter = (String) argument; blockEntity.filterChanged(); blockEntity.notifyUpdate(); - return blockEntity.addressFilter; + } else if (argument == null) { + blockEntity.addressFilter = ""; + blockEntity.filterChanged(); + blockEntity.notifyUpdate(); } else { - return null; + throw new LuaException("Argument must be string or nil"); } } @LuaFunction(mainThread = true) public final String getAddress() throws LuaException { - return blockEntity.addressFilter; + return blockEntity.addressFilter; } @NotNull diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java index d6623bf51b..134ddafa1b 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java @@ -51,27 +51,24 @@ public final boolean makePackage() { return result; } - // sets the packagaer's address. Clears once it gets reloaded for safety @LuaFunction(mainThread = true) - public final String setAddress(IArguments arguments) throws LuaException { + public final void setAddress(IArguments arguments) throws LuaException { Object argument = arguments.get(0); if (argument instanceof String) { blockEntity.CustomComputerAddress = (String) argument; blockEntity.hasCustomComputerAddress = true; - return blockEntity.CustomComputerAddress; - } else if (argument instanceof Double) { - if ((Double) argument == ((Double) argument).intValue()) // to get rid of the floating point - blockEntity.CustomComputerAddress = String.valueOf(((Double) argument).intValue()); - else - blockEntity.CustomComputerAddress = String.valueOf((Double) argument); - blockEntity.hasCustomComputerAddress = true; - return blockEntity.CustomComputerAddress; - } else { + } else if (argument == null) { blockEntity.hasCustomComputerAddress = false; - return null; + } else { + throw new LuaException("Argument must be string or nil"); } } + @LuaFunction(mainThread = true) + public final String getAddress() throws LuaException { + return blockEntity.signBasedAddress; + } + @LuaFunction(mainThread = true) public final Map> listDetailed() { Map> result = new HashMap<>(); diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PostboxPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PostboxPeripheral.java index aa35c7abce..3553fc308e 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PostboxPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PostboxPeripheral.java @@ -17,21 +17,24 @@ public PostboxPeripheral(PostboxBlockEntity blockEntity) { } @LuaFunction(mainThread = true) - public final String setAddress(IArguments arguments) throws LuaException { + public final void setAddress(IArguments arguments) throws LuaException { Object argument = arguments.get(0); if (argument instanceof String) { blockEntity.addressFilter = (String) argument; blockEntity.filterChanged(); blockEntity.notifyUpdate(); - return blockEntity.addressFilter; + } else if (argument == null) { + blockEntity.addressFilter = ""; + blockEntity.filterChanged(); + blockEntity.notifyUpdate(); } else { - return null; + throw new LuaException("Argument must be string or nil"); } } @LuaFunction(mainThread = true) public final String getAddress() throws LuaException { - return blockEntity.addressFilter; + return blockEntity.addressFilter; } @NotNull From e606850b914439f2be1f4b0bdd0b85ae6c5eb46e Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Thu, 6 Mar 2025 21:27:36 +0100 Subject: [PATCH 14/48] "why isn't this variable what i told it to be?" - says programmer forgetting to set a variable t what they want it to be --- .../implementation/peripherals/PackagerPeripheral.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java index 134ddafa1b..dc5a9732a1 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java @@ -56,6 +56,7 @@ public final void setAddress(IArguments arguments) throws LuaException { Object argument = arguments.get(0); if (argument instanceof String) { blockEntity.CustomComputerAddress = (String) argument; + blockEntity.signBasedAddress = (String) argument; blockEntity.hasCustomComputerAddress = true; } else if (argument == null) { blockEntity.hasCustomComputerAddress = false; From de5efa139a501d528b02551b7c77f62247ef6eca Mon Sep 17 00:00:00 2001 From: AsterAether Date: Thu, 6 Mar 2025 22:29:12 +0100 Subject: [PATCH 15/48] Add listPaymentInventory to StockTickerPeripheral --- .../{LuaUtil.java => ComputerUtil.java} | 34 +++++++++++++------ .../RedstoneRequesterPeripheral.java | 4 +-- .../peripherals/StockTickerPeripheral.java | 20 ++++++++--- .../stockTicker/StockTickerBlockEntity.java | 4 +++ 4 files changed, 46 insertions(+), 16 deletions(-) rename src/main/java/com/simibubi/create/compat/computercraft/implementation/{LuaUtil.java => ComputerUtil.java} (84%) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/LuaUtil.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java similarity index 84% rename from src/main/java/com/simibubi/create/compat/computercraft/implementation/LuaUtil.java rename to src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java index 438b4950ba..2fa1f584c2 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/LuaUtil.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java @@ -1,6 +1,7 @@ package com.simibubi.create.compat.computercraft.implementation; import com.simibubi.create.content.logistics.BigItemStack; + import dan200.computercraft.api.lua.LuaException; import java.util.HashMap; @@ -11,14 +12,16 @@ import dan200.computercraft.api.detail.VanillaDetailRegistries; -public class LuaUtil { +import net.neoforged.neoforge.items.IItemHandler; + +public class ComputerUtil { // tldr: the computercraft api lets you parse items into lua-like-tables that cc // uses for all it's items. to keep consistency with the rest of the inventory // api in other parts of the mod i must do this terribleness. i am sorry. public static int bigItemStackToLuaTableFilter(BigItemStack entry, Map filter) throws LuaException { Map details = new HashMap<>( - VanillaDetailRegistries.ITEM_STACK.getDetails(entry.stack)); + VanillaDetailRegistries.ITEM_STACK.getDetails(entry.stack)); details.put("count", entry.count); if (filter.containsKey("name")) if (filter.get("name") instanceof String) { @@ -68,7 +71,7 @@ public static int bigItemStackToLuaTableFilter(BigItemStack entry, Map fil for (Map.Entry filterTagEntry : filterTags.entrySet()) { if (!(filterTagEntry.getValue() instanceof Boolean)) { throw new LuaException( - "Tags filter must be a table of tags like: \n{tags = { \n [\"minecraft:logs\"] = true} \n {diamonds = true}\n}}"); + "Tags filter must be a table of tags like: \n{tags = { \n [\"minecraft:logs\"] = true} \n {diamonds = true}\n}}"); } int filterMatches = 0; for (Map.Entry itemTagEntry : itemTags.entrySet()) { @@ -104,7 +107,7 @@ public static int bigItemStackToLuaTableFilter(BigItemStack entry, Map fil int filterMatches = 0; if (!(filterEnchantmentNode.getValue() instanceof Map)) { throw new LuaException( - "Enchantments filter must be a table of enchant information like: \n{enchantments = { \n {name = \"minecraft:sharpness\"} \n {name = \"minecraft:protection\" \n level = 1\n }\n}}"); + "Enchantments filter must be a table of enchant information like: \n{enchantments = { \n {name = \"minecraft:sharpness\"} \n {name = \"minecraft:protection\" \n level = 1\n }\n}}"); } @SuppressWarnings("unchecked") Map filterEnchantmentEntry = (Map) (filterEnchantmentNode.getValue()); @@ -132,12 +135,12 @@ public static int bigItemStackToLuaTableFilter(BigItemStack entry, Map fil Integer itemEnchantmentLevel = (Integer) (itemEnchantmentEntry.get("level")); if (!matchedItemEnchantments.contains(itemEnchantmentEntry) - && (!CheckEnchantmentName || itemEnchantmentName.equals(filterEnchantmentName)) - && (!CheckEnchantmentDisplayName - || (itemEnchantmentDisplayName.equals(filterEnchantmentDisplayName))) - && (!CheckEnchantmentLevel - || (itemEnchantmentLevel - .doubleValue()) == filterEnchantmentLevel)) { + && (!CheckEnchantmentName || itemEnchantmentName.equals(filterEnchantmentName)) + && (!CheckEnchantmentDisplayName + || (itemEnchantmentDisplayName.equals(filterEnchantmentDisplayName))) + && (!CheckEnchantmentLevel + || (itemEnchantmentLevel + .doubleValue()) == filterEnchantmentLevel)) { matchedItemEnchantments.add(itemEnchantmentEntry); // one itemenchant per filter filterMatches++; } @@ -153,4 +156,15 @@ public static int bigItemStackToLuaTableFilter(BigItemStack entry, Map fil return entry.count; } + + public static Map> list(IItemHandler inventory) { + Map> result = new HashMap<>(); + var size = inventory.getSlots(); + for (var i = 0; i < size; i++) { + var stack = inventory.getStackInSlot(i); + if (!stack.isEmpty()) result.put(i + 1, VanillaDetailRegistries.ITEM_STACK.getBasicDetails(stack)); + } + + return result; + } } diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java index 7569fbcb0c..86be301a59 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java @@ -4,7 +4,7 @@ import com.simibubi.create.content.logistics.redstoneRequester.RedstoneRequesterBlockEntity; import com.simibubi.create.content.logistics.BigItemStack; -import com.simibubi.create.compat.computercraft.implementation.LuaUtil; +import com.simibubi.create.compat.computercraft.implementation.ComputerUtil; import com.simibubi.create.content.logistics.packagerLink.LogisticallyLinkedBehaviour.RequestType; import com.simibubi.create.content.logistics.stockTicker.PackageOrder; import java.util.Map; @@ -54,7 +54,7 @@ public final int request(IArguments arguments) throws LuaException { List validItems = new ArrayList<>(); int totalItemCount = 0; for (BigItemStack entry : blockEntity.getAccurateSummary().getStacks()) { - if (LuaUtil.bigItemStackToLuaTableFilter(entry, filter) > 0) { + if (ComputerUtil.bigItemStackToLuaTableFilter(entry, filter) > 0) { // limit the number of items pulled from the system equals to the requested // count parameter if (filter.containsKey("count")) { diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java index 2db037afe1..f4d97f9e1d 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java @@ -4,9 +4,10 @@ import com.simibubi.create.content.logistics.stockTicker.StockTickerBlockEntity; import com.simibubi.create.content.logistics.BigItemStack; -import com.simibubi.create.compat.computercraft.implementation.LuaUtil; +import com.simibubi.create.compat.computercraft.implementation.ComputerUtil; import com.simibubi.create.content.logistics.packagerLink.LogisticallyLinkedBehaviour.RequestType; import com.simibubi.create.content.logistics.stockTicker.PackageOrder; + import java.util.HashMap; import java.util.Map; import java.util.List; @@ -17,6 +18,8 @@ import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.detail.VanillaDetailRegistries; +import org.jetbrains.annotations.Nullable; + public class StockTickerPeripheral extends SyncedPeripheral { // private final ScrollValueBehaviour targetSpeed; @@ -38,7 +41,7 @@ public final int getItemCount() { for (BigItemStack entry : blockEntity.getAccurateSummary().getStacks()) { i++; Map details = new HashMap<>( - VanillaDetailRegistries.ITEM_STACK.getBasicDetails(entry.stack)); + VanillaDetailRegistries.ITEM_STACK.getBasicDetails(entry.stack)); details.put("count", entry.count); result.put(i, details); } @@ -52,7 +55,7 @@ public final int getItemCount() { for (BigItemStack entry : blockEntity.getAccurateSummary().getStacks()) { i++; Map details = new HashMap<>( - VanillaDetailRegistries.ITEM_STACK.getDetails(entry.stack)); + VanillaDetailRegistries.ITEM_STACK.getDetails(entry.stack)); details.put("count", entry.count); result.put(i, details); } @@ -89,7 +92,7 @@ public final int request(IArguments arguments) throws LuaException { List validItems = new ArrayList<>(); int totalItemCount = 0; for (BigItemStack entry : blockEntity.getAccurateSummary().getStacks()) { - if (LuaUtil.bigItemStackToLuaTableFilter(entry, filter) > 0) { + if (ComputerUtil.bigItemStackToLuaTableFilter(entry, filter) > 0) { // limit the number of items pulled from the system equals to the requested // count parameter if (filter.containsKey("count")) { @@ -128,10 +131,19 @@ public final int request(IArguments arguments) throws LuaException { return totalItemCount; } + @LuaFunction(mainThread = true) + public Map> listPaymentInventory() { + return ComputerUtil.list(blockEntity.getReceivedPaymentsHandler()); + } + @NotNull @Override public String getType() { return "Create_StockTicker"; } + @Override + public @Nullable Object getTarget() { + return blockEntity.getReceivedPaymentsHandler(); + } } diff --git a/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockTickerBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockTickerBlockEntity.java index b586329123..918b1aaf5f 100644 --- a/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockTickerBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockTickerBlockEntity.java @@ -111,6 +111,10 @@ public void refreshClientStockSnapshot() { .sendToServer(new LogisticalStockRequestPacket(worldPosition)); } + public IItemHandler getReceivedPaymentsHandler() { + return receivedPayments; + } + public List> getClientStockSnapshot() { return lastClientsideStockSnapshot; } From 83a0ebcd0a9e7340a1754c0e98a743e00c6fd278 Mon Sep 17 00:00:00 2001 From: AsterAether Date: Thu, 6 Mar 2025 23:09:20 +0100 Subject: [PATCH 16/48] cherry-pick 7 --- .../computercraft/implementation/ComputerUtil.java | 13 ++++++------- .../peripherals/RedstoneRequesterPeripheral.java | 1 + 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java index 2fa1f584c2..4cd4c9e03d 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java @@ -1,16 +1,15 @@ package com.simibubi.create.compat.computercraft.implementation; -import com.simibubi.create.content.logistics.BigItemStack; - -import dan200.computercraft.api.lua.LuaException; - +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.Set; import java.util.Map; -import java.util.ArrayList; +import java.util.Set; + +import com.simibubi.create.content.logistics.BigItemStack; import dan200.computercraft.api.detail.VanillaDetailRegistries; +import dan200.computercraft.api.lua.LuaException; import net.neoforged.neoforge.items.IItemHandler; @@ -21,7 +20,7 @@ public class ComputerUtil { // api in other parts of the mod i must do this terribleness. i am sorry. public static int bigItemStackToLuaTableFilter(BigItemStack entry, Map filter) throws LuaException { Map details = new HashMap<>( - VanillaDetailRegistries.ITEM_STACK.getDetails(entry.stack)); + VanillaDetailRegistries.ITEM_STACK.getDetails(entry.stack)); details.put("count", entry.count); if (filter.containsKey("name")) if (filter.get("name") instanceof String) { diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java index 86be301a59..06f1ba5f61 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java @@ -7,6 +7,7 @@ import com.simibubi.create.compat.computercraft.implementation.ComputerUtil; import com.simibubi.create.content.logistics.packagerLink.LogisticallyLinkedBehaviour.RequestType; import com.simibubi.create.content.logistics.stockTicker.PackageOrder; + import java.util.Map; import java.util.List; import java.util.ArrayList; From da31642e002285b787c37d25fa92f5ed2782cc2d Mon Sep 17 00:00:00 2001 From: Arctic Date: Thu, 6 Mar 2025 18:09:23 -0500 Subject: [PATCH 17/48] Added Configure method Order is off when placing into requester --- .../RedstoneRequesterPeripheral.java | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java index 06f1ba5f61..5fdc5f533b 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java @@ -1,5 +1,11 @@ package com.simibubi.create.compat.computercraft.implementation.peripherals; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; + +import net.minecraft.world.level.ItemLike; + import org.jetbrains.annotations.NotNull; import com.simibubi.create.content.logistics.redstoneRequester.RedstoneRequesterBlockEntity; @@ -7,7 +13,6 @@ import com.simibubi.create.compat.computercraft.implementation.ComputerUtil; import com.simibubi.create.content.logistics.packagerLink.LogisticallyLinkedBehaviour.RequestType; import com.simibubi.create.content.logistics.stockTicker.PackageOrder; - import java.util.Map; import java.util.List; import java.util.ArrayList; @@ -94,6 +99,46 @@ public final int request(IArguments arguments) throws LuaException { return totalItemCount; } + + @LuaFunction(mainThread = true) + public final void configure(IArguments arguments) throws LuaException{ + if (!(arguments.get(0) instanceof Map)) { + throw new LuaException("Argument Issue"); + } + Map items = (Map) arguments.get(0); + ArrayList list = new ArrayList<>(); + + if(items.size() > 9){ + throw new LuaException("Cannot input more than 9 items"); + } + + for (Map.Entry entry : items.entrySet()) { + Object obj = entry.getValue(); + + if (!(obj instanceof Map)) { + throw new LuaException("Table expected for each item entry"); + } + + Map itemData = (Map) obj; + String itemName = (String) itemData.getOrDefault("name", "minecraft:air"); + Object countObj = itemData.getOrDefault("count", 1.0); + int count = (countObj instanceof Number) ? ((Number) countObj).intValue() : 1; + if (itemName.isEmpty()) { + list.add(new BigItemStack(ItemStack.EMPTY, count)); + } else { + ResourceLocation resourceLocation = ResourceLocation.parse(itemName); + ItemLike item = BuiltInRegistries.ITEM.get(resourceLocation); + ItemStack itemStack = new ItemStack(item); + list.add(new BigItemStack(itemStack, count)); + } + } + + System.out.println(list); + this.blockEntity.encodedRequest = new PackageOrder(list); + System.out.println(arguments.getString(1)); + } + + @NotNull @Override public String getType() { From 16bdf35aa2c617c741caefb81659f78a443c459c Mon Sep 17 00:00:00 2001 From: Arctic Date: Thu, 6 Mar 2025 18:29:00 -0500 Subject: [PATCH 18/48] Updated Redstone Requester fixed the ordering bug --- .../peripherals/RedstoneRequesterPeripheral.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java index 5fdc5f533b..96c5b8cae5 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java @@ -112,8 +112,8 @@ public final void configure(IArguments arguments) throws LuaException{ throw new LuaException("Cannot input more than 9 items"); } - for (Map.Entry entry : items.entrySet()) { - Object obj = entry.getValue(); + for (double i = 1; i <= 9; i++) { + Object obj = items.get(i); if (!(obj instanceof Map)) { throw new LuaException("Table expected for each item entry"); @@ -133,8 +133,8 @@ public final void configure(IArguments arguments) throws LuaException{ } } - System.out.println(list); this.blockEntity.encodedRequest = new PackageOrder(list); + this.blockEntity.encodedRequestContext = new PackageOrder(list); System.out.println(arguments.getString(1)); } From dc5040c6f1c36e4a35ee8eb67d473e9ded6e5609 Mon Sep 17 00:00:00 2001 From: AsterAether Date: Fri, 7 Mar 2025 01:40:29 +0100 Subject: [PATCH 19/48] cherry-pick 8 --- .../implementation/ComputerBehaviour.java | 4 + .../implementation/ComputerUtil.java | 34 ++++++ .../peripherals/TableClothPeripheral.java | 30 +++++ .../tableCloth/TableClothBlockEntity.java | 112 ++++++++++++++++-- .../foundation/events/CommonEvents.java | 2 + .../highLogistics/TableClothScenes.java | 2 +- 6 files changed, 172 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java index 723763641a..011ee877c6 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java @@ -11,6 +11,7 @@ import com.simibubi.create.compat.computercraft.implementation.peripherals.StressGaugePeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.StockTickerPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.PackagerPeripheral; +import com.simibubi.create.compat.computercraft.implementation.peripherals.TableClothPeripheral; import com.simibubi.create.content.logistics.packagePort.frogport.FrogportBlockEntity; import com.simibubi.create.content.logistics.packagePort.postbox.PostboxBlockEntity; import com.simibubi.create.compat.computercraft.implementation.peripherals.RedstoneRequesterPeripheral; @@ -21,6 +22,7 @@ import com.simibubi.create.content.kinetics.gauge.StressGaugeBlockEntity; import com.simibubi.create.content.kinetics.speedController.SpeedControllerBlockEntity; import com.simibubi.create.content.kinetics.transmission.sequencer.SequencedGearshiftBlockEntity; +import com.simibubi.create.content.logistics.tableCloth.TableClothBlockEntity; import com.simibubi.create.content.redstone.displayLink.DisplayLinkBlockEntity; import com.simibubi.create.content.trains.station.StationBlockEntity; import com.simibubi.create.foundation.blockEntity.SmartBlockEntity; @@ -69,6 +71,8 @@ public static NonNullSupplier getPeripheralFor(SmartBlockEntity be) return () -> new RedstoneRequesterPeripheral(rrbe); if (be instanceof StationBlockEntity sbe) return () -> new StationPeripheral(sbe); + if (be instanceof TableClothBlockEntity tcbe) + return () -> new TableClothPeripheral(tcbe); throw new IllegalArgumentException( "No peripheral available for " + ForgeRegistries.BLOCK_ENTITY_TYPES.getKey(be.getType())); diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java index 4cd4c9e03d..9e7e01536d 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java @@ -11,10 +11,44 @@ import dan200.computercraft.api.detail.VanillaDetailRegistries; import dan200.computercraft.api.lua.LuaException; +import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.items.IItemHandler; +import org.jetbrains.annotations.NotNull; public class ComputerUtil { + public static IItemHandler NOOP_HANDLER = new IItemHandler() { + @Override + public int getSlots() { + return 0; + } + + @Override + public @NotNull ItemStack getStackInSlot(int i) { + return ItemStack.EMPTY; + } + + @Override + public @NotNull ItemStack insertItem(int i, ItemStack itemStack, boolean b) { + return ItemStack.EMPTY; + } + + @Override + public @NotNull ItemStack extractItem(int i, int i1, boolean b) { + return ItemStack.EMPTY; + } + + @Override + public int getSlotLimit(int i) { + return 0; + } + + @Override + public boolean isItemValid(int i, @NotNull ItemStack itemStack) { + return false; + } + }; + // tldr: the computercraft api lets you parse items into lua-like-tables that cc // uses for all it's items. to keep consistency with the rest of the inventory // api in other parts of the mod i must do this terribleness. i am sorry. diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java new file mode 100644 index 0000000000..eb4e03fddf --- /dev/null +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java @@ -0,0 +1,30 @@ +package com.simibubi.create.compat.computercraft.implementation.peripherals; + +import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; +import com.simibubi.create.compat.computercraft.implementation.ComputerUtil; +import com.simibubi.create.content.logistics.tableCloth.TableClothBlockEntity; + +import dan200.computercraft.api.lua.LuaFunction; +import org.jetbrains.annotations.Nullable; + +public class TableClothPeripheral extends SyncedPeripheral { + + public TableClothPeripheral(TableClothBlockEntity blockEntity) { + super(blockEntity); + } + + @Override + public String getType() { + return "Create_TableCloth"; + } + + @LuaFunction(mainThread = true) + public final boolean isShop() { + return blockEntity.isShop(); + } + + @Override + public @Nullable Object getTarget() { + return isShop() ? ComputerUtil.NOOP_HANDLER : blockEntity.manuallyAddedItems; + } +} diff --git a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java index 30bc0c4904..22aa8d1a3f 100644 --- a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java @@ -6,10 +6,15 @@ import javax.annotation.Nullable; +import com.simibubi.create.AllBlockEntityTypes; import com.simibubi.create.AllItems; import com.simibubi.create.AllPackets; import com.simibubi.create.AllSoundEvents; import com.simibubi.create.AllTags.AllBlockTags; +import com.simibubi.create.compat.Mods; +import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; +import com.simibubi.create.compat.computercraft.ComputerCraftProxy; +import com.simibubi.create.compat.computercraft.implementation.ComputerUtil; import com.simibubi.create.content.logistics.BigItemStack; import com.simibubi.create.content.logistics.packager.InventorySummary; import com.simibubi.create.content.logistics.redstoneRequester.AutoRequestData; @@ -19,6 +24,7 @@ import com.simibubi.create.foundation.blockEntity.SmartBlockEntity; import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; import com.simibubi.create.foundation.blockEntity.behaviour.filtering.FilteringBehaviour; +import com.simibubi.create.foundation.item.SmartInventory; import com.simibubi.create.foundation.utility.CreateLang; import net.createmod.catnip.data.IntAttached; @@ -43,10 +49,15 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; + public class TableClothBlockEntity extends SmartBlockEntity { + public AbstractComputerBehaviour computerBehaviour; + public AutoRequestData requestData; - public List manuallyAddedItems; + public SmartInventory manuallyAddedItems; public UUID owner; public Direction facing; @@ -54,10 +65,11 @@ public class TableClothBlockEntity extends SmartBlockEntity { public FilteringBehaviour priceTag; private List renderedItemsForShop; + private List cachedItems; public TableClothBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); - manuallyAddedItems = new ArrayList<>(); + manuallyAddedItems = new SmartInventory(4, this, 1, false); requestData = new AutoRequestData(); owner = null; facing = Direction.SOUTH; @@ -66,6 +78,28 @@ public TableClothBlockEntity(BlockEntityType type, BlockPos pos, BlockState s @Override public void addBehaviours(List behaviours) { behaviours.add(priceTag = new TableClothFilteringBehaviour(this)); + behaviours.add(computerBehaviour = ComputerCraftProxy.behaviour(this)); + } + + public static void registerCapabilities(RegisterCapabilitiesEvent event) { + event.registerBlockEntity( + Capabilities.ItemHandler.BLOCK, + AllBlockEntityTypes.TABLE_CLOTH.get(), + (be, context) -> { + if (be.isShop()) { + return ComputerUtil.NOOP_HANDLER; + } + return be.manuallyAddedItems; + } + ); + + if (Mods.COMPUTERCRAFT.isLoaded()) { + event.registerBlockEntity( + PeripheralCapability.get(), + AllBlockEntityTypes.TABLE_CLOTH.get(), + (be, context) -> be.computerBehaviour.getPeripheralCapability() + ); + } } public List getItemsForRender() { @@ -78,8 +112,7 @@ public List getItemsForRender() { .toList(); return renderedItemsForShop; } - - return manuallyAddedItems; + return cachedItems(); } @Override @@ -100,6 +133,57 @@ public boolean isShop() { return !requestData.encodedRequest.isEmpty(); } + public ItemStack popItem() { + if (isShop() || manuallyAddedItems.isEmpty()) + return ItemStack.EMPTY; + + for (int i = manuallyAddedItems.getSlots() - 1; i >= 0; i--) { + if (!manuallyAddedItems.getStackInSlot(i).isEmpty()) { + ItemStack item = manuallyAddedItems.getStackInSlot(i); + manuallyAddedItems.setStackInSlot(i, ItemStack.EMPTY); + return item; + } + } + return ItemStack.EMPTY; + } + + public void pushItem(ItemStack stack) { + if (isShop()) + return; + + for (int i = 0; i < manuallyAddedItems.getSlots(); i++) { + if (manuallyAddedItems.getStackInSlot(i).isEmpty()) { + manuallyAddedItems.setStackInSlot(i, stack); + return; + } + } + } + + public List items() { + List items = new ArrayList<>(); + for (int i = 0; i < manuallyAddedItems.getSlots(); i++) { + if (!manuallyAddedItems.getStackInSlot(i).isEmpty()) { + items.add(manuallyAddedItems.getStackInSlot(i)); + } + } + return items; + } + + public List cachedItems() { + if (cachedItems == null) + cachedItems = items(); + return cachedItems; + } + + public boolean isFull() { + for (int i = 0; i < manuallyAddedItems.getSlots(); i++) { + if (manuallyAddedItems.getStackInSlot(i).isEmpty()) { + return false; + } + } + return true; + } + public InteractionResult use(Player player, BlockHitResult ray) { if (isShop()) return useShop(player); @@ -111,8 +195,8 @@ public InteractionResult use(Player player, BlockHitResult ray) { return InteractionResult.SUCCESS; player.setItemInHand(InteractionHand.MAIN_HAND, manuallyAddedItems.remove(manuallyAddedItems.size() - 1)); level.playSound(null, worldPosition, SoundEvents.ITEM_FRAME_REMOVE_ITEM, SoundSource.BLOCKS, 0.5f, 1f); - - if (manuallyAddedItems.isEmpty()) { + cachedItems = items(); + if (manuallyAddedItems.isEmpty() && !computerBehaviour.hasAttachedComputer()) { level.setBlock(worldPosition, getBlockState().setValue(TableClothBlock.HAS_BE, false), 3); AllPackets.getChannel() .send(packetTarget(), new RemoveBlockEntityPacket(worldPosition)); @@ -122,11 +206,11 @@ public InteractionResult use(Player player, BlockHitResult ray) { return InteractionResult.SUCCESS; } - if (manuallyAddedItems.size() >= 4) + if (isFull()) return InteractionResult.SUCCESS; level.playSound(null, worldPosition, SoundEvents.ITEM_FRAME_ADD_ITEM, SoundSource.BLOCKS, 0.5f, 1f); - manuallyAddedItems.add(heldItem.copyWithCount(1)); + pushItem(heldItem.copyWithCount(1)); facing = player.getDirection() .getOpposite(); heldItem.shrink(1); @@ -298,7 +382,11 @@ protected void write(CompoundTag tag, boolean clientPacket) { @Override protected void read(CompoundTag tag, boolean clientPacket) { super.read(tag, clientPacket); - manuallyAddedItems = NBTHelper.readItemList(tag.getList("Items", Tag.TAG_COMPOUND)); + List items = NBTHelper.readItemList(tag.getList("Items", Tag.TAG_COMPOUND)); + for (int i = 0; i < items.size(); i++) { + manuallyAddedItems.setStackInSlot(i, items.get(i)); + } + cachedItems = items; requestData = AutoRequestData.read(tag); owner = tag.contains("OwnerUUID") ? tag.getUUID("OwnerUUID") : null; facing = Direction.from2DDataValue(Mth.positiveModulo(tag.getInt("Facing"), 4)); @@ -307,9 +395,11 @@ protected void read(CompoundTag tag, boolean clientPacket) { @Override public void destroy() { super.destroy(); - manuallyAddedItems.forEach(stack -> Containers.dropItemStack(level, worldPosition.getX(), worldPosition.getY(), + items().forEach(stack -> Containers.dropItemStack(level, worldPosition.getX(), worldPosition.getY(), worldPosition.getZ(), stack)); - manuallyAddedItems.clear(); + for (int i = 0; i < manuallyAddedItems.getSlots(); i++) { + manuallyAddedItems.setStackInSlot(i, ItemStack.EMPTY); + } } public ItemStack getPaymentItem() { diff --git a/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java b/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java index 7046785402..4a8d562433 100644 --- a/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java +++ b/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java @@ -30,6 +30,7 @@ import com.simibubi.create.content.logistics.packager.repackager.RepackagerBlockEntity; import com.simibubi.create.content.logistics.stockTicker.StockTickerBlockEntity; import com.simibubi.create.content.logistics.redstoneRequester.RedstoneRequesterBlockEntity; +import com.simibubi.create.content.logistics.tableCloth.TableClothBlockEntity; import com.simibubi.create.content.logistics.tunnel.BeltTunnelBlockEntity; import com.simibubi.create.content.logistics.tunnel.BrassTunnelBlockEntity; import com.simibubi.create.content.logistics.vault.ItemVaultBlockEntity; @@ -281,6 +282,7 @@ public static void registerCapabilities(net.neoforged.neoforge.capabilities.Regi RepackagerBlockEntity.registerCapabilities(event); PostboxBlockEntity.registerCapabilities(event); FrogportBlockEntity.registerCapabilities(event); + TableClothBlockEntity.registerCapabilities(event); } } } diff --git a/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/highLogistics/TableClothScenes.java b/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/highLogistics/TableClothScenes.java index 537da1c477..266f1679c3 100644 --- a/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/highLogistics/TableClothScenes.java +++ b/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/highLogistics/TableClothScenes.java @@ -89,7 +89,7 @@ public static void tableCloth(SceneBuilder builder, SceneBuildingUtil util) { .at(3, 2, 3), TableClothBlock.HAS_BE); scene.world() .modifyBlockEntity(util.grid() - .at(3, 2, 3), TableClothBlockEntity.class, be -> be.manuallyAddedItems.add(grass)); + .at(3, 2, 3), TableClothBlockEntity.class, be -> be.pushItem(grass)); scene.idle(10); scene.overlay() From 7ce95872d6f8bd33903193a0a81a07435c17e3c5 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Fri, 7 Mar 2025 02:06:57 +0100 Subject: [PATCH 20/48] rewrote the configure function, functionally the same (still broken) --- .../RedstoneRequesterPeripheral.java | 61 +++++++++++-------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java index 96c5b8cae5..a5cfdbe5d9 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java @@ -99,45 +99,52 @@ public final int request(IArguments arguments) throws LuaException { return totalItemCount; } - @LuaFunction(mainThread = true) - public final void configure(IArguments arguments) throws LuaException{ - if (!(arguments.get(0) instanceof Map)) { - throw new LuaException("Argument Issue"); - } - Map items = (Map) arguments.get(0); - ArrayList list = new ArrayList<>(); + public final void configure(IArguments arguments) throws LuaException { - if(items.size() > 9){ - throw new LuaException("Cannot input more than 9 items"); - } + ArrayList list = new ArrayList<>(); - for (double i = 1; i <= 9; i++) { - Object obj = items.get(i); + for (int i = 0; i <= 8; i++) { + Map itemData = arguments.getTable(i); - if (!(obj instanceof Map)) { - throw new LuaException("Table expected for each item entry"); + if (!(itemData instanceof Map)) { + throw new LuaException("Table or nil expected for each item entry"); } - - Map itemData = (Map) obj; - String itemName = (String) itemData.getOrDefault("name", "minecraft:air"); - Object countObj = itemData.getOrDefault("count", 1.0); - int count = (countObj instanceof Number) ? ((Number) countObj).intValue() : 1; - if (itemName.isEmpty()) { - list.add(new BigItemStack(ItemStack.EMPTY, count)); - } else { - ResourceLocation resourceLocation = ResourceLocation.parse(itemName); - ItemLike item = BuiltInRegistries.ITEM.get(resourceLocation); - ItemStack itemStack = new ItemStack(item); - list.add(new BigItemStack(itemStack, count)); + String itemName = "minecraft:air"; + if (itemData.get("name") instanceof String) { + itemName = (String) itemData.get("name"); + } + int count = 1; + if (itemData.get("count") instanceof Number) { + Object countObj = itemData.get("count"); + count = (countObj instanceof Number) ? ((Number) countObj).intValue() : 1; } + ResourceLocation resourceLocation = ResourceLocation.parse(itemName); + ItemLike item = BuiltInRegistries.ITEM.get(resourceLocation); + ItemStack itemStack = new ItemStack(item); + list.add(new BigItemStack(itemStack, 20)); } this.blockEntity.encodedRequest = new PackageOrder(list); this.blockEntity.encodedRequestContext = new PackageOrder(list); - System.out.println(arguments.getString(1)); } + @LuaFunction(mainThread = true) + public final void setAddress(IArguments arguments) throws LuaException { + Object argument = arguments.get(0); + if (argument instanceof String) { + blockEntity.encodedTargetAdress = (String) argument; + } else if (argument == null) { + blockEntity.encodedTargetAdress = ""; + } else { + throw new LuaException("Argument must be string or nil"); + } + } + + @LuaFunction(mainThread = true) + public final String getAddress() throws LuaException { + return blockEntity.encodedTargetAdress; + } @NotNull @Override From f60c2888c416751897d41a6e20c5ebccd017f507 Mon Sep 17 00:00:00 2001 From: Arctic Date: Thu, 6 Mar 2025 20:22:51 -0500 Subject: [PATCH 21/48] Updated Redstone Receiver Peripheral Added some safety stuff and made it actually save --- .../RedstoneRequesterPeripheral.java | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java index a5cfdbe5d9..365f8d0443 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java @@ -101,14 +101,27 @@ public final int request(IArguments arguments) throws LuaException { @LuaFunction(mainThread = true) public final void configure(IArguments arguments) throws LuaException { - + if (!(arguments.get(0) instanceof Map items)) { + throw new LuaException("First argument must be a table"); + } ArrayList list = new ArrayList<>(); - - for (int i = 0; i <= 8; i++) { - Map itemData = arguments.getTable(i); - - if (!(itemData instanceof Map)) { - throw new LuaException("Table or nil expected for each item entry"); + if (items.size() > 9) { + throw new LuaException("Cannot input more than 9 items"); + } + for (int i = 0; i < 9; i++) { + list.add(new BigItemStack(ItemStack.EMPTY, 0)); + } + for (Object key : items.keySet()) { + if (!(key instanceof Number)) { + continue; + } + int index = ((Number) key).intValue() - 1; + if (index < 0 || index >= 9) { + continue; + } + Object obj = items.get(key); + if (!(obj instanceof Map itemData)) { + throw new LuaException("Table expected for each item entry"); } String itemName = "minecraft:air"; if (itemData.get("name") instanceof String) { @@ -116,17 +129,21 @@ public final void configure(IArguments arguments) throws LuaException { } int count = 1; if (itemData.get("count") instanceof Number) { - Object countObj = itemData.get("count"); - count = (countObj instanceof Number) ? ((Number) countObj).intValue() : 1; + count = ((Number) itemData.get("count")).intValue(); + } + if (itemName.isEmpty() || "minecraft:air".equals(itemName)) { + list.set(index, new BigItemStack(ItemStack.EMPTY, count)); + } else { + ResourceLocation resourceLocation = ResourceLocation.parse(itemName); + ItemLike item = BuiltInRegistries.ITEM.get(resourceLocation); + ItemStack itemStack = new ItemStack(item); + list.set(index, new BigItemStack(itemStack, count)); } - ResourceLocation resourceLocation = ResourceLocation.parse(itemName); - ItemLike item = BuiltInRegistries.ITEM.get(resourceLocation); - ItemStack itemStack = new ItemStack(item); - list.add(new BigItemStack(itemStack, 20)); } this.blockEntity.encodedRequest = new PackageOrder(list); this.blockEntity.encodedRequestContext = new PackageOrder(list); + this.blockEntity.notifyUpdate(); } @LuaFunction(mainThread = true) From 969e6adce963e85bf403a7db84b65e96088887d6 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Fri, 7 Mar 2025 03:03:49 +0100 Subject: [PATCH 22/48] Name = "minecraft:air"? {}? nil? no argument at all? Who needs to throw an error? it's the same thing! --- .../RedstoneRequesterPeripheral.java | 54 ++++++++----------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java index 365f8d0443..ebc251d180 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java @@ -101,43 +101,30 @@ public final int request(IArguments arguments) throws LuaException { @LuaFunction(mainThread = true) public final void configure(IArguments arguments) throws LuaException { - if (!(arguments.get(0) instanceof Map items)) { - throw new LuaException("First argument must be a table"); - } + ArrayList list = new ArrayList<>(); - if (items.size() > 9) { - throw new LuaException("Cannot input more than 9 items"); - } - for (int i = 0; i < 9; i++) { - list.add(new BigItemStack(ItemStack.EMPTY, 0)); - } - for (Object key : items.keySet()) { - if (!(key instanceof Number)) { - continue; - } - int index = ((Number) key).intValue() - 1; - if (index < 0 || index >= 9) { - continue; - } - Object obj = items.get(key); - if (!(obj instanceof Map itemData)) { - throw new LuaException("Table expected for each item entry"); - } - String itemName = "minecraft:air"; - if (itemData.get("name") instanceof String) { - itemName = (String) itemData.get("name"); - } - int count = 1; - if (itemData.get("count") instanceof Number) { - count = ((Number) itemData.get("count")).intValue(); - } - if (itemName.isEmpty() || "minecraft:air".equals(itemName)) { - list.set(index, new BigItemStack(ItemStack.EMPTY, count)); + + for (int i = 0; i <= 8; i++) { + if (arguments.get(i) == null) { + list.add(new BigItemStack(ItemStack.EMPTY, 1)); } else { + Map itemData = arguments.getTable(i); + + if (!(itemData instanceof Map)) { + throw new LuaException("Table or nil expected for each item entry"); + } + String itemName = "minecraft:air"; + if (itemData.get("name") instanceof String) { + itemName = (String) itemData.get("name"); + } + int count = 1; + if (itemData.get("count") instanceof Number) { + Object countObj = itemData.get("count"); + count = (countObj instanceof Number) ? ((Number) countObj).intValue() : 1; + } ResourceLocation resourceLocation = ResourceLocation.parse(itemName); ItemLike item = BuiltInRegistries.ITEM.get(resourceLocation); - ItemStack itemStack = new ItemStack(item); - list.set(index, new BigItemStack(itemStack, count)); + list.add(new BigItemStack(new ItemStack(item), count)); } } @@ -156,6 +143,7 @@ public final void setAddress(IArguments arguments) throws LuaException { } else { throw new LuaException("Argument must be string or nil"); } + this.blockEntity.notifyUpdate(); } @LuaFunction(mainThread = true) From 78d1f6cc61dd97d9b0a04a59beb1cccdfcc09676 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Fri, 7 Mar 2025 18:24:52 +0100 Subject: [PATCH 23/48] Lobotomized the requester --- .../RedstoneRequesterPeripheral.java | 48 +------------------ 1 file changed, 2 insertions(+), 46 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java index ebc251d180..910c8d6bfa 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java @@ -51,52 +51,8 @@ public RedstoneRequesterPeripheral(RedstoneRequesterBlockEntity blockEntity) { * filter of {} requests all items from the network trollface.jpeg */ @LuaFunction(mainThread = true) - public final int request(IArguments arguments) throws LuaException { - if (!(arguments.get(0) instanceof Map)) - return 0; - Map filter = (Map) arguments.get(0); - String address; - // Computercraft has forced my hand to make this dollar store filter algo - List validItems = new ArrayList<>(); - int totalItemCount = 0; - for (BigItemStack entry : blockEntity.getAccurateSummary().getStacks()) { - if (ComputerUtil.bigItemStackToLuaTableFilter(entry, filter) > 0) { - // limit the number of items pulled from the system equals to the requested - // count parameter - if (filter.containsKey("count")) { - Object count = filter.get("count"); - if (count instanceof Double) { - int maxCount = ((Double) count).intValue(); - int remainingCount = maxCount - totalItemCount; - - if (remainingCount > 0) { - int itemsToAdd = Math.min(remainingCount, entry.count); - entry.count = itemsToAdd; - totalItemCount += itemsToAdd; - } else - break; - } - } else { - totalItemCount += entry.count; - } - validItems.add(entry); - } - } - if (arguments.get(1) instanceof String) - address = arguments.getString(1); - else - address = ""; - - PackageOrder order = new PackageOrder(validItems); - blockEntity.broadcastPackageRequest(RequestType.RESTOCK, order, null, address); - - /* - * CatnipServices.NETWORK - * .sendToServer(new PackageOrderRequestPacket(blockEntity.getBlockPos(), new - * PackageOrder(itemsToOrder), - * address, false, new PackageOrder(stacks); - */ - return totalItemCount; + public final void request() throws LuaException { + blockEntity.triggerRequest(); } @LuaFunction(mainThread = true) From 0032629044b8fd43017f8d026abab4b04be2b8f0 Mon Sep 17 00:00:00 2001 From: Arctic Date: Fri, 7 Mar 2025 13:04:09 -0500 Subject: [PATCH 24/48] Update RedstoneRequesterPeripheral.java Added a check to respect the redstone requesters default 256 max item limit --- .../implementation/peripherals/RedstoneRequesterPeripheral.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java index 910c8d6bfa..df2bc5feea 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java @@ -77,6 +77,7 @@ public final void configure(IArguments arguments) throws LuaException { if (itemData.get("count") instanceof Number) { Object countObj = itemData.get("count"); count = (countObj instanceof Number) ? ((Number) countObj).intValue() : 1; + if(count > 256) throw new LuaException("Count for item " + itemName + " exceeds 256"); } ResourceLocation resourceLocation = ResourceLocation.parse(itemName); ItemLike item = BuiltInRegistries.ITEM.get(resourceLocation); From 1a91e727e2cc9888a3140ec7e218bffe46c783b5 Mon Sep 17 00:00:00 2001 From: Karotte128 Date: Fri, 7 Mar 2025 19:44:14 +0100 Subject: [PATCH 25/48] fix cherry-pick mistake --- .../content/logistics/tableCloth/TableClothBlockEntity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java index 22aa8d1a3f..6107322994 100644 --- a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java @@ -193,7 +193,7 @@ public InteractionResult use(Player player, BlockHitResult ray) { if (heldItem.isEmpty()) { if (manuallyAddedItems.isEmpty()) return InteractionResult.SUCCESS; - player.setItemInHand(InteractionHand.MAIN_HAND, manuallyAddedItems.remove(manuallyAddedItems.size() - 1)); + player.setItemInHand(InteractionHand.MAIN_HAND, popItem()); level.playSound(null, worldPosition, SoundEvents.ITEM_FRAME_REMOVE_ITEM, SoundSource.BLOCKS, 0.5f, 1f); cachedItems = items(); if (manuallyAddedItems.isEmpty() && !computerBehaviour.hasAttachedComputer()) { @@ -372,7 +372,7 @@ public int getStockLevelForTrade(@Nullable ShoppingList otherPurchases) { @Override protected void write(CompoundTag tag, boolean clientPacket) { super.write(tag, clientPacket); - tag.put("Items", NBTHelper.writeItemList(manuallyAddedItems)); + tag.put("Items", NBTHelper.writeItemList(items())); tag.putInt("Facing", facing.get2DDataValue()); requestData.write(tag); if (owner != null) From 12485c509e2fa3b3dad098cfac1679fb43a2c0dc Mon Sep 17 00:00:00 2001 From: Karotte128 Date: Fri, 7 Mar 2025 20:31:20 +0100 Subject: [PATCH 26/48] fix some things --- .../implementation/ComputerUtil.java | 4 +- .../peripherals/PackagerPeripheral.java | 3 +- .../RedstoneRequesterPeripheral.java | 2 +- .../frogport/FrogportBlockEntity.java | 27 +++----- .../postbox/PostboxBlockEntity.java | 30 ++++---- .../packager/PackagerBlockEntity.java | 21 +----- .../RedstoneRequesterBlockEntity.java | 25 ++++--- .../stockTicker/StockTickerBlockEntity.java | 20 +----- .../tableCloth/TableClothBlockEntity.java | 33 +++------ .../foundation/events/CommonEvents.java | 68 ------------------- 10 files changed, 54 insertions(+), 179 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java index 9e7e01536d..803a8be503 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java @@ -12,7 +12,9 @@ import dan200.computercraft.api.lua.LuaException; import net.minecraft.world.item.ItemStack; -import net.neoforged.neoforge.items.IItemHandler; + +import net.minecraftforge.items.IItemHandler; + import org.jetbrains.annotations.NotNull; public class ComputerUtil { diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java index dc5a9732a1..96bf1ceaf6 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java @@ -1,5 +1,7 @@ package com.simibubi.create.compat.computercraft.implementation.peripherals; +import net.minecraftforge.items.ItemStackHandler; + import org.jetbrains.annotations.NotNull; import com.simibubi.create.content.logistics.packager.PackagerBlockEntity; @@ -12,7 +14,6 @@ import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; import net.minecraft.world.item.ItemStack; -import net.neoforged.neoforge.items.ItemStackHandler; import com.simibubi.create.content.logistics.box.PackageItem; import dan200.computercraft.api.detail.VanillaDetailRegistries; diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java index df2bc5feea..2b5805d18e 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java @@ -79,7 +79,7 @@ public final void configure(IArguments arguments) throws LuaException { count = (countObj instanceof Number) ? ((Number) countObj).intValue() : 1; if(count > 256) throw new LuaException("Count for item " + itemName + " exceeds 256"); } - ResourceLocation resourceLocation = ResourceLocation.parse(itemName); + ResourceLocation resourceLocation = ResourceLocation.tryParse(itemName); ItemLike item = BuiltInRegistries.ITEM.get(resourceLocation); list.add(new BigItemStack(new ItemStack(item), count)); } diff --git a/src/main/java/com/simibubi/create/content/logistics/packagePort/frogport/FrogportBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/packagePort/frogport/FrogportBlockEntity.java index 16ae6977f8..3f77df0b15 100644 --- a/src/main/java/com/simibubi/create/content/logistics/packagePort/frogport/FrogportBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/packagePort/frogport/FrogportBlockEntity.java @@ -5,7 +5,6 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; import com.simibubi.create.api.equipment.goggles.IHaveHoveringInformation; -import com.simibubi.create.compat.Mods; import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; import com.simibubi.create.compat.computercraft.ComputerCraftProxy; import com.simibubi.create.content.logistics.box.PackageItem; @@ -18,7 +17,6 @@ import com.simibubi.create.foundation.item.ItemHelper; import com.simibubi.create.foundation.item.TooltipHelper; -import dan200.computercraft.api.peripheral.PeripheralCapability; import net.createmod.catnip.animation.LerpedFloat; import net.createmod.catnip.animation.LerpedFloat.Chaser; import net.createmod.catnip.data.Iterate; @@ -41,10 +39,14 @@ import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; +import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ForgeCapabilities; +import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemHandlerHelper; +import org.jetbrains.annotations.NotNull; + public class FrogportBlockEntity extends PackagePortBlockEntity implements IHaveHoveringInformation { public ItemStack animatedPackage; @@ -79,20 +81,11 @@ public FrogportBlockEntity(BlockEntityType type, BlockPos pos, BlockState sta goggles = false; } - public static void registerCapabilities(RegisterCapabilitiesEvent event) { - event.registerBlockEntity( - Capabilities.ItemHandler.BLOCK, - AllBlockEntityTypes.PACKAGE_FROGPORT.get(), - (be, context) -> be.itemHandler - ); - - if (Mods.COMPUTERCRAFT.isLoaded()) { - event.registerBlockEntity( - PeripheralCapability.get(), - AllBlockEntityTypes.PACKAGE_FROGPORT.get(), - (be, context) -> be.computerBehaviour.getPeripheralCapability() - ); - } + @Override + public @NotNull LazyOptional getCapability(@NotNull Capability cap, Direction side) { + if (computerBehaviour.isPeripheralCap(cap)) + return computerBehaviour.getPeripheralCapability(); + return super.getCapability(cap, side); } @Override @@ -401,7 +394,7 @@ public InteractionResult use(Player player) { } @Override - public void invalidate() { + public void invalidateCaps() { super.invalidate(); computerBehaviour.removePeripheral(); } diff --git a/src/main/java/com/simibubi/create/content/logistics/packagePort/postbox/PostboxBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/packagePort/postbox/PostboxBlockEntity.java index 92cf64a92a..a1f155f2ba 100644 --- a/src/main/java/com/simibubi/create/content/logistics/packagePort/postbox/PostboxBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/packagePort/postbox/PostboxBlockEntity.java @@ -5,21 +5,19 @@ import com.simibubi.create.AllSoundEvents; import com.simibubi.create.Create; -import com.simibubi.create.compat.Mods; import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; import com.simibubi.create.compat.computercraft.ComputerCraftProxy; import com.simibubi.create.content.logistics.packagePort.PackagePortBlockEntity; import com.simibubi.create.content.trains.station.GlobalStation; import com.simibubi.create.content.trains.station.GlobalStation.GlobalPackagePort; -import com.simibubi.create.foundation.advancement.AdvancementBehaviour; import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; -import dan200.computercraft.api.peripheral.PeripheralCapability; import net.createmod.catnip.animation.LerpedFloat; import net.createmod.catnip.animation.LerpedFloat.Chaser; import net.createmod.catnip.nbt.NBTHelper; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; @@ -28,6 +26,11 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.util.LazyOptional; + +import org.jetbrains.annotations.NotNull; + public class PostboxBlockEntity extends PackagePortBlockEntity { public WeakReference trackedGlobalStation; @@ -46,20 +49,11 @@ public PostboxBlockEntity(BlockEntityType type, BlockPos pos, BlockState stat .startWithValue(0); } - public static void registerCapabilities(RegisterCapabilitiesEvent event) { - event.registerBlockEntity( - Capabilities.ItemHandler.BLOCK, - AllBlockEntityTypes.PACKAGE_POSTBOX.get(), - (be, context) -> be.itemHandler - ); - - if (Mods.COMPUTERCRAFT.isLoaded()) { - event.registerBlockEntity( - PeripheralCapability.get(), - AllBlockEntityTypes.PACKAGE_POSTBOX.get(), - (be, context) -> be.computerBehaviour.getPeripheralCapability() - ); - } + @Override + public @NotNull LazyOptional getCapability(@NotNull Capability cap, Direction side) { + if (computerBehaviour.isPeripheralCap(cap)) + return computerBehaviour.getPeripheralCapability(); + return super.getCapability(cap, side); } @Override @@ -143,7 +137,7 @@ public void onChunkUnloaded() { } @Override - public void invalidate() { + public void invalidateCaps() { super.invalidate(); computerBehaviour.removePeripheral(); } diff --git a/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java index 9b0b59b7f3..fc7be06f58 100644 --- a/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java @@ -6,11 +6,9 @@ import java.util.Set; import java.util.UUID; -import com.simibubi.create.AllBlockEntityTypes; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllSoundEvents; import com.simibubi.create.Create; -import com.simibubi.create.compat.Mods; import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; import com.simibubi.create.compat.computercraft.ComputerCraftProxy; import com.simibubi.create.content.contraptions.actors.psi.PortableStorageInterfaceBlockEntity; @@ -38,13 +36,10 @@ import com.simibubi.create.foundation.blockEntity.behaviour.inventory.VersionedInventoryTrackerBehaviour; import com.simibubi.create.foundation.item.ItemHelper; -import dan200.computercraft.api.peripheral.PeripheralCapability; -import net.createmod.catnip.codecs.CatnipCodecUtils; import net.createmod.catnip.data.Iterate; import net.createmod.catnip.nbt.NBTHelper; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; @@ -110,20 +105,6 @@ public PackagerBlockEntity(BlockEntityType typeIn, BlockPos pos, BlockState s buttonCooldown = 0; } - public static void registerCapabilities(RegisterCapabilitiesEvent event) { - event.registerBlockEntity( - Capabilities.ItemHandler.BLOCK, - AllBlockEntityTypes.PACKAGER.get(), - (be, context) -> be.inventory - ); - if (Mods.COMPUTERCRAFT.isLoaded()) { - event.registerBlockEntity( - PeripheralCapability.get(), - AllBlockEntityTypes.PACKAGER.get(), - (be, context) -> be.computerBehaviour.getPeripheralCapability()); - } - } - @Override public void addBehaviours(List behaviours) { behaviours.add(targetInventory = new InvManipulationBehaviour(this, InterfaceProvider.oppositeOfBlockFacing()) @@ -675,6 +656,8 @@ public void destroy() { public LazyOptional getCapability(Capability cap, Direction side) { if (cap == ForgeCapabilities.ITEM_HANDLER) return invProvider.cast(); + if (computerBehaviour.isPeripheralCap(cap)) + return computerBehaviour.getPeripheralCapability(); return super.getCapability(cap, side); } diff --git a/src/main/java/com/simibubi/create/content/logistics/redstoneRequester/RedstoneRequesterBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/redstoneRequester/RedstoneRequesterBlockEntity.java index dfa413f0a5..a204115e9f 100644 --- a/src/main/java/com/simibubi/create/content/logistics/redstoneRequester/RedstoneRequesterBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/redstoneRequester/RedstoneRequesterBlockEntity.java @@ -2,23 +2,22 @@ import com.simibubi.create.AllPackets; import com.simibubi.create.AllSoundEvents; -import com.simibubi.create.AllBlockEntityTypes; import com.simibubi.create.content.logistics.BigItemStack; import com.simibubi.create.content.logistics.packager.InventorySummary; import com.simibubi.create.content.logistics.packagerLink.LogisticallyLinkedBehaviour.RequestType; import com.simibubi.create.content.logistics.packagerLink.WiFiParticle; import com.simibubi.create.content.logistics.stockTicker.PackageOrder; import com.simibubi.create.content.logistics.stockTicker.StockCheckingBlockEntity; -import com.simibubi.create.compat.Mods; import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; import com.simibubi.create.compat.computercraft.ComputerCraftProxy; import java.util.List; import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; -import dan200.computercraft.api.peripheral.PeripheralCapability; -import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; -import net.createmod.catnip.codecs.CatnipCodecUtils; -import net.createmod.catnip.platform.CatnipServices; +import net.minecraft.core.Direction; + +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.util.LazyOptional; + import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.nbt.CompoundTag; @@ -35,6 +34,8 @@ import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.network.NetworkHooks; +import org.jetbrains.annotations.NotNull; + public class RedstoneRequesterBlockEntity extends StockCheckingBlockEntity implements MenuProvider { public boolean allowPartialRequests; @@ -59,13 +60,11 @@ public void addBehaviours(List behaviours) { behaviours.add(computerBehaviour = ComputerCraftProxy.behaviour(this)); } - public static void registerCapabilities(RegisterCapabilitiesEvent event) { - if (Mods.COMPUTERCRAFT.isLoaded()) { - event.registerBlockEntity( - PeripheralCapability.get(), - AllBlockEntityTypes.REDSTONE_REQUESTER.get(), - (be, context) -> be.computerBehaviour.getPeripheralCapability()); - } + @Override + public @NotNull LazyOptional getCapability(@NotNull Capability cap, Direction side) { + if (computerBehaviour.isPeripheralCap(cap)) + return computerBehaviour.getPeripheralCapability(); + return super.getCapability(cap, side); } protected void onRedstonePowerChanged() { diff --git a/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockTickerBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockTickerBlockEntity.java index 918b1aaf5f..626e848b88 100644 --- a/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockTickerBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockTickerBlockEntity.java @@ -13,7 +13,6 @@ import com.simibubi.create.AllBlockEntityTypes; import com.simibubi.create.AllPackets; -import com.simibubi.create.compat.Mods; import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; import com.simibubi.create.compat.computercraft.ComputerCraftProxy; import com.simibubi.create.AllSoundEvents; @@ -30,7 +29,6 @@ import com.simibubi.create.foundation.utility.CreateLang; import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; -import dan200.computercraft.api.peripheral.PeripheralCapability; import net.createmod.catnip.data.Iterate; import net.createmod.catnip.nbt.NBTHelper; import net.minecraft.ChatFormatting; @@ -90,21 +88,6 @@ public StockTickerBlockEntity(BlockEntityType type, BlockPos pos, BlockState hiddenCategoriesByPlayer = new HashMap<>(); } - public static void registerCapabilities(RegisterCapabilitiesEvent event) { - event.registerBlockEntity( - Capabilities.ItemHandler.BLOCK, - AllBlockEntityTypes.STOCK_TICKER.get(), - (be, context) -> be.receivedPayments - ); - - if (Mods.COMPUTERCRAFT.isLoaded()) { - event.registerBlockEntity( - PeripheralCapability.get(), - AllBlockEntityTypes.STOCK_TICKER.get(), - (be, context) -> be.computerBehaviour.getPeripheralCapability()); - } - } - public void refreshClientStockSnapshot() { ticksSinceLastUpdate = 0; AllPackets.getChannel() @@ -273,6 +256,9 @@ public boolean addToTooltip(List tooltip, boolean isPlayerSneaking) { public @NotNull LazyOptional getCapability(@NotNull Capability cap, @Nullable Direction side) { if (isItemHandlerCap(cap)) return capability.cast(); + if (computerBehaviour.isPeripheralCap(cap)) + return computerBehaviour.getPeripheralCapability(); + return super.getCapability(cap, side); } diff --git a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java index 6107322994..0e79344c6f 100644 --- a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java @@ -6,15 +6,12 @@ import javax.annotation.Nullable; -import com.simibubi.create.AllBlockEntityTypes; import com.simibubi.create.AllItems; import com.simibubi.create.AllPackets; import com.simibubi.create.AllSoundEvents; import com.simibubi.create.AllTags.AllBlockTags; -import com.simibubi.create.compat.Mods; import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; import com.simibubi.create.compat.computercraft.ComputerCraftProxy; -import com.simibubi.create.compat.computercraft.implementation.ComputerUtil; import com.simibubi.create.content.logistics.BigItemStack; import com.simibubi.create.content.logistics.packager.InventorySummary; import com.simibubi.create.content.logistics.redstoneRequester.AutoRequestData; @@ -49,8 +46,10 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; -import net.neoforged.neoforge.capabilities.Capabilities; -import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.util.LazyOptional; + +import org.jetbrains.annotations.NotNull; public class TableClothBlockEntity extends SmartBlockEntity { @@ -81,25 +80,11 @@ public void addBehaviours(List behaviours) { behaviours.add(computerBehaviour = ComputerCraftProxy.behaviour(this)); } - public static void registerCapabilities(RegisterCapabilitiesEvent event) { - event.registerBlockEntity( - Capabilities.ItemHandler.BLOCK, - AllBlockEntityTypes.TABLE_CLOTH.get(), - (be, context) -> { - if (be.isShop()) { - return ComputerUtil.NOOP_HANDLER; - } - return be.manuallyAddedItems; - } - ); - - if (Mods.COMPUTERCRAFT.isLoaded()) { - event.registerBlockEntity( - PeripheralCapability.get(), - AllBlockEntityTypes.TABLE_CLOTH.get(), - (be, context) -> be.computerBehaviour.getPeripheralCapability() - ); - } + @Override + public @NotNull LazyOptional getCapability(@NotNull Capability cap, Direction side) { + if (computerBehaviour.isPeripheralCap(cap)) + return computerBehaviour.getPeripheralCapability(); + return super.getCapability(cap, side); } public List getItemsForRender() { diff --git a/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java b/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java index 4a8d562433..7f94e72ec1 100644 --- a/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java +++ b/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java @@ -13,29 +13,6 @@ import com.simibubi.create.content.kinetics.belt.BeltHelper; import com.simibubi.create.content.kinetics.chainConveyor.ServerChainConveyorHandler; import com.simibubi.create.content.kinetics.drill.CobbleGenOptimisation; -import com.simibubi.create.content.kinetics.gauge.SpeedGaugeBlockEntity; -import com.simibubi.create.content.kinetics.gauge.StressGaugeBlockEntity; -import com.simibubi.create.content.kinetics.millstone.MillstoneBlockEntity; -import com.simibubi.create.content.kinetics.saw.SawBlockEntity; -import com.simibubi.create.content.kinetics.speedController.SpeedControllerBlockEntity; -import com.simibubi.create.content.kinetics.transmission.sequencer.SequencedGearshiftBlockEntity; -import com.simibubi.create.content.logistics.chute.ChuteBlockEntity; -import com.simibubi.create.content.logistics.chute.SmartChuteBlockEntity; -import com.simibubi.create.content.logistics.crate.CreativeCrateBlockEntity; -import com.simibubi.create.content.logistics.depot.DepotBlockEntity; -import com.simibubi.create.content.logistics.depot.EjectorBlockEntity; -import com.simibubi.create.content.logistics.packagePort.frogport.FrogportBlockEntity; -import com.simibubi.create.content.logistics.packagePort.postbox.PostboxBlockEntity; -import com.simibubi.create.content.logistics.packager.PackagerBlockEntity; -import com.simibubi.create.content.logistics.packager.repackager.RepackagerBlockEntity; -import com.simibubi.create.content.logistics.stockTicker.StockTickerBlockEntity; -import com.simibubi.create.content.logistics.redstoneRequester.RedstoneRequesterBlockEntity; -import com.simibubi.create.content.logistics.tableCloth.TableClothBlockEntity; -import com.simibubi.create.content.logistics.tunnel.BeltTunnelBlockEntity; -import com.simibubi.create.content.logistics.tunnel.BrassTunnelBlockEntity; -import com.simibubi.create.content.logistics.vault.ItemVaultBlockEntity; -import com.simibubi.create.content.processing.basin.BasinBlockEntity; -import com.simibubi.create.content.redstone.displayLink.DisplayLinkBlockEntity; import com.simibubi.create.content.redstone.link.controller.LinkedControllerServerHandler; import com.simibubi.create.content.trains.entity.CarriageEntityHandler; import com.simibubi.create.foundation.data.RuntimeDataGenerator; @@ -239,50 +216,5 @@ public static void addPackFinders(AddPackFindersEvent event) { event.addRepositorySource(new DynamicPackSource("create:dynamic_data", PackType.SERVER_DATA, Pack.Position.BOTTOM, dynamicPack)); } } - - @net.neoforged.bus.api.SubscribeEvent - public static void onRegisterMapDecorationRenderers(RegisterMapDecorationRenderersEvent event) { - event.register(AllMapDecorationTypes.STATION_MAP_DECORATION.value(), new StationMapDecorationRenderer()); - } - - @net.neoforged.bus.api.SubscribeEvent - public static void registerCapabilities(net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent event) { - ChuteBlockEntity.registerCapabilities(event); - SmartChuteBlockEntity.registerCapabilities(event); - BeltBlockEntity.registerCapabilities(event); - BasinBlockEntity.registerCapabilities(event); - BeltTunnelBlockEntity.registerCapabilities(event); - BrassTunnelBlockEntity.registerCapabilities(event); - CreativeCrateBlockEntity.registerCapabilities(event); - CrushingWheelControllerBlockEntity.registerCapabilities(event); - ToolboxBlockEntity.registerCapabilities(event); - DeployerBlockEntity.registerCapabilities(event); - DepotBlockEntity.registerCapabilities(event); - PortableFluidInterfaceBlockEntity.registerCapabilities(event); - SpoutBlockEntity.registerCapabilities(event); - PortableItemInterfaceBlockEntity.registerCapabilities(event); - SawBlockEntity.registerCapabilities(event); - EjectorBlockEntity.registerCapabilities(event); - FluidTankBlockEntity.registerCapabilities(event); - CreativeFluidTankBlockEntity.registerCapabilities(event); - HosePulleyBlockEntity.registerCapabilities(event); - ItemDrainBlockEntity.registerCapabilities(event); - ItemVaultBlockEntity.registerCapabilities(event); - MechanicalCrafterBlockEntity.registerCapabilities(event); - MillstoneBlockEntity.registerCapabilities(event); - StressGaugeBlockEntity.registerCapabilities(event); - SpeedGaugeBlockEntity.registerCapabilities(event); - StationBlockEntity.registerCapabilities(event); - SpeedControllerBlockEntity.registerCapabilities(event); - SequencedGearshiftBlockEntity.registerCapabilities(event); - DisplayLinkBlockEntity.registerCapabilities(event); - StockTickerBlockEntity.registerCapabilities(event); - RedstoneRequesterBlockEntity.registerCapabilities(event); - PackagerBlockEntity.registerCapabilities(event); - RepackagerBlockEntity.registerCapabilities(event); - PostboxBlockEntity.registerCapabilities(event); - FrogportBlockEntity.registerCapabilities(event); - TableClothBlockEntity.registerCapabilities(event); - } } } From d4c0aa1b7e21409d2c5e16d5141343bb2687aa92 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Fri, 7 Mar 2025 22:00:08 +0100 Subject: [PATCH 27/48] As squid suggested, replaced IArguments with Optional where possible :D --- .../peripherals/FrogportPeripheral.java | 13 +++++-------- .../peripherals/PackagerPeripheral.java | 15 ++++++--------- .../peripherals/PostboxPeripheral.java | 15 +++++---------- .../RedstoneRequesterPeripheral.java | 18 +++++++----------- 4 files changed, 23 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/FrogportPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/FrogportPeripheral.java index fda68a4ea1..ee288eb420 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/FrogportPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/FrogportPeripheral.java @@ -2,10 +2,10 @@ import com.simibubi.create.content.logistics.packagePort.frogport.FrogportBlockEntity; -import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; +import java.util.Optional; import org.jetbrains.annotations.NotNull; public class FrogportPeripheral extends SyncedPeripheral { @@ -15,18 +15,15 @@ public FrogportPeripheral(FrogportBlockEntity blockEntity) { } @LuaFunction(mainThread = true) - public final void setAddress(IArguments arguments) throws LuaException { - Object argument = arguments.get(0); - if (argument instanceof String) { - blockEntity.addressFilter = (String) argument; + public final void setAddress(Optional argument) throws LuaException { + if (argument.isPresent()) { + blockEntity.addressFilter = argument.get(); blockEntity.filterChanged(); blockEntity.notifyUpdate(); - } else if (argument == null) { + } else { blockEntity.addressFilter = ""; blockEntity.filterChanged(); blockEntity.notifyUpdate(); - } else { - throw new LuaException("Argument must be string or nil"); } } diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java index 96bf1ceaf6..8bf88b9c00 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java @@ -9,9 +9,9 @@ import com.simibubi.create.content.logistics.BigItemStack; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import dan200.computercraft.api.lua.LuaFunction; -import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; import net.minecraft.world.item.ItemStack; import com.simibubi.create.content.logistics.box.PackageItem; @@ -53,16 +53,13 @@ public final boolean makePackage() { } @LuaFunction(mainThread = true) - public final void setAddress(IArguments arguments) throws LuaException { - Object argument = arguments.get(0); - if (argument instanceof String) { - blockEntity.CustomComputerAddress = (String) argument; - blockEntity.signBasedAddress = (String) argument; + public final void setAddress(Optional argument) throws LuaException { + if (argument.isPresent()) { + blockEntity.CustomComputerAddress = argument.get(); + blockEntity.signBasedAddress = argument.get(); blockEntity.hasCustomComputerAddress = true; - } else if (argument == null) { - blockEntity.hasCustomComputerAddress = false; } else { - throw new LuaException("Argument must be string or nil"); + blockEntity.hasCustomComputerAddress = false; } } diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PostboxPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PostboxPeripheral.java index 3553fc308e..e316764345 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PostboxPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PostboxPeripheral.java @@ -1,12 +1,10 @@ package com.simibubi.create.compat.computercraft.implementation.peripherals; -import com.simibubi.create.content.logistics.packagePort.frogport.FrogportBlockEntity; - import com.simibubi.create.content.logistics.packagePort.postbox.PostboxBlockEntity; -import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; +import java.util.Optional; import org.jetbrains.annotations.NotNull; @@ -17,18 +15,15 @@ public PostboxPeripheral(PostboxBlockEntity blockEntity) { } @LuaFunction(mainThread = true) - public final void setAddress(IArguments arguments) throws LuaException { - Object argument = arguments.get(0); - if (argument instanceof String) { - blockEntity.addressFilter = (String) argument; + public final void setAddress(Optional argument) throws LuaException { + if (argument.isPresent()) { + blockEntity.addressFilter = argument.get(); blockEntity.filterChanged(); blockEntity.notifyUpdate(); - } else if (argument == null) { + } else { blockEntity.addressFilter = ""; blockEntity.filterChanged(); blockEntity.notifyUpdate(); - } else { - throw new LuaException("Argument must be string or nil"); } } diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java index 2b5805d18e..0c559afd9a 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java @@ -10,11 +10,9 @@ import com.simibubi.create.content.logistics.redstoneRequester.RedstoneRequesterBlockEntity; import com.simibubi.create.content.logistics.BigItemStack; -import com.simibubi.create.compat.computercraft.implementation.ComputerUtil; -import com.simibubi.create.content.logistics.packagerLink.LogisticallyLinkedBehaviour.RequestType; import com.simibubi.create.content.logistics.stockTicker.PackageOrder; import java.util.Map; -import java.util.List; +import java.util.Optional; import java.util.ArrayList; import dan200.computercraft.api.lua.LuaFunction; @@ -77,7 +75,8 @@ public final void configure(IArguments arguments) throws LuaException { if (itemData.get("count") instanceof Number) { Object countObj = itemData.get("count"); count = (countObj instanceof Number) ? ((Number) countObj).intValue() : 1; - if(count > 256) throw new LuaException("Count for item " + itemName + " exceeds 256"); + if (count > 256) + throw new LuaException("Count for item " + itemName + " exceeds 256"); } ResourceLocation resourceLocation = ResourceLocation.tryParse(itemName); ItemLike item = BuiltInRegistries.ITEM.get(resourceLocation); @@ -91,14 +90,11 @@ public final void configure(IArguments arguments) throws LuaException { } @LuaFunction(mainThread = true) - public final void setAddress(IArguments arguments) throws LuaException { - Object argument = arguments.get(0); - if (argument instanceof String) { - blockEntity.encodedTargetAdress = (String) argument; - } else if (argument == null) { - blockEntity.encodedTargetAdress = ""; + public final void setAddress(Optional argument) throws LuaException { + if (argument.isPresent()) { + blockEntity.encodedTargetAdress = argument.get(); } else { - throw new LuaException("Argument must be string or nil"); + blockEntity.encodedTargetAdress = ""; } this.blockEntity.notifyUpdate(); } From c12b9590a8efd95d65f93147302ad18baaa61b83 Mon Sep 17 00:00:00 2001 From: Karotte128 Date: Sat, 8 Mar 2025 17:22:19 +0100 Subject: [PATCH 28/48] repackager peripheral --- .../implementation/ComputerBehaviour.java | 8 +++- .../peripherals/RepackagerPeripheral.java | 40 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RepackagerPeripheral.java diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java index 011ee877c6..b806ef693d 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java @@ -4,6 +4,7 @@ import com.simibubi.create.compat.computercraft.implementation.peripherals.DisplayLinkPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.FrogportPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.PostboxPeripheral; +import com.simibubi.create.compat.computercraft.implementation.peripherals.RepackagerPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.SequencedGearshiftPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.SpeedControllerPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.SpeedGaugePeripheral; @@ -15,6 +16,7 @@ import com.simibubi.create.content.logistics.packagePort.frogport.FrogportBlockEntity; import com.simibubi.create.content.logistics.packagePort.postbox.PostboxBlockEntity; import com.simibubi.create.compat.computercraft.implementation.peripherals.RedstoneRequesterPeripheral; +import com.simibubi.create.content.logistics.packager.repackager.RepackagerBlockEntity; import com.simibubi.create.content.logistics.redstoneRequester.RedstoneRequesterBlockEntity; import com.simibubi.create.content.logistics.packager.PackagerBlockEntity; import com.simibubi.create.content.logistics.stockTicker.StockTickerBlockEntity; @@ -66,7 +68,11 @@ public static NonNullSupplier getPeripheralFor(SmartBlockEntity be) if (be instanceof StockTickerBlockEntity sgbe) return () -> new StockTickerPeripheral(sgbe); if (be instanceof PackagerBlockEntity pgbe) - return () -> new PackagerPeripheral(pgbe); + if (!(be instanceof RepackagerBlockEntity)){ // I really hate this, but I did not find any other way + return () -> new PackagerPeripheral(pgbe); + } + if (be instanceof RepackagerBlockEntity rpbe) + return () -> new RepackagerPeripheral(rpbe); if (be instanceof RedstoneRequesterBlockEntity rrbe) return () -> new RedstoneRequesterPeripheral(rrbe); if (be instanceof StationBlockEntity sbe) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RepackagerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RepackagerPeripheral.java new file mode 100644 index 0000000000..edff61c24d --- /dev/null +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RepackagerPeripheral.java @@ -0,0 +1,40 @@ +package com.simibubi.create.compat.computercraft.implementation.peripherals; + +import java.util.Optional; + +import com.simibubi.create.content.logistics.packager.repackager.RepackagerBlockEntity; + +import org.jetbrains.annotations.NotNull; + +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.lua.LuaFunction; + +public class RepackagerPeripheral extends SyncedPeripheral { + + public RepackagerPeripheral(RepackagerBlockEntity blockEntity) { + super(blockEntity); + } + + @LuaFunction(mainThread = true) + public final void setAddress(Optional argument) throws LuaException { + if (argument.isPresent()) { + blockEntity.CustomComputerAddress = argument.get(); + blockEntity.signBasedAddress = argument.get(); + blockEntity.hasCustomComputerAddress = true; + } else { + blockEntity.hasCustomComputerAddress = false; + } + } + + @LuaFunction(mainThread = true) + public final String getAddress() throws LuaException { + return blockEntity.signBasedAddress; + } + + @NotNull + @Override + public String getType() { + return "Create_Repackager"; + } + +} From e985970872268d2dba7f12f41160612f8e9f4715 Mon Sep 17 00:00:00 2001 From: Karotte128 Date: Sat, 8 Mar 2025 17:32:05 +0100 Subject: [PATCH 29/48] add makePackage to Repackager --- .../peripherals/RepackagerPeripheral.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RepackagerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RepackagerPeripheral.java index edff61c24d..84e51d2220 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RepackagerPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RepackagerPeripheral.java @@ -31,6 +31,16 @@ public final String getAddress() throws LuaException { return blockEntity.signBasedAddress; } + @LuaFunction(mainThread = true) + public final boolean makePackage() { + if (!blockEntity.heldBox.isEmpty()) + return false; + blockEntity.activate(); + if (blockEntity.heldBox.isEmpty()) + return false; + return true; + } + @NotNull @Override public String getType() { From e75a31a40769607978d15c00b78560ed15df510a Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Sat, 8 Mar 2025 20:17:54 +0100 Subject: [PATCH 30/48] extra tablecloth functionality. half-working .setWares() included --- .../peripherals/TableClothPeripheral.java | 141 ++++++++++++++++-- 1 file changed, 125 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java index eb4e03fddf..ae6ec237c8 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java @@ -1,30 +1,139 @@ package com.simibubi.create.compat.computercraft.implementation.peripherals; -import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; import com.simibubi.create.compat.computercraft.implementation.ComputerUtil; import com.simibubi.create.content.logistics.tableCloth.TableClothBlockEntity; +import com.simibubi.create.content.logistics.stockTicker.PackageOrder; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceLocation; +import com.simibubi.create.content.logistics.BigItemStack; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.ItemLike; import dan200.computercraft.api.lua.LuaFunction; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.lua.IArguments; +import dan200.computercraft.api.detail.VanillaDetailRegistries; import org.jetbrains.annotations.Nullable; +import java.util.Optional; +import java.util.Map; +import java.util.HashMap; +import java.util.List; +import java.util.ArrayList; public class TableClothPeripheral extends SyncedPeripheral { - public TableClothPeripheral(TableClothBlockEntity blockEntity) { - super(blockEntity); - } + public TableClothPeripheral(TableClothBlockEntity blockEntity) { + super(blockEntity); + } - @Override - public String getType() { - return "Create_TableCloth"; - } + @LuaFunction(mainThread = true) + public final boolean isShop() { + return blockEntity.isShop(); + } - @LuaFunction(mainThread = true) - public final boolean isShop() { - return blockEntity.isShop(); - } + @LuaFunction(mainThread = true) + public final String getAddress() throws LuaException { + return blockEntity.requestData.encodedTargetAdress; + } - @Override - public @Nullable Object getTarget() { - return isShop() ? ComputerUtil.NOOP_HANDLER : blockEntity.manuallyAddedItems; - } + @LuaFunction(mainThread = true) + public final void setAddress(Optional argument) throws LuaException { + if (argument.isPresent()) + blockEntity.requestData.encodedTargetAdress = argument.get(); + else + blockEntity.requestData.encodedTargetAdress = ""; + + } + + @LuaFunction(mainThread = true) + public final Map getPriceTagItem() throws LuaException { + return VanillaDetailRegistries.ITEM_STACK.getDetails(blockEntity.priceTag.getFilter()); + } + + @LuaFunction(mainThread = true) + public final boolean setPriceTagItem(Optional itemName) throws LuaException { + ResourceLocation resourceLocation = ResourceLocation.tryParse("minecraft:air"); + if (itemName.isPresent()) + resourceLocation = ResourceLocation.tryParse(itemName.get()); + ItemLike item = BuiltInRegistries.ITEM.get(resourceLocation); + blockEntity.priceTag.setFilter(new ItemStack(item)); + return true; + } + + @LuaFunction(mainThread = true) + public final int getPriceTagCount() throws LuaException { + return blockEntity.priceTag.count; + } + + @LuaFunction(mainThread = true) + public final void setPriceTagCount(Optional argument) throws LuaException { + if (argument.isPresent()) + blockEntity.priceTag.count = (Math.max(1, Math.min(100, argument.get().intValue()))); + else + blockEntity.priceTag.count = 1; + this.blockEntity.notifyUpdate(); + } + + @LuaFunction(mainThread = true) + public final Map> getWares() throws LuaException { + List wares = blockEntity.requestData.encodedRequest.stacks(); + Map> result = new HashMap<>(); + for (int i = 0; i < wares.size(); i++) { + ItemStack stack = wares.get(i).stack; + Map details = new HashMap<>( + VanillaDetailRegistries.ITEM_STACK.getDetails(stack)); + details.put("count", wares.get(i).count); + result.put(i + 1, details); // +1 because lua + } + return result; + } + + /* + * this functionally works, but none of us have been able to figure out how to + * visually update the store's wares without reloading the chunk. The render + * pipeline is difficult :( + * + * @LuaFunction(mainThread = true) + * public final void setWares(IArguments arguments) throws LuaException { + * if (!blockEntity.manuallyAddedItems.isEmpty()) + * throw new LuaException("Tablecloth isn't empty."); + * ArrayList list = new ArrayList<>(); + * for (int i = 0; i <= 8; i++) { + * if (arguments.get(i) != null) { + * Map itemData = arguments.getTable(i); + * + * if (!(itemData instanceof Map)) { + * throw new LuaException("Table or nil expected for each item entry"); + * } + * String itemName = "minecraft:air"; + * if (itemData.get("name") instanceof String) { + * itemName = (String) itemData.get("name"); + * } + * int count = 1; + * if (itemData.get("count") instanceof Number) { + * Object countObj = itemData.get("count"); + * count = (countObj instanceof Number) ? ((Number) countObj).intValue() : 1; + * if (count > 256) + * throw new LuaException("Count for item " + itemName + " exceeds 256"); + * } + * ResourceLocation resourceLocation = ResourceLocation.tryParse(itemName); + * ItemLike item = BuiltInRegistries.ITEM.get(resourceLocation); + * list.add(new BigItemStack(new ItemStack(item), count)); + * } + * } + * blockEntity.requestData.encodedRequest = new PackageOrder(list); + * blockEntity.requestData.encodedRequestContext = new PackageOrder(list); + * blockEntity.notifyUpdate(); + * } + */ + + @Override + public String getType() { + return "Create_TableCloth"; + } + + @Override + public @Nullable Object getTarget() { + return isShop() ? ComputerUtil.NOOP_HANDLER : blockEntity.manuallyAddedItems; + } } From 2f1456e4e110d353f4825679b4c105ab73fb9483 Mon Sep 17 00:00:00 2001 From: Karotte128 Date: Sat, 8 Mar 2025 21:29:45 +0100 Subject: [PATCH 31/48] somehow fix TableCloth item rendering on setWares --- .../peripherals/TableClothPeripheral.java | 67 ++++++++++--------- .../tableCloth/TableClothBlockEntity.java | 4 ++ 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java index ae6ec237c8..1270ead84f 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java @@ -93,39 +93,42 @@ public final void setPriceTagCount(Optional argument) throws LuaExceptio * visually update the store's wares without reloading the chunk. The render * pipeline is difficult :( * - * @LuaFunction(mainThread = true) - * public final void setWares(IArguments arguments) throws LuaException { - * if (!blockEntity.manuallyAddedItems.isEmpty()) - * throw new LuaException("Tablecloth isn't empty."); - * ArrayList list = new ArrayList<>(); - * for (int i = 0; i <= 8; i++) { - * if (arguments.get(i) != null) { - * Map itemData = arguments.getTable(i); - * - * if (!(itemData instanceof Map)) { - * throw new LuaException("Table or nil expected for each item entry"); - * } - * String itemName = "minecraft:air"; - * if (itemData.get("name") instanceof String) { - * itemName = (String) itemData.get("name"); - * } - * int count = 1; - * if (itemData.get("count") instanceof Number) { - * Object countObj = itemData.get("count"); - * count = (countObj instanceof Number) ? ((Number) countObj).intValue() : 1; - * if (count > 256) - * throw new LuaException("Count for item " + itemName + " exceeds 256"); - * } - * ResourceLocation resourceLocation = ResourceLocation.tryParse(itemName); - * ItemLike item = BuiltInRegistries.ITEM.get(resourceLocation); - * list.add(new BigItemStack(new ItemStack(item), count)); - * } - * } - * blockEntity.requestData.encodedRequest = new PackageOrder(list); - * blockEntity.requestData.encodedRequestContext = new PackageOrder(list); - * blockEntity.notifyUpdate(); - * } + * update: I got it working by sending a RemoveBlockEntityPacket. + * Do not ask why it works, this is black magic. */ + @LuaFunction(mainThread = true) + public final void setWares(IArguments arguments) throws LuaException { + if (!blockEntity.manuallyAddedItems.isEmpty()) + throw new LuaException("Tablecloth isn't empty."); + ArrayList list = new ArrayList<>(); + for (int i = 0; i <= 8; i++) { + if (arguments.get(i) != null) { + Map itemData = arguments.getTable(i); + + if (!(itemData instanceof Map)) { + throw new LuaException("Table or nil expected for each item entry"); + } + String itemName = "minecraft:air"; + if (itemData.get("name") instanceof String) { + itemName = (String) itemData.get("name"); + } + int count = 1; + if (itemData.get("count") instanceof Number) { + Object countObj = itemData.get("count"); + count = (countObj instanceof Number) ? ((Number) countObj).intValue() : 1; + if (count > 256) + throw new LuaException("Count for item " + itemName + " exceeds 256"); + } + ResourceLocation resourceLocation = ResourceLocation.tryParse(itemName); + ItemLike item = BuiltInRegistries.ITEM.get(resourceLocation); + list.add(new BigItemStack(new ItemStack(item), count)); + blockEntity.updateShopRender(); + } + } + blockEntity.requestData.encodedRequest = new PackageOrder(list); + blockEntity.requestData.encodedRequestContext = new PackageOrder(list); + blockEntity.notifyUpdate(); + } @Override public String getType() { diff --git a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java index 0e79344c6f..f3ae06372c 100644 --- a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java @@ -100,6 +100,10 @@ public List getItemsForRender() { return cachedItems(); } + public void updateShopRender() { + AllPackets.getChannel().send(packetTarget(), new RemoveBlockEntityPacket(worldPosition)); + } + @Override public void lazyTick() { super.lazyTick(); From 3181e9944ea1493f07acce772966f680297f5f63 Mon Sep 17 00:00:00 2001 From: Karotte128 Date: Sat, 8 Mar 2025 23:01:52 +0100 Subject: [PATCH 32/48] 1.21.1 port --- .../implementation/ComputerUtil.java | 2 +- .../peripherals/PackagerPeripheral.java | 2 +- .../frogport/FrogportBlockEntity.java | 15 +++++++++ .../postbox/PostboxBlockEntity.java | 16 ++++++++++ .../packager/PackagerBlockEntity.java | 16 ++++++++++ .../RedstoneRequesterBlockEntity.java | 32 +++++++++++-------- .../stockTicker/StockTickerBlockEntity.java | 16 ++++++++++ .../tableCloth/TableClothBlockEntity.java | 31 +++++++++++++++--- .../foundation/events/CommonEvents.java | 4 +++ .../highLogistics/TableClothScenes.java | 2 +- 10 files changed, 115 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java index 803a8be503..29757f9d60 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java @@ -13,7 +13,7 @@ import net.minecraft.world.item.ItemStack; -import net.minecraftforge.items.IItemHandler; +import net.neoforged.neoforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java index 8bf88b9c00..e778493d8b 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/PackagerPeripheral.java @@ -1,6 +1,6 @@ package com.simibubi.create.compat.computercraft.implementation.peripherals; -import net.minecraftforge.items.ItemStackHandler; +import net.neoforged.neoforge.items.ItemStackHandler; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/simibubi/create/content/logistics/packagePort/frogport/FrogportBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/packagePort/frogport/FrogportBlockEntity.java index e961225ade..a8fdc4b230 100644 --- a/src/main/java/com/simibubi/create/content/logistics/packagePort/frogport/FrogportBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/packagePort/frogport/FrogportBlockEntity.java @@ -6,6 +6,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; import com.simibubi.create.api.equipment.goggles.IHaveHoveringInformation; +import com.simibubi.create.compat.Mods; import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; import com.simibubi.create.compat.computercraft.ComputerCraftProxy; import com.simibubi.create.content.logistics.box.PackageItem; @@ -18,6 +19,7 @@ import com.simibubi.create.foundation.item.ItemHelper; import com.simibubi.create.foundation.item.TooltipHelper; +import dan200.computercraft.api.peripheral.PeripheralCapability; import net.createmod.catnip.animation.LerpedFloat; import net.createmod.catnip.animation.LerpedFloat.Chaser; import net.createmod.catnip.data.Iterate; @@ -87,6 +89,14 @@ public static void registerCapabilities(RegisterCapabilitiesEvent event) { AllBlockEntityTypes.PACKAGE_FROGPORT.get(), (be, context) -> be.itemHandler ); + + if (Mods.COMPUTERCRAFT.isLoaded()) { + event.registerBlockEntity( + PeripheralCapability.get(), + AllBlockEntityTypes.PACKAGE_FROGPORT.get(), + (be, context) -> be.computerBehaviour.getPeripheralCapability() + ); + } } @Override @@ -392,4 +402,9 @@ public ItemInteractionResult use(Player player) { return super.use(player); } + @Override + public void invalidate() { + super.invalidate(); + computerBehaviour.removePeripheral(); + } } diff --git a/src/main/java/com/simibubi/create/content/logistics/packagePort/postbox/PostboxBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/packagePort/postbox/PostboxBlockEntity.java index ae3c1d5dcf..c0e3ad2940 100644 --- a/src/main/java/com/simibubi/create/content/logistics/packagePort/postbox/PostboxBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/packagePort/postbox/PostboxBlockEntity.java @@ -6,6 +6,7 @@ import com.simibubi.create.AllBlockEntityTypes; import com.simibubi.create.AllSoundEvents; import com.simibubi.create.Create; +import com.simibubi.create.compat.Mods; import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; import com.simibubi.create.compat.computercraft.ComputerCraftProxy; import com.simibubi.create.content.logistics.packagePort.PackagePortBlockEntity; @@ -14,6 +15,7 @@ import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; +import dan200.computercraft.api.peripheral.PeripheralCapability; import net.createmod.catnip.animation.LerpedFloat; import net.createmod.catnip.animation.LerpedFloat.Chaser; import net.createmod.catnip.nbt.NBTHelper; @@ -53,6 +55,14 @@ public static void registerCapabilities(RegisterCapabilitiesEvent event) { AllBlockEntityTypes.PACKAGE_POSTBOX.get(), (be, context) -> be.itemHandler ); + + if (Mods.COMPUTERCRAFT.isLoaded()) { + event.registerBlockEntity( + PeripheralCapability.get(), + AllBlockEntityTypes.PACKAGE_POSTBOX.get(), + (be, context) -> be.computerBehaviour.getPeripheralCapability() + ); + } } @Override @@ -135,4 +145,10 @@ public void onChunkUnloaded() { super.onChunkUnloaded(); } + @Override + public void invalidate() { + super.invalidate(); + computerBehaviour.removePeripheral(); + } + } diff --git a/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java index 4d3462ed04..1f9e4d9608 100644 --- a/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java @@ -10,6 +10,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.AllSoundEvents; import com.simibubi.create.Create; +import com.simibubi.create.compat.Mods; import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; import com.simibubi.create.compat.computercraft.ComputerCraftProxy; import com.simibubi.create.content.contraptions.actors.psi.PortableStorageInterfaceBlockEntity; @@ -37,6 +38,7 @@ import com.simibubi.create.foundation.blockEntity.behaviour.inventory.VersionedInventoryTrackerBehaviour; import com.simibubi.create.foundation.item.ItemHelper; +import dan200.computercraft.api.peripheral.PeripheralCapability; import net.createmod.catnip.codecs.CatnipCodecUtils; import net.createmod.catnip.data.Iterate; import net.createmod.catnip.nbt.NBTHelper; @@ -112,6 +114,14 @@ public static void registerCapabilities(RegisterCapabilitiesEvent event) { AllBlockEntityTypes.PACKAGER.get(), (be, context) -> be.inventory ); + + if (Mods.COMPUTERCRAFT.isLoaded()) { + event.registerBlockEntity( + PeripheralCapability.get(), + AllBlockEntityTypes.PACKAGER.get(), + (be, context) -> be.computerBehaviour.getPeripheralCapability() + ); + } } @Override @@ -692,4 +702,10 @@ public boolean isTargetingSameInventory(IItemHandler inventory) { return false; } + @Override + public void invalidate() { + super.invalidate(); + computerBehaviour.removePeripheral(); + } + } diff --git a/src/main/java/com/simibubi/create/content/logistics/redstoneRequester/RedstoneRequesterBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/redstoneRequester/RedstoneRequesterBlockEntity.java index 0d3629f983..939991b69e 100644 --- a/src/main/java/com/simibubi/create/content/logistics/redstoneRequester/RedstoneRequesterBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/redstoneRequester/RedstoneRequesterBlockEntity.java @@ -1,6 +1,8 @@ package com.simibubi.create.content.logistics.redstoneRequester; +import com.simibubi.create.AllBlockEntityTypes; import com.simibubi.create.AllSoundEvents; +import com.simibubi.create.compat.Mods; import com.simibubi.create.content.logistics.BigItemStack; import com.simibubi.create.content.logistics.packager.InventorySummary; import com.simibubi.create.content.logistics.packagerLink.LogisticallyLinkedBehaviour.RequestType; @@ -12,10 +14,7 @@ import java.util.List; import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; -import net.minecraft.core.Direction; - -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.util.LazyOptional; +import dan200.computercraft.api.peripheral.PeripheralCapability; import net.createmod.catnip.codecs.CatnipCodecUtils; import net.createmod.catnip.platform.CatnipServices; @@ -34,10 +33,9 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; import net.neoforged.neoforge.common.util.FakePlayer; -import org.jetbrains.annotations.NotNull; - public class RedstoneRequesterBlockEntity extends StockCheckingBlockEntity implements MenuProvider { public boolean allowPartialRequests; @@ -56,19 +54,22 @@ public RedstoneRequesterBlockEntity(BlockEntityType type, BlockPos pos, Block public AbstractComputerBehaviour computerBehaviour; + public static void registerCapabilities(RegisterCapabilitiesEvent event) { + if (Mods.COMPUTERCRAFT.isLoaded()) { + event.registerBlockEntity( + PeripheralCapability.get(), + AllBlockEntityTypes.REDSTONE_REQUESTER.get(), + (be, context) -> be.computerBehaviour.getPeripheralCapability() + ); + } + } + @Override public void addBehaviours(List behaviours) { super.addBehaviours(behaviours); behaviours.add(computerBehaviour = ComputerCraftProxy.behaviour(this)); } - @Override - public @NotNull LazyOptional getCapability(@NotNull Capability cap, Direction side) { - if (computerBehaviour.isPeripheralCap(cap)) - return computerBehaviour.getPeripheralCapability(); - return super.getCapability(cap, side); - } - protected void onRedstonePowerChanged() { boolean hasNeighborSignal = level.hasNeighborSignal(worldPosition); if (redstonePowered == hasNeighborSignal) @@ -178,4 +179,9 @@ public void playEffect(boolean success) { } } + @Override + public void invalidate() { + super.invalidate(); + computerBehaviour.removePeripheral(); + } } diff --git a/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockTickerBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockTickerBlockEntity.java index 06bcd82423..b75ba86041 100644 --- a/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockTickerBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockTickerBlockEntity.java @@ -11,6 +11,7 @@ import javax.annotation.Nullable; import com.simibubi.create.AllBlockEntityTypes; +import com.simibubi.create.compat.Mods; import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; import com.simibubi.create.compat.computercraft.ComputerCraftProxy; import com.simibubi.create.AllSoundEvents; @@ -27,6 +28,7 @@ import com.simibubi.create.foundation.utility.CreateLang; import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; +import dan200.computercraft.api.peripheral.PeripheralCapability; import net.createmod.catnip.data.Iterate; import net.createmod.catnip.nbt.NBTHelper; import net.createmod.catnip.platform.CatnipServices; @@ -91,6 +93,14 @@ public static void registerCapabilities(RegisterCapabilitiesEvent event) { AllBlockEntityTypes.STOCK_TICKER.get(), (be, context) -> be.receivedPayments ); + + if (Mods.COMPUTERCRAFT.isLoaded()) { + event.registerBlockEntity( + PeripheralCapability.get(), + AllBlockEntityTypes.STOCK_TICKER.get(), + (be, context) -> be.computerBehaviour.getPeripheralCapability() + ); + } } public void refreshClientStockSnapshot() { @@ -300,4 +310,10 @@ public Component getDisplayName() { } + @Override + public void invalidate() { + super.invalidate(); + computerBehaviour.removePeripheral(); + } + } diff --git a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java index ee2c0b3192..c1c89aa939 100644 --- a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java @@ -6,11 +6,14 @@ import javax.annotation.Nullable; +import com.simibubi.create.AllBlockEntityTypes; import com.simibubi.create.AllItems; import com.simibubi.create.AllSoundEvents; import com.simibubi.create.AllTags.AllBlockTags; +import com.simibubi.create.compat.Mods; import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; import com.simibubi.create.compat.computercraft.ComputerCraftProxy; +import com.simibubi.create.compat.computercraft.implementation.ComputerUtil; import com.simibubi.create.content.logistics.BigItemStack; import com.simibubi.create.content.logistics.packager.InventorySummary; import com.simibubi.create.content.logistics.redstoneRequester.AutoRequestData; @@ -23,6 +26,7 @@ import com.simibubi.create.foundation.item.SmartInventory; import com.simibubi.create.foundation.utility.CreateLang; +import dan200.computercraft.api.peripheral.PeripheralCapability; import net.createmod.catnip.codecs.CatnipCodecUtils; import net.createmod.catnip.data.IntAttached; import net.createmod.catnip.nbt.NBTHelper; @@ -50,6 +54,9 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; + import org.jetbrains.annotations.NotNull; public class TableClothBlockEntity extends SmartBlockEntity { @@ -81,11 +88,25 @@ public void addBehaviours(List behaviours) { behaviours.add(computerBehaviour = ComputerCraftProxy.behaviour(this)); } - @Override - public @NotNull LazyOptional getCapability(@NotNull Capability cap, Direction side) { - if (computerBehaviour.isPeripheralCap(cap)) - return computerBehaviour.getPeripheralCapability(); - return super.getCapability(cap, side); + public static void registerCapabilities(RegisterCapabilitiesEvent event) { + event.registerBlockEntity( + Capabilities.ItemHandler.BLOCK, + AllBlockEntityTypes.TABLE_CLOTH.get(), + (be, context) -> { + if (be.isShop()) { + return ComputerUtil.NOOP_HANDLER; + } + return be.manuallyAddedItems; + } + ); + + if (Mods.COMPUTERCRAFT.isLoaded()) { + event.registerBlockEntity( + PeripheralCapability.get(), + AllBlockEntityTypes.TABLE_CLOTH.get(), + (be, context) -> be.computerBehaviour.getPeripheralCapability() + ); + } } public List getItemsForRender() { diff --git a/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java b/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java index b22f4be018..ebc4077612 100644 --- a/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java +++ b/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java @@ -41,7 +41,9 @@ import com.simibubi.create.content.logistics.packagePort.postbox.PostboxBlockEntity; import com.simibubi.create.content.logistics.packager.PackagerBlockEntity; import com.simibubi.create.content.logistics.packager.repackager.RepackagerBlockEntity; +import com.simibubi.create.content.logistics.redstoneRequester.RedstoneRequesterBlockEntity; import com.simibubi.create.content.logistics.stockTicker.StockTickerBlockEntity; +import com.simibubi.create.content.logistics.tableCloth.TableClothBlockEntity; import com.simibubi.create.content.logistics.tunnel.BeltTunnelBlockEntity; import com.simibubi.create.content.logistics.tunnel.BrassTunnelBlockEntity; import com.simibubi.create.content.logistics.vault.ItemVaultBlockEntity; @@ -288,10 +290,12 @@ public static void registerCapabilities(net.neoforged.neoforge.capabilities.Regi SequencedGearshiftBlockEntity.registerCapabilities(event); DisplayLinkBlockEntity.registerCapabilities(event); StockTickerBlockEntity.registerCapabilities(event); + RedstoneRequesterBlockEntity.registerCapabilities(event); PackagerBlockEntity.registerCapabilities(event); RepackagerBlockEntity.registerCapabilities(event); PostboxBlockEntity.registerCapabilities(event); FrogportBlockEntity.registerCapabilities(event); + TableClothBlockEntity.registerCapabilities(event); } } } diff --git a/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/highLogistics/TableClothScenes.java b/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/highLogistics/TableClothScenes.java index d136fcd794..25a323be29 100644 --- a/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/highLogistics/TableClothScenes.java +++ b/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/highLogistics/TableClothScenes.java @@ -90,7 +90,7 @@ public static void tableCloth(SceneBuilder builder, SceneBuildingUtil util) { .at(3, 2, 3), TableClothBlock.HAS_BE); scene.world() .modifyBlockEntity(util.grid() - .at(3, 2, 3), TableClothBlockEntity.class, be -> be.manuallyAddedItems.add(grass)); + .at(3, 2, 3), TableClothBlockEntity.class, be -> be.pushItem(grass)); scene.idle(10); scene.overlay() From 9297d84c3a3f1d0db53c93c2b1cafd590eeec7a9 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Sat, 8 Mar 2025 23:09:38 +0100 Subject: [PATCH 33/48] Removed a pointless comment and differencaited the .request functions between stock ticker and redstone requester peripheral --- .../RedstoneRequesterPeripheral.java | 20 ------------------- .../peripherals/StockTickerPeripheral.java | 6 +++--- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java index 0c559afd9a..adadd72f0b 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java @@ -28,26 +28,6 @@ public RedstoneRequesterPeripheral(RedstoneRequesterBlockEntity blockEntity) { // this.targetSpeed = targetSpeed; } - /* - * for every item in the netowrk, this will compare that item to the CC args - * filter, a table that looks something like this: - * { - * name = "minecraft:jungle_log", - * tags = { - * ["minecraft:logs"] = true - * }, - * count = 5 - * }, - * and the second optional String arg which is the address: - * "home_address" - * (default value "") - * - * It then adds items that match the name if provided, nbt if provided, have all - * of the tags if provided, has all the enchants if provided and - * stops looking after adding items equal to count or finishing - * going through the summary. - * filter of {} requests all items from the network trollface.jpeg - */ @LuaFunction(mainThread = true) public final void request() throws LuaException { blockEntity.triggerRequest(); diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java index f4d97f9e1d..aebc90114f 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StockTickerPeripheral.java @@ -41,7 +41,7 @@ public final int getItemCount() { for (BigItemStack entry : blockEntity.getAccurateSummary().getStacks()) { i++; Map details = new HashMap<>( - VanillaDetailRegistries.ITEM_STACK.getBasicDetails(entry.stack)); + VanillaDetailRegistries.ITEM_STACK.getBasicDetails(entry.stack)); details.put("count", entry.count); result.put(i, details); } @@ -55,7 +55,7 @@ public final int getItemCount() { for (BigItemStack entry : blockEntity.getAccurateSummary().getStacks()) { i++; Map details = new HashMap<>( - VanillaDetailRegistries.ITEM_STACK.getDetails(entry.stack)); + VanillaDetailRegistries.ITEM_STACK.getDetails(entry.stack)); details.put("count", entry.count); result.put(i, details); } @@ -83,7 +83,7 @@ public final int getItemCount() { * filter of {} requests all items from the network trollface.jpeg */ @LuaFunction(mainThread = true) - public final int request(IArguments arguments) throws LuaException { + public final int requestFiltered(IArguments arguments) throws LuaException { if (!(arguments.get(0) instanceof Map)) return 0; Map filter = (Map) arguments.get(0); From c07a865dddfe415f338f2aa33fba9510ea41b8b7 Mon Sep 17 00:00:00 2001 From: Karotte128 Date: Sat, 8 Mar 2025 23:17:51 +0100 Subject: [PATCH 34/48] fix 1.21.1 repackager --- .../packager/repackager/RepackagerBlockEntity.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/packager/repackager/RepackagerBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/packager/repackager/RepackagerBlockEntity.java index e11a00f46d..712fa89cc4 100644 --- a/src/main/java/com/simibubi/create/content/logistics/packager/repackager/RepackagerBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/packager/repackager/RepackagerBlockEntity.java @@ -3,6 +3,7 @@ import java.util.List; import com.simibubi.create.AllBlockEntityTypes; +import com.simibubi.create.compat.Mods; import com.simibubi.create.content.logistics.box.PackageItem; import com.simibubi.create.content.logistics.crate.BottomlessItemHandler; import com.simibubi.create.content.logistics.packager.PackageDefragmenter; @@ -10,6 +11,7 @@ import com.simibubi.create.content.logistics.packager.PackagerItemHandler; import com.simibubi.create.content.logistics.packager.PackagingRequest; +import dan200.computercraft.api.peripheral.PeripheralCapability; import net.minecraft.core.BlockPos; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntityType; @@ -134,13 +136,21 @@ protected void attemptToDefrag(IItemHandler targetInv) { notifyUpdate(); } - + public static void registerCapabilities(RegisterCapabilitiesEvent event) { event.registerBlockEntity( Capabilities.ItemHandler.BLOCK, AllBlockEntityTypes.REPACKAGER.get(), (be, context) -> be.inventory ); + + if (Mods.COMPUTERCRAFT.isLoaded()) { + event.registerBlockEntity( + PeripheralCapability.get(), + AllBlockEntityTypes.REPACKAGER.get(), + (be, context) -> be.computerBehaviour.getPeripheralCapability() + ); + } } } From 737e1a142abd5587bf45e020db3893b90cd405a0 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Sun, 9 Mar 2025 00:43:32 +0100 Subject: [PATCH 35/48] made tablecloth setPriceTagItem be a void function like the rest --- .../implementation/peripherals/TableClothPeripheral.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java index 1270ead84f..a80c34bf0b 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java @@ -51,13 +51,12 @@ public final void setAddress(Optional argument) throws LuaException { } @LuaFunction(mainThread = true) - public final boolean setPriceTagItem(Optional itemName) throws LuaException { + public final void setPriceTagItem(Optional itemName) throws LuaException { ResourceLocation resourceLocation = ResourceLocation.tryParse("minecraft:air"); if (itemName.isPresent()) resourceLocation = ResourceLocation.tryParse(itemName.get()); ItemLike item = BuiltInRegistries.ITEM.get(resourceLocation); blockEntity.priceTag.setFilter(new ItemStack(item)); - return true; } @LuaFunction(mainThread = true) From c5de7b66b8a85fd7515fb62bda722fc6a353daa5 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Sun, 9 Mar 2025 01:39:30 +0100 Subject: [PATCH 36/48] Sins agaionst immutability. (Still need to fix tablecloth rendering) --- .../peripherals/TableClothPeripheral.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java index a80c34bf0b..e19e6697af 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java @@ -3,6 +3,7 @@ import com.simibubi.create.compat.computercraft.implementation.ComputerUtil; import com.simibubi.create.content.logistics.tableCloth.TableClothBlockEntity; import com.simibubi.create.content.logistics.stockTicker.PackageOrder; +import com.simibubi.create.content.logistics.redstoneRequester.AutoRequestData; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import com.simibubi.create.content.logistics.BigItemStack; @@ -33,16 +34,17 @@ public final boolean isShop() { @LuaFunction(mainThread = true) public final String getAddress() throws LuaException { - return blockEntity.requestData.encodedTargetAdress; + return blockEntity.requestData.encodedTargetAddress(); } @LuaFunction(mainThread = true) public final void setAddress(Optional argument) throws LuaException { + AutoRequestData.Mutable mutable = new AutoRequestData.Mutable(blockEntity.requestData); if (argument.isPresent()) - blockEntity.requestData.encodedTargetAdress = argument.get(); + mutable.encodedTargetAddress = argument.get(); else - blockEntity.requestData.encodedTargetAdress = ""; - + mutable.encodedTargetAddress = ""; + blockEntity.requestData = mutable.toImmutable(); } @LuaFunction(mainThread = true) @@ -75,7 +77,7 @@ public final void setPriceTagCount(Optional argument) throws LuaExceptio @LuaFunction(mainThread = true) public final Map> getWares() throws LuaException { - List wares = blockEntity.requestData.encodedRequest.stacks(); + List wares = blockEntity.requestData.encodedRequest().stacks(); Map> result = new HashMap<>(); for (int i = 0; i < wares.size(); i++) { ItemStack stack = wares.get(i).stack; @@ -124,8 +126,10 @@ public final void setWares(IArguments arguments) throws LuaException { blockEntity.updateShopRender(); } } - blockEntity.requestData.encodedRequest = new PackageOrder(list); - blockEntity.requestData.encodedRequestContext = new PackageOrder(list); + AutoRequestData.Mutable mutable = new AutoRequestData.Mutable(blockEntity.requestData); + mutable.encodedRequest = new PackageOrder(list); + mutable.encodedRequestContext = new PackageOrder(list); + blockEntity.requestData = mutable.toImmutable(); blockEntity.notifyUpdate(); } From 2b651f27bc2c3da3f2730076d4d473785da0271e Mon Sep 17 00:00:00 2001 From: Arctic Date: Sat, 8 Mar 2025 21:05:03 -0500 Subject: [PATCH 37/48] So, trying to just get this key but I cant seem to access it without jank --- .../peripherals/RedstoneRequesterPeripheral.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java index adadd72f0b..a2d5895295 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java @@ -11,6 +11,9 @@ import com.simibubi.create.content.logistics.redstoneRequester.RedstoneRequesterBlockEntity; import com.simibubi.create.content.logistics.BigItemStack; import com.simibubi.create.content.logistics.stockTicker.PackageOrder; + +import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.ArrayList; @@ -84,6 +87,19 @@ public final String getAddress() throws LuaException { return blockEntity.encodedTargetAdress; } + @LuaFunction(mainThread = true) + public final Map> getConfiguration() throws LuaException { + PackageOrder packageOrder = this.blockEntity.encodedRequest; + Map> table = new HashMap<>(); + //Loop through the packageOrder get each bigItem stack + for(BigItemStack itemStack : packageOrder.stacks()){ + Map tableEntry = new HashMap<>(); + //SO LIKE HOW GET KEY??? AM I DUMB??? losing it fr fr + System.out.println(itemStack.stack.getItem()); + } + return table; + } + @NotNull @Override public String getType() { From 5c7699d626a1045991fd6671b9e7412aeede3545 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Sun, 9 Mar 2025 03:18:30 +0100 Subject: [PATCH 38/48] added the last feature: .getConfiguration() for the redstone requester --- .../RedstoneRequesterPeripheral.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java index a2d5895295..df2fd08e16 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/RedstoneRequesterPeripheral.java @@ -18,6 +18,7 @@ import java.util.Optional; import java.util.ArrayList; +import dan200.computercraft.api.detail.VanillaDetailRegistries; import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; @@ -88,16 +89,21 @@ public final String getAddress() throws LuaException { } @LuaFunction(mainThread = true) - public final Map> getConfiguration() throws LuaException { - PackageOrder packageOrder = this.blockEntity.encodedRequest; - Map> table = new HashMap<>(); - //Loop through the packageOrder get each bigItem stack - for(BigItemStack itemStack : packageOrder.stacks()){ - Map tableEntry = new HashMap<>(); - //SO LIKE HOW GET KEY??? AM I DUMB??? losing it fr fr - System.out.println(itemStack.stack.getItem()); + public final Map> getConfiguration() throws LuaException { + List stacks = blockEntity.encodedRequest.stacks(); + Map> result = new HashMap<>(); + // Loop through the packageOrder get each bigItem stack + // + for (int i = 0; i < stacks.size(); i++) { + ItemStack stack = stacks.get(i).stack; + Map details = new HashMap<>( + VanillaDetailRegistries.ITEM_STACK.getDetails(stack)); + if (!details.get("name").equals("minecraft:air")) { + details.put("count", stacks.get(i).count); + result.put(i + 1, details); // +1 because lua + } } - return table; + return result; } @NotNull From 73de0d8e4e09f56c73c90934f56162286d49e005 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Mon, 10 Mar 2025 02:15:53 +0100 Subject: [PATCH 39/48] added back .isShop() because we love changing states --- .../implementation/peripherals/TableClothPeripheral.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java index e19e6697af..97676857ca 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java @@ -32,6 +32,11 @@ public final boolean isShop() { return blockEntity.isShop(); } + @LuaFunction(mainThread = true) + public final boolean isShop() { + return blockEntity.isShop(); + } + @LuaFunction(mainThread = true) public final String getAddress() throws LuaException { return blockEntity.requestData.encodedTargetAddress(); From a94f42d56b47d94b6c10af052af178b6f101264e Mon Sep 17 00:00:00 2001 From: AsterAether Date: Mon, 10 Mar 2025 02:06:36 +0100 Subject: [PATCH 40/48] Actually actually send the packet --- .../logistics/tableCloth/TableClothBlockEntity.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java index c1c89aa939..79d67319b1 100644 --- a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java @@ -122,9 +122,13 @@ public List getItemsForRender() { return cachedItems(); } - public void updateShopRender() { - if (level instanceof ServerLevel serverLevel) - CatnipServices.NETWORK.sendToClientsTrackingChunk(serverLevel, new ChunkPos(worldPosition), new RemoveBlockEntityPacket(worldPosition)); + public void invalidateItemsForRender() { + renderedItemsForShop = null; + } + + public void notifyShopUpdate() { + AllPackets.getChannel() + .send(packetTarget(), new ShopUpdatePacket(worldPosition)); } @Override From 28f6a14f4249e5d94b96769be30b799fb0a89b00 Mon Sep 17 00:00:00 2001 From: AsterAether Date: Mon, 10 Mar 2025 01:47:46 +0100 Subject: [PATCH 41/48] Actually send the packet --- .../implementation/peripherals/TableClothPeripheral.java | 1 + .../content/logistics/tableCloth/TableClothBlockEntity.java | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java index 97676857ca..6d44292490 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java @@ -136,6 +136,7 @@ public final void setWares(IArguments arguments) throws LuaException { mutable.encodedRequestContext = new PackageOrder(list); blockEntity.requestData = mutable.toImmutable(); blockEntity.notifyUpdate(); + blockEntity.notifyShopUpdate(); } @Override diff --git a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java index 79d67319b1..f308ef6923 100644 --- a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java @@ -211,7 +211,11 @@ public ItemInteractionResult use(Player player, BlockHitResult ray) { return ItemInteractionResult.SUCCESS; player.setItemInHand(InteractionHand.MAIN_HAND, popItem()); level.playSound(null, worldPosition, SoundEvents.ITEM_FRAME_REMOVE_ITEM, SoundSource.BLOCKS, 0.5f, 1f); +<<<<<<< HEAD cachedItems = items(); +======= + +>>>>>>> f20cfdce1 (Actually send the packet) if (manuallyAddedItems.isEmpty() && !computerBehaviour.hasAttachedComputer()) { level.setBlock(worldPosition, getBlockState().setValue(TableClothBlock.HAS_BE, false), 3); if (level instanceof ServerLevel serverLevel) From 33f81002bf6a43ec7995ce736454ce6eaf544e57 Mon Sep 17 00:00:00 2001 From: AsterAether Date: Mon, 10 Mar 2025 01:33:52 +0100 Subject: [PATCH 42/48] Removed normal TableCloth as peripheral Added ShopUpdate packet for updating shop rendering on computer updates --- .../java/com/simibubi/create/AllPackets.java | 6 +-- .../implementation/ComputerBehaviour.java | 4 +- .../implementation/ComputerUtil.java | 32 ------------ ...ral.java => TableClothShopPeripheral.java} | 47 +++++++++++------ .../tableCloth/ShopUpdatePacket.java | 32 ++++++++++++ .../tableCloth/TableClothBlockEntity.java | 50 +++++++++++++++---- .../highLogistics/TableClothScenes.java | 2 +- 7 files changed, 111 insertions(+), 62 deletions(-) rename src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/{TableClothPeripheral.java => TableClothShopPeripheral.java} (72%) create mode 100644 src/main/java/com/simibubi/create/content/logistics/tableCloth/ShopUpdatePacket.java diff --git a/src/main/java/com/simibubi/create/AllPackets.java b/src/main/java/com/simibubi/create/AllPackets.java index aeeb1d6e66..6b7eb8d992 100644 --- a/src/main/java/com/simibubi/create/AllPackets.java +++ b/src/main/java/com/simibubi/create/AllPackets.java @@ -72,6 +72,7 @@ import com.simibubi.create.content.logistics.stockTicker.StockKeeperCategoryHidingPacket; import com.simibubi.create.content.logistics.stockTicker.StockKeeperCategoryRefundPacket; import com.simibubi.create.content.logistics.stockTicker.StockKeeperLockPacket; +import com.simibubi.create.content.logistics.tableCloth.ShopUpdatePacket; import com.simibubi.create.content.logistics.tunnel.TunnelFlapPacket; import com.simibubi.create.content.redstone.displayLink.DisplayLinkConfigurationPacket; import com.simibubi.create.content.redstone.link.controller.LinkedControllerBindPacket; @@ -234,9 +235,8 @@ public enum AllPackets implements BasePacketPayload.PacketTypeProvider { REDSTONE_REQUESTER_EFFECT(RedstoneRequesterEffectPacket.class, RedstoneRequesterEffectPacket.STREAM_CODEC), KNOCKBACK(KnockbackPacket.class, KnockbackPacket.STREAM_CODEC), TRAIN_MAP_SYNC(TrainMapSyncPacket.class, TrainMapSyncPacket.STREAM_CODEC), - CLIENTBOUND_CHAIN_CONVEYOR(ClientboundChainConveyorRidingPacket.class, ClientboundChainConveyorRidingPacket.STREAM_CODEC) - ; - + CLIENTBOUND_CHAIN_CONVEYOR(ClientboundChainConveyorRidingPacket.class, ClientboundChainConveyorRidingPacket.STREAM_CODEC), + SHOP_UPDATE(ShopUpdatePacket.class, ShopUpdatePacket::new, PLAY_TO_CLIENT); static { ClientboundSimpleActionPacket.addAction("rainbowDebug", () -> SimpleCreateActions::rainbowDebug); ClientboundSimpleActionPacket.addAction("overlayReset", () -> SimpleCreateActions::overlayReset); diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java index ffedfb8157..e080f4d5e9 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java @@ -14,7 +14,7 @@ import com.simibubi.create.compat.computercraft.implementation.peripherals.StressGaugePeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.StockTickerPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.PackagerPeripheral; -import com.simibubi.create.compat.computercraft.implementation.peripherals.TableClothPeripheral; +import com.simibubi.create.compat.computercraft.implementation.peripherals.TableClothShopPeripheral; import com.simibubi.create.content.logistics.packagePort.frogport.FrogportBlockEntity; import com.simibubi.create.content.logistics.packagePort.postbox.PostboxBlockEntity; import com.simibubi.create.compat.computercraft.implementation.peripherals.RedstoneRequesterPeripheral; @@ -74,7 +74,7 @@ public static Supplier getPeripheralFor(SmartBlockEntity be) { if (be instanceof StationBlockEntity sbe) return () -> new StationPeripheral(sbe); if (be instanceof TableClothBlockEntity tcbe) - return () -> new TableClothPeripheral(tcbe); + return () -> new TableClothShopPeripheral(tcbe); throw new IllegalArgumentException( "No peripheral available for " + BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(be.getType())); diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java index 29757f9d60..e5084a5a12 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java @@ -19,38 +19,6 @@ public class ComputerUtil { - public static IItemHandler NOOP_HANDLER = new IItemHandler() { - @Override - public int getSlots() { - return 0; - } - - @Override - public @NotNull ItemStack getStackInSlot(int i) { - return ItemStack.EMPTY; - } - - @Override - public @NotNull ItemStack insertItem(int i, ItemStack itemStack, boolean b) { - return ItemStack.EMPTY; - } - - @Override - public @NotNull ItemStack extractItem(int i, int i1, boolean b) { - return ItemStack.EMPTY; - } - - @Override - public int getSlotLimit(int i) { - return 0; - } - - @Override - public boolean isItemValid(int i, @NotNull ItemStack itemStack) { - return false; - } - }; - // tldr: the computercraft api lets you parse items into lua-like-tables that cc // uses for all it's items. to keep consistency with the rest of the inventory // api in other parts of the mod i must do this terribleness. i am sorry. diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java similarity index 72% rename from src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java rename to src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java index 6d44292490..0f26db7557 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java @@ -1,12 +1,17 @@ package com.simibubi.create.compat.computercraft.implementation.peripherals; -import com.simibubi.create.compat.computercraft.implementation.ComputerUtil; import com.simibubi.create.content.logistics.tableCloth.TableClothBlockEntity; import com.simibubi.create.content.logistics.stockTicker.PackageOrder; +<<<<<<< HEAD:src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java import com.simibubi.create.content.logistics.redstoneRequester.AutoRequestData; +======= + +>>>>>>> a21c86c61 (Removed normal TableCloth as peripheral):src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; + import com.simibubi.create.content.logistics.BigItemStack; + import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ItemLike; @@ -14,22 +19,22 @@ import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.detail.VanillaDetailRegistries; -import org.jetbrains.annotations.Nullable; + import java.util.Optional; import java.util.Map; import java.util.HashMap; import java.util.List; import java.util.ArrayList; -public class TableClothPeripheral extends SyncedPeripheral { +public class TableClothShopPeripheral extends SyncedPeripheral { - public TableClothPeripheral(TableClothBlockEntity blockEntity) { + public TableClothShopPeripheral(TableClothBlockEntity blockEntity) { super(blockEntity); } - @LuaFunction(mainThread = true) - public final boolean isShop() { - return blockEntity.isShop(); + private void assertShop() throws LuaException { + if (!blockEntity.isShop()) + throw new LuaException("TableCloth is not a shop!"); } @LuaFunction(mainThread = true) @@ -39,12 +44,21 @@ public final boolean isShop() { @LuaFunction(mainThread = true) public final String getAddress() throws LuaException { +<<<<<<< HEAD:src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java return blockEntity.requestData.encodedTargetAddress(); +======= + assertShop(); + return blockEntity.requestData.encodedTargetAdress; +>>>>>>> a21c86c61 (Removed normal TableCloth as peripheral):src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java } @LuaFunction(mainThread = true) public final void setAddress(Optional argument) throws LuaException { +<<<<<<< HEAD:src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java AutoRequestData.Mutable mutable = new AutoRequestData.Mutable(blockEntity.requestData); +======= + assertShop(); +>>>>>>> a21c86c61 (Removed normal TableCloth as peripheral):src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java if (argument.isPresent()) mutable.encodedTargetAddress = argument.get(); else @@ -54,11 +68,13 @@ public final void setAddress(Optional argument) throws LuaException { @LuaFunction(mainThread = true) public final Map getPriceTagItem() throws LuaException { + assertShop(); return VanillaDetailRegistries.ITEM_STACK.getDetails(blockEntity.priceTag.getFilter()); } @LuaFunction(mainThread = true) public final void setPriceTagItem(Optional itemName) throws LuaException { + assertShop(); ResourceLocation resourceLocation = ResourceLocation.tryParse("minecraft:air"); if (itemName.isPresent()) resourceLocation = ResourceLocation.tryParse(itemName.get()); @@ -68,11 +84,13 @@ public final void setPriceTagItem(Optional itemName) throws LuaException @LuaFunction(mainThread = true) public final int getPriceTagCount() throws LuaException { + assertShop(); return blockEntity.priceTag.count; } @LuaFunction(mainThread = true) public final void setPriceTagCount(Optional argument) throws LuaException { + assertShop(); if (argument.isPresent()) blockEntity.priceTag.count = (Math.max(1, Math.min(100, argument.get().intValue()))); else @@ -82,12 +100,17 @@ public final void setPriceTagCount(Optional argument) throws LuaExceptio @LuaFunction(mainThread = true) public final Map> getWares() throws LuaException { +<<<<<<< HEAD:src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java List wares = blockEntity.requestData.encodedRequest().stacks(); +======= + assertShop(); + List wares = blockEntity.requestData.encodedRequest.stacks(); +>>>>>>> a21c86c61 (Removed normal TableCloth as peripheral):src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java Map> result = new HashMap<>(); for (int i = 0; i < wares.size(); i++) { ItemStack stack = wares.get(i).stack; Map details = new HashMap<>( - VanillaDetailRegistries.ITEM_STACK.getDetails(stack)); + VanillaDetailRegistries.ITEM_STACK.getDetails(stack)); details.put("count", wares.get(i).count); result.put(i + 1, details); // +1 because lua } @@ -104,6 +127,7 @@ public final void setPriceTagCount(Optional argument) throws LuaExceptio */ @LuaFunction(mainThread = true) public final void setWares(IArguments arguments) throws LuaException { + assertShop(); if (!blockEntity.manuallyAddedItems.isEmpty()) throw new LuaException("Tablecloth isn't empty."); ArrayList list = new ArrayList<>(); @@ -128,7 +152,6 @@ public final void setWares(IArguments arguments) throws LuaException { ResourceLocation resourceLocation = ResourceLocation.tryParse(itemName); ItemLike item = BuiltInRegistries.ITEM.get(resourceLocation); list.add(new BigItemStack(new ItemStack(item), count)); - blockEntity.updateShopRender(); } } AutoRequestData.Mutable mutable = new AutoRequestData.Mutable(blockEntity.requestData); @@ -141,11 +164,7 @@ public final void setWares(IArguments arguments) throws LuaException { @Override public String getType() { - return "Create_TableCloth"; + return "Create_TableClothShop"; } - @Override - public @Nullable Object getTarget() { - return isShop() ? ComputerUtil.NOOP_HANDLER : blockEntity.manuallyAddedItems; - } } diff --git a/src/main/java/com/simibubi/create/content/logistics/tableCloth/ShopUpdatePacket.java b/src/main/java/com/simibubi/create/content/logistics/tableCloth/ShopUpdatePacket.java new file mode 100644 index 0000000000..5d3f452f1b --- /dev/null +++ b/src/main/java/com/simibubi/create/content/logistics/tableCloth/ShopUpdatePacket.java @@ -0,0 +1,32 @@ +package com.simibubi.create.content.logistics.tableCloth; + +import com.simibubi.create.foundation.blockEntity.SyncedBlockEntity; +import com.simibubi.create.foundation.networking.BlockEntityDataPacket; + +import net.minecraft.core.BlockPos; +import net.minecraft.network.FriendlyByteBuf; + +public class ShopUpdatePacket extends BlockEntityDataPacket { + + public ShopUpdatePacket(BlockPos pos) { + super(pos); + } + + public ShopUpdatePacket(FriendlyByteBuf buffer) { + super(buffer); + } + + @Override + protected void writeData(FriendlyByteBuf buffer) { + } + + @Override + protected void handlePacket(TableClothBlockEntity be) { + if (!be.hasLevel()) { + return; + } + + be.invalidateItemsForRender(); + } + +} diff --git a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java index f308ef6923..5d6f6805ab 100644 --- a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java @@ -23,7 +23,6 @@ import com.simibubi.create.foundation.blockEntity.SmartBlockEntity; import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; import com.simibubi.create.foundation.blockEntity.behaviour.filtering.FilteringBehaviour; -import com.simibubi.create.foundation.item.SmartInventory; import com.simibubi.create.foundation.utility.CreateLang; import dan200.computercraft.api.peripheral.PeripheralCapability; @@ -64,7 +63,7 @@ public class TableClothBlockEntity extends SmartBlockEntity { public AbstractComputerBehaviour computerBehaviour; public AutoRequestData requestData; - public SmartInventory manuallyAddedItems; + public List manuallyAddedItems; public UUID owner; public Direction facing; @@ -72,11 +71,10 @@ public class TableClothBlockEntity extends SmartBlockEntity { public FilteringBehaviour priceTag; private List renderedItemsForShop; - private List cachedItems; public TableClothBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); - manuallyAddedItems = new SmartInventory(4, this, 1, false); + manuallyAddedItems = new ArrayList<>(); requestData = new AutoRequestData(); owner = null; facing = Direction.SOUTH; @@ -119,16 +117,20 @@ public List getItemsForRender() { .toList(); return renderedItemsForShop; } - return cachedItems(); + + return manuallyAddedItems; } public void invalidateItemsForRender() { renderedItemsForShop = null; +<<<<<<< HEAD } public void notifyShopUpdate() { AllPackets.getChannel() .send(packetTarget(), new ShopUpdatePacket(worldPosition)); +======= +>>>>>>> a21c86c61 (Removed normal TableCloth as peripheral) } @Override @@ -149,6 +151,7 @@ public boolean isShop() { return !requestData.encodedRequest().isEmpty(); } +<<<<<<< HEAD public ItemStack popItem() { if (isShop() || manuallyAddedItems.isEmpty()) return ItemStack.EMPTY; @@ -201,6 +204,9 @@ public boolean isFull() { } public ItemInteractionResult use(Player player, BlockHitResult ray) { +======= + public InteractionResult use(Player player, BlockHitResult ray) { +>>>>>>> a21c86c61 (Removed normal TableCloth as peripheral) if (isShop()) return useShop(player); @@ -208,6 +214,7 @@ public ItemInteractionResult use(Player player, BlockHitResult ray) { if (heldItem.isEmpty()) { if (manuallyAddedItems.isEmpty()) +<<<<<<< HEAD return ItemInteractionResult.SUCCESS; player.setItemInHand(InteractionHand.MAIN_HAND, popItem()); level.playSound(null, worldPosition, SoundEvents.ITEM_FRAME_REMOVE_ITEM, SoundSource.BLOCKS, 0.5f, 1f); @@ -217,6 +224,13 @@ public ItemInteractionResult use(Player player, BlockHitResult ray) { >>>>>>> f20cfdce1 (Actually send the packet) if (manuallyAddedItems.isEmpty() && !computerBehaviour.hasAttachedComputer()) { +======= + return InteractionResult.SUCCESS; + player.setItemInHand(InteractionHand.MAIN_HAND, manuallyAddedItems.remove(manuallyAddedItems.size() - 1)); + level.playSound(null, worldPosition, SoundEvents.ITEM_FRAME_REMOVE_ITEM, SoundSource.BLOCKS, 0.5f, 1f); + + if (manuallyAddedItems.isEmpty()) { +>>>>>>> a21c86c61 (Removed normal TableCloth as peripheral) level.setBlock(worldPosition, getBlockState().setValue(TableClothBlock.HAS_BE, false), 3); if (level instanceof ServerLevel serverLevel) CatnipServices.NETWORK.sendToClientsTrackingChunk(serverLevel, new ChunkPos(worldPosition), new RemoveBlockEntityPacket(worldPosition)); @@ -226,11 +240,16 @@ >>>>>>> f20cfdce1 (Actually send the packet) return ItemInteractionResult.SUCCESS; } +<<<<<<< HEAD if (isFull()) return ItemInteractionResult.SUCCESS; +======= + if (manuallyAddedItems.size() >= 4) + return InteractionResult.SUCCESS; +>>>>>>> a21c86c61 (Removed normal TableCloth as peripheral) level.playSound(null, worldPosition, SoundEvents.ITEM_FRAME_ADD_ITEM, SoundSource.BLOCKS, 0.5f, 1f); - pushItem(heldItem.copyWithCount(1)); + manuallyAddedItems.add(heldItem.copyWithCount(1)); facing = player.getDirection() .getOpposite(); heldItem.shrink(1); @@ -390,9 +409,15 @@ public int getStockLevelForTrade(@Nullable ShoppingList otherPurchases) { } @Override +<<<<<<< HEAD protected void write(CompoundTag tag, HolderLookup.Provider registries, boolean clientPacket) { super.write(tag, registries, clientPacket); tag.put("Items", NBTHelper.writeItemList(items(), registries)); +======= + protected void write(CompoundTag tag, boolean clientPacket) { + super.write(tag, clientPacket); + tag.put("Items", NBTHelper.writeItemList(manuallyAddedItems)); +>>>>>>> a21c86c61 (Removed normal TableCloth as peripheral) tag.putInt("Facing", facing.get2DDataValue()); tag.put("RequestData", CatnipCodecUtils.encode(AutoRequestData.CODEC, requestData).orElseThrow()); if (owner != null) @@ -400,6 +425,7 @@ protected void write(CompoundTag tag, HolderLookup.Provider registries, boolean } @Override +<<<<<<< HEAD protected void read(CompoundTag tag, HolderLookup.Provider registries, boolean clientPacket) { super.read(tag, registries, clientPacket); List items = NBTHelper.readItemList(tag.getList("Items", Tag.TAG_COMPOUND), registries); @@ -409,6 +435,12 @@ protected void read(CompoundTag tag, HolderLookup.Provider registries, boolean c cachedItems = items; requestData = CatnipCodecUtils.decode(AutoRequestData.CODEC, tag.get("RequestData")) .orElse(new AutoRequestData()); +======= + protected void read(CompoundTag tag, boolean clientPacket) { + super.read(tag, clientPacket); + manuallyAddedItems = NBTHelper.readItemList(tag.getList("Items", Tag.TAG_COMPOUND)); + requestData = AutoRequestData.read(tag); +>>>>>>> a21c86c61 (Removed normal TableCloth as peripheral) owner = tag.contains("OwnerUUID") ? tag.getUUID("OwnerUUID") : null; facing = Direction.from2DDataValue(Mth.positiveModulo(tag.getInt("Facing"), 4)); } @@ -416,11 +448,9 @@ protected void read(CompoundTag tag, HolderLookup.Provider registries, boolean c @Override public void destroy() { super.destroy(); - items().forEach(stack -> Containers.dropItemStack(level, worldPosition.getX(), worldPosition.getY(), + manuallyAddedItems.forEach(stack -> Containers.dropItemStack(level, worldPosition.getX(), worldPosition.getY(), worldPosition.getZ(), stack)); - for (int i = 0; i < manuallyAddedItems.getSlots(); i++) { - manuallyAddedItems.setStackInSlot(i, ItemStack.EMPTY); - } + manuallyAddedItems.clear(); } public ItemStack getPaymentItem() { diff --git a/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/highLogistics/TableClothScenes.java b/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/highLogistics/TableClothScenes.java index 25a323be29..d136fcd794 100644 --- a/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/highLogistics/TableClothScenes.java +++ b/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/highLogistics/TableClothScenes.java @@ -90,7 +90,7 @@ public static void tableCloth(SceneBuilder builder, SceneBuildingUtil util) { .at(3, 2, 3), TableClothBlock.HAS_BE); scene.world() .modifyBlockEntity(util.grid() - .at(3, 2, 3), TableClothBlockEntity.class, be -> be.pushItem(grass)); + .at(3, 2, 3), TableClothBlockEntity.class, be -> be.manuallyAddedItems.add(grass)); scene.idle(10); scene.overlay() From 3c22e8f6e8465f0d93c9f5882b269963bbe3a21a Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Mon, 10 Mar 2025 11:23:54 +0100 Subject: [PATCH 43/48] hopefully the last merge with 1.20.1 branch --- .../peripherals/TableClothShopPeripheral.java | 16 ---- .../tableCloth/TableClothBlockEntity.java | 93 ------------------- 2 files changed, 109 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java index 0f26db7557..d84267778f 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java @@ -2,11 +2,7 @@ import com.simibubi.create.content.logistics.tableCloth.TableClothBlockEntity; import com.simibubi.create.content.logistics.stockTicker.PackageOrder; -<<<<<<< HEAD:src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java import com.simibubi.create.content.logistics.redstoneRequester.AutoRequestData; -======= - ->>>>>>> a21c86c61 (Removed normal TableCloth as peripheral):src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; @@ -44,21 +40,13 @@ public final boolean isShop() { @LuaFunction(mainThread = true) public final String getAddress() throws LuaException { -<<<<<<< HEAD:src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java - return blockEntity.requestData.encodedTargetAddress(); -======= assertShop(); return blockEntity.requestData.encodedTargetAdress; ->>>>>>> a21c86c61 (Removed normal TableCloth as peripheral):src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java } @LuaFunction(mainThread = true) public final void setAddress(Optional argument) throws LuaException { -<<<<<<< HEAD:src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java - AutoRequestData.Mutable mutable = new AutoRequestData.Mutable(blockEntity.requestData); -======= assertShop(); ->>>>>>> a21c86c61 (Removed normal TableCloth as peripheral):src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java if (argument.isPresent()) mutable.encodedTargetAddress = argument.get(); else @@ -100,12 +88,8 @@ public final void setPriceTagCount(Optional argument) throws LuaExceptio @LuaFunction(mainThread = true) public final Map> getWares() throws LuaException { -<<<<<<< HEAD:src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothPeripheral.java - List wares = blockEntity.requestData.encodedRequest().stacks(); -======= assertShop(); List wares = blockEntity.requestData.encodedRequest.stacks(); ->>>>>>> a21c86c61 (Removed normal TableCloth as peripheral):src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java Map> result = new HashMap<>(); for (int i = 0; i < wares.size(); i++) { ItemStack stack = wares.get(i).stack; diff --git a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java index 5d6f6805ab..d1eb6ea43e 100644 --- a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java @@ -123,14 +123,11 @@ public List getItemsForRender() { public void invalidateItemsForRender() { renderedItemsForShop = null; -<<<<<<< HEAD } public void notifyShopUpdate() { AllPackets.getChannel() .send(packetTarget(), new ShopUpdatePacket(worldPosition)); -======= ->>>>>>> a21c86c61 (Removed normal TableCloth as peripheral) } @Override @@ -151,62 +148,7 @@ public boolean isShop() { return !requestData.encodedRequest().isEmpty(); } -<<<<<<< HEAD - public ItemStack popItem() { - if (isShop() || manuallyAddedItems.isEmpty()) - return ItemStack.EMPTY; - - for (int i = manuallyAddedItems.getSlots() - 1; i >= 0; i--) { - if (!manuallyAddedItems.getStackInSlot(i).isEmpty()) { - ItemStack item = manuallyAddedItems.getStackInSlot(i); - manuallyAddedItems.setStackInSlot(i, ItemStack.EMPTY); - return item; - } - } - return ItemStack.EMPTY; - } - - public void pushItem(ItemStack stack) { - if (isShop()) - return; - - for (int i = 0; i < manuallyAddedItems.getSlots(); i++) { - if (manuallyAddedItems.getStackInSlot(i).isEmpty()) { - manuallyAddedItems.setStackInSlot(i, stack); - return; - } - } - } - - public List items() { - List items = new ArrayList<>(); - for (int i = 0; i < manuallyAddedItems.getSlots(); i++) { - if (!manuallyAddedItems.getStackInSlot(i).isEmpty()) { - items.add(manuallyAddedItems.getStackInSlot(i)); - } - } - return items; - } - - public List cachedItems() { - if (cachedItems == null) - cachedItems = items(); - return cachedItems; - } - - public boolean isFull() { - for (int i = 0; i < manuallyAddedItems.getSlots(); i++) { - if (manuallyAddedItems.getStackInSlot(i).isEmpty()) { - return false; - } - } - return true; - } - public ItemInteractionResult use(Player player, BlockHitResult ray) { -======= - public InteractionResult use(Player player, BlockHitResult ray) { ->>>>>>> a21c86c61 (Removed normal TableCloth as peripheral) if (isShop()) return useShop(player); @@ -214,23 +156,11 @@ >>>>>>> a21c86c61 (Removed normal TableCloth as peripheral) if (heldItem.isEmpty()) { if (manuallyAddedItems.isEmpty()) -<<<<<<< HEAD - return ItemInteractionResult.SUCCESS; - player.setItemInHand(InteractionHand.MAIN_HAND, popItem()); - level.playSound(null, worldPosition, SoundEvents.ITEM_FRAME_REMOVE_ITEM, SoundSource.BLOCKS, 0.5f, 1f); -<<<<<<< HEAD - cachedItems = items(); -======= - ->>>>>>> f20cfdce1 (Actually send the packet) - if (manuallyAddedItems.isEmpty() && !computerBehaviour.hasAttachedComputer()) { -======= return InteractionResult.SUCCESS; player.setItemInHand(InteractionHand.MAIN_HAND, manuallyAddedItems.remove(manuallyAddedItems.size() - 1)); level.playSound(null, worldPosition, SoundEvents.ITEM_FRAME_REMOVE_ITEM, SoundSource.BLOCKS, 0.5f, 1f); if (manuallyAddedItems.isEmpty()) { ->>>>>>> a21c86c61 (Removed normal TableCloth as peripheral) level.setBlock(worldPosition, getBlockState().setValue(TableClothBlock.HAS_BE, false), 3); if (level instanceof ServerLevel serverLevel) CatnipServices.NETWORK.sendToClientsTrackingChunk(serverLevel, new ChunkPos(worldPosition), new RemoveBlockEntityPacket(worldPosition)); @@ -240,13 +170,8 @@ >>>>>>> a21c86c61 (Removed normal TableCloth as peripheral) return ItemInteractionResult.SUCCESS; } -<<<<<<< HEAD - if (isFull()) - return ItemInteractionResult.SUCCESS; -======= if (manuallyAddedItems.size() >= 4) return InteractionResult.SUCCESS; ->>>>>>> a21c86c61 (Removed normal TableCloth as peripheral) level.playSound(null, worldPosition, SoundEvents.ITEM_FRAME_ADD_ITEM, SoundSource.BLOCKS, 0.5f, 1f); manuallyAddedItems.add(heldItem.copyWithCount(1)); @@ -409,15 +334,9 @@ public int getStockLevelForTrade(@Nullable ShoppingList otherPurchases) { } @Override -<<<<<<< HEAD - protected void write(CompoundTag tag, HolderLookup.Provider registries, boolean clientPacket) { - super.write(tag, registries, clientPacket); - tag.put("Items", NBTHelper.writeItemList(items(), registries)); -======= protected void write(CompoundTag tag, boolean clientPacket) { super.write(tag, clientPacket); tag.put("Items", NBTHelper.writeItemList(manuallyAddedItems)); ->>>>>>> a21c86c61 (Removed normal TableCloth as peripheral) tag.putInt("Facing", facing.get2DDataValue()); tag.put("RequestData", CatnipCodecUtils.encode(AutoRequestData.CODEC, requestData).orElseThrow()); if (owner != null) @@ -425,22 +344,10 @@ >>>>>>> a21c86c61 (Removed normal TableCloth as peripheral) } @Override -<<<<<<< HEAD - protected void read(CompoundTag tag, HolderLookup.Provider registries, boolean clientPacket) { - super.read(tag, registries, clientPacket); - List items = NBTHelper.readItemList(tag.getList("Items", Tag.TAG_COMPOUND), registries); - for (int i = 0; i < items.size(); i++) { - manuallyAddedItems.setStackInSlot(i, items.get(i)); - } - cachedItems = items; - requestData = CatnipCodecUtils.decode(AutoRequestData.CODEC, tag.get("RequestData")) - .orElse(new AutoRequestData()); -======= protected void read(CompoundTag tag, boolean clientPacket) { super.read(tag, clientPacket); manuallyAddedItems = NBTHelper.readItemList(tag.getList("Items", Tag.TAG_COMPOUND)); requestData = AutoRequestData.read(tag); ->>>>>>> a21c86c61 (Removed normal TableCloth as peripheral) owner = tag.contains("OwnerUUID") ? tag.getUUID("OwnerUUID") : null; facing = Direction.from2DDataValue(Mth.positiveModulo(tag.getInt("Facing"), 4)); } From 615d952df86f0bb963641917c37fc0b5beef195e Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Mon, 10 Mar 2025 12:29:01 +0100 Subject: [PATCH 44/48] patched the 1.20.1 cherry picks to work with the new packet system. !!! There is a bug left to fix, the tablecloth stops being a blockentity even when a computer is plugged in, so after .setWares(nil) it stops being interactable with the computer. --- .../java/com/simibubi/create/AllPackets.java | 2 +- .../peripherals/TableClothShopPeripheral.java | 7 ++-- .../tableCloth/ShopUpdatePacket.java | 19 +++++----- .../tableCloth/TableClothBlockEntity.java | 35 +++++++------------ 4 files changed, 27 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/simibubi/create/AllPackets.java b/src/main/java/com/simibubi/create/AllPackets.java index 6b7eb8d992..d9f3277251 100644 --- a/src/main/java/com/simibubi/create/AllPackets.java +++ b/src/main/java/com/simibubi/create/AllPackets.java @@ -236,7 +236,7 @@ public enum AllPackets implements BasePacketPayload.PacketTypeProvider { KNOCKBACK(KnockbackPacket.class, KnockbackPacket.STREAM_CODEC), TRAIN_MAP_SYNC(TrainMapSyncPacket.class, TrainMapSyncPacket.STREAM_CODEC), CLIENTBOUND_CHAIN_CONVEYOR(ClientboundChainConveyorRidingPacket.class, ClientboundChainConveyorRidingPacket.STREAM_CODEC), - SHOP_UPDATE(ShopUpdatePacket.class, ShopUpdatePacket::new, PLAY_TO_CLIENT); + SHOP_UPDATE(ShopUpdatePacket.class, ShopUpdatePacket.STREAM_CODEC); static { ClientboundSimpleActionPacket.addAction("rainbowDebug", () -> SimpleCreateActions::rainbowDebug); ClientboundSimpleActionPacket.addAction("overlayReset", () -> SimpleCreateActions::overlayReset); diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java index d84267778f..a07bcb0372 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java @@ -41,12 +41,13 @@ public final boolean isShop() { @LuaFunction(mainThread = true) public final String getAddress() throws LuaException { assertShop(); - return blockEntity.requestData.encodedTargetAdress; + return blockEntity.requestData.encodedTargetAddress(); } @LuaFunction(mainThread = true) public final void setAddress(Optional argument) throws LuaException { assertShop(); + AutoRequestData.Mutable mutable = new AutoRequestData.Mutable(blockEntity.requestData); if (argument.isPresent()) mutable.encodedTargetAddress = argument.get(); else @@ -89,12 +90,12 @@ public final void setPriceTagCount(Optional argument) throws LuaExceptio @LuaFunction(mainThread = true) public final Map> getWares() throws LuaException { assertShop(); - List wares = blockEntity.requestData.encodedRequest.stacks(); + List wares = blockEntity.requestData.encodedRequest().stacks(); Map> result = new HashMap<>(); for (int i = 0; i < wares.size(); i++) { ItemStack stack = wares.get(i).stack; Map details = new HashMap<>( - VanillaDetailRegistries.ITEM_STACK.getDetails(stack)); + VanillaDetailRegistries.ITEM_STACK.getDetails(stack)); details.put("count", wares.get(i).count); result.put(i + 1, details); // +1 because lua } diff --git a/src/main/java/com/simibubi/create/content/logistics/tableCloth/ShopUpdatePacket.java b/src/main/java/com/simibubi/create/content/logistics/tableCloth/ShopUpdatePacket.java index 5d3f452f1b..9da6d8de92 100644 --- a/src/main/java/com/simibubi/create/content/logistics/tableCloth/ShopUpdatePacket.java +++ b/src/main/java/com/simibubi/create/content/logistics/tableCloth/ShopUpdatePacket.java @@ -1,25 +1,20 @@ package com.simibubi.create.content.logistics.tableCloth; -import com.simibubi.create.foundation.blockEntity.SyncedBlockEntity; +import com.simibubi.create.AllPackets; +import net.minecraft.network.codec.StreamCodec; +import io.netty.buffer.ByteBuf; import com.simibubi.create.foundation.networking.BlockEntityDataPacket; import net.minecraft.core.BlockPos; -import net.minecraft.network.FriendlyByteBuf; public class ShopUpdatePacket extends BlockEntityDataPacket { + public static final StreamCodec STREAM_CODEC = BlockPos.STREAM_CODEC.map(ShopUpdatePacket::new, p -> p.pos); + public ShopUpdatePacket(BlockPos pos) { super(pos); } - public ShopUpdatePacket(FriendlyByteBuf buffer) { - super(buffer); - } - - @Override - protected void writeData(FriendlyByteBuf buffer) { - } - @Override protected void handlePacket(TableClothBlockEntity be) { if (!be.hasLevel()) { @@ -29,4 +24,8 @@ protected void handlePacket(TableClothBlockEntity be) { be.invalidateItemsForRender(); } + @Override + public PacketTypeProvider getTypeProvider() { + return AllPackets.SHOP_UPDATE; + } } diff --git a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java index d1eb6ea43e..4b5a88ac60 100644 --- a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java @@ -9,6 +9,7 @@ import com.simibubi.create.AllBlockEntityTypes; import com.simibubi.create.AllItems; import com.simibubi.create.AllSoundEvents; +import com.simibubi.create.AllPackets; import com.simibubi.create.AllTags.AllBlockTags; import com.simibubi.create.compat.Mods; import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; @@ -87,17 +88,6 @@ public void addBehaviours(List behaviours) { } public static void registerCapabilities(RegisterCapabilitiesEvent event) { - event.registerBlockEntity( - Capabilities.ItemHandler.BLOCK, - AllBlockEntityTypes.TABLE_CLOTH.get(), - (be, context) -> { - if (be.isShop()) { - return ComputerUtil.NOOP_HANDLER; - } - return be.manuallyAddedItems; - } - ); - if (Mods.COMPUTERCRAFT.isLoaded()) { event.registerBlockEntity( PeripheralCapability.get(), @@ -126,8 +116,8 @@ public void invalidateItemsForRender() { } public void notifyShopUpdate() { - AllPackets.getChannel() - .send(packetTarget(), new ShopUpdatePacket(worldPosition)); + if (level instanceof ServerLevel serverLevel) + CatnipServices.NETWORK.sendToClientsTrackingChunk(serverLevel, new ChunkPos(worldPosition), new ShopUpdatePacket(worldPosition)); } @Override @@ -156,7 +146,7 @@ public ItemInteractionResult use(Player player, BlockHitResult ray) { if (heldItem.isEmpty()) { if (manuallyAddedItems.isEmpty()) - return InteractionResult.SUCCESS; + return ItemInteractionResult.SUCCESS; player.setItemInHand(InteractionHand.MAIN_HAND, manuallyAddedItems.remove(manuallyAddedItems.size() - 1)); level.playSound(null, worldPosition, SoundEvents.ITEM_FRAME_REMOVE_ITEM, SoundSource.BLOCKS, 0.5f, 1f); @@ -171,7 +161,7 @@ public ItemInteractionResult use(Player player, BlockHitResult ray) { } if (manuallyAddedItems.size() >= 4) - return InteractionResult.SUCCESS; + return ItemInteractionResult.SUCCESS; level.playSound(null, worldPosition, SoundEvents.ITEM_FRAME_ADD_ITEM, SoundSource.BLOCKS, 0.5f, 1f); manuallyAddedItems.add(heldItem.copyWithCount(1)); @@ -334,9 +324,9 @@ public int getStockLevelForTrade(@Nullable ShoppingList otherPurchases) { } @Override - protected void write(CompoundTag tag, boolean clientPacket) { - super.write(tag, clientPacket); - tag.put("Items", NBTHelper.writeItemList(manuallyAddedItems)); + protected void write(CompoundTag tag, HolderLookup.Provider registries, boolean clientPacket) { + super.write(tag, registries, clientPacket); + tag.put("Items", NBTHelper.writeItemList(manuallyAddedItems, registries)); tag.putInt("Facing", facing.get2DDataValue()); tag.put("RequestData", CatnipCodecUtils.encode(AutoRequestData.CODEC, requestData).orElseThrow()); if (owner != null) @@ -344,10 +334,11 @@ protected void write(CompoundTag tag, boolean clientPacket) { } @Override - protected void read(CompoundTag tag, boolean clientPacket) { - super.read(tag, clientPacket); - manuallyAddedItems = NBTHelper.readItemList(tag.getList("Items", Tag.TAG_COMPOUND)); - requestData = AutoRequestData.read(tag); + protected void read(CompoundTag tag, HolderLookup.Provider registries, boolean clientPacket) { + super.read(tag, registries, clientPacket); + manuallyAddedItems = NBTHelper.readItemList(tag.getList("Items", Tag.TAG_COMPOUND), registries); + requestData = CatnipCodecUtils.decode(AutoRequestData.CODEC, registries, tag.get("RequestData")) + .orElse(new AutoRequestData()); owner = tag.contains("OwnerUUID") ? tag.getUUID("OwnerUUID") : null; facing = Direction.from2DDataValue(Mth.positiveModulo(tag.getInt("Facing"), 4)); } From 30801e63c9e7a97b767c1c3ff1b6cbad4811bb56 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Mon, 10 Mar 2025 12:45:31 +0100 Subject: [PATCH 45/48] minor tweaks --- src/main/java/com/simibubi/create/AllPackets.java | 4 +++- .../implementation/peripherals/TableClothShopPeripheral.java | 1 - .../content/logistics/packager/PackagerBlockEntity.java | 2 +- .../logistics/packager/repackager/RepackagerBlockEntity.java | 2 +- .../content/logistics/tableCloth/TableClothBlockEntity.java | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/simibubi/create/AllPackets.java b/src/main/java/com/simibubi/create/AllPackets.java index d9f3277251..a348bbcdd4 100644 --- a/src/main/java/com/simibubi/create/AllPackets.java +++ b/src/main/java/com/simibubi/create/AllPackets.java @@ -236,7 +236,9 @@ public enum AllPackets implements BasePacketPayload.PacketTypeProvider { KNOCKBACK(KnockbackPacket.class, KnockbackPacket.STREAM_CODEC), TRAIN_MAP_SYNC(TrainMapSyncPacket.class, TrainMapSyncPacket.STREAM_CODEC), CLIENTBOUND_CHAIN_CONVEYOR(ClientboundChainConveyorRidingPacket.class, ClientboundChainConveyorRidingPacket.STREAM_CODEC), - SHOP_UPDATE(ShopUpdatePacket.class, ShopUpdatePacket.STREAM_CODEC); + SHOP_UPDATE(ShopUpdatePacket.class, ShopUpdatePacket.STREAM_CODEC) + ; + static { ClientboundSimpleActionPacket.addAction("rainbowDebug", () -> SimpleCreateActions::rainbowDebug); ClientboundSimpleActionPacket.addAction("overlayReset", () -> SimpleCreateActions::overlayReset); diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java index a07bcb0372..28e4a840dd 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java @@ -112,7 +112,6 @@ public final void setPriceTagCount(Optional argument) throws LuaExceptio */ @LuaFunction(mainThread = true) public final void setWares(IArguments arguments) throws LuaException { - assertShop(); if (!blockEntity.manuallyAddedItems.isEmpty()) throw new LuaException("Tablecloth isn't empty."); ArrayList list = new ArrayList<>(); diff --git a/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java index 1f9e4d9608..2da348b178 100644 --- a/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java @@ -423,7 +423,7 @@ public boolean unwrapBox(ItemStack box, boolean simulate) { itemsAddedToSlot += added; contents.setStackInSlot(boxSlot, - toInsert.copyWithCount(toInsert.getCount() - added)); + toInsert.copyWithCount(toInsert.getCount() - added)); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/packager/repackager/RepackagerBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/packager/repackager/RepackagerBlockEntity.java index 712fa89cc4..40262a617f 100644 --- a/src/main/java/com/simibubi/create/content/logistics/packager/repackager/RepackagerBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/packager/repackager/RepackagerBlockEntity.java @@ -136,7 +136,7 @@ protected void attemptToDefrag(IItemHandler targetInv) { notifyUpdate(); } - + public static void registerCapabilities(RegisterCapabilitiesEvent event) { event.registerBlockEntity( Capabilities.ItemHandler.BLOCK, diff --git a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java index 4b5a88ac60..1661554e27 100644 --- a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java @@ -337,7 +337,7 @@ protected void write(CompoundTag tag, HolderLookup.Provider registries, boolean protected void read(CompoundTag tag, HolderLookup.Provider registries, boolean clientPacket) { super.read(tag, registries, clientPacket); manuallyAddedItems = NBTHelper.readItemList(tag.getList("Items", Tag.TAG_COMPOUND), registries); - requestData = CatnipCodecUtils.decode(AutoRequestData.CODEC, registries, tag.get("RequestData")) + requestData = CatnipCodecUtils.decode(AutoRequestData.CODEC, tag.get("RequestData")) .orElse(new AutoRequestData()); owner = tag.contains("OwnerUUID") ? tag.getUUID("OwnerUUID") : null; facing = Direction.from2DDataValue(Mth.positiveModulo(tag.getInt("Facing"), 4)); From 86c68dcdcc1f41e887e16ea7630fc61a56f4bc8c Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Mon, 10 Mar 2025 01:26:19 +0100 Subject: [PATCH 46/48] epic air check that we forgor to pull --- .../implementation/peripherals/TableClothShopPeripheral.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java index 28e4a840dd..1b85cb771d 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/TableClothShopPeripheral.java @@ -135,7 +135,10 @@ public final void setWares(IArguments arguments) throws LuaException { } ResourceLocation resourceLocation = ResourceLocation.tryParse(itemName); ItemLike item = BuiltInRegistries.ITEM.get(resourceLocation); - list.add(new BigItemStack(new ItemStack(item), count)); + ItemStack itemStack = new ItemStack(item); + if (itemStack.isEmpty()) + throw new LuaException("Invalid item at index: " + (i + 1)); + list.add(new BigItemStack(itemStack, count)); } } AutoRequestData.Mutable mutable = new AutoRequestData.Mutable(blockEntity.requestData); From 36a65252d037c2329bf9a92a6c5c9e8705e43245 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Mon, 10 Mar 2025 12:57:25 +0100 Subject: [PATCH 47/48] missed this during rebasing. needed for the tablecloth to stay as a blockentity --- .../tableCloth/TableClothBlockEntity.java | 80 ++++++++++--------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java index 1661554e27..e51cbf969e 100644 --- a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java @@ -90,10 +90,9 @@ public void addBehaviours(List behaviours) { public static void registerCapabilities(RegisterCapabilitiesEvent event) { if (Mods.COMPUTERCRAFT.isLoaded()) { event.registerBlockEntity( - PeripheralCapability.get(), - AllBlockEntityTypes.TABLE_CLOTH.get(), - (be, context) -> be.computerBehaviour.getPeripheralCapability() - ); + PeripheralCapability.get(), + AllBlockEntityTypes.TABLE_CLOTH.get(), + (be, context) -> be.computerBehaviour.getPeripheralCapability()); } } @@ -101,10 +100,10 @@ public List getItemsForRender() { if (isShop()) { if (renderedItemsForShop == null) renderedItemsForShop = requestData.encodedRequest().stacks() - .stream() - .map(b -> b.stack) - .limit(4) - .toList(); + .stream() + .map(b -> b.stack) + .limit(4) + .toList(); return renderedItemsForShop; } @@ -117,7 +116,8 @@ public void invalidateItemsForRender() { public void notifyShopUpdate() { if (level instanceof ServerLevel serverLevel) - CatnipServices.NETWORK.sendToClientsTrackingChunk(serverLevel, new ChunkPos(worldPosition), new ShopUpdatePacket(worldPosition)); + CatnipServices.NETWORK.sendToClientsTrackingChunk(serverLevel, new ChunkPos(worldPosition), + new ShopUpdatePacket(worldPosition)); } @Override @@ -125,8 +125,8 @@ public void lazyTick() { super.lazyTick(); BlockPos relativePos = worldPosition.relative(facing); sideOccluded = AllBlockTags.TABLE_CLOTHS.matches(level.getBlockState(relativePos)) - || Block.isFaceFull(level.getBlockState(relativePos.below()) - .getOcclusionShape(level, relativePos.below()), facing.getOpposite()); + || Block.isFaceFull(level.getBlockState(relativePos.below()) + .getOcclusionShape(level, relativePos.below()), facing.getOpposite()); } @Override @@ -150,10 +150,11 @@ public ItemInteractionResult use(Player player, BlockHitResult ray) { player.setItemInHand(InteractionHand.MAIN_HAND, manuallyAddedItems.remove(manuallyAddedItems.size() - 1)); level.playSound(null, worldPosition, SoundEvents.ITEM_FRAME_REMOVE_ITEM, SoundSource.BLOCKS, 0.5f, 1f); - if (manuallyAddedItems.isEmpty()) { + if (manuallyAddedItems.isEmpty() && !computerBehaviour.hasAttachedComputer()) { level.setBlock(worldPosition, getBlockState().setValue(TableClothBlock.HAS_BE, false), 3); if (level instanceof ServerLevel serverLevel) - CatnipServices.NETWORK.sendToClientsTrackingChunk(serverLevel, new ChunkPos(worldPosition), new RemoveBlockEntityPacket(worldPosition)); + CatnipServices.NETWORK.sendToClientsTrackingChunk(serverLevel, new ChunkPos(worldPosition), + new RemoveBlockEntityPacket(worldPosition)); } else notifyUpdate(); @@ -166,7 +167,7 @@ public ItemInteractionResult use(Player player, BlockHitResult ray) { level.playSound(null, worldPosition, SoundEvents.ITEM_FRAME_ADD_ITEM, SoundSource.BLOCKS, 0.5f, 1f); manuallyAddedItems.add(heldItem.copyWithCount(1)); facing = player.getDirection() - .getOpposite(); + .getOpposite(); heldItem.shrink(1); if (heldItem.isEmpty()) player.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY); @@ -176,8 +177,8 @@ public ItemInteractionResult use(Player player, BlockHitResult ray) { public boolean targetsPriceTag(Player player, BlockHitResult ray) { return priceTag != null && priceTag.mayInteract(player) && priceTag.getSlotPositioning() - .testHit(level, worldPosition, getBlockState(), ray.getLocation() - .subtract(Vec3.atLowerCornerOf(worldPosition))); + .testHit(level, worldPosition, getBlockState(), ray.getLocation() + .subtract(Vec3.atLowerCornerOf(worldPosition))); } public ItemInteractionResult useShop(Player player) { @@ -188,13 +189,13 @@ public ItemInteractionResult useShop(Player player) { // Remove other lists from inventory for (int i = 0; i < 9; i++) { ItemStack item = player.getInventory() - .getItem(i); + .getItem(i); if (!AllItems.SHOPPING_LIST.isIn(item)) continue; prevListItem = item; addOntoList = true; player.getInventory() - .setItem(i, ItemStack.EMPTY); + .setItem(i, ItemStack.EMPTY); } // add onto existing list if in hand @@ -205,14 +206,14 @@ public ItemInteractionResult useShop(Player player) { if (!itemInHand.isEmpty() && !addOntoList) { CreateLang.translate("stock_keeper.shopping_list_empty_hand") - .sendStatus(player); + .sendStatus(player); AllSoundEvents.DENY.playOnServer(level, worldPosition, 0.5f, 1); return ItemInteractionResult.SUCCESS; } if (getPaymentItem().isEmpty()) { CreateLang.translate("stock_keeper.no_price_set") - .sendStatus(player); + .sendStatus(player); AllSoundEvents.DENY.playOnServer(level, worldPosition, 0.5f, 1); return ItemInteractionResult.SUCCESS; } @@ -226,24 +227,24 @@ public ItemInteractionResult useShop(Player player) { if (tickerID == null) { CreateLang.translate("stock_keeper.keeper_missing") - .style(ChatFormatting.RED) - .sendStatus(player); + .style(ChatFormatting.RED) + .sendStatus(player); AllSoundEvents.DENY.playOnServer(level, worldPosition, 0.5f, 1); return ItemInteractionResult.SUCCESS; } if (stockLevel == 0) { CreateLang.translate("stock_keeper.out_of_stock") - .style(ChatFormatting.RED) - .sendStatus(player); + .style(ChatFormatting.RED) + .sendStatus(player); AllSoundEvents.DENY.playOnServer(level, worldPosition, 0.5f, 1); if (!prevListItem.isEmpty()) { if (player.getItemInHand(InteractionHand.MAIN_HAND) - .isEmpty()) + .isEmpty()) player.setItemInHand(InteractionHand.MAIN_HAND, prevListItem); else player.getInventory() - .placeItemBackInInventory(prevListItem); + .placeItemBackInInventory(prevListItem); } return ItemInteractionResult.SUCCESS; @@ -265,29 +266,29 @@ public ItemInteractionResult useShop(Player player) { entry.setFirst(Math.min(stockLevel, entry.getFirst())); CreateLang.translate("stock_keeper.limited_stock") - .style(ChatFormatting.RED) - .sendStatus(player); + .style(ChatFormatting.RED) + .sendStatus(player); } else { AllSoundEvents.CONFIRM_2.playOnServer(level, worldPosition, 0.5f, 1.0f); list.addPurchases(worldPosition, 1); if (!addOntoList) CreateLang.translate("stock_keeper.use_list_to_add_purchases") - .color(0xeeeeee) - .sendStatus(player); + .color(0xeeeeee) + .sendStatus(player); if (!addOntoList) level.playSound(null, worldPosition, SoundEvents.BOOK_PAGE_TURN, SoundSource.BLOCKS, 1, 1.5f); } - ItemStack newListItem = - ShoppingListItem.saveList(AllItems.SHOPPING_LIST.asStack(), list, requestData.encodedTargetAddress()); + ItemStack newListItem = ShoppingListItem.saveList(AllItems.SHOPPING_LIST.asStack(), list, + requestData.encodedTargetAddress()); if (player.getItemInHand(InteractionHand.MAIN_HAND) - .isEmpty()) + .isEmpty()) player.setItemInHand(InteractionHand.MAIN_HAND, newListItem); else player.getInventory() - .placeItemBackInInventory(newListItem); + .placeItemBackInInventory(newListItem); return ItemInteractionResult.SUCCESS; } @@ -312,13 +313,14 @@ public int getStockLevelForTrade(@Nullable ShoppingList otherPurchases) { InventorySummary modifierSummary = new InventorySummary(); if (otherPurchases != null) modifierSummary = otherPurchases.bakeEntries(level, worldPosition) - .getFirst(); + .getFirst(); int smallestQuotient = Integer.MAX_VALUE; for (BigItemStack entry : requestData.encodedRequest().stacks()) if (entry.count > 0) smallestQuotient = Math.min(smallestQuotient, - (recentSummary.getCountOf(entry.stack) - modifierSummary.getCountOf(entry.stack)) / entry.count); + (recentSummary.getCountOf(entry.stack) - modifierSummary.getCountOf(entry.stack)) + / entry.count); return smallestQuotient; } @@ -338,7 +340,7 @@ protected void read(CompoundTag tag, HolderLookup.Provider registries, boolean c super.read(tag, registries, clientPacket); manuallyAddedItems = NBTHelper.readItemList(tag.getList("Items", Tag.TAG_COMPOUND), registries); requestData = CatnipCodecUtils.decode(AutoRequestData.CODEC, tag.get("RequestData")) - .orElse(new AutoRequestData()); + .orElse(new AutoRequestData()); owner = tag.contains("OwnerUUID") ? tag.getUUID("OwnerUUID") : null; facing = Direction.from2DDataValue(Mth.positiveModulo(tag.getInt("Facing"), 4)); } @@ -347,7 +349,7 @@ protected void read(CompoundTag tag, HolderLookup.Provider registries, boolean c public void destroy() { super.destroy(); manuallyAddedItems.forEach(stack -> Containers.dropItemStack(level, worldPosition.getX(), worldPosition.getY(), - worldPosition.getZ(), stack)); + worldPosition.getZ(), stack)); manuallyAddedItems.clear(); } @@ -357,7 +359,7 @@ public ItemStack getPaymentItem() { public int getPaymentAmount() { return priceTag.getFilter() - .isEmpty() ? 1 : priceTag.count; + .isEmpty() ? 1 : priceTag.count; } } From 63b71651d0b8b7c06ba140e835a45d857f5eaa53 Mon Sep 17 00:00:00 2001 From: BirbIrl Date: Mon, 10 Mar 2025 12:59:21 +0100 Subject: [PATCH 48/48] a fourth linting issue has hit the pr --- .../tableCloth/TableClothBlockEntity.java | 78 +++++++++---------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java index e51cbf969e..2b182b29d1 100644 --- a/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/tableCloth/TableClothBlockEntity.java @@ -90,9 +90,10 @@ public void addBehaviours(List behaviours) { public static void registerCapabilities(RegisterCapabilitiesEvent event) { if (Mods.COMPUTERCRAFT.isLoaded()) { event.registerBlockEntity( - PeripheralCapability.get(), - AllBlockEntityTypes.TABLE_CLOTH.get(), - (be, context) -> be.computerBehaviour.getPeripheralCapability()); + PeripheralCapability.get(), + AllBlockEntityTypes.TABLE_CLOTH.get(), + (be, context) -> be.computerBehaviour.getPeripheralCapability() + ); } } @@ -100,10 +101,10 @@ public List getItemsForRender() { if (isShop()) { if (renderedItemsForShop == null) renderedItemsForShop = requestData.encodedRequest().stacks() - .stream() - .map(b -> b.stack) - .limit(4) - .toList(); + .stream() + .map(b -> b.stack) + .limit(4) + .toList(); return renderedItemsForShop; } @@ -116,8 +117,7 @@ public void invalidateItemsForRender() { public void notifyShopUpdate() { if (level instanceof ServerLevel serverLevel) - CatnipServices.NETWORK.sendToClientsTrackingChunk(serverLevel, new ChunkPos(worldPosition), - new ShopUpdatePacket(worldPosition)); + CatnipServices.NETWORK.sendToClientsTrackingChunk(serverLevel, new ChunkPos(worldPosition), new ShopUpdatePacket(worldPosition)); } @Override @@ -125,8 +125,8 @@ public void lazyTick() { super.lazyTick(); BlockPos relativePos = worldPosition.relative(facing); sideOccluded = AllBlockTags.TABLE_CLOTHS.matches(level.getBlockState(relativePos)) - || Block.isFaceFull(level.getBlockState(relativePos.below()) - .getOcclusionShape(level, relativePos.below()), facing.getOpposite()); + || Block.isFaceFull(level.getBlockState(relativePos.below()) + .getOcclusionShape(level, relativePos.below()), facing.getOpposite()); } @Override @@ -153,8 +153,7 @@ public ItemInteractionResult use(Player player, BlockHitResult ray) { if (manuallyAddedItems.isEmpty() && !computerBehaviour.hasAttachedComputer()) { level.setBlock(worldPosition, getBlockState().setValue(TableClothBlock.HAS_BE, false), 3); if (level instanceof ServerLevel serverLevel) - CatnipServices.NETWORK.sendToClientsTrackingChunk(serverLevel, new ChunkPos(worldPosition), - new RemoveBlockEntityPacket(worldPosition)); + CatnipServices.NETWORK.sendToClientsTrackingChunk(serverLevel, new ChunkPos(worldPosition), new RemoveBlockEntityPacket(worldPosition)); } else notifyUpdate(); @@ -167,7 +166,7 @@ public ItemInteractionResult use(Player player, BlockHitResult ray) { level.playSound(null, worldPosition, SoundEvents.ITEM_FRAME_ADD_ITEM, SoundSource.BLOCKS, 0.5f, 1f); manuallyAddedItems.add(heldItem.copyWithCount(1)); facing = player.getDirection() - .getOpposite(); + .getOpposite(); heldItem.shrink(1); if (heldItem.isEmpty()) player.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY); @@ -177,8 +176,8 @@ public ItemInteractionResult use(Player player, BlockHitResult ray) { public boolean targetsPriceTag(Player player, BlockHitResult ray) { return priceTag != null && priceTag.mayInteract(player) && priceTag.getSlotPositioning() - .testHit(level, worldPosition, getBlockState(), ray.getLocation() - .subtract(Vec3.atLowerCornerOf(worldPosition))); + .testHit(level, worldPosition, getBlockState(), ray.getLocation() + .subtract(Vec3.atLowerCornerOf(worldPosition))); } public ItemInteractionResult useShop(Player player) { @@ -189,13 +188,13 @@ public ItemInteractionResult useShop(Player player) { // Remove other lists from inventory for (int i = 0; i < 9; i++) { ItemStack item = player.getInventory() - .getItem(i); + .getItem(i); if (!AllItems.SHOPPING_LIST.isIn(item)) continue; prevListItem = item; addOntoList = true; player.getInventory() - .setItem(i, ItemStack.EMPTY); + .setItem(i, ItemStack.EMPTY); } // add onto existing list if in hand @@ -206,14 +205,14 @@ public ItemInteractionResult useShop(Player player) { if (!itemInHand.isEmpty() && !addOntoList) { CreateLang.translate("stock_keeper.shopping_list_empty_hand") - .sendStatus(player); + .sendStatus(player); AllSoundEvents.DENY.playOnServer(level, worldPosition, 0.5f, 1); return ItemInteractionResult.SUCCESS; } if (getPaymentItem().isEmpty()) { CreateLang.translate("stock_keeper.no_price_set") - .sendStatus(player); + .sendStatus(player); AllSoundEvents.DENY.playOnServer(level, worldPosition, 0.5f, 1); return ItemInteractionResult.SUCCESS; } @@ -227,24 +226,24 @@ public ItemInteractionResult useShop(Player player) { if (tickerID == null) { CreateLang.translate("stock_keeper.keeper_missing") - .style(ChatFormatting.RED) - .sendStatus(player); + .style(ChatFormatting.RED) + .sendStatus(player); AllSoundEvents.DENY.playOnServer(level, worldPosition, 0.5f, 1); return ItemInteractionResult.SUCCESS; } if (stockLevel == 0) { CreateLang.translate("stock_keeper.out_of_stock") - .style(ChatFormatting.RED) - .sendStatus(player); + .style(ChatFormatting.RED) + .sendStatus(player); AllSoundEvents.DENY.playOnServer(level, worldPosition, 0.5f, 1); if (!prevListItem.isEmpty()) { if (player.getItemInHand(InteractionHand.MAIN_HAND) - .isEmpty()) + .isEmpty()) player.setItemInHand(InteractionHand.MAIN_HAND, prevListItem); else player.getInventory() - .placeItemBackInInventory(prevListItem); + .placeItemBackInInventory(prevListItem); } return ItemInteractionResult.SUCCESS; @@ -266,29 +265,29 @@ public ItemInteractionResult useShop(Player player) { entry.setFirst(Math.min(stockLevel, entry.getFirst())); CreateLang.translate("stock_keeper.limited_stock") - .style(ChatFormatting.RED) - .sendStatus(player); + .style(ChatFormatting.RED) + .sendStatus(player); } else { AllSoundEvents.CONFIRM_2.playOnServer(level, worldPosition, 0.5f, 1.0f); list.addPurchases(worldPosition, 1); if (!addOntoList) CreateLang.translate("stock_keeper.use_list_to_add_purchases") - .color(0xeeeeee) - .sendStatus(player); + .color(0xeeeeee) + .sendStatus(player); if (!addOntoList) level.playSound(null, worldPosition, SoundEvents.BOOK_PAGE_TURN, SoundSource.BLOCKS, 1, 1.5f); } - ItemStack newListItem = ShoppingListItem.saveList(AllItems.SHOPPING_LIST.asStack(), list, - requestData.encodedTargetAddress()); + ItemStack newListItem = + ShoppingListItem.saveList(AllItems.SHOPPING_LIST.asStack(), list, requestData.encodedTargetAddress()); if (player.getItemInHand(InteractionHand.MAIN_HAND) - .isEmpty()) + .isEmpty()) player.setItemInHand(InteractionHand.MAIN_HAND, newListItem); else player.getInventory() - .placeItemBackInInventory(newListItem); + .placeItemBackInInventory(newListItem); return ItemInteractionResult.SUCCESS; } @@ -313,14 +312,13 @@ public int getStockLevelForTrade(@Nullable ShoppingList otherPurchases) { InventorySummary modifierSummary = new InventorySummary(); if (otherPurchases != null) modifierSummary = otherPurchases.bakeEntries(level, worldPosition) - .getFirst(); + .getFirst(); int smallestQuotient = Integer.MAX_VALUE; for (BigItemStack entry : requestData.encodedRequest().stacks()) if (entry.count > 0) smallestQuotient = Math.min(smallestQuotient, - (recentSummary.getCountOf(entry.stack) - modifierSummary.getCountOf(entry.stack)) - / entry.count); + (recentSummary.getCountOf(entry.stack) - modifierSummary.getCountOf(entry.stack)) / entry.count); return smallestQuotient; } @@ -340,7 +338,7 @@ protected void read(CompoundTag tag, HolderLookup.Provider registries, boolean c super.read(tag, registries, clientPacket); manuallyAddedItems = NBTHelper.readItemList(tag.getList("Items", Tag.TAG_COMPOUND), registries); requestData = CatnipCodecUtils.decode(AutoRequestData.CODEC, tag.get("RequestData")) - .orElse(new AutoRequestData()); + .orElse(new AutoRequestData()); owner = tag.contains("OwnerUUID") ? tag.getUUID("OwnerUUID") : null; facing = Direction.from2DDataValue(Mth.positiveModulo(tag.getInt("Facing"), 4)); } @@ -349,7 +347,7 @@ protected void read(CompoundTag tag, HolderLookup.Provider registries, boolean c public void destroy() { super.destroy(); manuallyAddedItems.forEach(stack -> Containers.dropItemStack(level, worldPosition.getX(), worldPosition.getY(), - worldPosition.getZ(), stack)); + worldPosition.getZ(), stack)); manuallyAddedItems.clear(); } @@ -359,7 +357,7 @@ public ItemStack getPaymentItem() { public int getPaymentAmount() { return priceTag.getFilter() - .isEmpty() ? 1 : priceTag.count; + .isEmpty() ? 1 : priceTag.count; } }