-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to latest forge and replace fluid tag empty condition with a g…
…eneric tag one
- Loading branch information
1 parent
18e418e
commit bc336e9
Showing
4 changed files
with
74 additions
and
67 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
63 changes: 0 additions & 63 deletions
63
src/main/java/slimeknights/mantle/recipe/helper/FluidTagEmptyCondition.java
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
src/main/java/slimeknights/mantle/recipe/helper/TagEmptyCondition.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package slimeknights.mantle.recipe.helper; | ||
|
||
import com.google.gson.JsonObject; | ||
import lombok.RequiredArgsConstructor; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.tags.TagKey; | ||
import net.minecraftforge.common.crafting.conditions.ICondition; | ||
import net.minecraftforge.common.crafting.conditions.IConditionSerializer; | ||
import slimeknights.mantle.Mantle; | ||
import slimeknights.mantle.util.JsonHelper; | ||
|
||
/** Condition that checks when a fluid tag is empty. Same as {@link net.minecraftforge.common.crafting.conditions.TagEmptyCondition} but for fluids instead of items */ | ||
@RequiredArgsConstructor | ||
public class TagEmptyCondition<T> implements ICondition { | ||
private static final ResourceLocation NAME = Mantle.getResource("tag_empty"); | ||
public static final Serializer SERIALIZER = new Serializer(); | ||
private final TagKey<T> tag; | ||
|
||
public TagEmptyCondition(ResourceKey<? extends Registry<T>> registry, ResourceLocation name) { | ||
this(TagKey.create(registry, name)); | ||
} | ||
|
||
@Override | ||
public ResourceLocation getID() { | ||
return NAME; | ||
} | ||
|
||
@Override | ||
public boolean test() { | ||
Mantle.logger.error("Improperly calling TagEmpty condition for " + tag + ", use context sensitive test method"); | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean test(IContext context) { | ||
return context.getTag(tag).getValues().isEmpty(); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "tag_empty(\"" + tag + "\")"; | ||
} | ||
|
||
private static class Serializer implements IConditionSerializer<TagEmptyCondition<?>> { | ||
@Override | ||
public void write(JsonObject json, TagEmptyCondition<?> value) { | ||
json.addProperty("registry", value.tag.registry().location().toString()); | ||
json.addProperty("tag", value.tag.location().toString()); | ||
} | ||
|
||
private <T> TagEmptyCondition<T> readGeneric(JsonObject json) { | ||
ResourceKey<Registry<T>> registry = ResourceKey.createRegistryKey(JsonHelper.getResourceLocation(json, "registry")); | ||
return new TagEmptyCondition<>(registry, JsonHelper.getResourceLocation(json, "tag")); | ||
} | ||
|
||
@Override | ||
public TagEmptyCondition<?> read(JsonObject json) { | ||
return readGeneric(json); | ||
} | ||
|
||
@Override | ||
public ResourceLocation getID() | ||
{ | ||
return NAME; | ||
} | ||
} | ||
} |