Add abstractions for upcoming compressed sieve and hammer
This commit is contained in:
parent
a339bbe4ce
commit
c8e423129d
|
|
@ -27,12 +27,12 @@ import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.crafting.Ingredient;
|
import net.minecraft.world.item.crafting.Ingredient;
|
||||||
|
import net.minecraft.world.item.crafting.RecipeType;
|
||||||
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
|
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
|
||||||
import net.minecraft.world.level.storage.loot.providers.number.NumberProvider;
|
import net.minecraft.world.level.storage.loot.providers.number.NumberProvider;
|
||||||
import thedarkcolour.exdeorum.recipe.RecipeUtil;
|
import thedarkcolour.exdeorum.recipe.RecipeUtil;
|
||||||
import thedarkcolour.exdeorum.recipe.sieve.SieveRecipe;
|
import thedarkcolour.exdeorum.recipe.sieve.SieveRecipe;
|
||||||
import thedarkcolour.exdeorum.registry.EItems;
|
import thedarkcolour.exdeorum.registry.EItems;
|
||||||
import thedarkcolour.exdeorum.registry.ERecipeTypes;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
@ -43,11 +43,11 @@ import java.util.Objects;
|
||||||
public record GroupedSieveRecipe(Ingredient ingredient, ItemStack mesh, List<Result> results) {
|
public record GroupedSieveRecipe(Ingredient ingredient, ItemStack mesh, List<Result> results) {
|
||||||
public static int maxSieveRows;
|
public static int maxSieveRows;
|
||||||
|
|
||||||
public static ImmutableList<GroupedSieveRecipe> getAllRecipesGrouped() {
|
public static ImmutableList<GroupedSieveRecipe> getAllRecipesGrouped(RecipeType<SieveRecipe> recipeType) {
|
||||||
maxSieveRows = 1;
|
maxSieveRows = 1;
|
||||||
|
|
||||||
// copy the list so we can do removals
|
// copy the list so we can do removals
|
||||||
List<SieveRecipe> recipes = new ArrayList<>(Objects.requireNonNull(Minecraft.getInstance().level).getRecipeManager().getAllRecipesFor(ERecipeTypes.SIEVE.get()));
|
List<SieveRecipe> recipes = new ArrayList<>(Objects.requireNonNull(Minecraft.getInstance().level).getRecipeManager().getAllRecipesFor(recipeType));
|
||||||
Multimap<Ingredient, SieveRecipe> ingredientGrouper = ArrayListMultimap.create();
|
Multimap<Ingredient, SieveRecipe> ingredientGrouper = ArrayListMultimap.create();
|
||||||
|
|
||||||
for (int i = 0; i < recipes.size(); i++) {
|
for (int i = 0; i < recipes.size(); i++) {
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ public class ExDeorumJeiPlugin implements IModPlugin {
|
||||||
crookRecipes.add(CrookJeiRecipe.create(recipe));
|
crookRecipes.add(CrookJeiRecipe.create(recipe));
|
||||||
}
|
}
|
||||||
registration.addRecipes(CROOK, crookRecipes);
|
registration.addRecipes(CROOK, crookRecipes);
|
||||||
registration.addRecipes(SIEVE, GroupedSieveRecipe.getAllRecipesGrouped());
|
registration.addRecipes(SIEVE, GroupedSieveRecipe.getAllRecipesGrouped(ERecipeTypes.SIEVE.get()));
|
||||||
|
|
||||||
addCrucibleHeatSources(registration);
|
addCrucibleHeatSources(registration);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,13 @@ import net.minecraft.world.item.crafting.Ingredient;
|
||||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||||
import net.minecraft.world.item.crafting.RecipeType;
|
import net.minecraft.world.item.crafting.RecipeType;
|
||||||
import net.minecraft.world.level.storage.loot.providers.number.NumberProvider;
|
import net.minecraft.world.level.storage.loot.providers.number.NumberProvider;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import thedarkcolour.exdeorum.recipe.ProbabilityRecipe;
|
import thedarkcolour.exdeorum.recipe.ProbabilityRecipe;
|
||||||
import thedarkcolour.exdeorum.recipe.RecipeUtil;
|
import thedarkcolour.exdeorum.recipe.RecipeUtil;
|
||||||
import thedarkcolour.exdeorum.registry.ERecipeSerializers;
|
import thedarkcolour.exdeorum.registry.ERecipeSerializers;
|
||||||
import thedarkcolour.exdeorum.registry.ERecipeTypes;
|
import thedarkcolour.exdeorum.registry.ERecipeTypes;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class HammerRecipe extends ProbabilityRecipe {
|
public class HammerRecipe extends ProbabilityRecipe {
|
||||||
public HammerRecipe(ResourceLocation id, Ingredient ingredient, Item result, NumberProvider resultAmount) {
|
public HammerRecipe(ResourceLocation id, Ingredient ingredient, Item result, NumberProvider resultAmount) {
|
||||||
super(id, ingredient, result, resultAmount);
|
super(id, ingredient, result, resultAmount);
|
||||||
|
|
@ -48,28 +49,39 @@ public class HammerRecipe extends ProbabilityRecipe {
|
||||||
return ERecipeTypes.HAMMER.get();
|
return ERecipeTypes.HAMMER.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Serializer implements RecipeSerializer<HammerRecipe> {
|
public static abstract class AbstractSerializer implements RecipeSerializer<HammerRecipe> {
|
||||||
|
protected abstract HammerRecipe createHammerRecipe(ResourceLocation id, Ingredient ingredient, Item result, NumberProvider resultAmount);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HammerRecipe fromJson(ResourceLocation name, JsonObject json) {
|
public HammerRecipe fromJson(ResourceLocation name, JsonObject json) {
|
||||||
Ingredient ingredient = RecipeUtil.readIngredient(json, "ingredient");
|
Ingredient ingredient = RecipeUtil.readIngredient(json, "ingredient");
|
||||||
Item result = RecipeUtil.readItem(json, "result");
|
Item result = RecipeUtil.readItem(json, "result");
|
||||||
NumberProvider resultAmount = RecipeUtil.readNumberProvider(json, "result_amount");
|
NumberProvider resultAmount = RecipeUtil.readNumberProvider(json, "result_amount");
|
||||||
return new HammerRecipe(name, ingredient, result, resultAmount);
|
return createHammerRecipe(name, ingredient, result, resultAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable HammerRecipe fromNetwork(ResourceLocation name, FriendlyByteBuf buffer) {
|
@SuppressWarnings("deprecation")
|
||||||
|
public HammerRecipe fromNetwork(ResourceLocation name, FriendlyByteBuf buffer) {
|
||||||
Ingredient ingredient = Ingredient.fromNetwork(buffer);
|
Ingredient ingredient = Ingredient.fromNetwork(buffer);
|
||||||
Item result = buffer.readById(BuiltInRegistries.ITEM);
|
Item result = Objects.requireNonNull(buffer.readById(BuiltInRegistries.ITEM));
|
||||||
NumberProvider resultAmount = RecipeUtil.fromNetworkNumberProvider(buffer);
|
NumberProvider resultAmount = RecipeUtil.fromNetworkNumberProvider(buffer);
|
||||||
return new HammerRecipe(name, ingredient, result, resultAmount);
|
return createHammerRecipe(name, ingredient, result, resultAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void toNetwork(FriendlyByteBuf buffer, HammerRecipe recipe) {
|
public void toNetwork(FriendlyByteBuf buffer, HammerRecipe recipe) {
|
||||||
recipe.getIngredient().toNetwork(buffer);
|
recipe.getIngredient().toNetwork(buffer);
|
||||||
buffer.writeId(BuiltInRegistries.ITEM, recipe.result);
|
buffer.writeId(BuiltInRegistries.ITEM, recipe.result);
|
||||||
RecipeUtil.toNetworkNumberProvider(buffer, recipe.resultAmount);
|
RecipeUtil.toNetworkNumberProvider(buffer, recipe.resultAmount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Serializer extends AbstractSerializer {
|
||||||
|
@Override
|
||||||
|
protected HammerRecipe createHammerRecipe(ResourceLocation id, Ingredient ingredient, Item result, NumberProvider resultAmount) {
|
||||||
|
return new HammerRecipe(id, ingredient, result, resultAmount);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
package thedarkcolour.exdeorum.recipe.sieve;
|
package thedarkcolour.exdeorum.recipe.sieve;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
|
@ -39,6 +40,8 @@ import thedarkcolour.exdeorum.recipe.RecipeUtil;
|
||||||
import thedarkcolour.exdeorum.registry.ERecipeSerializers;
|
import thedarkcolour.exdeorum.registry.ERecipeSerializers;
|
||||||
import thedarkcolour.exdeorum.registry.ERecipeTypes;
|
import thedarkcolour.exdeorum.registry.ERecipeTypes;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class SieveRecipe extends ProbabilityRecipe {
|
public class SieveRecipe extends ProbabilityRecipe {
|
||||||
public final Item mesh;
|
public final Item mesh;
|
||||||
public final boolean byHandOnly;
|
public final boolean byHandOnly;
|
||||||
|
|
@ -60,7 +63,9 @@ public class SieveRecipe extends ProbabilityRecipe {
|
||||||
return ERecipeTypes.SIEVE.get();
|
return ERecipeTypes.SIEVE.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Serializer implements RecipeSerializer<SieveRecipe> {
|
public static abstract class AbstractSerializer implements RecipeSerializer<SieveRecipe> {
|
||||||
|
protected abstract SieveRecipe createSieveRecipe(ResourceLocation id, Ingredient ingredient, Item mesh, Item result, NumberProvider resultAmount, boolean byHandOnly);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SieveRecipe fromJson(ResourceLocation id, JsonObject json) {
|
public SieveRecipe fromJson(ResourceLocation id, JsonObject json) {
|
||||||
Ingredient ingredient = RecipeUtil.readIngredient(json, "ingredient");
|
Ingredient ingredient = RecipeUtil.readIngredient(json, "ingredient");
|
||||||
|
|
@ -78,23 +83,22 @@ public class SieveRecipe extends ProbabilityRecipe {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ExDeorum.LOGGER.error("Failed to load recipe {}, missing \"result\" item location or \"result_tag\" tag location", id);
|
throw new JsonSyntaxException("missing \"result\" item location or \"result_tag\" tag location");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NumberProvider resultAmount = RecipeUtil.readNumberProvider(json, "result_amount");
|
NumberProvider resultAmount = RecipeUtil.readNumberProvider(json, "result_amount");
|
||||||
boolean byHandOnly = json.has("by_hand_only") && json.get("by_hand_only").getAsBoolean();
|
boolean byHandOnly = json.has("by_hand_only") && json.get("by_hand_only").getAsBoolean();
|
||||||
return new SieveRecipe(id, ingredient, mesh, result, resultAmount, byHandOnly);
|
return createSieveRecipe(id, ingredient, mesh, result, resultAmount, byHandOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public @Nullable SieveRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf buffer) {
|
public @Nullable SieveRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf buffer) {
|
||||||
Ingredient ingredient = Ingredient.fromNetwork(buffer);
|
Ingredient ingredient = Ingredient.fromNetwork(buffer);
|
||||||
Item mesh = buffer.readById(BuiltInRegistries.ITEM);
|
Item mesh = Objects.requireNonNull(buffer.readById(BuiltInRegistries.ITEM));
|
||||||
Item result = buffer.readById(BuiltInRegistries.ITEM);
|
Item result = Objects.requireNonNull(buffer.readById(BuiltInRegistries.ITEM));
|
||||||
NumberProvider resultAmount = RecipeUtil.fromNetworkNumberProvider(buffer);
|
NumberProvider resultAmount = RecipeUtil.fromNetworkNumberProvider(buffer);
|
||||||
return new SieveRecipe(id, ingredient, mesh, result, resultAmount, buffer.readBoolean());
|
return createSieveRecipe(id, ingredient, mesh, result, resultAmount, buffer.readBoolean());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
|
@ -107,4 +111,11 @@ public class SieveRecipe extends ProbabilityRecipe {
|
||||||
buffer.writeBoolean(recipe.byHandOnly);
|
buffer.writeBoolean(recipe.byHandOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Serializer extends AbstractSerializer {
|
||||||
|
@Override
|
||||||
|
protected SieveRecipe createSieveRecipe(ResourceLocation id, Ingredient ingredient, Item mesh, Item result, NumberProvider resultAmount, boolean byHandOnly) {
|
||||||
|
return new SieveRecipe(id, ingredient, mesh, result, resultAmount, byHandOnly);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user