mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Improved Ancient Altar Recipe Recognition System
This commit is contained in:
parent
330f439472
commit
b333cfd7a5
@ -13,7 +13,7 @@ public class AltarRecipe {
|
||||
|
||||
public AltarRecipe(List<ItemStack> input, ItemStack output) {
|
||||
this.catalyst = input.get(4);
|
||||
this.input = new ArrayList<ItemStack>();
|
||||
this.input = new ArrayList<>();
|
||||
for (int i = 0; i < input.size(); i++) {
|
||||
if (i != 4) this.input.add(input.get(i));
|
||||
}
|
||||
|
@ -15,35 +15,35 @@ import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
|
||||
public class Pedestals {
|
||||
|
||||
public static List<AltarRecipe> recipes = new ArrayList<AltarRecipe>();
|
||||
public static List<AltarRecipe> recipes = new ArrayList<>();
|
||||
|
||||
public static List<Block> getPedestals(Block altar) {
|
||||
List<Block> list = new ArrayList<Block>();
|
||||
List<Block> list = new ArrayList<>();
|
||||
|
||||
if (BlockStorage.check(altar.getRelative(3, 0, 0), "ANCIENT_PEDESTAL")) {
|
||||
list.add(altar.getRelative(3, 0, 0));
|
||||
}
|
||||
if (BlockStorage.check(altar.getRelative(-3, 0, 0), "ANCIENT_PEDESTAL")) {
|
||||
list.add(altar.getRelative(-3, 0, 0));
|
||||
if (BlockStorage.check(altar.getRelative(2, 0, 2), "ANCIENT_PEDESTAL")) {
|
||||
list.add(altar.getRelative(2, 0, 2));
|
||||
}
|
||||
if (BlockStorage.check(altar.getRelative(0, 0, 3), "ANCIENT_PEDESTAL")) {
|
||||
list.add(altar.getRelative(0, 0, 3));
|
||||
}
|
||||
if (BlockStorage.check(altar.getRelative(0, 0, -3), "ANCIENT_PEDESTAL")) {
|
||||
list.add(altar.getRelative(0, 0, -3));
|
||||
}
|
||||
if (BlockStorage.check(altar.getRelative(2, 0, 2), "ANCIENT_PEDESTAL")) {
|
||||
list.add(altar.getRelative(2, 0, 2));
|
||||
}
|
||||
if (BlockStorage.check(altar.getRelative(2, 0, -2), "ANCIENT_PEDESTAL")) {
|
||||
list.add(altar.getRelative(2, 0, -2));
|
||||
}
|
||||
if (BlockStorage.check(altar.getRelative(-2, 0, 2), "ANCIENT_PEDESTAL")) {
|
||||
list.add(altar.getRelative(-2, 0, 2));
|
||||
}
|
||||
if (BlockStorage.check(altar.getRelative(-3, 0, 0), "ANCIENT_PEDESTAL")) {
|
||||
list.add(altar.getRelative(-3, 0, 0));
|
||||
}
|
||||
if (BlockStorage.check(altar.getRelative(-2, 0, -2), "ANCIENT_PEDESTAL")) {
|
||||
list.add(altar.getRelative(-2, 0, -2));
|
||||
}
|
||||
if (BlockStorage.check(altar.getRelative(0, 0, -3), "ANCIENT_PEDESTAL")) {
|
||||
list.add(altar.getRelative(0, 0, -3));
|
||||
}
|
||||
if (BlockStorage.check(altar.getRelative(2, 0, -2), "ANCIENT_PEDESTAL")) {
|
||||
list.add(altar.getRelative(2, 0, -2));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
@ -62,38 +62,28 @@ public class Pedestals {
|
||||
return checkRecipe(catalyst, input);
|
||||
}
|
||||
|
||||
private static ItemStack checkRecipe(ItemStack catalyst, List<ItemStack> input) {
|
||||
AltarRecipe r = null;
|
||||
for (AltarRecipe recipe : recipes) {
|
||||
if (SlimefunManager.isItemSimiliar(catalyst, recipe.getCatalyst(), true)) {
|
||||
r = recipe;
|
||||
|
||||
List<ItemStack> copy = new ArrayList<ItemStack>(input);
|
||||
|
||||
recipe:
|
||||
for (ItemStack item : recipe.getInput()) {
|
||||
Iterator<ItemStack> iterator = copy.iterator();
|
||||
boolean match = false;
|
||||
|
||||
items:
|
||||
while (iterator.hasNext()) {
|
||||
ItemStack altar_item = iterator.next();
|
||||
if (SlimefunManager.isItemSimiliar(altar_item, item, true)) {
|
||||
match = true;
|
||||
iterator.remove();
|
||||
break items;
|
||||
}
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
r = null;
|
||||
break recipe;
|
||||
private static ItemStack checkRecipe(ItemStack catalyst, List<ItemStack> items) {
|
||||
loop:
|
||||
for (AltarRecipe recipe: recipes) {
|
||||
if (!SlimefunManager.isItemSimiliar(catalyst, recipe.getCatalyst(), true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (!SlimefunManager.isItemSimiliar(items.get(i), recipe.getInput().get(0), true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 1; j < 8; j++) {
|
||||
if (!SlimefunManager.isItemSimiliar(items.get((i + j) % items.size()), recipe.getInput().get(j), true)) {
|
||||
continue loop;
|
||||
}
|
||||
}
|
||||
|
||||
if (r != null) return r.getOutput();
|
||||
}
|
||||
}
|
||||
|
||||
return recipe.getOutput();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +70,8 @@ public class SlimefunManager {
|
||||
return isItemSimiliar(item, SFitem, lore, DataType.IF_COLORED);
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public static enum DataType {
|
||||
|
||||
ALWAYS,
|
||||
@ -78,21 +80,14 @@ public class SlimefunManager {
|
||||
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static boolean isItemSimiliar(ItemStack item, ItemStack SFitem, boolean lore, DataType data) {
|
||||
if (item == null) return SFitem == null;
|
||||
if (SFitem == null) return false;
|
||||
|
||||
if (item.getType() == SFitem.getType() && item.getAmount() >= SFitem.getAmount()) {
|
||||
//ToDo: Removed data_safe - is that correct?
|
||||
if (data.equals(DataType.ALWAYS)/* || (data.equals(DataType.IF_COLORED) && data_safe.contains(item.getType()))*/) {
|
||||
/* if (data_safe.contains(item.getType())) {
|
||||
if (item.getData().getData() != SFitem.getData().getData()) {
|
||||
if (!(SFitem.getDurability() == item.getData().getData() && SFitem.getData().getData() == item.getDurability())) return false;
|
||||
}
|
||||
}
|
||||
else*/ if (data.equals(DataType.ALWAYS) && ((Damageable) item.getItemMeta()).getDamage() != ((Damageable) SFitem.getItemMeta()).getDamage()) {
|
||||
return false;
|
||||
}
|
||||
if (((Damageable) item.getItemMeta()).getDamage() != ((Damageable) SFitem.getItemMeta()).getDamage()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (item.hasItemMeta() && SFitem.hasItemMeta()) {
|
||||
|
@ -98,7 +98,7 @@ public class AncientAltarListener implements Listener {
|
||||
Variables.altarinuse.add(pblock.getLocation());
|
||||
});
|
||||
if (catalyst != null && !catalyst.getType().equals(Material.AIR)) {
|
||||
List<ItemStack> input = new ArrayList<ItemStack>();
|
||||
List<ItemStack> input = new ArrayList<>();
|
||||
for (Block pedestal: pedestals) {
|
||||
Item stack = findItem(pedestal);
|
||||
if (stack != null) input.add(fixItemStack(stack.getItemStack(), stack.getCustomName()));
|
||||
@ -106,7 +106,7 @@ public class AncientAltarListener implements Listener {
|
||||
|
||||
ItemStack result = Pedestals.getRecipeOutput(catalyst, input);
|
||||
if (result != null) {
|
||||
List<ItemStack> consumed = new ArrayList<ItemStack>();
|
||||
List<ItemStack> consumed = new ArrayList<>();
|
||||
consumed.add(catalyst);
|
||||
PlayerInventory.consumeItemInHand(e.getPlayer());
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, new RitualAnimation(altars, b, b.getLocation().add(0.5, 1.3, 0.5), result, pedestals, consumed), 10L);
|
||||
|
Loading…
Reference in New Issue
Block a user