aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorLinnea Gräf <roman.graef@gmail.com>2023-10-28 11:29:31 +0200
committerGitHub <noreply@github.com>2023-10-28 11:29:31 +0200
commit862ca27a37a898d6600828ebc70cca0ebf1d1db6 (patch)
tree4cb2f3003fadd91f61a583f37f61637dd7b45a9c /src/main
parentaf965ca7b13f5220d97565ee1829043d659a665f (diff)
downloadNotEnoughUpdates-862ca27a37a898d6600828ebc70cca0ebf1d1db6.tar.gz
NotEnoughUpdates-862ca27a37a898d6600828ebc70cca0ebf1d1db6.tar.bz2
NotEnoughUpdates-862ca27a37a898d6600828ebc70cca0ebf1d1db6.zip
Add rotating drops to mob loot. (#906)
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java69
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeGenerator.java2
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);