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

replace isitemsimilar #4120

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

J3fftw1
Copy link
Contributor

@J3fftw1 J3fftw1 commented Feb 5, 2024

Description

This PR replaces isItemSImilar with a new method for now called compareItem()

Proposed changes

Replace isItemSImilar with a better check

Related Issues (if applicable)

Checklist

  • I have fully tested the proposed changes and promise that they will not break everything into chaos.
  • I have also tested the proposed changes in combination with various popular addons and can confirm my changes do not break them.
  • I have made sure that the proposed changes do not break compatibility across the supported Minecraft versions (1.16.* - 1.20.*).
  • I followed the existing code standards and didn't mess up the formatting.
  • I did my best to add documentation to any public classes or methods I added.
  • I have added Nonnull and Nullable annotations to my methods to indicate their behaviour for null values
  • I added sufficient Unit Tests to cover my code.

ToDo

  • add tests for all lines of the new code
  • Add comments
  • performance test

@github-actions github-actions bot added the 🧹 Chores Refactoring / Cleanup. label Feb 5, 2024
Copy link
Contributor

github-actions bot commented Feb 5, 2024

Your Pull Request was automatically labelled as: "🧹 Chores"
Thank you for contributing to this project! ❤️

@J3fftw1 J3fftw1 marked this pull request as ready for review February 5, 2024 19:14
@J3fftw1 J3fftw1 requested a review from a team as a code owner February 5, 2024 19:14
Copy link
Contributor

github-actions bot commented Feb 5, 2024

Slimefun preview build

A Slimefun preview build is available for testing!
Commit: 9f01d73f

https://preview-builds.walshy.dev/download/Slimefun/4120/9f01d73f

Note: This is not a supported build and is only here for the purposes of testing.
Do not run this on a live server and do not report bugs anywhere but this PR!

@J3fftw1 J3fftw1 added the 🔧 API This Pull Request introduces API changes. label Feb 5, 2024
@WalshyDev WalshyDev added the 🎯 Needs testing This Issue needs to be tested by our team to see if it can be reproduced. label Feb 6, 2024
@WalshyDev
Copy link
Member

Testing required

This will need just general Slimefun testing. Some areas to specifically cover:

  • Can use a variety of items
  • Can craft items in enhanced crafting table
  • Can build multi block
  • Can craft with ancient alter
  • Backpacks still work
  • Cargo can move items as normal

@J3fftw1 J3fftw1 requested a review from a team as a code owner February 17, 2024 18:26
@J3fftw1 J3fftw1 added the 💡 Performance Optimization This pull request improves performance. label Feb 19, 2024
@WalshyDev
Copy link
Member

Boomer:

I even added teleporting, basic dust farming, tested a few nodes going thru cargo, and everything seems to work as expected. backpacks are fine. no issues on ancient altar. all i tested with though was core slimefun. no addons or outside plugins. Added multiple power generators, geo mining, teleporting with the gps pad, and everything seems to be running as expected.

the environment was 1.20.4, paper version 405. probably need to update that but, eh for now

@WalshyDev WalshyDev added Build tested Used to indicate the PR preview build has been tested by one of the team and removed 🎯 Needs testing This Issue needs to be tested by our team to see if it can be reproduced. labels Feb 20, 2024
Copy link
Contributor

@ybw0014 ybw0014 left a comment

Choose a reason for hiding this comment

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

the type check is the third check,


// If neither have meta, compare the types and return
if (!itemOneHasMeta && !itemTwoHasMeta) {
return itemOne.getType() == itemTwo.getType();
Copy link
Contributor

Choose a reason for hiding this comment

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

why do a type check again here?

ItemMeta itemMetaTwo = itemTwo.getItemMeta();
// If both metas are null, compare the types and return
if (itemMetaOne == null && itemMetaTwo == null) {
return itemOne.getType() == itemTwo.getType();
Copy link
Contributor

Choose a reason for hiding this comment

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

and here?

// -- Vanilla items --
// This should only be vanilla items now
// Compare types and metas
return itemOne.getType() == itemTwo.getType()
Copy link
Contributor

Choose a reason for hiding this comment

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

and here?

Copy link
Member

@TheBusyBiscuit TheBusyBiscuit left a comment

Choose a reason for hiding this comment

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

Good optimization but in its current form this will break a lot of machines because it is missing a check for the amount and special handling for some items.

@@ -200,7 +200,7 @@ public boolean test(@Nonnull ItemStack item) {
* and thus only perform .getItemMeta() once
*/
for (ItemStackWrapper stack : items) {
if (SlimefunUtils.isItemSimilar(subject, stack, checkLore, false)) {
if (SlimefunUtils.compareItem(subject, stack)) {
Copy link
Member

Choose a reason for hiding this comment

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

The "checkLore" option is ignored here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We already check lore in the method. We don’t specifically need to check for it with a boolean

Copy link
Member

Choose a reason for hiding this comment

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

The option exists in the gui yet it has no effect on the check.

@@ -40,7 +40,7 @@ protected void tick(Block b) {

for (Entity n : b.getWorld().getNearbyEntities(b.getLocation(), RADIUS, RADIUS, RADIUS, this::isReadyToGrow)) {
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFood, false, false)) {
if (SlimefunUtils.compareItem(inv.getItemInSlot(slot), organicFood)) {
Copy link
Member

Choose a reason for hiding this comment

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

This compares with an unobtainable blank organic food item.
So this would break this machine.

@@ -58,7 +58,7 @@ private boolean grow(Block machine, BlockMenu inv, Block crop) {

if (ageable.getAge() < ageable.getMaximumAge()) {
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false, false)) {
if (SlimefunUtils.compareItem(inv.getItemInSlot(slot), organicFertilizer)) {
Copy link
Member

Choose a reason for hiding this comment

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

This compares with an unobtainable blank organic fertilizer item.
So this would break this machine.

@@ -120,7 +120,7 @@ private boolean updateSaplingData(Block machine, Block block, BlockMenu inv, Sap
}

protected boolean isFertilizer(@Nullable ItemStack item) {
return SlimefunUtils.isItemSimilar(item, organicFertilizer, false, false);
return SlimefunUtils.compareItem(item, organicFertilizer);
Copy link
Member

Choose a reason for hiding this comment

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

This compares with an unobtainable blank organic fertilizer item.
So this would break this machine.

@@ -111,7 +111,7 @@ protected void tick(Block b) {

for (Entity n : b.getWorld().getNearbyEntities(b.getLocation(), 4.0, 2.0, 4.0, this::canBreed)) {
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFood, false)) {
if (SlimefunUtils.compareItem(inv.getItemInSlot(slot), organicFood)) {
Copy link
Member

Choose a reason for hiding this comment

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

This compares with an unobtainable blank organic food item.
So this would break this machine.

@ybw0014
Copy link
Contributor

ybw0014 commented Feb 24, 2024

Type check is the first, so items with changed item type (e.g. explosive pickaxe is diamond pickaxe, and using the improvement forge from FoxyMachines to upgrade it to netherite) will not match.
maybe we can have some sort of whitelist for tools and weapons. and other type mismatches will return immediately.

@WalshyDev
Copy link
Member

WalshyDev commented Feb 25, 2024

An allowlist just leads to unmaintable again annoyingly

I'd say just do this when we know it isn't an Slimefun item but that will slow down a bunch...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔧 API This Pull Request introduces API changes. Build tested Used to indicate the PR preview build has been tested by one of the team 🧹 Chores Refactoring / Cleanup. 💡 Performance Optimization This pull request improves performance.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants