Skip to content

Commit

Permalink
Improve a few modifier icons
Browse files Browse the repository at this point in the history
Modifier icons now support two layer icons to make it easier to reuse vanilla icons without having two things look the same in JEI
  • Loading branch information
KnightMiner committed Oct 3, 2022
1 parent 3ade0bd commit 4fc2e84
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package slimeknights.tconstruct.library.client.modifiers;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import com.mojang.blaze3d.vertex.PoseStack;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
Expand All @@ -28,6 +30,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Consumer;

/**
* Class handling the loading of modifier UI icons
Expand All @@ -45,7 +48,7 @@ public class ModifierIconManager implements IEarlySafeManagerReloadListener {
public static final ModifierIconManager INSTANCE = new ModifierIconManager();

/** Map of icons for each modifier */
private static Map<ModifierId,ResourceLocation> modifierIcons = Collections.emptyMap();
private static Map<ModifierId,List<ResourceLocation>> modifierIcons = Collections.emptyMap();

/**
* Initializes this manager, registering it relevant event busses
Expand All @@ -64,7 +67,8 @@ private static void onResourceManagerRegister(RegisterClientReloadListenersEvent
/** Called on texture stitch to add the new textures */
private static void textureStitch(TextureStitchEvent.Pre event) {
if (event.getAtlas().location().equals(InventoryMenu.BLOCK_ATLAS)) {
modifierIcons.values().forEach(event::addSprite);
Consumer<ResourceLocation> spriteAdder = event::addSprite;
modifierIcons.values().forEach(list -> list.forEach(spriteAdder));
event.addSprite(DEFAULT_COVER);
event.addSprite(DEFAULT_PAGES);
}
Expand All @@ -73,7 +77,7 @@ private static void textureStitch(TextureStitchEvent.Pre event) {
@Override
public void onReloadSafe(ResourceManager manager) {
// start building the model map
Map<ModifierId,ResourceLocation> icons = new HashMap<>();
Map<ModifierId,List<ResourceLocation>> icons = new HashMap<>();

// get a list of files from all namespaces
List<JsonObject> jsonFiles = JsonHelper.getFileInAllDomainsAndPacks(manager, ICONS, null);
Expand All @@ -93,11 +97,19 @@ public void onReloadSafe(ResourceManager manager) {
JsonElement element = entry.getValue();
if (element.isJsonNull()) {
icons.remove(name);
} else if (element.isJsonArray()) {
// list of paths, renders one after another
JsonArray array = element.getAsJsonArray();
try {
icons.put(name, JsonHelper.parseList(array, key, JsonHelper::convertToResourceLocation));
} catch (JsonSyntaxException e) {
log.error("Skipping invalid modifier " + key + " due to error parsing path list: ", e);
}
} else if (element.isJsonPrimitive()) {
// primitive means texture path
ResourceLocation path = ResourceLocation.tryParse(element.getAsString());
if (path != null) {
icons.put(name, path);
icons.put(name, Collections.singletonList(path));
} else {
log.error("Skipping invalid modifier " + key + " as the path is invalid");
}
Expand All @@ -124,9 +136,11 @@ public static void renderIcon(PoseStack matrices, Modifier modifier, int x, int
RenderUtils.setup(InventoryMenu.BLOCK_ATLAS);
TextureAtlas atlas = Minecraft.getInstance().getModelManager().getAtlas(InventoryMenu.BLOCK_ATLAS);

ResourceLocation icon = modifierIcons.get(modifier.getId());
if (icon != null) {
Screen.blit(matrices, x, y, z, size, size, atlas.getSprite(icon));
List<ResourceLocation> icons = modifierIcons.getOrDefault(modifier.getId(), Collections.emptyList());
if (!icons.isEmpty()) {
for (ResourceLocation icon : icons) {
Screen.blit(matrices, x, y, z, size, size, atlas.getSprite(icon));
}
} else {
Screen.blit(matrices, x, y, z, size, size, atlas.getSprite(DEFAULT_PAGES));
RenderUtils.setColorRGBA(0xFF000000 | modifier.getColor());
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 29 additions & 28 deletions src/main/resources/assets/tconstruct/tinkering/modifier_icons.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
{
"tconstruct:reinforced": "tconstruct:item/materials/reinforcement/iron",
"tconstruct:unbreakable": "tconstruct:gui/modifiers/unbreakable",
"tconstruct:emerald": "minecraft:item/emerald",
"tconstruct:diamond": "minecraft:item/diamond",
"tconstruct:netherite": "minecraft:item/netherite_ingot",
"tconstruct:overforced": "tconstruct:item/materials/reinforcement/slimesteel",
"tconstruct:overslime": "minecraft:item/slime_ball",
"tconstruct:soulbound": "minecraft:item/totem_of_undying",
"tconstruct:worldbound": "minecraft:item/netherite_scrap",
"tconstruct:reinforced": ["tconstruct:item/materials/reinforcement/iron", "tconstruct:gui/modifiers/book"],
"tconstruct:unbreakable": ["tconstruct:gui/modifiers/unbreakable", "tconstruct:gui/modifiers/book"],
"tconstruct:overforced": ["tconstruct:item/materials/reinforcement/slimesteel", "tconstruct:gui/modifiers/book"],
"tconstruct:overslime": ["minecraft:item/slime_ball", "tconstruct:gui/modifiers/book"],
"tconstruct:soulbound": ["minecraft:item/totem_of_undying", "tconstruct:gui/modifiers/book"],
"tconstruct:tank": "tconstruct:gui/modifiers/tank",

"tconstruct:emerald": ["minecraft:item/emerald", "tconstruct:gui/modifiers/tier"],
"tconstruct:diamond": ["minecraft:item/diamond", "tconstruct:gui/modifiers/tier"],
"tconstruct:netherite": ["minecraft:item/netherite_ingot", "tconstruct:gui/modifiers/tier"],
"tconstruct:worldbound": ["minecraft:item/netherite_scrap", "tconstruct:gui/modifiers/tier"],

"tconstruct:autosmelt": "tconstruct:gui/modifiers/harvest/autosmelt",
"tconstruct:fortune": "tconstruct:gui/modifiers/luck",
"tconstruct:looting": "tconstruct:gui/modifiers/luck",
"tconstruct:luck": "tconstruct:gui/modifiers/luck",
"tconstruct:melting": "tconstruct:gui/modifiers/harvest/melting",
"tconstruct:silky": "tconstruct:item/materials/silky_cloth",
"tconstruct:silky": ["tconstruct:item/materials/silky_cloth", "tconstruct:gui/modifiers/book"],

"tconstruct:bucketing": "minecraft:item/bucket",
"tconstruct:firestarter": "minecraft:item/flint_and_steel",
"tconstruct:fireprimer": "minecraft:item/fire_charge",
"tconstruct:bucketing": ["minecraft:item/bucket", "tconstruct:gui/modifiers/book"],
"tconstruct:firestarter": ["minecraft:item/flint_and_steel", "tconstruct:gui/modifiers/book"],
"tconstruct:fireprimer": ["minecraft:item/fire_charge", "tconstruct:gui/modifiers/book"],
"tconstruct:glowing": "tconstruct:gui/modifiers/glowing",
"tconstruct:pathing": "minecraft:item/iron_shovel",
"tconstruct:stripping": "minecraft:item/iron_axe",
"tconstruct:tilling": "minecraft:item/iron_hoe",
"tconstruct:pathing": "tconstruct:gui/modifiers/held/pathing",
"tconstruct:stripping": "tconstruct:gui/modifiers/held/stripping",
"tconstruct:tilling": "tconstruct:gui/modifiers/held/tilling",

"tconstruct:exchanging": "tconstruct:gui/modifiers/harvest/exchanging",
"tconstruct:expanded": "tconstruct:gui/modifiers/harvest/expanded",
Expand All @@ -45,7 +46,7 @@

"tconstruct:dual_wielding": "tconstruct:gui/modifiers/melee/dual_wielding",
"tconstruct:fiery": "tconstruct:gui/modifiers/melee/fiery",
"tconstruct:experienced": "minecraft:item/experience_bottle",
"tconstruct:experienced": ["minecraft:item/experience_bottle", "tconstruct:gui/modifiers/book"],
"tconstruct:knockback": "tconstruct:gui/modifiers/melee/knockback",
"tconstruct:knockback_armor": "tconstruct:gui/modifiers/melee/knockback",
"tconstruct:necrotic": "tconstruct:gui/modifiers/melee/necrotic",
Expand All @@ -71,11 +72,11 @@
"tconstruct:sticky": "tconstruct:gui/modifiers/armor/sticky",
"tconstruct:thorns": "tconstruct:gui/modifiers/armor/thorns",

"tconstruct:aqua_affinity": "minecraft:item/heart_of_the_sea",
"tconstruct:item_frame": "minecraft:item/item_frame",
"tconstruct:aqua_affinity": ["minecraft:item/heart_of_the_sea", "tconstruct:gui/modifiers/book"],
"tconstruct:item_frame": ["minecraft:item/item_frame", "tconstruct:gui/modifiers/book"],
"tconstruct:respiration": "tconstruct:gui/modifiers/armor/respiration",
"tconstruct:slurping": "tconstruct:gui/modifiers/armor/slurping",
"tconstruct:zoom": "minecraft:item/spyglass",
"tconstruct:zoom": ["minecraft:item/spyglass", "tconstruct:gui/modifiers/book"],

"tconstruct:reach": "tconstruct:gui/modifiers/armor/reach",
"tconstruct:strength": "tconstruct:gui/modifiers/armor/strength",
Expand All @@ -100,13 +101,13 @@
"tconstruct:snowdrift": "tconstruct:gui/modifiers/armor/snowdrift",
"tconstruct:soulspeed": "tconstruct:gui/modifiers/armor/soulspeed",

"tconstruct:gilded": "minecraft:item/golden_apple",
"tconstruct:writable": "minecraft:item/writable_book",
"tconstruct:harmonious": "minecraft:item/music_disc_13",
"tconstruct:recapitated": "tconstruct:gui/modifiers/recapitated",
"tconstruct:resurrected": "minecraft:item/end_crystal",
"tconstruct:draconic": "tconstruct:gui/modifiers/draconic",
"tconstruct:gilded": ["minecraft:item/golden_apple", "tconstruct:gui/modifiers/plus"],
"tconstruct:writable": ["minecraft:item/writable_book", "tconstruct:gui/modifiers/plus"],
"tconstruct:harmonious": ["minecraft:item/music_disc_13", "tconstruct:gui/modifiers/plus"],
"tconstruct:recapitated": ["tconstruct:gui/modifiers/recapitated", "tconstruct:gui/modifiers/plus"],
"tconstruct:resurrected": ["minecraft:item/end_crystal", "tconstruct:gui/modifiers/plus"],
"tconstruct:draconic": ["tconstruct:gui/modifiers/draconic", "tconstruct:gui/modifiers/plus"],

"tconstruct:golden": "minecraft:item/golden_chestplate",
"tconstruct:dyed": "minecraft:item/green_dye"
"tconstruct:golden": ["minecraft:item/golden_chestplate", "tconstruct:gui/modifiers/book"],
"tconstruct:dyed": ["minecraft:item/green_dye", "tconstruct:gui/modifiers/book"]
}

0 comments on commit 4fc2e84

Please sign in to comment.