Skip to content

Commit

Permalink
remove some duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed May 24, 2024
1 parent d8986bd commit c13409c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 19 deletions.
18 changes: 0 additions & 18 deletions src/main/java/io/ix0rai/rainglow/Rainglow.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ public class Rainglow implements ModInitializer {
public static final Gson GSON = new Gson();

private static final List<RainglowColour> COLOURS = new ArrayList<>();
private static final Map<String, Identifier> GLOW_SQUID_TEXTURES = new HashMap<>();
private static final Map<String, Identifier> ALLAY_TEXTURES = new HashMap<>();
private static final Map<String, Identifier> SLIME_TEXTURES = new HashMap<>();

public static final String CUSTOM_NBT_KEY = "Colour";

Expand Down Expand Up @@ -61,9 +58,6 @@ public static void setMode(RainglowMode mode) {
LOGGER.warn("attempted to load missing mode, resetting to rainbow");
}

GLOW_SQUID_TEXTURES.clear();
ALLAY_TEXTURES.clear();
SLIME_TEXTURES.clear();
COLOURS.clear();

List<RainglowColour> colours = mode.getColours();
Expand All @@ -79,23 +73,11 @@ public static void setMode(RainglowMode mode) {
private static void addColour(RainglowColour colour) {
COLOURS.add(colour);

GLOW_SQUID_TEXTURES.put(colour.getId(), colour.getTexture(RainglowEntity.GLOW_SQUID));
ALLAY_TEXTURES.put(colour.getId(), colour.getTexture(RainglowEntity.ALLAY));
SLIME_TEXTURES.put(colour.getId(), colour.getTexture(RainglowEntity.SLIME));

if (COLOURS.size() >= 100) {
throw new RuntimeException("Too many colours registered! Only up to 99 are allowed");
}
}

public static Identifier getTexture(RainglowEntity entityType, String colour) {
return switch (entityType) {
case ALLAY -> ALLAY_TEXTURES.get(colour);
case SLIME -> SLIME_TEXTURES.get(colour);
case GLOW_SQUID -> GLOW_SQUID_TEXTURES.get(colour);
};
}

public static String generateRandomColourId(RandomGenerator random) {
return COLOURS.get(random.nextInt(COLOURS.size())).getId();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/ix0rai/rainglow/data/RainglowEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void overrideTexture(Entity entity, CallbackInfoReturnable<Identifier> ci
// if the colour is default we don't need to override the method
// this optimises a tiny bit
if (Rainglow.CONFIG.isEntityEnabled(this) && colour != this.getDefaultColour()) {
Identifier texture = Rainglow.getTexture(this, colour.getId());
Identifier texture = colour.getTexture(this);
cir.setReturnValue(texture != null ? texture : this.getDefaultTexture());
}
}
Expand Down

0 comments on commit c13409c

Please sign in to comment.