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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public static boolean isGuideItem(@Nullable ItemStack item) {
} else if (item instanceof SlimefunGuideItem) {
return true;
} else {
return SlimefunUtils.isItemSimilar(item, getItem(SlimefunGuideMode.SURVIVAL_MODE), true) || SlimefunUtils.isItemSimilar(item, getItem(SlimefunGuideMode.CHEAT_MODE), true);
return SlimefunUtils.compareItem(item, getItem(SlimefunGuideMode.SURVIVAL_MODE))
|| SlimefunUtils.compareItem(item, getItem(SlimefunGuideMode.CHEAT_MODE));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private SlimefunGuideMode getNextMode(@Nonnull Player p, @Nonnull SlimefunGuideM
@Nonnull
@Override
public Optional<SlimefunGuideMode> getSelectedOption(@Nonnull Player p, @Nonnull ItemStack guide) {
if (SlimefunUtils.isItemSimilar(guide, SlimefunGuide.getItem(SlimefunGuideMode.CHEAT_MODE), true, false)) {
if (SlimefunUtils.compareItem(guide, SlimefunGuide.getItem(SlimefunGuideMode.CHEAT_MODE))) {
return Optional.of(SlimefunGuideMode.CHEAT_MODE);
} else {
return Optional.of(SlimefunGuideMode.SURVIVAL_MODE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private void filter(@Nullable ItemStack stack, List<ItemStackAndInteger> items,
boolean add = true;

for (ItemStackAndInteger item : items) {
if (SlimefunUtils.isItemSimilar(stack, item.getItemStackWrapper(), true, false)) {
if (SlimefunUtils.compareItem(stack, item.getItemStackWrapper())) {
add = false;
item.add(stack.getAmount());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static ItemStack withdraw(AbstractItemNetwork network, Map<Location, Inventory>
ItemStack is = menu.getItemInSlot(slot);
ItemStackWrapper wrapperItemInSlot = ItemStackWrapper.wrap(is);

if (SlimefunUtils.isItemSimilar(wrapperItemInSlot, wrapperTemplate, true) && matchesFilter(network, node, wrapperItemInSlot)) {
if (SlimefunUtils.compareItem(wrapperItemInSlot, wrapperTemplate) && matchesFilter(network, node, wrapperItemInSlot)) {
if (is.getAmount() > template.getAmount()) {
is.setAmount(is.getAmount() - template.getAmount());
menu.replaceExistingItem(slot, is);
Expand Down Expand Up @@ -178,7 +178,7 @@ static ItemStack withdrawFromVanillaInventory(AbstractItemNetwork network, Block
}

ItemStackWrapper wrapperInSlot = ItemStackWrapper.wrap(itemInSlot);
if (SlimefunUtils.isItemSimilar(wrapperInSlot, wrapper, true, false) && matchesFilter(network, node, wrapperInSlot)) {
if (SlimefunUtils.compareItem(wrapperInSlot, wrapper) && matchesFilter(network, node, wrapperInSlot)) {
if (itemInSlot.getAmount() > template.getAmount()) {
itemInSlot.setAmount(itemInSlot.getAmount() - template.getAmount());
return template;
Expand Down Expand Up @@ -289,7 +289,7 @@ static ItemStack insert(AbstractItemNetwork network, Map<Location, Inventory> in
continue;
}

if (SlimefunUtils.isItemSimilar(itemInSlot, wrapper, true, false)) {
if (SlimefunUtils.compareItem(itemInSlot, wrapper)) {
if (currentAmount < maxStackSize) {
int amount = currentAmount + stack.getAmount();

Expand Down Expand Up @@ -342,7 +342,7 @@ private static ItemStack insertIntoVanillaInventory(@Nonnull ItemStack stack, @N
continue;
}

if (SlimefunUtils.isItemSimilar(itemInSlot, wrapper, true, false)) {
if (SlimefunUtils.compareItem(itemInSlot, wrapper)) {
if (currentAmount < maxStackSize) {
int amount = currentAmount + stack.getAmount();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

/*
* The filter has found a match, we can return the opposite
* of our default value. If we exclude items, this is where we
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ private boolean insertFuel(BlockMenu menu, Inventory dispenser, int slot, ItemSt
menu.replaceExistingItem(43, newFuel);
dispenser.setItem(slot, null);
return true;
} else if (SlimefunUtils.isItemSimilar(newFuel, currentFuel, true, false)) {
} else if (SlimefunUtils.compareItem(newFuel, currentFuel)) {
int rest = newFuel.getType().getMaxStackSize() - currentFuel.getAmount();

if (rest > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static Collection<Predicate<ItemStack>> getInputs(@Nonnull SlimefunItem
ItemStack ingredient = item.getRecipe()[i];

if (ingredient != null && !ingredient.getType().isAir()) {
predicates.add(stack -> SlimefunUtils.isItemSimilar(stack, ingredient, true));
predicates.add(stack -> SlimefunUtils.compareItem(stack, ingredient));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private ItemStack getOutput(Player p, ItemStack input) {
for (int i = 0; i < recipes.size(); i += 2) {
ItemStack convert = recipes.get(i);

if (convert != null && SlimefunUtils.isItemSimilar(input, convert, true)) {
if (convert != null && SlimefunUtils.compareItem(input, convert)) {
ItemStack removing = input.clone();
removing.setAmount(convert.getAmount());
p.getInventory().removeItem(removing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private boolean craft(Player p, ItemStack input) {
for (int i = 0; i < recipes.size(); i += 2) {
ItemStack catalyst = recipes.get(i);

if (SlimefunUtils.isItemSimilar(input, catalyst, true)) {
if (SlimefunUtils.compareItem(input, catalyst)) {
ItemStack removing = input.clone();
removing.setAmount(catalyst.getAmount());
p.getInventory().removeItem(removing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected MachineRecipe findNextRecipe(BlockMenu menu) {
ItemStack item = menu.getItemInSlot(slot);

if (item != null && item.getType().getMaxDurability() > 0 && ((Damageable) item.getItemMeta()).getDamage() > 0) {
if (SlimefunUtils.isItemSimilar(ductTape, SlimefunItems.DUCT_TAPE, true, false)) {
if (SlimefunUtils.compareItem(ductTape, SlimefunItems.DUCT_TAPE)) {
ItemStack repairedItem = repair(item);

if (!menu.fits(repairedItem, getOutputSlots())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected MachineRecipe findNextRecipe(BlockMenu menu) {
for (int slot : getInputSlots()) {
ItemStack input = menu.getItemInSlot(slot);
MachineRecipe recipe = null;
if (SlimefunUtils.isItemSimilar(input, SlimefunItems.SIFTED_ORE, true, false)) {
if (SlimefunUtils.compareItem(input, SlimefunItems.SIFTED_ORE)) {
if (!legacyMode && !hasFreeSlot(menu)) {
return null;
}
Expand All @@ -59,9 +59,10 @@ protected MachineRecipe findNextRecipe(BlockMenu menu) {
menu.consumeItem(slot);
return recipe;
}
} else if (SlimefunUtils.isItemSimilar(input, SlimefunItems.PULVERIZED_ORE, true)) {

} else if (SlimefunUtils.compareItem(input, SlimefunItems.PULVERIZED_ORE)) {
recipe = new MachineRecipe(4 / getSpeed(), new ItemStack[] { SlimefunItems.PULVERIZED_ORE }, new ItemStack[] { SlimefunItems.PURE_ORE_CLUSTER });
} else if (SlimefunUtils.isItemSimilar(input, new ItemStack(Material.SAND), true)) {
} else if (SlimefunUtils.compareItem(input, new ItemStack(Material.SAND))) {
recipe = new MachineRecipe(4 / getSpeed(), new ItemStack[] { new ItemStack(Material.SAND) }, new ItemStack[] { SlimefunItems.SALT });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public int[] getSlotsAccessedByItemTransport(DirtyChestMenu menu, ItemTransportF

for (int slot : getInputSlots()) {
ItemStack stack = menu.getItemInSlot(slot);
if (stack != null && SlimefunUtils.isItemSimilar(stack, item, true, false)) {
if (stack != null && SlimefunUtils.compareItem(stack, item)) {
if (stack.getAmount() >= stack.getMaxStackSize()) {
fullSlots++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected void tick(@Nonnull Block b) {
for (int slot : getInputSlots()) {
ItemStack itemInSlot = menu.getItemInSlot(slot);

if (SlimefunUtils.isItemSimilar(itemInSlot, emptyBucket, true, false)) {
if (SlimefunUtils.compareItem(itemInSlot, emptyBucket)) {
ItemStack bucket = getFilledBucket(fluid);

if (!menu.fits(bucket, getOutputSlots())) {
Expand All @@ -161,7 +161,7 @@ protected void tick(@Nonnull Block b) {
}

return;
} else if (SlimefunUtils.isItemSimilar(itemInSlot, emptyBottle, true, false)) {
} else if (SlimefunUtils.compareItem(itemInSlot, emptyBottle)) {
ItemStack bottle = getFilledBottle(fluid);

if (!menu.fits(bottle, getOutputSlots())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public int[] getSlotsAccessedByItemTransport(DirtyChestMenu menu, ItemTransportF
List<Integer> slots = new ArrayList<>();

for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), item, true)) {
if (SlimefunUtils.compareItem(menu.getItemInSlot(slot), item)) {
slots.add(slot);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

if (getCharge(b.getLocation()) < ENERGY_CONSUMPTION) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

removeCharge(machine.getLocation(), getEnergyConsumption());
inv.consumeItem(slot);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private boolean findResource(BlockMenu menu, ItemStack item, int[] slots) {
int found = 0;

for (int slot : slots) {
if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), item, true, false)) {
if (SlimefunUtils.compareItem(menu.getItemInSlot(slot), item)) {
found += menu.getItemInSlot(slot).getAmount();

if (found >= item.getAmount()) {
Expand All @@ -250,7 +250,7 @@ private void consumeResources(BlockMenu inv) {
int headCount = getHead().getAmount();

for (int slot : bodySlots) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), getBody(), true, false)) {
if (SlimefunUtils.compareItem(inv.getItemInSlot(slot), getBody())) {
int amount = inv.getItemInSlot(slot).getAmount();

if (amount >= bodyCount) {
Expand All @@ -264,7 +264,7 @@ private void consumeResources(BlockMenu inv) {
}

for (int slot : headSlots) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), getHead(), true, false)) {
if (SlimefunUtils.compareItem(inv.getItemInSlot(slot), getHead())) {
int amount = inv.getItemInSlot(slot).getAmount();

if (amount >= headCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

if (getCharge(b.getLocation()) < ENERGY_CONSUMPTION) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public boolean isSynchronized() {
for (AnimalProduce produce : animalProduces) {
ItemStack item = inv.getItemInSlot(slot);

if (!SlimefunUtils.isItemSimilar(item, produce.getInput()[0], true) || !InvUtils.fits(inv.toInventory(), produce.getOutput()[0], getOutputSlots())) {
if (!SlimefunUtils.compareItem(item, produce.getInput()[0]) || !InvUtils.fits(inv.toInventory(), produce.getOutput()[0], getOutputSlots())) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,15 @@ private boolean hasEnoughCoolant(@Nonnull Location reactor, @Nonnull BlockMenu m

if (accessPort != null) {
for (int slot : getCoolantSlots()) {
if (SlimefunUtils.isItemSimilar(accessPort.getItemInSlot(slot), coolant, true, false)) {
if (SlimefunUtils.compareItem(accessPort.getItemInSlot(slot), coolant)) {
ItemStack remainingItem = menu.pushItem(accessPort.getItemInSlot(slot), getCoolantSlots());
accessPort.replaceExistingItem(slot, remainingItem);
}
}
}

for (int slot : getCoolantSlots()) {
if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), coolant, true, false)) {
if (SlimefunUtils.compareItem(menu.getItemInSlot(slot), coolant)) {
menu.consumeItem(slot);
updateHologram(reactor.getBlock(), "&b\u2744 &7100%");
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ public ItemConsumptionHandler getItemHandler() {
*/
@ParametersAreNonnullByDefault
private void removeGlassBottle(Player p, ItemStack item) {
if (SlimefunUtils.isItemSimilar(item, p.getInventory().getItemInMainHand(), true)) {
if (SlimefunUtils.compareItem(item, p.getInventory().getItemInMainHand())) {
if (p.getInventory().getItemInMainHand().getAmount() == 1) {
p.getEquipment().getItemInMainHand().setAmount(0);
} else {
p.getInventory().removeItem(new ItemStack(Material.GLASS_BOTTLE, 1));
}
} else if (SlimefunUtils.isItemSimilar(item, p.getInventory().getItemInOffHand(), true)) {
} else if (SlimefunUtils.compareItem(item, p.getInventory().getItemInOffHand())) {
if (p.getInventory().getItemInOffHand().getAmount() == 1) {
p.getEquipment().getItemInOffHand().setAmount(0);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected MachineRecipe findNextRecipe(BlockMenu inv) {
Block b = inv.getBlock();

for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), emptyBucket, true, false)) {
if (SlimefunUtils.compareItem(inv.getItemInSlot(slot), emptyBucket)) {
OptionalInt supplies = Slimefun.getGPSNetwork().getResourceManager().getSupplies(oil, b.getWorld(), b.getX() >> 4, b.getZ() >> 4);

if (supplies.isPresent() && supplies.getAsInt() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public MagicEyeOfEnder(ItemGroup itemGroup, SlimefunItemStack item, RecipeType r

private boolean hasArmor(@Nonnull PlayerInventory inv) {
// @formatter:off
return SlimefunUtils.isItemSimilar(inv.getHelmet(), SlimefunItems.ENDER_HELMET, true)
&& SlimefunUtils.isItemSimilar(inv.getChestplate(), SlimefunItems.ENDER_CHESTPLATE, true)
&& SlimefunUtils.isItemSimilar(inv.getLeggings(), SlimefunItems.ENDER_LEGGINGS, true)
&& SlimefunUtils.isItemSimilar(inv.getBoots(), SlimefunItems.ENDER_BOOTS, true);
return SlimefunUtils.compareItem(inv.getHelmet(), SlimefunItems.ENDER_HELMET)
&& SlimefunUtils.compareItem(inv.getChestplate(), SlimefunItems.ENDER_CHESTPLATE)
&& SlimefunUtils.compareItem(inv.getLeggings(), SlimefunItems.ENDER_LEGGINGS)
&& SlimefunUtils.compareItem(inv.getBoots(), SlimefunItems.ENDER_BOOTS);
// @formatter:on
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private static void consumeItem(Inventory inv, Talisman talisman, ItemStack tali
for (int i = 0; i < contents.length; i++) {
ItemStack item = contents[i];

if (SlimefunUtils.isItemSimilar(item, talismanItem, true, false)) {
if (SlimefunUtils.compareItem(item, talismanItem)) {
ItemUtils.consumeItem(item, false);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ private boolean canCraft(Inventory inv, List<ItemStack[]> inputs, int i) {
for (ItemStack expectedInput : inputs.get(i)) {
if (expectedInput != null) {
for (int j = 0; j < inv.getContents().length; j++) {
if (j == (inv.getContents().length - 1) && !SlimefunUtils.isItemSimilar(inv.getContents()[j], expectedInput, true)) {
if (j == (inv.getContents().length - 1) && !SlimefunUtils.compareItem(inv.getContents()[j], expectedInput)) {
return false;
} else if (SlimefunUtils.isItemSimilar(inv.getContents()[j], expectedInput, true)) {
} else if (SlimefunUtils.compareItem(inv.getContents()[j], expectedInput)) {
break;
}
}
Expand All @@ -90,7 +90,7 @@ private boolean canCraft(Inventory inv, List<ItemStack[]> inputs, int i) {
protected void craft(Player p, Block b, Inventory inv, ItemStack[] recipe, ItemStack output, Inventory outputInv) {
for (ItemStack removing : recipe) {
if (removing != null) {
InvUtils.removeItem(inv, removing.getAmount(), true, stack -> SlimefunUtils.isItemSimilar(stack, removing, true));
InvUtils.removeItem(inv, removing.getAmount(), true, stack -> SlimefunUtils.compareItem(stack, removing));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void onInteract(Player p, Block b) {

private boolean isCraftable(Inventory inv, ItemStack[] recipe) {
for (int j = 0; j < inv.getContents().length; j++) {
if (!SlimefunUtils.isItemSimilar(inv.getContents()[j], recipe[j], true)) {
if (!SlimefunUtils.compareItem(inv.getContents()[j], recipe[j])) {
return false;
}
}
Expand Down
Loading