Skip to content

Commit

Permalink
Deprecase parseColor in JsonHelper and migrate usages to IntLoadable
Browse files Browse the repository at this point in the history
Just more flexible and more clear with the two color types
  • Loading branch information
KnightMiner committed Mar 28, 2024
1 parent caf9e33 commit abf5ae7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
Expand Up @@ -30,6 +30,7 @@
import net.minecraftforge.client.model.geometry.IGeometryBakingContext;
import net.minecraftforge.client.model.geometry.IGeometryLoader;
import slimeknights.mantle.Mantle;
import slimeknights.mantle.data.loadable.common.ColorLoadable;
import slimeknights.mantle.util.JsonHelper;
import slimeknights.mantle.util.LogicHelper;

Expand Down Expand Up @@ -162,7 +163,7 @@ public boolean isUvLock(boolean defaultLock) {
* Parses the color data from JSON
*/
public static ColorData fromJson(JsonObject json) {
int color = JsonHelper.parseColor(GsonHelper.getAsString(json, "color", ""));
int color = ColorLoadable.ALPHA.getOrDefault(json, "color", -1);
int luminosity = GsonHelper.getAsInt(json, "luminosity", -1);
Boolean uvlock = null;
if (json.has("uvlock")) {
Expand Down
Expand Up @@ -30,6 +30,7 @@
import net.minecraftforge.client.model.geometry.UnbakedGeometryHelper;
import net.minecraftforge.client.model.pipeline.QuadBakingVertexConsumer;
import net.minecraftforge.client.model.pipeline.TransformingVertexPipeline;
import slimeknights.mantle.data.loadable.common.ColorLoadable;
import slimeknights.mantle.util.ItemLayerPixels;
import slimeknights.mantle.util.JsonHelper;
import slimeknights.mantle.util.LogicHelper;
Expand Down Expand Up @@ -500,7 +501,7 @@ public RenderTypeGroup getRenderType(IGeometryBakingContext context, RenderTypeG
* Parses the layer data from JSON
*/
public static LayerData fromJson(JsonObject json) {
int color = JsonHelper.parseColor(GsonHelper.getAsString(json, "color", ""));
int color = ColorLoadable.ALPHA.getOrDefault(json, "color", -1);
// TODO: rename this field?
int luminosity = GsonHelper.getAsInt(json, "luminosity");
boolean noTint = GsonHelper.getAsBoolean(json, "no_tint", false);
Expand Down
Expand Up @@ -5,9 +5,9 @@
import lombok.Setter;
import lombok.experimental.Accessors;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.GsonHelper;
import net.minecraftforge.fluids.FluidType;
import net.minecraftforge.registries.ForgeRegistries;
import slimeknights.mantle.data.loadable.common.ColorLoadable;
import slimeknights.mantle.util.IdExtender.LocationExtender;
import slimeknights.mantle.util.JsonHelper;

Expand Down Expand Up @@ -43,7 +43,7 @@ public static FluidTexture deserialize(JsonObject json) {
if (json.has("camera")) {
camera = LocationExtender.INSTANCE.wrap(JsonHelper.getResourceLocation(json, "camera"), "textures/", ".png");
}
int color = JsonHelper.parseColor(GsonHelper.getAsString(json, "color"));
int color = ColorLoadable.ALPHA.getOrDefault(json, "color", -1);
return new FluidTexture(still, flowing, overlay, camera, color);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/slimeknights/mantle/util/JsonHelper.java
Expand Up @@ -221,7 +221,9 @@ public static <T extends Enum<T>> T getAsEnum(JsonObject json, String key, Class
* Parses a color as a string
* @param color Color to parse
* @return Parsed string
* @deprecated use {@link ColorLoadable#parseString(String, String)}
*/
@Deprecated(forRemoval = true)
public static int parseColor(@Nullable String color) {
if (color == null || color.isEmpty()) {
return -1;
Expand Down

0 comments on commit abf5ae7

Please sign in to comment.