diff options
author | nea <nea@nea.moe> | 2023-10-27 00:56:49 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-10-27 01:02:50 +0200 |
commit | f7fb7c4c8af875196a8fd70a51c486ce16bbc8e9 (patch) | |
tree | 6af2e187d72498b02f822bd2038531a691324fb2 | |
parent | d0777258570d0f70239352fdaa625b25dc5a2b45 (diff) | |
download | NotEnoughUpdates-f7fb7c4c8af875196a8fd70a51c486ce16bbc8e9.tar.gz NotEnoughUpdates-f7fb7c4c8af875196a8fd70a51c486ce16bbc8e9.tar.bz2 NotEnoughUpdates-f7fb7c4c8af875196a8fd70a51c486ce16bbc8e9.zip |
Add rotating drops to mob loot.janitheaccuser
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java | 69 | ||||
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeGenerator.java | 2 |
2 files changed, 46 insertions, 25 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java index 41bfe443..97ab2a5f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java @@ -34,6 +34,7 @@ import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; import java.util.ArrayList; import java.util.Collections; @@ -41,6 +42,7 @@ import java.util.List; import java.util.Set; import java.util.function.BiConsumer; import java.util.stream.Collectors; +import java.util.stream.Stream; public class MobLootRecipe implements NeuRecipe { @@ -50,31 +52,41 @@ public class MobLootRecipe implements NeuRecipe { public static class MobDrop { public final Ingredient drop; public final String chance; + public final List<MobDrop> alternatives; public final List<String> extra; private ItemStack itemStack; - public MobDrop(Ingredient drop, String chance, List<String> extra) { + private int lastHoveredIndex = 0; + + public MobDrop(Ingredient drop, String chance, List<String> extra, List<MobDrop> alternatives) { this.drop = drop; this.chance = chance; this.extra = extra; + this.alternatives = alternatives; } public ItemStack getItemStack() { - if (itemStack == null) { - itemStack = drop.getItemStack().copy(); - List<String> arrayList = new ArrayList<>(extra); - arrayList.add("§r§e§lDrop Chance: §6" + formatDropChance()); - ItemUtils.appendLore(itemStack, arrayList); + if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { + lastHoveredIndex = (int) ((System.currentTimeMillis() / 2000) % (alternatives.size() + 1)); + } + if (lastHoveredIndex == alternatives.size()) { + if (itemStack == null) { + itemStack = drop.getItemStack().copy(); + List<String> arrayList = new ArrayList<>(extra); + arrayList.add("§r§e§lDrop Chance: §6" + formatDropChance()); + ItemUtils.appendLore(itemStack, arrayList); + } + return itemStack; } - return itemStack; + return alternatives.get(lastHoveredIndex).getItemStack(); } private String formatDropChance() { if (chance == null) { return ""; } - + if (!chance.endsWith("%")) { return chance; } @@ -187,7 +199,10 @@ public class MobLootRecipe implements NeuRecipe { @Override public Set<Ingredient> getOutputs() { - return drops.stream().map(it -> it.drop).collect(Collectors.toSet()); + return drops + .stream() + .flatMap(it -> Stream.concat(Stream.of(it.drop), it.alternatives.stream().map(that -> that.drop))) + .collect(Collectors.toSet()); } @Override @@ -311,25 +326,31 @@ public class MobLootRecipe implements NeuRecipe { return BACKGROUND; } - public static MobLootRecipe parseRecipe(NEUManager manager, JsonObject recipe, JsonObject outputItemJson) { - List<MobDrop> drops = new ArrayList<>(); - for (JsonElement jsonElement : recipe.getAsJsonArray("drops")) { - if (jsonElement.isJsonPrimitive()) { - drops.add(new MobDrop(new Ingredient(manager, jsonElement.getAsString()), null, Collections.emptyList())); - } else { - JsonObject jsonObject = jsonElement.getAsJsonObject(); - drops.add( - new MobDrop( - new Ingredient(manager, jsonObject.get("id").getAsString()), - jsonObject.has("chance") ? jsonObject.get("chance").getAsString() : null, - JsonUtils.getJsonArrayOrEmpty(jsonObject, "extra", JsonElement::getAsString) - )); - } + private static MobDrop parseMobDrop(NEUManager manager, JsonElement jsonElement) { + if (jsonElement.isJsonPrimitive()) { + return (new MobDrop( + new Ingredient(manager, jsonElement.getAsString()), + null, + Collections.emptyList(), + Collections.emptyList() + )); + } else { + JsonObject jsonObject = jsonElement.getAsJsonObject(); + return ( + new MobDrop( + new Ingredient(manager, jsonObject.get("id").getAsString()), + jsonObject.has("chance") ? jsonObject.get("chance").getAsString() : null, + JsonUtils.getJsonArrayOrEmpty(jsonObject, "extra", JsonElement::getAsString), + JsonUtils.getJsonArrayOrEmpty(jsonObject, "alternatives", element -> parseMobDrop(manager, element)) + )); } + } + + public static MobLootRecipe parseRecipe(NEUManager manager, JsonObject recipe, JsonObject outputItemJson) { return new MobLootRecipe( new Ingredient(manager, outputItemJson.get("internalname").getAsString(), 1), - drops, + JsonUtils.getJsonArrayOrEmpty(recipe, "drops", element -> parseMobDrop(manager, element)), recipe.has("level") ? recipe.get("level").getAsInt() : 0, recipe.has("coins") ? recipe.get("coins").getAsInt() : 0, recipe.has("xp") ? recipe.get("xp").getAsInt() : 0, diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeGenerator.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeGenerator.java index 54daf42d..e8b03a1a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeGenerator.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeGenerator.java @@ -189,7 +189,7 @@ public class RecipeGenerator { String chance = loreMatcher.group("dropChances") != null ? loreMatcher.group("dropChances") : loreMatcher.group("dropCount"); - drops.add(new MobLootRecipe.MobDrop(item, chance, new ArrayList<>())); + drops.add(new MobLootRecipe.MobDrop(item, chance, new ArrayList<>(), Collections.emptyList())); } if (loreMatcher.group("missing") != null) { Utils.addChatMessage("[WARNING] You are missing Bestiary levels for drop: " + loreLine); |