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

Conversation

BirbIrl
Copy link

@BirbIrl BirbIrl commented Mar 4, 2025

Hi, this is cross-linked with the wiki pr that has all the documenation. you can preview the documentation here. I added a new folder called "logistics" with the 2 new peripherals.

I also made an unlisted youtube video showcasing the PR: https://youtu.be/_zsRSmOwv90

The most notable additions are:
The blockentity for the packager now gets a new variable that only gets used if a powered on computer is actively connected to it - it overwrites the address it'd get from a sign with one from the computer, if one exists.
There is a full item-filtering-search-requesting algorithm made to work with the type-unsafeness of lua, working in spirit with how native Computer Craft does, and similarly to that of AdvancedPeripherals and similar bridging mods. Basically, type in some data, the Logistical system will get you a package matching that data under a given address. Full documentation here.

Couple notes:

  • I don't want to impede on the existing code, so I made 0 deletions and only insertions. Feel free to integrate anything into the game's main code if it's not a problem (packager's makePackage currently has to check if the package was made manually becuase .activate() doesn't return a value)
  • The filter algo i made and the item-listing method is made to match that of the native ComputerCraft library, hence why it's so cursed - along with all the lua type checking. I'm NOT super experienced with java so if any of you have wayyy better ideas on how to implement it, i wouldn't be surprised. It works - but it's hard to work with for anyone in the future wanting to contribute on this. I'm trying to make all the functions as feature-complete as possible though, as to not mess with people's existing code between versions.
  • I try and match each block's power equal to that of doing things manually. You can manually change the packager's address - so you can .setAddress(). You can request pretty much anything if you try hard enough manually, so the stock ticker can request via the filter algo i provided to HOPEFULLY match all cases. i based it off "i wonder how the filter worked in advanced peripherals" and tried to make it as good as possible :P
  • Default address for .request() is an empty string instead of no address because skill issue. Just sending null causes issues down the stack. the packager can handle null addresses just fine tho.
  • I burnt out before i could add frogposts :(. if anyone wants to take a shot at implementing them - feel invited!
    if this gets pulled in i'd also like to use their function to send events whenever a package is sent, whenever a package is received - et cetra. tons of room here. Could also add events to packagers to fire with the address of the package and contents whenever it pulls in an item :D.
  • Advanced Peripherals has a system for AE/RS integration that, whenever you try and get an item's details - it also gives you a fingerprint, that is all of the item's nbt, plus name, plus count - might be a good idea to implement that so we can pull out specific items in the storage without having to write filters.
  • I've also not set up ordering crafting recipes. Genuinely looked at how that system works, looked back at me trying to parse lua item details and went "ok i think i'll pass". If the code gets ever straightened out, getting that implemented somewhere in the future would be great,

and even with all that, this is a major CC implementation that expands the amount of things you can do in create by a LOT, while encouraging to use create's new features instead of sending and reading items by a wired CC network.
(oh also there is also full type checking and error handling with custom messages and examples to help guide players :>)

And thank you for making one of the best designed mods, i'm in love with 6.0!

@BirbIrl
Copy link
Author

BirbIrl commented Mar 4, 2025

I've been grinding the pr for 3 days on and on, while i was in the zoneee but now i'm taking a bit of a break. I'll be editing this message with random things i might need to change (even if the fixes are really really easy, i don't have the time to test):

  • The stock ticker's "request" function probably shouldn't work if the network is locked. anyone could just put a pc next to it and request any item otherwise. Maybe that's still fine? unsure.
  • The packager should send an error whenever you try and make a package but it's connected to a network. currently it just returns false, which is fine, but errors are probably a better idea for this kind of behaviour.

@simibubi
Copy link
Collaborator

simibubi commented Mar 6, 2025

Thanks for the PR. Is it possible to target 1.20 for feature parity? If not that's okay, you'll just have to make it clear in the wiki that 1.20 users do not have access to this

@BirbIrl
Copy link
Author

BirbIrl commented Mar 6, 2025

I definitely want to at least try getting this working for 1.20!
I'm also going to try and garner everyone within the CC community that is working on similar features into one group chat to talk about the best way to implement things, that lets people make the best use of the integration, without swamping the github with tons of comments.
If you're interested in doing ANY cc integration and i haven't dm'ed you on discord yet - feel free to add me, @BirbIrl.
I wanna make the best of all worlds :D

@BirbIrl BirbIrl marked this pull request as draft March 6, 2025 18:57
@BirbIrl
Copy link
Author

BirbIrl commented Mar 6, 2025

Turning this into a draft for a bit.
Me, @McArctic, @Karotte128 and @AsterAether have teamed up to add extra features, quality control each other, port to 1.20.1 and make sure everything is as good as it can be :D
I'll re-open when we have all put our seal of approval on this ❤️

We're also completely open to pulling in #7453 ! Once that gets pulled we'll have even more features :D

}

@LuaFunction(mainThread = true)
public final void setAddress(IArguments arguments) throws LuaException {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, drive by review here — you can use Optional here, to skip having to do the arg checking yourself.

Suggested change
public final void setAddress(IArguments arguments) throws LuaException {
public final void setAddress(Optional<String> argument) throws LuaException {
if (argument.isPresent()) {
blockEntity.addressFilter = argument.get();

Copy link
Author

@BirbIrl BirbIrl Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much squid! I'll tweak every case of setAddress and the sort to match this :D

Also, psst, if you wanna see the pharaoh's curse (also known as baby's first time dealing with type madness) i suggest looking at bigItemStackToLuaTableFilter: https://github.com/BirbIrl/Create/blob/mc1.21.1/dev/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerUtil.java#L19

it's so much spaghetti - i.. i can't even explain it. there's some documentation on how it's supposed to work here:
https://birbirl.github.io/wiki/users/cc-tweaked-integration/logistics/stock-ticker#request

if you look at it and instantly have ideas, i'd highly appreciate notes on any tweaks to make it comprehensible :D
(it works, just... i don't want random maintainers to stumble upon it when they find some issue with the filtering)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@SquidDev SquidDev Mar 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, had missed your comment!

Oh, hah. That is a gnarly beast. Frankly, I'm not sure there's any nice way to write this code, parsing Lua structures is a right pain.

Honestly, what I'd probably recommend is instead of trying to compare the map against the result of VanillaDetailRegistries.ITEM_STACK.getDetails, parse the filter into a predicate, and then match that against the actual ItemStack. So maybe something like:

record ItemStackFilter(
  Optional<Item> item,
  Optional<String> displayName,
  List<ResourceLocation> tags,
  List<EnchantmentFilter> enchantments,
) : Predicate<ItemStack> {
  @Override
  public boolean test(ItemStack stack) {
    if(item.isPresent() && stack.getItem() != item.get()) return false;
    if(diplayName.isPresent() && !stack.getHoverName().getString().equals(displayName.get()) return false;
    // ...
  }
}

For the actual parsing, I was going to suggest using LuaTable's helper methods for extracting keys out the table, but that actually has much less functionality then I thought it did. I will try to flesh that out. I would instead recommend using something like CC:T's TableHelper (I'm happy to share that under Create's license), so shift some of the parsing away.

So for instance, you might have:

var displayName = Optional.ofNullable(optStringField(filter, "displayName", null));
// ...
return ItemStackFilter(..., displayName, ...)

Honestly, the Ideal(TM) thing to do would probably be to add this to CC's API (so other mods can register their own filter). I'd have to have a think — this probably only makes sense if other mods would find it useful, and not entirely sure if that's true!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaah by now we're reaching a point of burnout as we increased the number of peripherals from 2 to 7 and finishing off documentation, so it's reassuring to know my way of doing things is not the worst :DDD. It works and i'm terrified of breaking it so i'll leave it at that.

If there's ever going to be a native CC way we'll definitely try to implement it, to be consistent with all other peripheral implementations :D

I've also made us of Optional<> as much as possible, it's made the code so much easier to read.

Thanks for the in depth overview squid!

BirbIrl and others added 23 commits March 7, 2025 18:42
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
…getting to set a variable t what they want it to be
Order is off when placing into requester
fixed the ordering bug
Added some safety stuff and made it actually save
@BirbIrl BirbIrl marked this pull request as ready for review March 10, 2025 12:44
@BirbIrl
Copy link
Author

BirbIrl commented Mar 10, 2025

With unified effort, @AsterAether, @Karotte128, @McArctic and I have finished the PR! We have quadrupled the amount of features, going from 2 to 7 peripherals, now supporting:

  • Packager
  • Re-packager
  • Stock Ticker
  • Redstone Requester
  • Table Cloth
  • Package Frogport
  • Postbox

All of which serve different purposes and have unique functionality :D
the coverage of the additions is mentioned on the wiki PR: Creators-of-Create/wiki#4
You can preview it on my fork of the github page here. The entire integration category is our new features!
This pr lets you:

  • Dynamically set tablecloth shop items and prices
  • Configure and request packages that are accepted by auto-crafters, letting you craft anything using computers
  • Look inside the packages when using the packager
  • Request items from your network using a filter algorithm provided by the stock ticker
  • Set the addresses of all of the peripherals

...And more!

We've also managed to backport this to 1.20.1 and tested both versions. I'll be opening a PR today with our 1.20.1 branch as well.
This pr now has all the 1.20.1 commits + 1.21.1 patching commits.

Thank you to Aster, Karotte, Arctic for doing the other 75% of the work! This wouldn't've been possible without their help.
Also thanks Squid popping up for a bit to help us, as well!

PS. We plan to add more features when we regenerate and #7453 gets pulled in. Their event system works wonders with what we've done, and adding their functionality to the logistics blocks will be a walk in the park. Hopefully. So please consider pulling that in as well!

@BirbIrl
Copy link
Author

BirbIrl commented Mar 12, 2025

closed in favor of #7883

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants