mirror of
https://github.com/songoda/EpicHoppers.git
synced 2025-02-15 19:31:58 +01:00
fix cache material check
This commit is contained in:
parent
0cc2e0278b
commit
0309fcff5e
@ -71,7 +71,7 @@ public class ModuleAutoCrafting extends Module {
|
||||
for(ItemStack item : recipe.recipe) {
|
||||
int amountHave = 0;
|
||||
for (ItemStack hopperItem : hopperCache.cachedInventory) {
|
||||
if (hopperItem != null && Methods.isSimilar(hopperItem, item))
|
||||
if (hopperItem != null && Methods.isSimilarMaterial(hopperItem, item))
|
||||
amountHave += hopperItem.getAmount();
|
||||
}
|
||||
if (amountHave < item.getAmount()) {
|
||||
@ -149,7 +149,7 @@ public class ModuleAutoCrafting extends Module {
|
||||
try {
|
||||
Recipe recipe = recipeIterator.next();
|
||||
ItemStack stack = recipe.getResult();
|
||||
if (Methods.isSimilar(stack, toCraft))
|
||||
if (Methods.isSimilarMaterial(stack, toCraft))
|
||||
recipes.addRecipe(recipe);
|
||||
} catch (Throwable ignored) {}
|
||||
}
|
||||
|
@ -83,13 +83,13 @@ public class ModuleSuction extends Module {
|
||||
// whitelist has priority
|
||||
if (!hopper.getFilter().getWhiteList().isEmpty()) {
|
||||
// is this item on the whitelist?
|
||||
if (!hopper.getFilter().getWhiteList().stream().anyMatch(filterItem -> Methods.isSimilar(itemStack, filterItem))) {
|
||||
if (!hopper.getFilter().getWhiteList().stream().anyMatch(filterItem -> Methods.isSimilarMaterial(itemStack, filterItem))) {
|
||||
// nope!
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
// check the blacklist
|
||||
if (hopper.getFilter().getBlackList().stream().anyMatch(filterItem -> Methods.isSimilar(itemStack, filterItem))) {
|
||||
if (hopper.getFilter().getBlackList().stream().anyMatch(filterItem -> Methods.isSimilarMaterial(itemStack, filterItem))) {
|
||||
// don't grab this, then
|
||||
continue;
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ public class HopperListeners implements Listener {
|
||||
// if we're not moving the item that we're trying to craft, we need to verify that we're not trying to fill the last slot
|
||||
// (filling every slot leaves no room for the crafter to function)
|
||||
if (toCraft != null && toCraft.getType() != Material.AIR
|
||||
&& !Methods.isSimilar(toMove, toCraft)
|
||||
&& !Methods.isSimilarMaterial(toMove, toCraft)
|
||||
&& !Methods.canMoveReserved(destination, toMove)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -88,14 +88,14 @@ public class HopperListeners implements Listener {
|
||||
// whitelist has priority
|
||||
if (!toHopper.getFilter().getWhiteList().isEmpty()) {
|
||||
// is this item on the whitelist?
|
||||
allowItem = toHopper.getFilter().getWhiteList().stream().anyMatch(item -> Methods.isSimilar(toMove, item));
|
||||
allowItem = toHopper.getFilter().getWhiteList().stream().anyMatch(item -> Methods.isSimilarMaterial(toMove, item));
|
||||
if(!allowItem) {
|
||||
// can we change the item to something else?
|
||||
searchReplacement:
|
||||
for(ItemStack sourceItem : source.getContents()) {
|
||||
if(sourceItem != null && Methods.canMove(destination, sourceItem)) {
|
||||
for(ItemStack item : toHopper.getFilter().getWhiteList()) {
|
||||
if(Methods.isSimilar(sourceItem, item)) {
|
||||
if(Methods.isSimilarMaterial(sourceItem, item)) {
|
||||
moveInstead = new ItemStack(sourceItem);
|
||||
moveInstead.setAmount(1);
|
||||
break searchReplacement;
|
||||
@ -106,13 +106,13 @@ public class HopperListeners implements Listener {
|
||||
}
|
||||
} else {
|
||||
// check the blacklist
|
||||
allowItem = !toHopper.getFilter().getBlackList().stream().anyMatch(item -> Methods.isSimilar(toMove, item));
|
||||
allowItem = !toHopper.getFilter().getBlackList().stream().anyMatch(item -> Methods.isSimilarMaterial(toMove, item));
|
||||
if (!allowItem) {
|
||||
// can we change the item to something else?
|
||||
searchReplacement:
|
||||
for (ItemStack sourceItem : source.getContents()) {
|
||||
if (sourceItem != null && Methods.canMove(destination, sourceItem)) {
|
||||
boolean blacklisted = toHopper.getFilter().getBlackList().stream().anyMatch(item -> Methods.isSimilar(sourceItem, item));
|
||||
boolean blacklisted = toHopper.getFilter().getBlackList().stream().anyMatch(item -> Methods.isSimilarMaterial(sourceItem, item));
|
||||
if (!blacklisted) {
|
||||
moveInstead = new ItemStack(sourceItem);
|
||||
moveInstead.setAmount(1);
|
||||
|
@ -132,7 +132,7 @@ public class HopTask extends BukkitRunnable {
|
||||
|| (hopperCache.cacheChanged[i] && item.getAmount() - hopperCache.cacheAdded[i] < maxToMove)
|
||||
// skip if blocked or voidlisted
|
||||
|| blockedMaterials.contains(item.getType())
|
||||
|| hopper.getFilter().getVoidList().stream().anyMatch(itemStack -> Methods.isSimilar(itemStack, item)))
|
||||
|| hopper.getFilter().getVoidList().stream().anyMatch(itemStack -> Methods.isSimilarMaterial(itemStack, item)))
|
||||
continue;
|
||||
|
||||
doProcess = true;
|
||||
@ -262,7 +262,7 @@ public class HopTask extends BukkitRunnable {
|
||||
|
||||
// if we're not moving the item that we're trying to craft, we need to verify that we're not trying to fill the last slot
|
||||
// (filling every slot leaves no room for the crafter to function)
|
||||
if (toCraft != null && !Methods.isSimilar(toMove, toCraft) && !Methods.canMoveReserved(hopperCache.cachedInventory, toMove))
|
||||
if (toCraft != null && !Methods.isSimilarMaterial(toMove, toCraft) && !Methods.canMoveReserved(hopperCache.cachedInventory, toMove))
|
||||
continue;
|
||||
|
||||
// respect whitelist/blacklist filters
|
||||
@ -272,13 +272,13 @@ public class HopTask extends BukkitRunnable {
|
||||
// whitelist has priority
|
||||
if (!toHopper.getFilter().getWhiteList().isEmpty()) {
|
||||
// is this item on the whitelist?
|
||||
if (!toHopper.getFilter().getWhiteList().stream().anyMatch(item -> Methods.isSimilar(toMove, item))) {
|
||||
if (!toHopper.getFilter().getWhiteList().stream().anyMatch(item -> Methods.isSimilarMaterial(toMove, item))) {
|
||||
// nope!
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
// check the blacklist
|
||||
if (toHopper.getFilter().getBlackList().stream().anyMatch(item -> Methods.isSimilar(toMove, item))) {
|
||||
if (toHopper.getFilter().getBlackList().stream().anyMatch(item -> Methods.isSimilarMaterial(toMove, item))) {
|
||||
// don't grab this, then
|
||||
continue;
|
||||
}
|
||||
@ -407,7 +407,7 @@ public class HopTask extends BukkitRunnable {
|
||||
|| (hopperCache.cacheChanged[i] && item.getAmount() - hopperCache.cacheAdded[i] < maxToMove)
|
||||
// skip if blocked or voidlisted
|
||||
|| blockedMaterials.contains(item.getType())
|
||||
|| hopper.getFilter().getVoidList().stream().anyMatch(itemStack -> Methods.isSimilar(itemStack, item)))
|
||||
|| hopper.getFilter().getVoidList().stream().anyMatch(itemStack -> Methods.isSimilarMaterial(itemStack, item)))
|
||||
continue;
|
||||
|
||||
// Create item that will be moved.
|
||||
@ -443,7 +443,7 @@ public class HopTask extends BukkitRunnable {
|
||||
ItemStack[] hopperContents = hopperCache.cachedInventory;
|
||||
for (int i = 0; i < hopperContents.length; i++) {
|
||||
final ItemStack item = hopperContents[i];
|
||||
if (item != null && hopper.getFilter().getVoidList().stream().anyMatch(itemStack -> Methods.isSimilar(itemStack, item))) {
|
||||
if (item != null && hopper.getFilter().getVoidList().stream().anyMatch(itemStack -> Methods.isSimilarMaterial(itemStack, item))) {
|
||||
int amt = Math.min(0, item.getAmount() - maxToMove);
|
||||
if (amt == 0) {
|
||||
hopperCache.removeItem(i);
|
||||
|
@ -145,7 +145,7 @@ public class Methods {
|
||||
return glass;
|
||||
}
|
||||
|
||||
public static boolean isSimilar(ItemStack is1, ItemStack is2) {
|
||||
public static boolean isSimilarMaterial(ItemStack is1, ItemStack is2) {
|
||||
if (EpicHoppers.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)) {
|
||||
return is1.getType() == is2.getType();
|
||||
} else {
|
||||
@ -159,7 +159,7 @@ public class Methods {
|
||||
final ItemMeta itemMeta = item.getItemMeta();
|
||||
for (ItemStack stack : inventory) {
|
||||
final ItemMeta stackMeta;
|
||||
if (isSimilar(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize()
|
||||
if (isSimilarMaterial(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize()
|
||||
&& ((itemMeta == null) == ((stackMeta = stack.getItemMeta()) == null))
|
||||
&& (itemMeta == null || Bukkit.getItemFactory().equals(itemMeta, stackMeta))) {
|
||||
return true;
|
||||
@ -175,7 +175,7 @@ public class Methods {
|
||||
if (stack == null || stack.getAmount() == 0)
|
||||
return true;
|
||||
final ItemMeta stackMeta;
|
||||
if (isSimilar(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize()
|
||||
if (isSimilarMaterial(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize()
|
||||
&& ((itemMeta == null) == ((stackMeta = stack.getItemMeta()) == null))
|
||||
&& (itemMeta == null || Bukkit.getItemFactory().equals(itemMeta, stackMeta))) {
|
||||
return true;
|
||||
@ -192,7 +192,7 @@ public class Methods {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
final ItemStack stack = contents[i];
|
||||
final ItemMeta stackMeta;
|
||||
if (isSimilar(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize()
|
||||
if (isSimilarMaterial(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize()
|
||||
&& ((itemMeta == null) == ((stackMeta = stack.getItemMeta()) == null))
|
||||
&& (itemMeta == null || Bukkit.getItemFactory().equals(itemMeta, stackMeta))) {
|
||||
return true;
|
||||
@ -208,7 +208,7 @@ public class Methods {
|
||||
if (stack == null || stack.getAmount() == 0)
|
||||
return true;
|
||||
final ItemMeta stackMeta;
|
||||
if (isSimilar(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize()
|
||||
if (isSimilarMaterial(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize()
|
||||
&& ((itemMeta == null) == ((stackMeta = stack.getItemMeta()) == null))
|
||||
&& (itemMeta == null || Bukkit.getItemFactory().equals(itemMeta, stackMeta))) {
|
||||
return true;
|
||||
|
@ -111,7 +111,7 @@ public class StorageContainerCache {
|
||||
int toRemove = item.getAmount();
|
||||
for (int i = 0; toRemove > 0 && i < cachedInventory.length; i++) {
|
||||
final ItemStack cacheItem = cachedInventory[i];
|
||||
if (cacheItem != null && cacheItem.getAmount() != 0 && Methods.isSimilar(item, cacheItem)) {
|
||||
if (cacheItem != null && cacheItem.getAmount() != 0 && item.isSimilar(cacheItem)) {
|
||||
int have = cacheItem.getAmount();
|
||||
if (have > toRemove) {
|
||||
cachedInventory[i].setAmount(have - toRemove);
|
||||
@ -155,7 +155,7 @@ public class StorageContainerCache {
|
||||
cacheAdded[i] = toAdd;
|
||||
totalAdded += toAdd;
|
||||
amountToAdd -= toAdd;
|
||||
} else if (maxStack > cacheItem.getAmount() && Methods.isSimilar(item, cacheItem)) {
|
||||
} else if (maxStack > cacheItem.getAmount() && item.isSimilar(cacheItem)) {
|
||||
// free space!
|
||||
int toAdd = Math.min(maxStack - cacheItem.getAmount(), amountToAdd);
|
||||
cachedInventory[i].setAmount(toAdd + cacheItem.getAmount());
|
||||
|
Loading…
Reference in New Issue
Block a user