Skip to content
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

Fix inventory renaming error. #6159

Closed
wants to merge 15 commits into from

Conversation

Moderocky
Copy link
Member

Description

Prevents attempts at creating a non-creatable inventory type.
Also (actually) fixes an error when trying to rename inventory types.

A cherry pick of #5943 for patch branch with extra bugs fixed.


Target Minecraft Versions: any
Requirements: none
Related Issues: #5495 and #5923

@Moderocky Moderocky added bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. 2.7 Targeting a 2.7.X version release labels Oct 31, 2023
Moderocky and others added 8 commits October 31, 2023 18:15
Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
Copy link
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

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

Concerns aren't blocking, though they should be addressed somehow.

return null;
return Bukkit.createInventory(null, type);
}
return object; // Return the same ItemType they passed without applying a name.
Copy link
Member

Choose a reason for hiding this comment

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

The other get below handles converting ItemStacks to ItemTypes. Do we need to handle that here too (to avoid an ArrayStoreException)? I'm not actually sure that ItemStacks could even be passed into this method though.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know, TheLimeGlass didn't do this in the original PR but there was another change made to this class since that added that converter outside the getter, so I merged the changes together but since I don't know what/why that's there I can't say whether it's needed.

Comment on lines +146 to +149
if (Skript.isRunningMinecraft(1, 14) && type == InventoryType.COMPOSTER)
return false;
if (Skript.isRunningMinecraft(1, 20) && type == InventoryType.CHISELED_BOOKSHELF)
return false;
Copy link
Member

Choose a reason for hiding this comment

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

caching still maybe a good idea ;)

@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
if (exprs[0].getReturnType().equals(ItemStack.class)) {
setExpr(exprs[0].getConvertedExpression(ItemType.class));
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed? Can you add a comment explaining why it is if so

Copy link
Member Author

Choose a reason for hiding this comment

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

I have no idea what it is, what it does or why it's there, I didn't write it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Existing code had casting to ensure the type was not an ItemStack. For some reason in the past an ItemType could have been an ItemStack. This enforces that and removes the need for casting in runtime. This was discussed on the skriptlang Discord a long time ago to do it this way.

@TheLimeGlass
Copy link
Collaborator

Refactored #5943 for dev/patch if that's the reasoning for this pull

@sovdeeth
Copy link
Member

@Moderocky @TheLimeGlass
Which pr should be used? I would prefer merging the original one by Lime but this one seems to have added bug fixes. Can you guys decide which one should be merged for 2.7.3?

@APickledWalrus APickledWalrus removed the 2.7 Targeting a 2.7.X version release label Dec 1, 2023
@sovdeeth
Copy link
Member

sovdeeth commented Feb 1, 2024

Closing in favour of #5943

@sovdeeth sovdeeth closed this Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants