-
Notifications
You must be signed in to change notification settings - Fork 551
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
replace isitemsimilar #4120
Conversation
Your Pull Request was automatically labelled as: "🧹 Chores" |
Slimefun preview buildA Slimefun preview build is available for testing! https://preview-builds.walshy.dev/download/Slimefun/4120/9f01d73f
|
src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java
Outdated
Show resolved
Hide resolved
src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java
Outdated
Show resolved
Hide resolved
Testing required This will need just general Slimefun testing. Some areas to specifically cover:
|
f0da19c
to
f4e7ac1
Compare
f4e7ac1
to
cbb40ef
Compare
Boomer:
|
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.
the type check is the third check,
|
||
// If neither have meta, compare the types and return | ||
if (!itemOneHasMeta && !itemTwoHasMeta) { | ||
return itemOne.getType() == itemTwo.getType(); |
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 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(); |
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.
and here?
// -- Vanilla items -- | ||
// This should only be vanilla items now | ||
// Compare types and metas | ||
return itemOne.getType() == itemTwo.getType() |
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.
and here?
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.
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.
src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java
Outdated
Show resolved
Hide resolved
@@ -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)) { |
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.
The "checkLore" option is ignored here
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.
We already check lore in the method. We don’t specifically need to check for it with a boolean
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.
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)) { |
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.
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)) { |
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.
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); |
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.
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)) { |
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.
This compares with an unobtainable blank organic food item.
So this would break this machine.
...main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/OreWasher.java
Outdated
Show resolved
Hide resolved
src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java
Outdated
Show resolved
Hide resolved
src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java
Outdated
Show resolved
Hide resolved
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. |
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... |
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
Nonnull
andNullable
annotations to my methods to indicate their behaviour for null valuesToDo