Skip to content

Computer Craft integration for Update 6 Logistics Blocks #7669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
90dbcbe
cherry-pick 1
BirbIrl Mar 2, 2025
ac5a05b
walking around packager's actiavte() since it doesn't return a variable.
BirbIrl Mar 3, 2025
449b634
i forgor to make StockTicker's .request() return an int
BirbIrl Mar 3, 2025
6010323
Made it so names in the enchant filter are optional
BirbIrl Mar 3, 2025
df88af8
Made it so you can check enchantments by displayName (why not), made
BirbIrl Mar 3, 2025
a192be4
Packager now can get the num of items in attached storage
BirbIrl Mar 4, 2025
1e5c4f7
remove old comments because i'm silly
BirbIrl Mar 4, 2025
d246b11
cherry-pick 2
BirbIrl Mar 6, 2025
455c776
cherry-pick 3
BirbIrl Mar 6, 2025
9944205
cherry-pick 4
Karotte128 Mar 6, 2025
b4a06de
cherry-pick 5
Karotte128 Mar 6, 2025
06eda4f
cherry-pick 6
BirbIrl Mar 6, 2025
8b561e3
made the getAddress and setAddress functions consistent accross
BirbIrl Mar 6, 2025
e606850
"why isn't this variable what i told it to be?" - says programmer for…
BirbIrl Mar 6, 2025
de5efa1
Add listPaymentInventory to StockTickerPeripheral
AsterAether Mar 6, 2025
83a0ebc
cherry-pick 7
AsterAether Mar 6, 2025
da31642
Added Configure method
McArctic Mar 6, 2025
16bdf35
Updated Redstone Requester
McArctic Mar 6, 2025
dc5040c
cherry-pick 8
AsterAether Mar 7, 2025
7ce9587
rewrote the configure function, functionally the same (still broken)
BirbIrl Mar 7, 2025
f60c288
Updated Redstone Receiver Peripheral
McArctic Mar 7, 2025
969e6ad
Name = "minecraft:air"? {}? nil? no argument at all? Who needs to throw
BirbIrl Mar 7, 2025
78d1f6c
Lobotomized the requester
BirbIrl Mar 7, 2025
0032629
Update RedstoneRequesterPeripheral.java
McArctic Mar 7, 2025
1a91e72
fix cherry-pick mistake
Karotte128 Mar 7, 2025
12485c5
fix some things
Karotte128 Mar 7, 2025
d4c0aa1
As squid suggested, replaced IArguments with Optional<String> where
BirbIrl Mar 7, 2025
c12b959
repackager peripheral
Karotte128 Mar 8, 2025
e985970
add makePackage to Repackager
Karotte128 Mar 8, 2025
e75a31a
extra tablecloth functionality. half-working .setWares() included
BirbIrl Mar 8, 2025
2f1456e
somehow fix TableCloth item rendering on setWares
Karotte128 Mar 8, 2025
b2d522a
merge 1.20 into 1.21
Karotte128 Mar 8, 2025
3181e99
1.21.1 port
Karotte128 Mar 8, 2025
9297d84
Removed a pointless comment and differencaited the .request functions
BirbIrl Mar 8, 2025
c07a865
fix 1.21.1 repackager
Karotte128 Mar 8, 2025
4d5a0a4
Merge branch 'mc1.20.1/dev' into mc1.21.1/dev
Karotte128 Mar 8, 2025
737e1a1
made tablecloth setPriceTagItem be a void function like the rest
BirbIrl Mar 8, 2025
b6123be
Merge branch 'mc1.20.1/dev' into mc1.21.1/dev
Karotte128 Mar 8, 2025
c5de7b6
Sins agaionst immutability. (Still need to fix tablecloth rendering)
BirbIrl Mar 9, 2025
2b651f2
So, trying to just get this key but I cant seem to access it without …
McArctic Mar 9, 2025
5c7699d
added the last feature: .getConfiguration() for the redstone requester
BirbIrl Mar 9, 2025
700ba56
Merge branch 'mc1.20.1/dev' into mc1.21.1/dev
Karotte128 Mar 9, 2025
73de0d8
added back .isShop() because we love changing states
BirbIrl Mar 10, 2025
a94f42d
Actually actually send the packet
AsterAether Mar 10, 2025
28f6a14
Actually send the packet
AsterAether Mar 10, 2025
33f8100
Removed normal TableCloth as peripheral
AsterAether Mar 10, 2025
3c22e8f
hopefully the last merge with 1.20.1 branch
BirbIrl Mar 10, 2025
615d952
patched the 1.20.1 cherry picks to work with the new packet system.
BirbIrl Mar 10, 2025
30801e6
minor tweaks
BirbIrl Mar 10, 2025
86c68dc
epic air check that we forgor to pull
BirbIrl Mar 10, 2025
36a6525
missed this during rebasing. needed for the tablecloth to stay as a
BirbIrl Mar 10, 2025
63b7165
a fourth linting issue has hit the pr
BirbIrl Mar 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/com/simibubi/create/AllPackets.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -234,7 +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.STREAM_CODEC)
;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,29 @@

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.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;
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.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;
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;
import com.simibubi.create.content.kinetics.gauge.SpeedGaugeBlockEntity;
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;
Expand All @@ -37,14 +51,30 @@ public static Supplier<IPeripheral> 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 PostboxBlockEntity pbbe)
return () -> new PostboxPeripheral(pbbe);
if (be instanceof SequencedGearshiftBlockEntity sgbe)
return () -> new SequencedGearshiftPeripheral(sgbe);
if (be instanceof SpeedGaugeBlockEntity sgbe)
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)
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)
return () -> new StationPeripheral(sbe);
if (be instanceof TableClothBlockEntity tcbe)
return () -> new TableClothShopPeripheral(tcbe);

throw new IllegalArgumentException(
"No peripheral available for " + BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(be.getType()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package com.simibubi.create.compat.computercraft.implementation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
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.minecraft.world.item.ItemStack;

import net.neoforged.neoforge.items.IItemHandler;

import org.jetbrains.annotations.NotNull;

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<String, Object> 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<String, Class<?>> 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<String, Boolean> filterTags = (Map<String, Boolean>) filterTagsObject;
@SuppressWarnings("unchecked")
Map<String, Boolean> itemTags = (Map<String, Boolean>) itemTagsObject;
for (Map.Entry<String, Boolean> 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<String, Boolean> 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<String, Map<String, ?>> filterEnchantments = (Map<String, Map<String, ?>>) filterEnchantmentsObject;
@SuppressWarnings("unchecked")
ArrayList<HashMap<String, ?>> itemEnchantments = (ArrayList<HashMap<String, ?>>) itemEnchantmentsObject;
if (filterEnchantments.size() != itemEnchantments.size())
return 0;
Set<HashMap<String, ?>> matchedItemEnchantments = new HashSet<>();
for (Map.Entry<String, ?> 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<String, ?> filterEnchantmentEntry = (Map<String, ?>) (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<String, ?> 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;

}

public static Map<Integer, Map<String, ?>> list(IItemHandler inventory) {
Map<Integer, Map<String, ?>> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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.LuaException;
import dan200.computercraft.api.lua.LuaFunction;

import java.util.Optional;
import org.jetbrains.annotations.NotNull;

public class FrogportPeripheral extends SyncedPeripheral<FrogportBlockEntity> {

public FrogportPeripheral(FrogportBlockEntity blockEntity) {
super(blockEntity);
}

@LuaFunction(mainThread = true)
public final void setAddress(Optional<String> argument) throws LuaException {
if (argument.isPresent()) {
blockEntity.addressFilter = argument.get();
blockEntity.filterChanged();
blockEntity.notifyUpdate();
} else {
blockEntity.addressFilter = "";
blockEntity.filterChanged();
blockEntity.notifyUpdate();
}
}

@LuaFunction(mainThread = true)
public final String getAddress() throws LuaException {
return blockEntity.addressFilter;
}

@NotNull
@Override
public String getType() {
return "Create_Frogport";
}

}
Loading