Skip to content

Commit

Permalink
Update to latest forge and replace fluid tag empty condition with a g…
Browse files Browse the repository at this point in the history
…eneric tag one
  • Loading branch information
KnightMiner committed Apr 2, 2022
1 parent 18e418e commit bc336e9
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 67 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ minecraft_range=[1.18.2,1.19)

# Forge Version Information
loader_range=[39.0,)
forge_version=40.0.30
forge_range=[40.0.30,)
forge_version=40.0.36
forge_range=[40.0.36,)
parchment_version=2022.03.13

# Build dependencies
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/slimeknights/mantle/Mantle.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import slimeknights.mantle.network.MantleNetwork;
import slimeknights.mantle.recipe.crafting.ShapedFallbackRecipe;
import slimeknights.mantle.recipe.crafting.ShapedRetexturedRecipe;
import slimeknights.mantle.recipe.helper.FluidTagEmptyCondition;
import slimeknights.mantle.recipe.helper.TagEmptyCondition;
import slimeknights.mantle.recipe.helper.TagPreference;
import slimeknights.mantle.recipe.ingredient.FluidContainerIngredient;
import slimeknights.mantle.registration.adapter.BlockEntityTypeRegistryAdapter;
Expand Down Expand Up @@ -79,7 +79,7 @@ private void registerRecipeSerializers(final RegistryEvent.Register<RecipeSerial
adapter.register(new ShapedFallbackRecipe.Serializer(), "crafting_shaped_fallback");
adapter.register(new ShapedRetexturedRecipe.Serializer(), "crafting_shaped_retextured");

CraftingHelper.register(FluidTagEmptyCondition.SERIALIZER);
CraftingHelper.register(TagEmptyCondition.SERIALIZER);
CraftingHelper.register(FluidContainerIngredient.ID, FluidContainerIngredient.SERIALIZER);
}

Expand Down

This file was deleted.

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;
}
}
}

0 comments on commit bc336e9

Please sign in to comment.