mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 11:45: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) {
|
public AltarRecipe(List<ItemStack> input, ItemStack output) {
|
||||||
this.catalyst = input.get(4);
|
this.catalyst = input.get(4);
|
||||||
this.input = new ArrayList<ItemStack>();
|
this.input = new ArrayList<>();
|
||||||
for (int i = 0; i < input.size(); i++) {
|
for (int i = 0; i < input.size(); i++) {
|
||||||
if (i != 4) this.input.add(input.get(i));
|
if (i != 4) this.input.add(input.get(i));
|
||||||
}
|
}
|
||||||
|
@ -15,35 +15,35 @@ import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
|||||||
|
|
||||||
public class Pedestals {
|
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) {
|
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")) {
|
if (BlockStorage.check(altar.getRelative(3, 0, 0), "ANCIENT_PEDESTAL")) {
|
||||||
list.add(altar.getRelative(3, 0, 0));
|
list.add(altar.getRelative(3, 0, 0));
|
||||||
}
|
}
|
||||||
if (BlockStorage.check(altar.getRelative(-3, 0, 0), "ANCIENT_PEDESTAL")) {
|
if (BlockStorage.check(altar.getRelative(2, 0, 2), "ANCIENT_PEDESTAL")) {
|
||||||
list.add(altar.getRelative(-3, 0, 0));
|
list.add(altar.getRelative(2, 0, 2));
|
||||||
}
|
}
|
||||||
if (BlockStorage.check(altar.getRelative(0, 0, 3), "ANCIENT_PEDESTAL")) {
|
if (BlockStorage.check(altar.getRelative(0, 0, 3), "ANCIENT_PEDESTAL")) {
|
||||||
list.add(altar.getRelative(0, 0, 3));
|
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")) {
|
if (BlockStorage.check(altar.getRelative(-2, 0, 2), "ANCIENT_PEDESTAL")) {
|
||||||
list.add(altar.getRelative(-2, 0, 2));
|
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")) {
|
if (BlockStorage.check(altar.getRelative(-2, 0, -2), "ANCIENT_PEDESTAL")) {
|
||||||
list.add(altar.getRelative(-2, 0, -2));
|
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;
|
return list;
|
||||||
}
|
}
|
||||||
@ -62,38 +62,28 @@ public class Pedestals {
|
|||||||
return checkRecipe(catalyst, input);
|
return checkRecipe(catalyst, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ItemStack checkRecipe(ItemStack catalyst, List<ItemStack> input) {
|
private static ItemStack checkRecipe(ItemStack catalyst, List<ItemStack> items) {
|
||||||
AltarRecipe r = null;
|
loop:
|
||||||
for (AltarRecipe recipe : recipes) {
|
for (AltarRecipe recipe: recipes) {
|
||||||
if (SlimefunManager.isItemSimiliar(catalyst, recipe.getCatalyst(), true)) {
|
if (!SlimefunManager.isItemSimiliar(catalyst, recipe.getCatalyst(), true)) {
|
||||||
r = recipe;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
List<ItemStack> copy = new ArrayList<ItemStack>(input);
|
for (int i = 0; i < 8; i++) {
|
||||||
|
if (!SlimefunManager.isItemSimiliar(items.get(i), recipe.getInput().get(0), true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
recipe:
|
for (int j = 1; j < 8; j++) {
|
||||||
for (ItemStack item : recipe.getInput()) {
|
if (!SlimefunManager.isItemSimiliar(items.get((i + j) % items.size()), recipe.getInput().get(j), true)) {
|
||||||
Iterator<ItemStack> iterator = copy.iterator();
|
continue loop;
|
||||||
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) {
|
return recipe.getOutput();
|
||||||
r = null;
|
|
||||||
break recipe;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r != null) return r.getOutput();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,8 @@ public class SlimefunManager {
|
|||||||
return isItemSimiliar(item, SFitem, lore, DataType.IF_COLORED);
|
return isItemSimiliar(item, SFitem, lore, DataType.IF_COLORED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public static enum DataType {
|
public static enum DataType {
|
||||||
|
|
||||||
ALWAYS,
|
ALWAYS,
|
||||||
@ -78,22 +80,15 @@ public class SlimefunManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public static boolean isItemSimiliar(ItemStack item, ItemStack SFitem, boolean lore, DataType data) {
|
public static boolean isItemSimiliar(ItemStack item, ItemStack SFitem, boolean lore, DataType data) {
|
||||||
if (item == null) return SFitem == null;
|
if (item == null) return SFitem == null;
|
||||||
if (SFitem == null) return false;
|
if (SFitem == null) return false;
|
||||||
|
|
||||||
if (item.getType() == SFitem.getType() && item.getAmount() >= SFitem.getAmount()) {
|
if (item.getType() == SFitem.getType() && item.getAmount() >= SFitem.getAmount()) {
|
||||||
//ToDo: Removed data_safe - is that correct?
|
if (((Damageable) item.getItemMeta()).getDamage() != ((Damageable) SFitem.getItemMeta()).getDamage()) {
|
||||||
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (item.hasItemMeta() && SFitem.hasItemMeta()) {
|
if (item.hasItemMeta() && SFitem.hasItemMeta()) {
|
||||||
if (item.getItemMeta().hasDisplayName() && SFitem.getItemMeta().hasDisplayName()) {
|
if (item.getItemMeta().hasDisplayName() && SFitem.getItemMeta().hasDisplayName()) {
|
||||||
|
@ -98,7 +98,7 @@ public class AncientAltarListener implements Listener {
|
|||||||
Variables.altarinuse.add(pblock.getLocation());
|
Variables.altarinuse.add(pblock.getLocation());
|
||||||
});
|
});
|
||||||
if (catalyst != null && !catalyst.getType().equals(Material.AIR)) {
|
if (catalyst != null && !catalyst.getType().equals(Material.AIR)) {
|
||||||
List<ItemStack> input = new ArrayList<ItemStack>();
|
List<ItemStack> input = new ArrayList<>();
|
||||||
for (Block pedestal: pedestals) {
|
for (Block pedestal: pedestals) {
|
||||||
Item stack = findItem(pedestal);
|
Item stack = findItem(pedestal);
|
||||||
if (stack != null) input.add(fixItemStack(stack.getItemStack(), stack.getCustomName()));
|
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);
|
ItemStack result = Pedestals.getRecipeOutput(catalyst, input);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
List<ItemStack> consumed = new ArrayList<ItemStack>();
|
List<ItemStack> consumed = new ArrayList<>();
|
||||||
consumed.add(catalyst);
|
consumed.add(catalyst);
|
||||||
PlayerInventory.consumeItemInHand(e.getPlayer());
|
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);
|
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