Skip to content

Commit 50dc6c7

Browse files
committed
default staff color stuff
1 parent 485be79 commit 50dc6c7

File tree

5 files changed

+87
-0
lines changed

5 files changed

+87
-0
lines changed

common/src/main/java/com/samsthenerd/hexgloop/HexGloopClient.java

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.samsthenerd.hexgloop.items.ItemLibraryCard;
2727
import com.samsthenerd.hexgloop.items.ItemSlateLoader;
2828
import com.samsthenerd.hexgloop.keybinds.HexGloopKeybinds;
29+
import com.samsthenerd.hexgloop.misc.StaffColorLoader;
2930
import com.samsthenerd.hexgloop.misc.clientgreatbook.GreatBook;
3031
import com.samsthenerd.hexgloop.network.HexGloopNetwork;
3132
import com.samsthenerd.hexgloop.network.ServerSideCheckClient;
@@ -94,6 +95,7 @@ public static void onInitializeClient() {
9495
registerModelPredicates();
9596
registerColorProviders();
9697
registerScryingDisplayers();
98+
StaffColorLoader.init();
9799
HexGloopKeybinds.registerKeybinds();
98100

99101
ServerSideCheckClient.registerDisconnectUpdate();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.samsthenerd.hexgloop.misc;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import com.google.gson.Gson;
7+
import com.google.gson.GsonBuilder;
8+
import com.google.gson.JsonElement;
9+
import com.google.gson.JsonObject;
10+
import com.google.gson.JsonPrimitive;
11+
import com.samsthenerd.hexgloop.HexGloop;
12+
13+
import dev.architectury.registry.ReloadListenerRegistry;
14+
import net.minecraft.resource.JsonDataLoader;
15+
import net.minecraft.resource.ResourceManager;
16+
import net.minecraft.resource.ResourceType;
17+
import net.minecraft.util.Identifier;
18+
import net.minecraft.util.profiler.Profiler;
19+
20+
public class StaffColorLoader extends JsonDataLoader{
21+
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
22+
23+
public static final Map<Identifier, Integer> STAFF_COLORS = new HashMap<>();
24+
25+
public StaffColorLoader() {
26+
super(GSON, "staffcolors");
27+
}
28+
29+
protected void apply(Map<Identifier, JsonElement> map, ResourceManager resourceManager, Profiler profiler) {
30+
STAFF_COLORS.clear(); // maybe ?
31+
for(Map.Entry<Identifier, JsonElement> entry : map.entrySet()){
32+
Identifier id = entry.getKey();
33+
JsonObject obj = entry.getValue().getAsJsonObject();
34+
for(Map.Entry<String, JsonElement> staff_entry : obj.entrySet()){
35+
JsonPrimitive colorVal = staff_entry.getValue().getAsJsonPrimitive();
36+
int color = 0;
37+
if(colorVal.isNumber()){
38+
color = colorVal.getAsInt();
39+
} else if(colorVal.isString()) {
40+
String colorStr = colorVal.getAsString();
41+
colorStr = colorStr.replace("#", "");
42+
try {
43+
color = Integer.parseInt(colorStr, 16);
44+
} catch (NumberFormatException e) {
45+
HexGloop.LOGGER.error("Invalid color value for staff color: " + staff_entry.getKey() + " in " + id.toString());
46+
continue;
47+
}
48+
} else {
49+
HexGloop.LOGGER.error("Invalid color value for staff color: " + staff_entry.getKey() + " in " + id.toString());
50+
continue;
51+
}
52+
53+
STAFF_COLORS.put(new Identifier(staff_entry.getKey()), color);
54+
}
55+
}
56+
}
57+
58+
// register the event(s)
59+
public static void init(){
60+
ReloadListenerRegistry.register(ResourceType.CLIENT_RESOURCES, new StaffColorLoader());
61+
}
62+
}

common/src/main/java/com/samsthenerd/hexgloop/mixins/dyeablestaffs/MixinInjectDyeableStaff.java

+9
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
import org.spongepowered.asm.mixin.Mixin;
44

5+
import com.samsthenerd.hexgloop.misc.StaffColorLoader;
6+
57
import at.petrak.hexcasting.common.items.ItemStaff;
68
import net.minecraft.item.DyeableItem;
79
import net.minecraft.item.ItemStack;
810
import net.minecraft.nbt.NbtCompound;
911
import net.minecraft.nbt.NbtElement;
12+
import net.minecraft.util.Identifier;
13+
import net.minecraft.util.registry.Registry;
1014

1115
@Mixin(ItemStaff.class)
1216
public class MixinInjectDyeableStaff implements DyeableItem{
@@ -16,6 +20,11 @@ public int getColor(ItemStack stack) {
1620
if (nbtCompound != null && nbtCompound.contains(COLOR_KEY, NbtElement.NUMBER_TYPE)) {
1721
return nbtCompound.getInt(COLOR_KEY);
1822
}
23+
Identifier stackId = Registry.ITEM.getId(stack.getItem());
24+
Integer color = StaffColorLoader.STAFF_COLORS.get(stackId);
25+
if(color != null){
26+
return color;
27+
}
1928
return 0xff7e4f;
2029
}
2130
}

devdocs/datapacks.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Datapacks

devdocs/staves.md

+13
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,17 @@ Since addons/resource packs may want to support the dyeable staves when gloop is
5252
"layer1": "mymod:item/mystaff_dyepart_casting" // part of the texture to be dyed
5353
}
5454
}
55+
```
56+
57+
## Default staff color
58+
59+
In v0.2.1 and up you can define the default color for the dyeable bit of an undyed staff using resource packs. By default this is a leather-y color to match the original textures.
60+
61+
### .../mymod/staffcolors/whatever.json :
62+
63+
```json
64+
{
65+
"mymod:mystaff": "#69eb96", // hex code
66+
"mymod:myotherstaff": 2523373 // raw integer value
67+
}
5568
```

0 commit comments

Comments
 (0)