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