mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
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 <canitzp@gmail.com>
This commit is contained in:
parent
395b6d0491
commit
2c07ef0fa0
14 changed files with 184 additions and 313 deletions
|
@ -6,10 +6,12 @@ import net.minecraft.item.crafting.IRecipeSerializer;
|
||||||
import net.minecraft.item.crafting.IRecipeType;
|
import net.minecraft.item.crafting.IRecipeType;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recipe class for the AtomicReconstructor when hitting a items stack
|
* Recipe class for the AtomicReconstructor when hitting a items stack
|
||||||
*/
|
*/
|
||||||
public class AtomicReconstructorBlockRecipe implements IDummyRecipe {
|
public class AtomicReconstructorBlockRecipe implements IDummyRecipe<AtomicReconstructorBlockRecipe> {
|
||||||
|
|
||||||
public static final IRecipeType<AtomicReconstructorBlockRecipe> ATOMIC_RECONSTRUCTOR_BLOCK_RECIPE_TYPE = IRecipeType.register("actuallyadditions:atomic_reconstructor_block");
|
public static final IRecipeType<AtomicReconstructorBlockRecipe> ATOMIC_RECONSTRUCTOR_BLOCK_RECIPE_TYPE = IRecipeType.register("actuallyadditions:atomic_reconstructor_block");
|
||||||
|
|
||||||
|
@ -44,16 +46,19 @@ public class AtomicReconstructorBlockRecipe implements IDummyRecipe {
|
||||||
return energyConsumption;
|
return energyConsumption;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getId(){
|
public ResourceLocation getId(){
|
||||||
return this.recipeId;
|
return this.recipeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public IRecipeSerializer<?> getSerializer(){
|
public IRecipeSerializer<AtomicReconstructorBlockRecipe> getSerializer(){
|
||||||
return AtomicReconstructorBlockRecipeFactory.INSTANCE;
|
return AtomicReconstructorBlockRecipeFactory.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public IRecipeType<?> getType(){
|
public IRecipeType<?> getType(){
|
||||||
return ATOMIC_RECONSTRUCTOR_BLOCK_RECIPE_TYPE;
|
return ATOMIC_RECONSTRUCTOR_BLOCK_RECIPE_TYPE;
|
||||||
|
|
|
@ -7,21 +7,23 @@ import net.minecraft.item.crafting.IRecipeType;
|
||||||
import net.minecraft.item.crafting.Ingredient;
|
import net.minecraft.item.crafting.Ingredient;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recipe class for the AtomicReconstructor when hitting a items stack
|
* Recipe class for the AtomicReconstructor when hitting a items stack
|
||||||
*/
|
*/
|
||||||
public class AtomicReconstructorItemRecipe implements IDummyRecipe {
|
public class AtomicReconstructorItemRecipe implements IDummyRecipe<AtomicReconstructorItemRecipe> {
|
||||||
|
|
||||||
public static final IRecipeType<AtomicReconstructorItemRecipe> ATOMIC_RECONSTRUCTOR_ITEM_RECIPE_TYPE = IRecipeType.register("actuallyadditions:atomic_reconstructor_item");
|
public static final IRecipeType<AtomicReconstructorItemRecipe> ATOMIC_RECONSTRUCTOR_ITEM_RECIPE_TYPE = IRecipeType.register("actuallyadditions:atomic_reconstructor_item");
|
||||||
|
|
||||||
private final ResourceLocation recipeId;
|
@Nonnull private final ResourceLocation recipeId;
|
||||||
|
|
||||||
private final Lens lens;
|
@Nonnull private final Lens lens;
|
||||||
private final Ingredient input;
|
@Nonnull private final Ingredient input;
|
||||||
private final ItemStack output;
|
@Nonnull private final ItemStack output;
|
||||||
private final int energyConsumption;
|
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.recipeId = recipeId;
|
||||||
this.lens = lens;
|
this.lens = lens;
|
||||||
this.input = input;
|
this.input = input;
|
||||||
|
@ -29,14 +31,17 @@ public class AtomicReconstructorItemRecipe implements IDummyRecipe {
|
||||||
this.energyConsumption = energyConsumption;
|
this.energyConsumption = energyConsumption;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
public Lens getLens(){
|
public Lens getLens(){
|
||||||
return lens;
|
return lens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
public Ingredient getInput(){
|
public Ingredient getInput(){
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
public ItemStack getOutput(){
|
public ItemStack getOutput(){
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -45,16 +50,19 @@ public class AtomicReconstructorItemRecipe implements IDummyRecipe {
|
||||||
return energyConsumption;
|
return energyConsumption;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getId(){
|
public ResourceLocation getId(){
|
||||||
return this.recipeId;
|
return this.recipeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public IRecipeSerializer<?> getSerializer(){
|
public IRecipeSerializer<AtomicReconstructorItemRecipe> getSerializer(){
|
||||||
return AtomicReconstructorItemRecipeFactory.INSTANCE;
|
return AtomicReconstructorItemRecipeFactory.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public IRecipeType<?> getType(){
|
public IRecipeType<?> getType(){
|
||||||
return ATOMIC_RECONSTRUCTOR_ITEM_RECIPE_TYPE;
|
return ATOMIC_RECONSTRUCTOR_ITEM_RECIPE_TYPE;
|
||||||
|
|
|
@ -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<BallOfFurRecipe> 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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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<IRecipeSerializer<?>> implements IRecipeSerializer<BallOfFurRecipe> {
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -6,22 +6,25 @@ import net.minecraft.item.crafting.Ingredient;
|
||||||
import net.minecraft.potion.EffectInstance;
|
import net.minecraft.potion.EffectInstance;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
public class CoffeeMachineIngredient implements IDummyRecipe{
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public class CoffeeMachineIngredient implements IDummyRecipe<CoffeeMachineIngredient> {
|
||||||
|
|
||||||
public static final IRecipeType<CoffeeMachineIngredient> COFFEE_MACHINE_RECIPE_TYPE = IRecipeType.register("actuallyadditions:coffee_machine");
|
public static final IRecipeType<CoffeeMachineIngredient> COFFEE_MACHINE_RECIPE_TYPE = IRecipeType.register("actuallyadditions:coffee_machine");
|
||||||
|
|
||||||
protected final ResourceLocation recipeId;
|
@Nonnull private final ResourceLocation recipeId;
|
||||||
protected final Ingredient input;
|
@Nonnull private final Ingredient input;
|
||||||
protected final int maxAmplifier;
|
private final int maxAmplifier;
|
||||||
protected final EffectInstance[] effects;
|
@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.recipeId = recipeId;
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.maxAmplifier = maxAmplifier;
|
this.maxAmplifier = maxAmplifier;
|
||||||
this.effects = effects;
|
this.effects = effects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
public Ingredient getInput(){
|
public Ingredient getInput(){
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
@ -30,20 +33,24 @@ public class CoffeeMachineIngredient implements IDummyRecipe{
|
||||||
return maxAmplifier;
|
return maxAmplifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
public EffectInstance[] getEffects(){
|
public EffectInstance[] getEffects(){
|
||||||
return effects;
|
return effects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getId(){
|
public ResourceLocation getId(){
|
||||||
return this.recipeId;
|
return this.recipeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public IRecipeSerializer<?> getSerializer(){
|
public IRecipeSerializer<CoffeeMachineIngredient> getSerializer(){
|
||||||
return CoffeeMachineIngredientFactory.INSTANCE;
|
return CoffeeMachineIngredientFactory.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public IRecipeType<?> getType(){
|
public IRecipeType<?> getType(){
|
||||||
return COFFEE_MACHINE_RECIPE_TYPE;
|
return COFFEE_MACHINE_RECIPE_TYPE;
|
||||||
|
|
|
@ -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<CompostRecipe> 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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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<IRecipeSerializer<?>> implements IRecipeSerializer<CompostRecipe> {
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -12,16 +12,20 @@ import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class CrusherRecipe implements IDummyRecipe {
|
public class CrusherRecipe implements IDummyRecipe<CrusherRecipe> {
|
||||||
|
|
||||||
public static final IRecipeType<CrusherRecipe> RECIPE_TYPE = IRecipeType.register("actuallyadditions:crusher");
|
public static final IRecipeType<CrusherRecipe> RECIPE_TYPE = IRecipeType.register("actuallyadditions:crusher");
|
||||||
public static final CrusherRecipeFactory FACTORY = IRecipeSerializer.register("actuallyadditions:crusher", new CrusherRecipeFactory());
|
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
|
||||||
@Nonnull private final ItemStack output;
|
private final Ingredient input;
|
||||||
@Nonnull private final ItemStack secondaryOutput;
|
@Nonnull
|
||||||
|
private final ItemStack output;
|
||||||
|
@Nonnull
|
||||||
|
private final ItemStack secondaryOutput;
|
||||||
private final int outputChance;
|
private final int outputChance;
|
||||||
|
|
||||||
public CrusherRecipe(@Nonnull ResourceLocation recipeId, @Nonnull Ingredient input, @Nonnull ItemStack output, @Nonnull ItemStack secondaryOutput, 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;
|
this.outputChance = outputChance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CrusherRecipe(@Nonnull ResourceLocation recipeId, @Nonnull Ingredient input, @Nonnull ItemStack output){
|
||||||
|
this(recipeId, input, output, ItemStack.EMPTY, 0);
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public Ingredient getInput(){
|
public Ingredient getInput(){
|
||||||
return input;
|
return input;
|
||||||
|
@ -59,7 +67,7 @@ public class CrusherRecipe implements IDummyRecipe {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public IRecipeSerializer<?> getSerializer(){
|
public IRecipeSerializer<CrusherRecipe> getSerializer(){
|
||||||
return FACTORY;
|
return FACTORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +101,17 @@ public class CrusherRecipe implements IDummyRecipe {
|
||||||
return new CrusherRecipe(recipeId, input, firstOutput, secondOutput, secondaryOutputChance);
|
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
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CrusherRecipe read(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer){
|
public CrusherRecipe read(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer){
|
||||||
|
|
|
@ -1,25 +1,37 @@
|
||||||
package de.ellpeck.actuallyadditions.common.recipes;
|
package de.ellpeck.actuallyadditions.common.recipes;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import net.minecraft.data.IFinishedRecipe;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.crafting.IRecipe;
|
import net.minecraft.item.crafting.IRecipe;
|
||||||
|
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.world.World;
|
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,
|
* 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.
|
* 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
|
* Additionally the "isDynamic()" methods now returns true, because this indicates that the recipe book doesn't list
|
||||||
* this recipe at all.
|
* this recipe at all.
|
||||||
*/
|
*/
|
||||||
public interface IDummyRecipe extends IRecipe<IInventory> {
|
public interface IDummyRecipe<T extends IDummyRecipe<T>> extends IRecipe<IInventory>, IFinishedRecipe {
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
IRecipeSerializer<T> getSerializer();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default boolean matches(IInventory inv, World worldIn){
|
default boolean matches(@Nonnull IInventory inv, @Nonnull World world){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
default ItemStack getCraftingResult(IInventory inv){
|
default ItemStack getCraftingResult(@Nonnull IInventory inv){
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +40,7 @@ public interface IDummyRecipe extends IRecipe<IInventory> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
default ItemStack getRecipeOutput(){
|
default ItemStack getRecipeOutput(){
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
|
@ -39,4 +52,28 @@ public interface IDummyRecipe extends IRecipe<IInventory> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void serialize(@Nonnull JsonObject json){
|
||||||
|
if(this.getSerializer() instanceof RecipeFactoryBase){
|
||||||
|
(((RecipeFactoryBase<T>) 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
package de.ellpeck.actuallyadditions.common.recipes;
|
package de.ellpeck.actuallyadditions.common.recipes;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||||
import net.minecraft.item.crafting.Ingredient;
|
import net.minecraft.item.crafting.Ingredient;
|
||||||
import net.minecraft.item.crafting.ShapedRecipe;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||||
|
|
||||||
public abstract class RecipeFactoryBase<T extends IDummyRecipe> extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<T> {
|
public abstract class RecipeFactoryBase<T extends IDummyRecipe<T>> extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<T> {
|
||||||
|
|
||||||
|
public abstract void write(JsonObject json, T recipe);
|
||||||
|
|
||||||
protected Ingredient readIngredient(JsonObject json, String key){
|
protected Ingredient readIngredient(JsonObject json, String key){
|
||||||
if(json.has(key)){
|
if(json.has(key)){
|
||||||
|
@ -31,7 +34,7 @@ public abstract class RecipeFactoryBase<T extends IDummyRecipe> extends ForgeReg
|
||||||
protected ItemStack readItemStack(JsonObject json, String key){
|
protected ItemStack readItemStack(JsonObject json, String key){
|
||||||
if(json.has(key)){
|
if(json.has(key)){
|
||||||
if(json.get(key).isJsonObject()){
|
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()){
|
} else if(json.get(key).isJsonPrimitive()){
|
||||||
ResourceLocation itemKey = new ResourceLocation(json.get(key).getAsString());
|
ResourceLocation itemKey = new ResourceLocation(json.get(key).getAsString());
|
||||||
if(ForgeRegistries.ITEMS.containsKey(itemKey)){
|
if(ForgeRegistries.ITEMS.containsKey(itemKey)){
|
||||||
|
@ -47,6 +50,16 @@ public abstract class RecipeFactoryBase<T extends IDummyRecipe> 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){
|
protected ItemStack readItemStack(JsonObject json, String key, ItemStack alternative){
|
||||||
try{
|
try{
|
||||||
return this.readItemStack(json, key);
|
return this.readItemStack(json, key);
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package de.ellpeck.actuallyadditions.data;
|
package de.ellpeck.actuallyadditions.data;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
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.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.event.lifecycle.GatherDataEvent;
|
import net.minecraftforge.fml.event.lifecycle.GatherDataEvent;
|
||||||
|
@ -9,7 +12,11 @@ import net.minecraftforge.fml.event.lifecycle.GatherDataEvent;
|
||||||
public class AADataGenerator {
|
public class AADataGenerator {
|
||||||
|
|
||||||
@SubscribeEvent
|
@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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<Block> 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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<IFinishedRecipe> consumer){
|
||||||
|
super.registerRecipes(consumer);
|
||||||
|
consumer.accept(new CrusherRecipe(new ResourceLocation(ActuallyAdditions.MODID, "test"), Ingredient.fromItems(Items.DIAMOND), new ItemStack(Items.DIRT, 64)));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue