-
Notifications
You must be signed in to change notification settings - Fork 324
Spoilage #3874
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
base: 1.20.1-v8.0.0
Are you sure you want to change the base?
Spoilage #3874
Conversation
jurrejelle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very quick review before I have to go do other things, these are my initial thoughts
| @Inject(at = @At("HEAD"), method = "isSameItemSameTags", cancellable = true) | ||
| private static void mergeSpoilables(ItemStack stack, ItemStack other, CallbackInfoReturnable<Boolean> cir) { | ||
| CompoundTag tag1 = stack.getTagElement("GTCEu_spoilable"); | ||
| CompoundTag tag2 = other.getTagElement("GTCEu_spoilable"); | ||
| boolean isSameItem = ItemStack.isSameItem(stack, other) && stack.areCapsCompatible(other); | ||
| if (tag1 != null && tag2 != null) { | ||
| long tick1 = tag1.getLong("creation_tick"); | ||
| long tick2 = tag2.getLong("creation_tick"); | ||
| if (tick1 != tick2) { | ||
| long avg = (tick1 * stack.getCount() + tick2 * other.getCount()) / | ||
| (stack.getCount() + other.getCount()); | ||
| tag1.putLong("creation_tick", avg); | ||
| tag2.putLong("creation_tick", avg); | ||
| } | ||
| } | ||
| cir.setReturnValue(isSameItem && Objects.equals(stack.getTag(), other.getTag())); | ||
| cir.cancel(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this done in isSameItemSameTags? Now, when we e.g. compare two itemstacks for recipe checking but the recipe can't run, it will still assign the average spoil value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be fair, it's very difficult to know when to merge spoilability status and items don't really have a "merge" function. I'm not sure how we would implement this
|
Some thoughts I had laid out in the discord, ramble style, that I'd like to document here:
|
src/main/java/com/gregtechceu/gtceu/api/item/ISpoilableItemStackExtension.java
Show resolved
Hide resolved
src/main/java/com/gregtechceu/gtceu/core/mixins/ItemStackMixin.java
Outdated
Show resolved
Hide resolved
src/main/java/com/gregtechceu/gtceu/core/mixins/ItemStackMixin.java
Outdated
Show resolved
Hide resolved
src/main/java/com/gregtechceu/gtceu/core/mixins/ItemStackMixin.java
Outdated
Show resolved
Hide resolved
src/main/java/com/gregtechceu/gtceu/core/mixins/ItemStackMixin.java
Outdated
Show resolved
Hide resolved
src/main/java/com/gregtechceu/gtceu/core/mixins/ItemStackMixin.java
Outdated
Show resolved
Hide resolved
Co-authored-by: screret <68943070+screret@users.noreply.github.com>
What
Spoilage yay!
Added API to modify item outputs and read item inputs in recipe modifiers.
Also made an event that fires just before a machine is registered to allow modifying it's parameters from addons (most notably add recipe modifiers)
Implementation Details
Stores the creation tick of a spoilable item in its nbt, thus bypassing the need to actively tick it.
Should be noted that the item has to be updated at least once after it finished crafting for it to start spoiling (done by updating items inserted into
CustomItemStackHandler)Basically everything is done via a mixin into
ItemStacklolsDoesn't actually make any items spoilable, only adds the functionality to do so.
Outcome
GLEBA