Last active
February 22, 2020 05:45
-
-
Save Daomephsta/73370cf57ddb174f6fea9ef2cf482d28 to your computer and use it in GitHub Desktop.
LazilyParsedCondition.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.minecraftforge.common.crafting.conditions; | |
import com.google.gson.JsonElement; | |
import com.google.gson.JsonObject; | |
import java.util.Map; | |
import net.minecraft.util.ResourceLocation; | |
import net.minecraftforge.common.crafting.CraftingHelper; | |
import net.minecraftforge.common.util.Lazy; | |
public class LazilyParsedCondition implements ICondition | |
{ | |
private static final ResourceLocation NAME = new ResourceLocation("forge", "lazily_parse"); | |
private final Lazy<ICondition> condition; | |
public LazilyParsedCondition(JsonObject conditionJson) | |
{ | |
this.condition = Lazy.of(() -> CraftingHelper.getCondition(conditionJson)); | |
} | |
@Override | |
public ResourceLocation getID() | |
{ | |
return NAME; | |
} | |
@Override | |
public boolean test() | |
{ | |
return condition.get().test(); | |
} | |
@Override | |
public String toString() | |
{ | |
return condition.get().toString(); | |
} | |
public static class Serializer implements IConditionSerializer<LazilyParsedCondition> | |
{ | |
public static final Serializer INSTANCE = new Serializer(); | |
@Override | |
public void write(JsonObject json, LazilyParsedCondition value) | |
{ | |
for(Map.Entry<String, JsonElement> member: CraftingHelper.serialize(value.condition.get()).entrySet()) | |
{ | |
json.add(member.getKey(), member.getValue()); | |
} | |
} | |
@Override | |
public LazilyParsedCondition read(JsonObject json) | |
{ | |
return new LazilyParsedCondition(json); | |
} | |
@Override | |
public ResourceLocation getID() | |
{ | |
return LazilyParsedCondition.NAME; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment