Skip to content

Commit

Permalink
some more minion work
Browse files Browse the repository at this point in the history
  • Loading branch information
ItzKatze committed Jul 27, 2024
1 parent 94954f8 commit a4d2918
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package net.swofty.types.generic.collection;

import net.kyori.adventure.text.Component;
import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import net.swofty.commons.item.ItemType;
import net.swofty.types.generic.gui.inventory.ItemStackCreator;
import net.swofty.types.generic.item.ItemTypeLinker;
import net.swofty.types.generic.item.SkyBlockItem;
import net.swofty.types.generic.item.impl.Minion;
import net.swofty.types.generic.item.impl.SkyBlockRecipe;
import net.swofty.types.generic.item.updater.NonPlayerItemUpdater;
import net.swofty.types.generic.user.SkyBlockPlayer;
Expand Down Expand Up @@ -55,7 +58,11 @@ public List<String> getDisplay(List<String> lore, String itemDisplay) {
switch (unlock.type()) {
case RECIPE -> {
((UnlockRecipe) unlock).getRecipes().forEach(recipe -> {
lore.add("§7 §e" + recipe.getResult().getDisplayName() + " §7Recipes");
if (recipe.getResult().getDisplayName().contains("Minion") && !Arrays.toString(lore.toArray()).contains("Minion §7Recipes")) {
lore.add("§9 " + StringUtility.toNormalCase(recipe.getResult().getAttributeHandler().getMinionType().toString()) + " Minion §7Recipes");
} else if (!recipe.getResult().getDisplayName().contains("Minion")) {
lore.add("§7 §e" + recipe.getResult().getDisplayName() + " §7Recipe");
}
});
}
case CUSTOM_AWARD -> {
Expand Down Expand Up @@ -92,16 +99,28 @@ public UnlockType type() {

@Override
public ItemStack.Builder getDisplay(SkyBlockPlayer player) {
SkyBlockItem skyBlockItem = getRecipes().getFirst().getResult();
ItemStack.Builder updatedItem = new NonPlayerItemUpdater(getRecipes().getFirst().getResult()).getUpdatedItem();
ArrayList<String> lore = new ArrayList<>(
updatedItem.build().get(ItemComponent.LORE).stream().map(StringUtility::getTextFromComponent).toList()
);
lore.add(" ");
int others = getRecipes().size() - 1;
if (others > 0) {
lore.add("§8+" + others + " more recipes");
ArrayList<String> lore = new ArrayList<>(updatedItem.build().get(ItemComponent.LORE).stream().map(StringUtility::getTextFromComponent).toList());
if (skyBlockItem.getGenericInstance() instanceof Minion) {
String material = StringUtility.toNormalCase(skyBlockItem.getAttributeHandler().getMinionType().toString());
updatedItem.customName(Component.text("§r§9" + material + " Minion Recipes"));
lore.clear();
lore.add("§7Place this minion and it will start");
lore.add("§7generating and mining " + material + "!");
lore.add("§7Requires an open area to place");
lore.add("§7" + material + ".");
lore.add("");
lore.add("§eClick to view recipes!");
} else {
lore.add(" ");
int others = getRecipes().size() - 1;

if (others > 0) {
lore.add("§8+" + others + " more recipes");
}
lore.add("§eClick to view recipe");
}
lore.add("§eClick to view recipe");

return ItemStackCreator.updateLore(updatedItem, lore);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import net.swofty.types.generic.collection.CollectionCategory;
import net.swofty.types.generic.gui.inventory.ItemStackCreator;
import net.swofty.types.generic.gui.inventory.SkyBlockInventoryGUI;
import net.swofty.types.generic.gui.inventory.inventories.sbmenu.recipe.GUIMinionRecipes;
import net.swofty.types.generic.gui.inventory.inventories.sbmenu.recipe.GUIRecipe;
import net.swofty.types.generic.gui.inventory.item.GUIClickableItem;
import net.swofty.types.generic.gui.inventory.item.GUIItem;
import net.swofty.types.generic.item.ItemTypeLinker;
import net.swofty.types.generic.item.SkyBlockItem;
import net.swofty.types.generic.item.impl.Minion;
import net.swofty.types.generic.user.SkyBlockPlayer;
import net.swofty.commons.StringUtility;

Expand Down Expand Up @@ -82,8 +84,16 @@ public ItemStack.Builder getItem(SkyBlockPlayer player) {
@Override
public void run(InventoryPreClickEvent e, SkyBlockPlayer player) {
if (unlock instanceof CollectionCategory.UnlockRecipe) {
SkyBlockItem item = ((CollectionCategory.UnlockRecipe) unlock).getRecipe().getResult();
new GUIRecipe(item.getAttributeHandler().getPotentialClassLinker(), null).open(player);
try {
SkyBlockItem skyBlockItem = ((CollectionCategory.UnlockRecipe) unlock).getRecipes().getFirst().getResult();
if (skyBlockItem.getGenericInstance() instanceof Minion) {
new GUIMinionRecipes(skyBlockItem.getAttributeHandler().getMinionType(), new GUICollectionReward(item, reward)).open(player);
} else {
new GUIRecipe(skyBlockItem.getAttributeHandler().getPotentialClassLinker(), null).open(player);
}
} catch (NullPointerException exception) {
player.sendMessage("There is no recipe available for this item!");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package net.swofty.types.generic.gui.inventory.inventories.sbmenu.recipe;

import net.minestom.server.event.inventory.InventoryCloseEvent;
import net.minestom.server.event.inventory.InventoryPreClickEvent;
import net.minestom.server.inventory.Inventory;
import net.minestom.server.inventory.InventoryType;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import net.swofty.commons.StringUtility;
import net.swofty.commons.item.attribute.attributes.ItemAttributeMinionData;
import net.swofty.types.generic.gui.inventory.ItemStackCreator;
import net.swofty.types.generic.gui.inventory.SkyBlockInventoryGUI;
import net.swofty.types.generic.gui.inventory.item.GUIClickableItem;
import net.swofty.types.generic.item.SkyBlockItem;
import net.swofty.types.generic.minion.MinionRegistry;
import net.swofty.types.generic.minion.SkyBlockMinion;
import net.swofty.types.generic.user.SkyBlockPlayer;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GUIMinionRecipes extends SkyBlockInventoryGUI {
private static final Map<Integer, int[]> SLOTS = new HashMap<>(Map.of(
10, new int[] { 11, 12, 13, 14, 15, 20, 21, 22, 23, 24 },
11, new int[] { 11, 12, 13, 14, 15, 21, 22, 23, 30, 31, 32 }
));

SkyBlockInventoryGUI previousGUI;
MinionRegistry minionRegistry;

public GUIMinionRecipes(MinionRegistry minionRegistry, SkyBlockInventoryGUI previousGUI) {
super(StringUtility.toNormalCase(minionRegistry.toString()) + " Minion Recipes", InventoryType.CHEST_6_ROW);
this.previousGUI = previousGUI;
this.minionRegistry = minionRegistry;
}

@Override
public void onOpen(InventoryGUIOpenEvent e) {
fill(ItemStackCreator.createNamedItemStack(Material.BLACK_STAINED_GLASS_PANE));
set(GUIClickableItem.getCloseItem(49));
set(GUIClickableItem.getGoBackItem(48, previousGUI));

List<SkyBlockMinion.MinionTier> craftableMinionTiers = new ArrayList<>();

for (SkyBlockMinion.MinionTier minionTier : minionRegistry.asSkyBlockMinion().getTiers()) {
if (minionTier.craftable()) craftableMinionTiers.add(minionTier);
}

int[] slots = SLOTS.get(craftableMinionTiers.size());
int i = 0;
for (SkyBlockMinion.MinionTier minionTier : craftableMinionTiers) {
int slot = slots[i];
i++;
SkyBlockItem minion = new SkyBlockItem(minionRegistry.getItemTypeLinker());
minion.getAttributeHandler().setMinionData(new ItemAttributeMinionData.MinionData(minionTier.tier(), 0));

set(new GUIClickableItem(slot) {
@Override
public void run(InventoryPreClickEvent e, SkyBlockPlayer player) {
new GUIRecipe(minion, new GUIMinionRecipes(minionRegistry, previousGUI), minionTier.tier() - 1).open(player);
}

@Override
public ItemStack.Builder getItem(SkyBlockPlayer player) {
return ItemStackCreator.getStackHead(minion.getDisplayName(), minionTier.texture(), 1,
minion.getLore());
}
});
}

updateItemStacks(getInventory(), getPlayer());
}

@Override
public boolean allowHotkeying() {
return false;
}

@Override
public void onClose(InventoryCloseEvent e, CloseReason reason) {

}

@Override
public void suddenlyQuit(Inventory inventory, SkyBlockPlayer player) {

}

@Override
public void onBottomClick(InventoryPreClickEvent e) {
e.setCancelled(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.swofty.types.generic.user.SkyBlockPlayer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class GUIRecipe extends SkyBlockInventoryGUI {
Expand Down Expand Up @@ -82,6 +83,8 @@ public ItemStack.Builder getItem(SkyBlockPlayer player) {
recipeIndex = 0;
SkyBlockRecipe recipe = recipes.get(recipeIndex);

Arrays.stream(recipe.getRecipeDisplay()).toList().forEach(recipeList -> System.out.println("RecipeList: " + recipeList.toString()));

if (recipes.size() > recipeIndex + 1) {
set(new GUIClickableItem(32) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,27 @@ default List<SkyBlockRecipe<?>> getRawRecipes() {
)),
pattern
);
try {
for (SkyBlockItem skyBlockItem : recipe.getRecipeDisplay()) {
System.out.println("Before addExtraRequirement: " + skyBlockItem);
}
} catch (NullPointerException _) {

}
recipe.addExtraRequirement('B', (minionItem) -> {
System.out.println("1: " + minionItem.toString());
if (minionItem.getGenericInstance() instanceof Minion)
return minionItem.getAttributeHandler().getMinionData().tier() == Math.max(1, tier.tier() - 1);
System.out.println("2: " + minionItem.toString());
return true;
});
try {
for (SkyBlockItem skyBlockItem : recipe.getRecipeDisplay()) {
System.out.println("After addExtraRequirement: " + skyBlockItem);
}
} catch (NullPointerException _) {

}

toReturn.add(recipe);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static SkyBlockRecipe<?> parseRecipe(ItemStack[] stacks) {
return ShapelessRecipe.parseShapelessRecipe(stacks);
}

public static @NotNull List<SkyBlockRecipe<?>> getFromType(ItemTypeLinker type) {
public static @NotNull List<SkyBlockRecipe<?>> getFromType(ItemTypeLinker type) {
ArrayList<SkyBlockRecipe<?>> recipes = new ArrayList<>();
ShapedRecipe.CACHED_RECIPES.forEach(recipe -> {
ItemTypeLinker itemTypeLinker = recipe.getResult().getAttributeHandler().getPotentialClassLinker();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,26 +232,29 @@ public static ShapedRecipe parseShapedRecipe(ItemStack[] stacks) {
}
}
}

System.out.println("First Filter: " + recipe.getRecipeDisplay().toString());
return false;
})
.filter(recipe -> {
for (Map.Entry<Character, List<Integer>> entry : recipe.getPositionsOfItems(stacks).entrySet()) {
Character character = entry.getKey();

Function<SkyBlockItem, Boolean> extraRequirements = recipe.getExtraRequirements().get(character);
System.out.println("ExtraRequirements: " + extraRequirements.toString());
if (extraRequirements == null) {
continue;
}

for (int position : entry.getValue()) {
SkyBlockItem item = new SkyBlockItem(stacks[position]);
System.out.println("Item: " + item.toString());
if (!extraRequirements.apply(item)) {
return false;
}
//extraRequirements.apply(item);
}
}

System.out.println("Second Filter: " + recipe.getRecipeDisplay().toString());
return true;
})
.max(Comparator.comparing(recipe -> {
Expand Down

0 comments on commit a4d2918

Please sign in to comment.