Skip to content

Commit

Permalink
add serializers so mod actually works in prod
Browse files Browse the repository at this point in the history
  • Loading branch information
Draylar committed Apr 28, 2020
1 parent 4955577 commit 173145c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main/java/draylar/tiered/data/AttributeDataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
import com.google.gson.JsonParseException;
import draylar.tiered.api.PotentialAttribute;
import draylar.tiered.gson.EntityAttributeModifierDeserializer;
import draylar.tiered.gson.EquipmentSlotDeserializer;
import draylar.tiered.gson.FormattingDeserializer;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.resource.JsonDataLoader;
import net.minecraft.resource.ResourceManager;
import net.minecraft.text.Style;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.profiler.Profiler;
Expand All @@ -25,14 +28,11 @@ public class AttributeDataLoader extends JsonDataLoader {
private static final Gson GSON = new GsonBuilder()
.setPrettyPrinting()
.disableHtmlEscaping()
.registerTypeAdapter(
EntityAttributeModifier.class,
new EntityAttributeModifierDeserializer()
)
.registerTypeAdapter(
Formatting.class,
new FormattingDeserializer()
).create();
.registerTypeAdapter(EntityAttributeModifier.class, new EntityAttributeModifierDeserializer())
.registerTypeAdapter(EquipmentSlot.class, new EquipmentSlotDeserializer())
.registerTypeHierarchyAdapter(Style.class, new Style.Serializer())
.registerTypeAdapter(Formatting.class, new FormattingDeserializer())
.create();

private static final String PARSING_ERROR_MESSAGE = "Parsing error loading recipe {}";
private static final String LOADED_RECIPES_MESSAGE = "Loaded {} recipes";
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/draylar/tiered/gson/EquipmentSlotDeserializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package draylar.tiered.gson;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import net.minecraft.entity.EquipmentSlot;

import java.lang.reflect.Type;

public class EquipmentSlotDeserializer implements JsonDeserializer<EquipmentSlot> {

@Override
public EquipmentSlot deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return EquipmentSlot.byName(json.getAsString().toLowerCase());
}
}

0 comments on commit 173145c

Please sign in to comment.