Skip to content

Commit

Permalink
De-enumify MaterialIconSet + MaterialIconType (GregTechCEu#82)
Browse files Browse the repository at this point in the history
- Names are converted to the right format in the ctor
  • Loading branch information
Rongmario authored Aug 16, 2021
1 parent 826556a commit 612bc74
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public class CTItemRegistry {
@ZenMethod("registerItem")
public static void registerItem(String name, short id, int rgb, String materialIconSet, String orePrefix) {
new MetaOreDictItem.OreDictValueItem(
id, name, rgb, MaterialIconSet.valueOf(materialIconSet), OrePrefix.getPrefix(orePrefix));
id, name, rgb, MaterialIconSet.ICON_SETS.get(materialIconSet), OrePrefix.getPrefix(orePrefix));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void registerModels() {
for (short metaItem : generatedItems) {
MaterialIconSet materialIconSet = MaterialRegistry.MATERIAL_REGISTRY.getObjectById(metaItem).getMaterialIconSet();

short registrationKey = (short) (prefix.id + materialIconSet.ordinal());
short registrationKey = (short) (prefix.id + materialIconSet.id);
if (!alreadyRegistered.containsKey(registrationKey)) {
ResourceLocation resourceLocation = prefix.materialIconType.getItemModelPath(materialIconSet);
ModelBakery.registerItemVariants(this, resourceLocation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void registerModels() {
MaterialIconSet materialIconSet = metaItem.getValue().materialIconSet;
if (prefix.materialIconType == null || DISALLOWED_TYPES.contains(prefix.materialIconType))
continue;
int registrationKey = prefix.id * 1000 + materialIconSet.ordinal();
int registrationKey = prefix.id * 1000 + materialIconSet.id;
if (!alreadyRegistered.containsKey(registrationKey)) {
prefix.materialIconType.getItemModelPath(materialIconSet);
ResourceLocation resourceLocation = prefix.materialIconType.getItemModelPath(materialIconSet);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,69 @@
package gregtech.api.unification.material.info;

import com.google.common.base.Preconditions;
import crafttweaker.annotations.ZenRegister;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMethod;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

@ZenClass("mods.gregtech.material.MaterialIconSet")
@ZenRegister
public enum MaterialIconSet {

NONE,
METALLIC,
DULL,
MAGNETIC,
QUARTZ,
DIAMOND,
EMERALD,
SHINY,
SHARDS,
ROUGH,
FINE,
SAND,
FLINT,
RUBY,
LAPIS,
FLUID,
GAS,
LIGNITE,
OPAL,
GLASS,
WOOD,
LEAF,
GEM_HORIZONTAL,
GEM_VERTICAL,
PAPER,
NETHERSTAR,
BRIGHT;
public class MaterialIconSet {

public static final Map<String, MaterialIconSet> ICON_SETS = new HashMap<>();

static int idCounter = 0;

public static final MaterialIconSet NONE = new MaterialIconSet("NONE");
public static final MaterialIconSet METALLIC = new MaterialIconSet("METALLIC");
public static final MaterialIconSet DULL = new MaterialIconSet("DULL");
public static final MaterialIconSet MAGNETIC = new MaterialIconSet("MAGNETIC");
public static final MaterialIconSet QUARTZ = new MaterialIconSet("QUARTZ");
public static final MaterialIconSet DIAMOND = new MaterialIconSet("DIAMOND");
public static final MaterialIconSet EMERALD = new MaterialIconSet("EMERALD");
public static final MaterialIconSet SHINY = new MaterialIconSet("SHINY");
public static final MaterialIconSet SHARDS = new MaterialIconSet("SHARDS");
public static final MaterialIconSet ROUGH = new MaterialIconSet("ROUGH");
public static final MaterialIconSet FINE = new MaterialIconSet("FINE");
public static final MaterialIconSet SAND = new MaterialIconSet("SAND");
public static final MaterialIconSet FLINT = new MaterialIconSet("FLINT");
public static final MaterialIconSet RUBY = new MaterialIconSet("RUBY");
public static final MaterialIconSet LAPIS = new MaterialIconSet("LAPIS");
public static final MaterialIconSet FLUID = new MaterialIconSet("FLUID");
public static final MaterialIconSet GAS = new MaterialIconSet("GAS");
public static final MaterialIconSet LIGNITE = new MaterialIconSet("LIGNITE");
public static final MaterialIconSet OPAL = new MaterialIconSet("OPAL");
public static final MaterialIconSet GLASS = new MaterialIconSet("GLASS");
public static final MaterialIconSet WOOD = new MaterialIconSet("WOOD");
public static final MaterialIconSet LEAF = new MaterialIconSet("LEAF");
public static final MaterialIconSet GEM_HORIZONTAL = new MaterialIconSet("GEM_HORIZONTAL");
public static final MaterialIconSet GEM_VERTICAL = new MaterialIconSet("GEM_VERTICAL");
public static final MaterialIconSet PAPER = new MaterialIconSet("PAPER");
public static final MaterialIconSet NETHERSTAR = new MaterialIconSet("NETHERSTAR");
public static final MaterialIconSet BRIGHT = new MaterialIconSet("BRIGHT");

public final String name;
public final int id;

public MaterialIconSet(String name) {
this.name = name.toLowerCase(Locale.ROOT);
Preconditions.checkArgument(!ICON_SETS.containsKey(this.name), "MaterialIconSet " + this.name + " already registered!");
this.id = idCounter++;
ICON_SETS.put(this.name, this);
}

@ZenGetter("name")
public String getName() {
return name().toLowerCase();
return name;
}

@ZenMethod("get")
public static MaterialIconSet getByName(String name) {
return valueOf(name.toUpperCase());
return ICON_SETS.get(name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,135 +1,145 @@
package gregtech.api.unification.material.info;

import com.google.common.base.CaseFormat;
import com.google.common.collect.ImmutableMap;
import com.google.common.base.Preconditions;
import gregtech.api.GTValues;
import net.minecraft.util.ResourceLocation;

public enum MaterialIconType {

//ITEM TEXTURES
dustTiny,
dustSmall,
dust,
dustImpure,
dustPure,
crushed,
crushedPurified,
crushedCentrifuged,
gem,
nugget,
ingot,
ingotHot,
ingotDouble,
ingotTriple,
ingotQuadruple,
ingotQuintuple,
plate,
plateDouble,
plateTriple,
plateQuadruple,
plateQuintuple,
plateDense,
stick,
lens,
round,
bolt,
screw,
ring,
cell,
cellPlasma,
toolHeadSword,
toolHeadPickaxe,
toolHeadShovel,
toolHeadAxe,
toolHeadHoe,
toolHeadHammer,
toolHeadFile,
toolHeadSaw,
toolHeadBuzzSaw,
toolHeadDrill,
toolHeadChainsaw,
toolHeadSense,
toolHeadArrow,
toolHeadScrewdriver,
toolHeadBuzSaw,
toolHeadSoldering,
toolHeadWrench,
toolHeadUniversalSpade,
wireFine,
gearSmall,
rotor,
stickLong,
springSmall,
spring,
arrow,
gemChipped,
gemFlawed,
gemFlawless,
gemExquisite,
gear,
foil,
crateGtDust,
crateGtIngot,
crateGtGem,
crateGtPlate,
turbineBlade,
handleMallet,
toolHeadMallet,
plateCurved,
coke,

//BLOCK TEXTURES
block,
fluid,
foilBlock, //todo unused
wire, //todo unused
ore,
frameGt,
pipeSide, //todo unused
pipeTiny,
pipeSmall,
pipeMedium,
pipeLarge,
pipeHuge,
pipeQuadruple,
pipeNonuple,

//USED FOR GREGIFICATION ADDON
oreChunk,
oreEnderChunk,
oreNetherChunk,
oreSandyChunk,
seed,
crop,
essence;

public static final ImmutableMap<String, MaterialIconType> values;

static {
ImmutableMap.Builder<String, MaterialIconType> builder = ImmutableMap.builder();
for (MaterialIconType value : values()) {
builder.put(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, value.name()), value);
}
values = builder.build();
import java.util.HashMap;
import java.util.Map;

public class MaterialIconType {

public static final Map<String, MaterialIconType> ICON_TYPES = new HashMap<>();

static int idCounter = 0;

public static final MaterialIconType dustTiny = new MaterialIconType("dustTiny");
public static final MaterialIconType dustSmall = new MaterialIconType("dustSmall");
public static final MaterialIconType dust = new MaterialIconType("dust");
public static final MaterialIconType dustImpure = new MaterialIconType("dustImpure");
public static final MaterialIconType dustPure = new MaterialIconType("dustPure");

public static final MaterialIconType crushed = new MaterialIconType("crushed");
public static final MaterialIconType crushedPurified = new MaterialIconType("crushedPurified");
public static final MaterialIconType crushedCentrifuged = new MaterialIconType("crushedCentrifuged");

public static final MaterialIconType gem = new MaterialIconType("gem");
public static final MaterialIconType gemChipped = new MaterialIconType("gemChipped");
public static final MaterialIconType gemFlawed = new MaterialIconType("gemFlawed");
public static final MaterialIconType gemFlawless = new MaterialIconType("gemFlawless");
public static final MaterialIconType gemExquisite = new MaterialIconType("gemExquisite");

public static final MaterialIconType nugget = new MaterialIconType("nugget");

public static final MaterialIconType ingot = new MaterialIconType("ingot");
public static final MaterialIconType ingotHot = new MaterialIconType("ingotHot");
public static final MaterialIconType ingotDouble = new MaterialIconType("ingotDouble");
public static final MaterialIconType ingotTriple = new MaterialIconType("ingotTriple");
public static final MaterialIconType ingotQuadruple = new MaterialIconType("ingotQuadruple");
public static final MaterialIconType ingotQuintuple = new MaterialIconType("ingotQuintuple");

public static final MaterialIconType plate = new MaterialIconType("plate");
public static final MaterialIconType plateDouble = new MaterialIconType("plateDouble");
public static final MaterialIconType plateTriple = new MaterialIconType("plateTriple");
public static final MaterialIconType plateQuadruple = new MaterialIconType("plateQuadruple");
public static final MaterialIconType plateQuintuple = new MaterialIconType("plateQuintuple");
public static final MaterialIconType plateDense = new MaterialIconType("plateDense");

public static final MaterialIconType stick = new MaterialIconType("stick");
public static final MaterialIconType lens = new MaterialIconType("lens");
public static final MaterialIconType round = new MaterialIconType("round");
public static final MaterialIconType bolt = new MaterialIconType("bolt");
public static final MaterialIconType screw = new MaterialIconType("screw");
public static final MaterialIconType ring = new MaterialIconType("ring");
public static final MaterialIconType wireFine = new MaterialIconType("wireFine");
public static final MaterialIconType gearSmall = new MaterialIconType("gearSmall");
public static final MaterialIconType rotor = new MaterialIconType("rotor");
public static final MaterialIconType stickLong = new MaterialIconType("stickLong");
public static final MaterialIconType springSmall = new MaterialIconType("springSmall");
public static final MaterialIconType spring = new MaterialIconType("spring");
public static final MaterialIconType arrow = new MaterialIconType("arrow");
public static final MaterialIconType gear = new MaterialIconType("gear");
public static final MaterialIconType foil = new MaterialIconType("foil");

public static final MaterialIconType cell = new MaterialIconType("cell");
public static final MaterialIconType cellPlasma = new MaterialIconType("cellPlasma");

public static final MaterialIconType toolHeadSword = new MaterialIconType("toolHeadSword");
public static final MaterialIconType toolHeadPickaxe = new MaterialIconType("toolHeadPickaxe");
public static final MaterialIconType toolHeadShovel = new MaterialIconType("toolHeadShovel");
public static final MaterialIconType toolHeadAxe = new MaterialIconType("toolHeadAxe");
public static final MaterialIconType toolHeadHoe = new MaterialIconType("toolHeadHoe");
public static final MaterialIconType toolHeadHammer = new MaterialIconType("toolHeadHammer");
public static final MaterialIconType toolHeadFile = new MaterialIconType("toolHeadFile");
public static final MaterialIconType toolHeadSaw = new MaterialIconType("toolHeadSaw");
public static final MaterialIconType toolHeadBuzzSaw = new MaterialIconType("toolHeadBuzzSaw");
public static final MaterialIconType toolHeadDrill = new MaterialIconType("toolHeadDrill");
public static final MaterialIconType toolHeadChainsaw = new MaterialIconType("toolHeadChainsaw");
public static final MaterialIconType toolHeadSense = new MaterialIconType("toolHeadSense");
public static final MaterialIconType toolHeadArrow = new MaterialIconType("toolHeadArrow");
public static final MaterialIconType toolHeadScrewdriver = new MaterialIconType("toolHeadScrewdriver");
public static final MaterialIconType toolHeadSoldering = new MaterialIconType("toolHeadSoldering");
public static final MaterialIconType toolHeadWrench = new MaterialIconType("toolHeadWrench");
public static final MaterialIconType toolHeadUniversalSpade = new MaterialIconType("toolHeadUniversalSpade");

public static final MaterialIconType crateGtDust = new MaterialIconType("crateGtDust");
public static final MaterialIconType crateGtIngot = new MaterialIconType("crateGtIngot");
public static final MaterialIconType crateGtGem = new MaterialIconType("crateGtGem");
public static final MaterialIconType crateGtPlate = new MaterialIconType("crateGtPlate");

public static final MaterialIconType turbineBlade = new MaterialIconType("turbineBlade");
public static final MaterialIconType handleMallet = new MaterialIconType("handleMallet");
public static final MaterialIconType toolHeadMallet = new MaterialIconType("toolHeadMallet");
public static final MaterialIconType plateCurved = new MaterialIconType("plateCurved");
public static final MaterialIconType coke = new MaterialIconType("coke");

// BLOCK TEXTURES
public static final MaterialIconType block = new MaterialIconType("block");
public static final MaterialIconType fluid = new MaterialIconType("fluid");
public static final MaterialIconType foilBlock = new MaterialIconType("foilBlock");
public static final MaterialIconType wire = new MaterialIconType("wire"); // TODO unused
public static final MaterialIconType ore = new MaterialIconType("ore");
public static final MaterialIconType frameGt = new MaterialIconType("frameGt");

public static final MaterialIconType pipeSide = new MaterialIconType("pipeSide"); // TODO unused
public static final MaterialIconType pipeTiny = new MaterialIconType("pipeTiny");
public static final MaterialIconType pipeSmall = new MaterialIconType("pipeSmall");
public static final MaterialIconType pipeMedium = new MaterialIconType("pipeMedium");
public static final MaterialIconType pipeLarge = new MaterialIconType("pipeLarge");
public static final MaterialIconType pipeHuge = new MaterialIconType("pipeHuge");
public static final MaterialIconType pipeQuadruple = new MaterialIconType("pipeQuadruple");
public static final MaterialIconType pipeNonuple = new MaterialIconType("pipeNonuple");

// USED FOR GREGIFICATION ADDON
public static final MaterialIconType oreChunk = new MaterialIconType("oreChunk");
public static final MaterialIconType oreEnderChunk = new MaterialIconType("oreEnderChunk");
public static final MaterialIconType oreNetherChunk = new MaterialIconType("oreNetherChunk");
public static final MaterialIconType oreSandyChunk = new MaterialIconType("oreSandyChunk");
public static final MaterialIconType seed = new MaterialIconType("seed");
public static final MaterialIconType crop = new MaterialIconType("crop");
public static final MaterialIconType essence = new MaterialIconType("essence");

public final String name;
public final int id;

public MaterialIconType(String name) {
this.name = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name);
Preconditions.checkArgument(!ICON_TYPES.containsKey(this.name), "MaterialIconType " + this.name + " already registered!");
this.id = idCounter++;
ICON_TYPES.put(this.name, this);
}

public ResourceLocation getBlockPath(MaterialIconSet materialIconSet) {
String iconSet = materialIconSet.name().toLowerCase();
String iconType = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name());
return new ResourceLocation(GTValues.MODID, "blocks/material_sets/" + iconSet + "/" + iconType);
return new ResourceLocation(GTValues.MODID, "blocks/material_sets/" + materialIconSet.name + "/" + this.name);
}

public ResourceLocation getItemModelPath(MaterialIconSet materialIconSet) {
String iconSet = materialIconSet.name().toLowerCase();
String iconType = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name());
return new ResourceLocation(GTValues.MODID, "material_sets/" + iconSet + "/" + iconType);
return new ResourceLocation(GTValues.MODID, "material_sets/" + materialIconSet.name + "/" + this.name);
}

public ResourceLocation getItemOverlayPath(MaterialIconSet materialIconSet) {
String iconSet = materialIconSet.name().toLowerCase();
String iconType = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name());
return new ResourceLocation(GTValues.MODID, "material_sets/" + iconSet + "/" + iconType + "_overlay");
return new ResourceLocation(GTValues.MODID, "material_sets/" + materialIconSet.name + "/" + this.name + "_overlay");
}

}

0 comments on commit 612bc74

Please sign in to comment.