From 2c07ef0fa0625fa6072b3dec64980ce87fd9ea7c Mon Sep 17 00:00:00 2001 From: canitzp Date: Wed, 7 Oct 2020 08:25:54 +0200 Subject: [PATCH] Start to work on DataGenerator. Crusher Recipes should now be able to be serialized to json by its Factory. In general the serializing to json is handled by the RecipeFactoryBase class. Removed some Recipes after the decision to not port it or change it to loot tables in favor of recipes. A lot more @Nonnull annotations. Signed-off-by: canitzp --- .../AtomicReconstructorBlockRecipe.java | 9 +- .../AtomicReconstructorItemRecipe.java | 22 ++-- .../common/recipes/BallOfFurRecipe.java | 45 -------- .../recipes/BallOfFurRecipeFactory.java | 65 ----------- .../recipes/CoffeeMachineIngredient.java | 21 ++-- .../common/recipes/CompostRecipe.java | 59 ---------- .../common/recipes/CompostRecipeFactory.java | 101 ------------------ .../common/recipes/CrusherRecipe.java | 39 +++++-- .../common/recipes/IDummyRecipe.java | 43 +++++++- .../common/recipes/RecipeFactoryBase.java | 19 +++- .../data/AADataGenerator.java | 11 +- .../data/BlockStateGenerator.java | 28 +++++ .../data/recipes/CrusherRecipeGenerator.java | 26 +++++ .../actuallyadditions/recipes/_factories.json | 9 -- 14 files changed, 184 insertions(+), 313 deletions(-) delete mode 100644 src/main/java/de/ellpeck/actuallyadditions/common/recipes/BallOfFurRecipe.java delete mode 100644 src/main/java/de/ellpeck/actuallyadditions/common/recipes/BallOfFurRecipeFactory.java delete mode 100644 src/main/java/de/ellpeck/actuallyadditions/common/recipes/CompostRecipe.java delete mode 100644 src/main/java/de/ellpeck/actuallyadditions/common/recipes/CompostRecipeFactory.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/data/BlockStateGenerator.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/data/recipes/CrusherRecipeGenerator.java delete mode 100644 src/main/resources/assets/actuallyadditions/recipes/_factories.json diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/AtomicReconstructorBlockRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/common/recipes/AtomicReconstructorBlockRecipe.java index babad16c0..30d6b3c14 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/AtomicReconstructorBlockRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/common/recipes/AtomicReconstructorBlockRecipe.java @@ -6,10 +6,12 @@ import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.item.crafting.IRecipeType; import net.minecraft.util.ResourceLocation; +import javax.annotation.Nonnull; + /** * Recipe class for the AtomicReconstructor when hitting a items stack */ -public class AtomicReconstructorBlockRecipe implements IDummyRecipe { +public class AtomicReconstructorBlockRecipe implements IDummyRecipe { public static final IRecipeType ATOMIC_RECONSTRUCTOR_BLOCK_RECIPE_TYPE = IRecipeType.register("actuallyadditions:atomic_reconstructor_block"); @@ -44,16 +46,19 @@ public class AtomicReconstructorBlockRecipe implements IDummyRecipe { return energyConsumption; } + @Nonnull @Override public ResourceLocation getId(){ return this.recipeId; } + @Nonnull @Override - public IRecipeSerializer getSerializer(){ + public IRecipeSerializer getSerializer(){ return AtomicReconstructorBlockRecipeFactory.INSTANCE; } + @Nonnull @Override public IRecipeType getType(){ return ATOMIC_RECONSTRUCTOR_BLOCK_RECIPE_TYPE; diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/AtomicReconstructorItemRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/common/recipes/AtomicReconstructorItemRecipe.java index 67626bf61..90dbe8130 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/AtomicReconstructorItemRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/common/recipes/AtomicReconstructorItemRecipe.java @@ -7,21 +7,23 @@ import net.minecraft.item.crafting.IRecipeType; import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.ResourceLocation; +import javax.annotation.Nonnull; + /** * Recipe class for the AtomicReconstructor when hitting a items stack */ -public class AtomicReconstructorItemRecipe implements IDummyRecipe { +public class AtomicReconstructorItemRecipe implements IDummyRecipe { public static final IRecipeType ATOMIC_RECONSTRUCTOR_ITEM_RECIPE_TYPE = IRecipeType.register("actuallyadditions:atomic_reconstructor_item"); - private final ResourceLocation recipeId; + @Nonnull private final ResourceLocation recipeId; - private final Lens lens; - private final Ingredient input; - private final ItemStack output; + @Nonnull private final Lens lens; + @Nonnull private final Ingredient input; + @Nonnull private final ItemStack output; private final int energyConsumption; - public AtomicReconstructorItemRecipe(ResourceLocation recipeId, Lens lens, Ingredient input, ItemStack output, int energyConsumption){ + public AtomicReconstructorItemRecipe(@Nonnull ResourceLocation recipeId, @Nonnull Lens lens, @Nonnull Ingredient input, @Nonnull ItemStack output, int energyConsumption){ this.recipeId = recipeId; this.lens = lens; this.input = input; @@ -29,14 +31,17 @@ public class AtomicReconstructorItemRecipe implements IDummyRecipe { this.energyConsumption = energyConsumption; } + @Nonnull public Lens getLens(){ return lens; } + @Nonnull public Ingredient getInput(){ return input; } + @Nonnull public ItemStack getOutput(){ return output; } @@ -45,16 +50,19 @@ public class AtomicReconstructorItemRecipe implements IDummyRecipe { return energyConsumption; } + @Nonnull @Override public ResourceLocation getId(){ return this.recipeId; } + @Nonnull @Override - public IRecipeSerializer getSerializer(){ + public IRecipeSerializer getSerializer(){ return AtomicReconstructorItemRecipeFactory.INSTANCE; } + @Nonnull @Override public IRecipeType getType(){ return ATOMIC_RECONSTRUCTOR_ITEM_RECIPE_TYPE; diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/BallOfFurRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/common/recipes/BallOfFurRecipe.java deleted file mode 100644 index c938bbcb7..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/BallOfFurRecipe.java +++ /dev/null @@ -1,45 +0,0 @@ -package de.ellpeck.actuallyadditions.common.recipes; - -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipeSerializer; -import net.minecraft.item.crafting.IRecipeType; -import net.minecraft.util.ResourceLocation; - -public class BallOfFurRecipe implements IDummyRecipe { - - public static final IRecipeType BALL_OF_FUR_RECIPE_TYPE = IRecipeType.register("actuallyadditions:ball_of_fur"); - - private final ResourceLocation recipeId; - - private final ItemStack returnItem; - private final int chance; - - public BallOfFurRecipe(ResourceLocation recipeId, ItemStack returnItem, int chance){ - this.recipeId = recipeId; - this.returnItem = returnItem; - this.chance = chance; - } - - public ItemStack getReturnItem(){ - return this.returnItem; - } - - public int getChance(){ - return this.chance; - } - - @Override - public ResourceLocation getId(){ - return this.recipeId; - } - - @Override - public IRecipeSerializer getSerializer(){ - return BallOfFurRecipeFactory.INSTANCE; - } - - @Override - public IRecipeType getType(){ - return BALL_OF_FUR_RECIPE_TYPE; - } -} diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/BallOfFurRecipeFactory.java b/src/main/java/de/ellpeck/actuallyadditions/common/recipes/BallOfFurRecipeFactory.java deleted file mode 100644 index e713b5b33..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/BallOfFurRecipeFactory.java +++ /dev/null @@ -1,65 +0,0 @@ -package de.ellpeck.actuallyadditions.common.recipes; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipeSerializer; -import net.minecraft.item.crafting.ShapedRecipe; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.registries.ForgeRegistryEntry; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -public class BallOfFurRecipeFactory extends ForgeRegistryEntry> implements IRecipeSerializer { - - public static final BallOfFurRecipeFactory INSTANCE = IRecipeSerializer.register("actuallyadditions:ball_of_fur", new BallOfFurRecipeFactory()); - - @Nonnull - @Override - public BallOfFurRecipe read(@Nonnull ResourceLocation recipeId, @Nonnull JsonObject json){ - ItemStack stack; - int chance; - - if(json.has("stack")){ - JsonElement stackJsonElement = json.get("stack"); - if(stackJsonElement.isJsonObject()){ - stack = ShapedRecipe.deserializeItem(stackJsonElement.getAsJsonObject()); - } else { - throw new JsonParseException("BallOfFurRecipe stack has to be a json object!"); - } - } else { - throw new JsonParseException("BallOfFurRecipe has no json stack object!"); - } - - if(json.has("chance")){ - JsonElement chanceJsonElement = json.get("chance"); - if(chanceJsonElement.isJsonPrimitive()){ - chance = chanceJsonElement.getAsInt(); - } else { - throw new JsonParseException("BallOfFurRecipe chance is not a json integer!"); - } - } else { - throw new JsonParseException("BallOfFurRecipe has no chance integer!"); - } - - return new BallOfFurRecipe(recipeId, stack, chance); - } - - @Nullable - @Override - public BallOfFurRecipe read(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer){ - ItemStack stack = buffer.readItemStack(); - int chance = buffer.readInt(); - return new BallOfFurRecipe(recipeId, stack, chance); - } - - @Override - public void write(@Nonnull PacketBuffer buffer, @Nonnull BallOfFurRecipe recipe){ - buffer.writeItemStack(recipe.getReturnItem()); - buffer.writeInt(recipe.getChance()); - } - -} diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/CoffeeMachineIngredient.java b/src/main/java/de/ellpeck/actuallyadditions/common/recipes/CoffeeMachineIngredient.java index fdc02d823..b8f607c46 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/CoffeeMachineIngredient.java +++ b/src/main/java/de/ellpeck/actuallyadditions/common/recipes/CoffeeMachineIngredient.java @@ -6,22 +6,25 @@ import net.minecraft.item.crafting.Ingredient; import net.minecraft.potion.EffectInstance; import net.minecraft.util.ResourceLocation; -public class CoffeeMachineIngredient implements IDummyRecipe{ +import javax.annotation.Nonnull; + +public class CoffeeMachineIngredient implements IDummyRecipe { public static final IRecipeType COFFEE_MACHINE_RECIPE_TYPE = IRecipeType.register("actuallyadditions:coffee_machine"); - protected final ResourceLocation recipeId; - protected final Ingredient input; - protected final int maxAmplifier; - protected final EffectInstance[] effects; + @Nonnull private final ResourceLocation recipeId; + @Nonnull private final Ingredient input; + private final int maxAmplifier; + @Nonnull private final EffectInstance[] effects; - public CoffeeMachineIngredient(ResourceLocation recipeId, Ingredient input, int maxAmplifier, EffectInstance[] effects){ + public CoffeeMachineIngredient(@Nonnull ResourceLocation recipeId, @Nonnull Ingredient input, int maxAmplifier, @Nonnull EffectInstance[] effects){ this.recipeId = recipeId; this.input = input; this.maxAmplifier = maxAmplifier; this.effects = effects; } + @Nonnull public Ingredient getInput(){ return input; } @@ -30,20 +33,24 @@ public class CoffeeMachineIngredient implements IDummyRecipe{ return maxAmplifier; } + @Nonnull public EffectInstance[] getEffects(){ return effects; } + @Nonnull @Override public ResourceLocation getId(){ return this.recipeId; } + @Nonnull @Override - public IRecipeSerializer getSerializer(){ + public IRecipeSerializer getSerializer(){ return CoffeeMachineIngredientFactory.INSTANCE; } + @Nonnull @Override public IRecipeType getType(){ return COFFEE_MACHINE_RECIPE_TYPE; diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/CompostRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/common/recipes/CompostRecipe.java deleted file mode 100644 index cf158ceb0..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/CompostRecipe.java +++ /dev/null @@ -1,59 +0,0 @@ -package de.ellpeck.actuallyadditions.common.recipes; - -import net.minecraft.block.BlockState; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipeSerializer; -import net.minecraft.item.crafting.IRecipeType; -import net.minecraft.item.crafting.Ingredient; -import net.minecraft.util.ResourceLocation; - -public class CompostRecipe implements IDummyRecipe { - - public static final IRecipeType COMPOST_RECIPE_TYPE = IRecipeType.register("actuallyadditions:compost"); - - private final ResourceLocation recipeId; - - private final Ingredient input; - private final ItemStack output; - private final BlockState inputDisplay; - private final BlockState outputDisplay; - - public CompostRecipe(ResourceLocation recipeId, Ingredient input, ItemStack output, BlockState inputDisplay, BlockState outputDisplay){ - this.recipeId = recipeId; - this.input = input; - this.output = output; - this.inputDisplay = inputDisplay; - this.outputDisplay = outputDisplay; - } - - public Ingredient getInput(){ - return this.input; - } - - public ItemStack getOutput(){ - return this.output; - } - - public BlockState getInputDisplay(){ - return this.inputDisplay; - } - - public BlockState getOutputDisplay(){ - return this.outputDisplay; - } - - @Override - public ResourceLocation getId(){ - return this.recipeId; - } - - @Override - public IRecipeSerializer getSerializer(){ - return CompostRecipeFactory.INSTANCE; - } - - @Override - public IRecipeType getType(){ - return COMPOST_RECIPE_TYPE; - } -} diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/CompostRecipeFactory.java b/src/main/java/de/ellpeck/actuallyadditions/common/recipes/CompostRecipeFactory.java deleted file mode 100644 index fd33a176c..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/CompostRecipeFactory.java +++ /dev/null @@ -1,101 +0,0 @@ -package de.ellpeck.actuallyadditions.common.recipes; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.mojang.datafixers.Dynamic; -import com.mojang.datafixers.types.JsonOps; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipeSerializer; -import net.minecraft.item.crafting.Ingredient; -import net.minecraft.item.crafting.ShapedRecipe; -import net.minecraft.nbt.*; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.registries.ForgeRegistryEntry; - -import javax.annotation.Nullable; - -public class CompostRecipeFactory extends ForgeRegistryEntry> implements IRecipeSerializer { - - public static final CompostRecipeFactory INSTANCE = IRecipeSerializer.register("actuallyadditions:compost", new CompostRecipeFactory()); - - @Override - public CompostRecipe read(ResourceLocation recipeId, JsonObject json){ - Ingredient input; - ItemStack output; - BlockState inputDisplay; - BlockState outputDisplay; - - if(json.has("input")){ - input = Ingredient.deserialize(json.get("input")); - } else { - throw new JsonParseException("CompostRecipe needs a input ingredient json element!"); - } - - if(json.has("output")){ - JsonElement outputJsonElement = json.get("output"); - if(outputJsonElement.isJsonObject()){ - output = ShapedRecipe.deserializeItem(outputJsonElement.getAsJsonObject()); - } else { - throw new JsonParseException("CompostRecipe output element is not a json object!"); - } - } else { - throw new JsonParseException("CompostRecipe needs a output itemstack json object!"); - } - - if(json.has("display")){ - JsonElement displayJsonElement = json.get("display"); - if(displayJsonElement.isJsonObject()){ - JsonObject displayJsonObject = displayJsonElement.getAsJsonObject(); - if(displayJsonObject.has("input")){ - inputDisplay = BlockState.deserialize(new Dynamic<>(JsonOps.INSTANCE, displayJsonObject.get("input"))); - } else { - throw new JsonParseException("CompostRecipe display needs an input json element!"); - } - - if(displayJsonObject.has("output")){ - outputDisplay = BlockState.deserialize(new Dynamic<>(JsonOps.INSTANCE, displayJsonObject.get("output"))); - } else { - throw new JsonParseException("CompostRecipe display needs an output json element!"); - } - } else { - throw new JsonParseException("CompostRecipe display has to be a json object!"); - } - } else { - // no exception but default values - inputDisplay = Blocks.DIRT.getDefaultState(); - outputDisplay = Blocks.COARSE_DIRT.getDefaultState(); - } - - return new CompostRecipe(recipeId, input, output, inputDisplay, outputDisplay); - } - - @Nullable - @Override - public CompostRecipe read(ResourceLocation recipeId, PacketBuffer buffer){ - Ingredient input = Ingredient.read(buffer); - ItemStack output = buffer.readItemStack(); - CompoundNBT inputNBT = buffer.readCompoundTag(); - CompoundNBT outputNBT = buffer.readCompoundTag(); - - BlockState inputDisplay = BlockState.deserialize(new Dynamic<>(NBTDynamicOps.INSTANCE, inputNBT)); - BlockState outputDisplay = BlockState.deserialize(new Dynamic<>(NBTDynamicOps.INSTANCE, outputNBT)); - - return new CompostRecipe(recipeId, input, output, inputDisplay, outputDisplay); - } - - @Override - public void write(PacketBuffer buffer, CompostRecipe recipe){ - recipe.getInput().write(buffer); - buffer.writeItemStack(recipe.getOutput()); - - INBT inputNBT = BlockState.serialize(NBTDynamicOps.INSTANCE, recipe.getInputDisplay()).getValue(); - buffer.writeCompoundTag((CompoundNBT) inputNBT); // if it isn't a compound than something real big is wrong and a crash should be the best way to handle it - - INBT outputNBT = BlockState.serialize(NBTDynamicOps.INSTANCE, recipe.getOutputDisplay()).getValue(); - buffer.writeCompoundTag((CompoundNBT) outputNBT); - } -} diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/CrusherRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/common/recipes/CrusherRecipe.java index 0365a18da..d1dff27cb 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/CrusherRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/common/recipes/CrusherRecipe.java @@ -12,16 +12,20 @@ import net.minecraft.util.ResourceLocation; import javax.annotation.Nonnull; -public class CrusherRecipe implements IDummyRecipe { +public class CrusherRecipe implements IDummyRecipe { public static final IRecipeType RECIPE_TYPE = IRecipeType.register("actuallyadditions:crusher"); public static final CrusherRecipeFactory FACTORY = IRecipeSerializer.register("actuallyadditions:crusher", new CrusherRecipeFactory()); - @Nonnull private final ResourceLocation recipeId; + @Nonnull + private final ResourceLocation recipeId; - @Nonnull private final Ingredient input; - @Nonnull private final ItemStack output; - @Nonnull private final ItemStack secondaryOutput; + @Nonnull + private final Ingredient input; + @Nonnull + private final ItemStack output; + @Nonnull + private final ItemStack secondaryOutput; private final int outputChance; public CrusherRecipe(@Nonnull ResourceLocation recipeId, @Nonnull Ingredient input, @Nonnull ItemStack output, @Nonnull ItemStack secondaryOutput, int outputChance){ @@ -32,6 +36,10 @@ public class CrusherRecipe implements IDummyRecipe { this.outputChance = outputChance; } + public CrusherRecipe(@Nonnull ResourceLocation recipeId, @Nonnull Ingredient input, @Nonnull ItemStack output){ + this(recipeId, input, output, ItemStack.EMPTY, 0); + } + @Nonnull public Ingredient getInput(){ return input; @@ -59,7 +67,7 @@ public class CrusherRecipe implements IDummyRecipe { @Nonnull @Override - public IRecipeSerializer getSerializer(){ + public IRecipeSerializer getSerializer(){ return FACTORY; } @@ -89,10 +97,21 @@ public class CrusherRecipe implements IDummyRecipe { throw new JsonSyntaxException("Secondary is not valid!"); } } - + return new CrusherRecipe(recipeId, input, firstOutput, secondOutput, secondaryOutputChance); } - + + @Override + public void write(@Nonnull JsonObject json, @Nonnull CrusherRecipe recipe){ + json.add("input", recipe.getInput().serialize()); + json.add("output", this.writeItemStack(recipe.getOutput())); + if(!recipe.getSecondaryOutput().isEmpty() && recipe.getOutputChance() > 0){ + JsonObject secondary = new JsonObject(); + secondary.add("output", this.writeItemStack(recipe.getSecondaryOutput())); + secondary.addProperty("chance", recipe.getOutputChance()); + } + } + @Nonnull @Override public CrusherRecipe read(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer){ @@ -100,10 +119,10 @@ public class CrusherRecipe implements IDummyRecipe { ItemStack output = buffer.readItemStack(); ItemStack secondaryOutput = buffer.readItemStack(); int chance = buffer.readVarInt(); - + return new CrusherRecipe(recipeId, input, output, secondaryOutput, chance); } - + @Override public void write(@Nonnull PacketBuffer buffer, @Nonnull CrusherRecipe recipe){ recipe.getInput().write(buffer); diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/IDummyRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/common/recipes/IDummyRecipe.java index e480a93b2..27fc1c639 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/IDummyRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/common/recipes/IDummyRecipe.java @@ -1,25 +1,37 @@ package de.ellpeck.actuallyadditions.common.recipes; +import com.google.gson.JsonObject; +import net.minecraft.data.IFinishedRecipe; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; +import net.minecraft.item.crafting.IRecipeSerializer; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * A dummy Recipe implementation, because the minecraft recipe system forces us to use IRecipe with all of it's methods, * but we don't need any of them. * Additionally the "isDynamic()" methods now returns true, because this indicates that the recipe book doesn't list * this recipe at all. */ -public interface IDummyRecipe extends IRecipe { +public interface IDummyRecipe> extends IRecipe, IFinishedRecipe { + + @Nonnull + @Override + IRecipeSerializer getSerializer(); @Override - default boolean matches(IInventory inv, World worldIn){ + default boolean matches(@Nonnull IInventory inv, @Nonnull World world){ return false; } + @Nonnull @Override - default ItemStack getCraftingResult(IInventory inv){ + default ItemStack getCraftingResult(@Nonnull IInventory inv){ return ItemStack.EMPTY; } @@ -28,6 +40,7 @@ public interface IDummyRecipe extends IRecipe { return false; } + @Nonnull @Override default ItemStack getRecipeOutput(){ return ItemStack.EMPTY; @@ -39,4 +52,28 @@ public interface IDummyRecipe extends IRecipe { return true; } + @Override + default void serialize(@Nonnull JsonObject json){ + if(this.getSerializer() instanceof RecipeFactoryBase){ + (((RecipeFactoryBase) this.getSerializer())).write(json, (T) this); + } + } + + @Nonnull + @Override + default ResourceLocation getID(){ + return this.getId(); + } + + @Nullable + @Override + default JsonObject getAdvancementJson(){ + return null; + } + + @Nullable + @Override + default ResourceLocation getAdvancementID(){ + return null; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/RecipeFactoryBase.java b/src/main/java/de/ellpeck/actuallyadditions/common/recipes/RecipeFactoryBase.java index 56c3c8d30..6d05f6168 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/common/recipes/RecipeFactoryBase.java +++ b/src/main/java/de/ellpeck/actuallyadditions/common/recipes/RecipeFactoryBase.java @@ -1,16 +1,19 @@ package de.ellpeck.actuallyadditions.common.recipes; import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.item.crafting.Ingredient; -import net.minecraft.item.crafting.ShapedRecipe; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistryEntry; -public abstract class RecipeFactoryBase extends ForgeRegistryEntry> implements IRecipeSerializer { +public abstract class RecipeFactoryBase> extends ForgeRegistryEntry> implements IRecipeSerializer { + + public abstract void write(JsonObject json, T recipe); protected Ingredient readIngredient(JsonObject json, String key){ if(json.has(key)){ @@ -31,7 +34,7 @@ public abstract class RecipeFactoryBase extends ForgeReg protected ItemStack readItemStack(JsonObject json, String key){ if(json.has(key)){ if(json.get(key).isJsonObject()){ - return ShapedRecipe.deserializeItem(json.get(key).getAsJsonObject()); + return CraftingHelper.getItemStack(json.get(key).getAsJsonObject(), true); } else if(json.get(key).isJsonPrimitive()){ ResourceLocation itemKey = new ResourceLocation(json.get(key).getAsString()); if(ForgeRegistries.ITEMS.containsKey(itemKey)){ @@ -47,6 +50,16 @@ public abstract class RecipeFactoryBase extends ForgeReg } } + protected JsonObject writeItemStack(ItemStack stack){ + JsonObject json = new JsonObject(); + json.addProperty("item", stack.getItem().getRegistryName().toString()); + json.addProperty("count", stack.getCount()); + if(stack.hasTag()){ + json.add("nbt", new JsonParser().parse(stack.getTag().toString())); + } + return json; + } + protected ItemStack readItemStack(JsonObject json, String key, ItemStack alternative){ try{ return this.readItemStack(json, key); diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/AADataGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/AADataGenerator.java index 2c7c5f4cb..4d0a5a409 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/AADataGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/AADataGenerator.java @@ -1,6 +1,9 @@ package de.ellpeck.actuallyadditions.data; import de.ellpeck.actuallyadditions.common.ActuallyAdditions; +import de.ellpeck.actuallyadditions.data.recipes.CrusherRecipeGenerator; +import net.minecraft.data.DataGenerator; +import net.minecraftforge.client.model.generators.ExistingFileHelper; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.GatherDataEvent; @@ -9,7 +12,11 @@ import net.minecraftforge.fml.event.lifecycle.GatherDataEvent; public class AADataGenerator { @SubscribeEvent - public static void gatherData(GatherDataEvent event) { - + public static void gatherData(GatherDataEvent event){ + DataGenerator dataGenerator = event.getGenerator(); + ExistingFileHelper existingFileHelper = event.getExistingFileHelper(); + + dataGenerator.addProvider(new BlockStateGenerator(dataGenerator, existingFileHelper)); + dataGenerator.addProvider(new CrusherRecipeGenerator(dataGenerator)); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/BlockStateGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/BlockStateGenerator.java new file mode 100644 index 000000000..bcd7d746b --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/data/BlockStateGenerator.java @@ -0,0 +1,28 @@ +package de.ellpeck.actuallyadditions.data; + + +import de.ellpeck.actuallyadditions.common.ActuallyAdditions; +import de.ellpeck.actuallyadditions.common.blocks.InitBlocks; +import net.minecraft.block.Block; +import net.minecraft.data.DataGenerator; +import net.minecraftforge.client.model.generators.BlockStateProvider; +import net.minecraftforge.client.model.generators.ExistingFileHelper; +import net.minecraftforge.fml.RegistryObject; + +public class BlockStateGenerator extends BlockStateProvider { + + public BlockStateGenerator(DataGenerator dataGenerator, ExistingFileHelper existingFileHelper){ + super(dataGenerator, ActuallyAdditions.MODID, existingFileHelper); + } + + @Override + protected void registerStatesAndModels(){ + for(RegistryObject blockEntry : InitBlocks.BLOCKS.getEntries()){ + blockEntry.ifPresent(block -> { + // todo check if the blocks aren't "simple" and provide a different model, + // probably with the help of a interface the block implements, like naturesaura does + this.simpleBlock(block); + }); + } + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/recipes/CrusherRecipeGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/recipes/CrusherRecipeGenerator.java new file mode 100644 index 000000000..c99486805 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/data/recipes/CrusherRecipeGenerator.java @@ -0,0 +1,26 @@ +package de.ellpeck.actuallyadditions.data.recipes; + +import de.ellpeck.actuallyadditions.common.ActuallyAdditions; +import de.ellpeck.actuallyadditions.common.recipes.CrusherRecipe; +import net.minecraft.data.DataGenerator; +import net.minecraft.data.IFinishedRecipe; +import net.minecraft.data.RecipeProvider; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.item.crafting.Ingredient; +import net.minecraft.util.ResourceLocation; + +import java.util.function.Consumer; + +public class CrusherRecipeGenerator extends RecipeProvider { + + public CrusherRecipeGenerator(DataGenerator dataGenerator){ + super(dataGenerator); + } + + @Override + protected void registerRecipes(Consumer consumer){ + super.registerRecipes(consumer); + consumer.accept(new CrusherRecipe(new ResourceLocation(ActuallyAdditions.MODID, "test"), Ingredient.fromItems(Items.DIAMOND), new ItemStack(Items.DIRT, 64))); + } +} diff --git a/src/main/resources/assets/actuallyadditions/recipes/_factories.json b/src/main/resources/assets/actuallyadditions/recipes/_factories.json deleted file mode 100644 index ef0e56c52..000000000 --- a/src/main/resources/assets/actuallyadditions/recipes/_factories.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "recipes": { - "atomic_reconstructor": "de.ellpeck.actuallyadditions.common.recipes.AtomicReconstructorRecipeFactory", - "ball_of_fur": "de.ellpeck.actuallyadditions.common.recipes.BallOfFurRecipeFactory", - "coffee_machine_ingredient": "de.ellpeck.actuallyadditions.common.recipes.CoffeeMachineIngredientFactory", - "compost": "de.ellpeck.actuallyadditions.common.recipes.CompostRecipeFactory", - "crusher": "de.ellpeck.actuallyadditions.common.recipes.CrusherRecipe$CrusherRecipeFactory" - } -} \ No newline at end of file