aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DefaultArmorColour.java83
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerArmorBase.java6
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java8
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt5
4 files changed, 100 insertions, 2 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DefaultArmorColour.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DefaultArmorColour.java
new file mode 100644
index 00000000..9d50e8ac
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DefaultArmorColour.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2023 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package io.github.moulberry.notenoughupdates.miscfeatures;
+
+import com.google.gson.JsonObject;
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe;
+import net.minecraft.item.ItemArmor;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.JsonToNBT;
+import net.minecraft.nbt.NBTException;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraftforge.event.world.WorldEvent;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+@NEUAutoSubscribe
+public class DefaultArmorColour {
+
+ private static Map<String, Integer> armorColourCache = new HashMap<>();
+ private static Set<String> erroredItems = new HashSet<>();
+
+ public static int getDefaultArmorColour(ItemArmor item, ItemStack stack) {
+ JsonObject itemJson = NotEnoughUpdates.INSTANCE.manager
+ .createItemResolutionQuery()
+ .withItemStack(stack)
+ .resolveToItemListJson();
+
+ if (itemJson == null) return item.getColor(stack);
+
+ String internalname = itemJson.get("internalname").getAsString();
+ if (armorColourCache.containsKey(internalname)) return armorColourCache.get(internalname);
+ if (erroredItems.contains(internalname)) return item.getColor(stack);
+
+ if (itemJson.has("nbttag")) {
+ try {
+ NBTTagCompound nbt = JsonToNBT.getTagFromJson(itemJson.get("nbttag").getAsString());
+ NBTTagCompound display;
+
+ if (nbt.hasKey("display") && (display = nbt.getCompoundTag("display")).hasKey("color")) {
+ int colour = display.getInteger("color");
+
+ if (colour != 0) {
+ armorColourCache.put(internalname, colour);
+ return colour;
+ }
+ }
+ } catch (NBTException exception) {
+ erroredItems.add(internalname);
+ System.out.println("[NEU] Ran into NBTException whilst converting Json into NBT with the JsonObject: " + itemJson);
+ exception.printStackTrace();
+ }
+ }
+
+ return item.getColor(stack);
+ }
+
+ @SubscribeEvent
+ public void onWorldChange(WorldEvent.Unload event) {
+ armorColourCache.clear();
+ }
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerArmorBase.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerArmorBase.java
index 0a5acedf..a50e5394 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerArmorBase.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerArmorBase.java
@@ -19,7 +19,9 @@
package io.github.moulberry.notenoughupdates.mixins;
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.core.ChromaColour;
+import io.github.moulberry.notenoughupdates.miscfeatures.DefaultArmorColour;
import io.github.moulberry.notenoughupdates.miscfeatures.ItemCustomizeManager;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.entity.layers.LayerArmorBase;
@@ -75,6 +77,10 @@ public abstract class MixinLayerArmorBase<T extends ModelBase> {
)
)
public int renderItem_getColor(ItemArmor item, ItemStack stack) {
+ if (NotEnoughUpdates.INSTANCE.config.misc.defaultArmorColour) {
+ return DefaultArmorColour.getDefaultArmorColour(item, stack);
+ }
+
ItemCustomizeManager.ItemData data = ItemCustomizeManager.getDataForItem(stack);
if (data != null && data.customLeatherColour != null && ItemCustomizeManager.shouldRenderLeatherColour(stack)) {
return ChromaColour.specialToChromaRGB(data.customLeatherColour);
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java
index 02630df9..10e835ba 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java
@@ -319,4 +319,12 @@ public class Misc {
)
@ConfigEditorBoolean
public boolean oldSkyBlockMenu = false;
+
+ @Expose
+ @ConfigOption(
+ name = "Default Armor Colour",
+ desc = "Changes all armor, on self and others, to the default item colour. Overwrites any /neucustomize changes also."
+ )
+ @ConfigEditorBoolean
+ public boolean defaultArmorColour = false;
}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt
index 3c45d1e1..bd566902 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt
@@ -64,8 +64,9 @@ class DevTestCommand {
"0ce87d5a-fa5f-4619-ae78-872d9c5e07fe", // ascynx
"a049a538-4dd8-43f8-87d5-03f09d48b4dc", // egirlefe
"7a9dc802-d401-4d7d-93c0-8dd1bc98c70d", // efefury
- "bb855349-dfd8-4125-a750-5fc2cf543ad5", // hannibal2
- "eaa5623c-8413-46b7-a74b-2d74a42b2841" // calmwolfs
+ "bb855349-dfd8-4125-a750-5fc2cf543ad5", // hannibal2
+ "eaa5623c-8413-46b7-a74b-2d74a42b2841", // calmwolfs
+ "e2c6f077-d45c-43ac-8322-857c7f8df3b9" // vixid
)
val SPECIAL_KICK = "SPECIAL_KICK"