From f105b4c2658a402b5bd96ee718ecf741126b0a53 Mon Sep 17 00:00:00 2001 From: Flanks255 <32142731+Flanks255@users.noreply.github.com> Date: Wed, 13 Oct 2021 18:54:14 -0500 Subject: [PATCH] Empowering recipe is done, datagen next. --- .../api/ActuallyAdditionsAPI.java | 2 +- .../api/recipe/EmpowererRecipe.java | 111 -------- .../data/ActuallyAdditionsData.java | 1 + .../data/MiscRecipeGenerator.java | 32 +++ .../mod/crafting/ActuallyRecipes.java | 3 +- .../mod/crafting/EmpowererRecipe.java | 252 ++++++++++++++++++ .../mod/crafting/LaserRecipe.java | 3 +- .../mod/items/metalists/Crystals.java | 12 +- .../mod/tile/TileEntityEmpowerer.java | 8 +- 9 files changed, 301 insertions(+), 123 deletions(-) delete mode 100644 src/main/java/de/ellpeck/actuallyadditions/api/recipe/EmpowererRecipe.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/data/MiscRecipeGenerator.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/crafting/EmpowererRecipe.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java index 65dc35fee..68eda4251 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java @@ -19,6 +19,7 @@ import de.ellpeck.actuallyadditions.api.laser.ILaserRelayConnectionHandler; import de.ellpeck.actuallyadditions.api.lens.Lens; import de.ellpeck.actuallyadditions.api.lens.LensConversion; import de.ellpeck.actuallyadditions.api.recipe.*; +import de.ellpeck.actuallyadditions.mod.crafting.EmpowererRecipe; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.item.Item; @@ -40,7 +41,6 @@ public final class ActuallyAdditionsAPI { public static final List BALL_OF_FUR_RETURN_ITEMS = new ArrayList<>(); // public static final List TREASURE_CHEST_LOOT = new ArrayList<>(); public static final List RECONSTRUCTOR_LENS_CONVERSION_RECIPES = new ArrayList<>(); - public static final List EMPOWERER_RECIPES = new ArrayList<>(); public static final Map RECONSTRUCTOR_LENS_COLOR_CHANGERS = new HashMap<>(); /** * Farmer behaviors are sorted when first accessed, this will not be done until after loading, but do not add behaviors at runtime. diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/EmpowererRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/EmpowererRecipe.java deleted file mode 100644 index ca8934577..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/EmpowererRecipe.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * This file ("EmpowererRecipe.java") is part of the Actually Additions mod for Minecraft. - * It is created and owned by Ellpeck and distributed - * under the Actually Additions License to be found at - * http://ellpeck.de/actaddlicense - * View the source code at https://github.com/Ellpeck/ActuallyAdditions - * - * © 2015-2017 Ellpeck - */ - -package de.ellpeck.actuallyadditions.api.recipe; - -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.Ingredient; - -import java.util.ArrayList; -import java.util.List; - -public class EmpowererRecipe { - - protected final Ingredient input; - protected final ItemStack output; - - protected final Ingredient modifier1; - protected final Ingredient modifier2; - protected final Ingredient modifier3; - protected final Ingredient modifier4; - - protected final int energyPerStand; - protected final float[] particleColor; - protected final int time; - - @Deprecated - public EmpowererRecipe(ItemStack input, ItemStack output, ItemStack modifier1, ItemStack modifier2, ItemStack modifier3, ItemStack modifier4, int energyPerStand, int time, float[] particleColor) { - this(Ingredient.of(input), output, Ingredient.of(modifier1), Ingredient.of(modifier2), Ingredient.of(modifier3), Ingredient.of(modifier4), energyPerStand, time, particleColor); - } - - public EmpowererRecipe(Ingredient input, ItemStack output, Ingredient modifier1, Ingredient modifier2, Ingredient modifier3, Ingredient modifier4, int energyPerStand, int time, float[] particleColor) { - this.input = input; - this.output = output; - this.modifier1 = modifier1; - this.modifier2 = modifier2; - this.modifier3 = modifier3; - this.modifier4 = modifier4; - this.energyPerStand = energyPerStand; - this.particleColor = particleColor; - this.time = time; - } - - public boolean matches(ItemStack base, ItemStack stand1, ItemStack stand2, ItemStack stand3, ItemStack stand4) { - if (!this.input.test(base)) { - return false; - } - List matches = new ArrayList<>(); - ItemStack[] stacks = {stand1, stand2, stand3, stand4}; - boolean[] unused = {true, true, true, true}; - for (ItemStack s : stacks) { - if (unused[0] && this.modifier1.test(s)) { - matches.add(this.modifier1); - unused[0] = false; - } else if (unused[1] && this.modifier2.test(s)) { - matches.add(this.modifier2); - unused[1] = false; - } else if (unused[2] && this.modifier3.test(s)) { - matches.add(this.modifier3); - unused[2] = false; - } else if (unused[3] && this.modifier4.test(s)) { - matches.add(this.modifier4); - unused[3] = false; - } - } - - return matches.size() == 4; - } - - public Ingredient getInput() { - return this.input; - } - - public ItemStack getOutput() { - return this.output; - } - - public Ingredient getStandOne() { - return this.modifier1; - } - - public Ingredient getStandTwo() { - return this.modifier2; - } - - public Ingredient getStandThree() { - return this.modifier3; - } - - public Ingredient getStandFour() { - return this.modifier4; - } - - public int getTime() { - return this.time; - } - - public int getEnergyPerStand() { - return this.energyPerStand; - } - - public float[] getParticleColors() { - return this.particleColor; - } -} diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java b/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java index b52409e1d..4695bd5fe 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java @@ -31,6 +31,7 @@ public class ActuallyAdditionsData { generator.addProvider(new ItemTagsGenerator(generator, generatorBlockTags, helper)); generator.addProvider(new LaserRecipeGenerator(generator)); + generator.addProvider(new MiscRecipeGenerator(generator)); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/MiscRecipeGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/MiscRecipeGenerator.java new file mode 100644 index 000000000..f42d4976c --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/data/MiscRecipeGenerator.java @@ -0,0 +1,32 @@ +package de.ellpeck.actuallyadditions.data; + +import com.google.gson.JsonObject; +import net.minecraft.data.DataGenerator; +import net.minecraft.data.DirectoryCache; +import net.minecraft.data.IFinishedRecipe; +import net.minecraft.data.RecipeProvider; +import net.minecraft.util.IItemProvider; + +import java.nio.file.Path; +import java.util.function.Consumer; + +public class MiscRecipeGenerator extends RecipeProvider { + public MiscRecipeGenerator(DataGenerator p_i48262_1_) { + super(p_i48262_1_); + } + + @Override + protected void saveAdvancement(DirectoryCache pCache, JsonObject pAdvancementJson, Path pPath) { + } + + @Override + protected void buildShapelessRecipes(Consumer p_200404_0_) { + + } + + + + private void addCrystalEmpowering(Consumer consumer) { + + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ActuallyRecipes.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ActuallyRecipes.java index 951771fe2..ff9256ce4 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ActuallyRecipes.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ActuallyRecipes.java @@ -17,12 +17,13 @@ public class ActuallyRecipes { public static final RegistryObject> KEEP_DATA_SHAPED_RECIPE = SERIALIZERS.register(RecipeKeepDataShaped.NAME, RecipeKeepDataShaped.Serializer::new); public static final RegistryObject> LASER_RECIPE = SERIALIZERS.register(LaserRecipe.NAME, LaserRecipe.Serializer::new); + public static final RegistryObject> EMPOWERING_RECIPE = SERIALIZERS.register(EmpowererRecipe.NAME, EmpowererRecipe.Serializer::new); public static class Types { public static final IRecipeType LASER = IRecipeType.register(ActuallyAdditions.MODID + ":laser"); - //public static final IRecipeType EMPOWERING = IRecipeType.register(ActuallyAdditions.MODID + ":empower"); + public static final IRecipeType EMPOWERING = IRecipeType.register(ActuallyAdditions.MODID + ":empower"); //public static final IRecipeType CRUSHING = IRecipeType.register(ActuallyAdditions.MODID + ":crush"); //public static final IRecipeType SOLIDFUEL = IRecipeType.register(ActuallyAdditions.MODID + ":solid_fuel"); //public static final IRecipeType LIQUIDFUEL = IRecipeType.register(ActuallyAdditions.MODID + ":liquid_fuel"); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/EmpowererRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/EmpowererRecipe.java new file mode 100644 index 000000000..071ef2538 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/EmpowererRecipe.java @@ -0,0 +1,252 @@ +package de.ellpeck.actuallyadditions.mod.crafting; + +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.item.crafting.IRecipeType; +import net.minecraft.item.crafting.Ingredient; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.IItemProvider; +import net.minecraft.util.JSONUtils; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; +import net.minecraftforge.registries.ForgeRegistryEntry; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; + +public class EmpowererRecipe implements IRecipe { + public static String NAME = "empowering"; + private ResourceLocation id; + protected final Ingredient input; + protected final ItemStack output; + + protected final Ingredient modifier1; + protected final Ingredient modifier2; + protected final Ingredient modifier3; + protected final Ingredient modifier4; + + protected final int energyPerStand; + protected final int particleColor; + protected final int time; + + public EmpowererRecipe(ResourceLocation id, ItemStack output, Ingredient input, Ingredient modifier1, Ingredient modifier2, Ingredient modifier3, Ingredient modifier4, int energyPerStand, int particleColor, int time) { + this.id = id; + this.input = input; + this.output = output; + this.modifier1 = modifier1; + this.modifier2 = modifier2; + this.modifier3 = modifier3; + this.modifier4 = modifier4; + this.energyPerStand = energyPerStand; + this.particleColor = particleColor; + this.time = time; + } + + public boolean matches(ItemStack base, ItemStack stand1, ItemStack stand2, ItemStack stand3, ItemStack stand4) { + if (!input.test(base) || stand1.isEmpty() || stand2.isEmpty() || stand3.isEmpty() || stand4.isEmpty()) + return false; + List matches = new ArrayList<>(); + ItemStack[] stacks = {stand1, stand2, stand3, stand4}; + boolean[] unused = {true, true, true, true}; + for (ItemStack s : stacks) { + if (unused[0] && this.modifier1.test(s)) { + matches.add(this.modifier1); + unused[0] = false; + } else if (unused[1] && this.modifier2.test(s)) { + matches.add(this.modifier2); + unused[1] = false; + } else if (unused[2] && this.modifier3.test(s)) { + matches.add(this.modifier3); + unused[2] = false; + } else if (unused[3] && this.modifier4.test(s)) { + matches.add(this.modifier4); + unused[3] = false; + } + } + + return matches.size() == 4; + } + + @Override + public boolean matches(IInventory pInv, World pLevel) { + return false; + } + + @Override + public ItemStack assemble(IInventory pInv) { + return output.copy(); + } + + @Override + public boolean canCraftInDimensions(int pWidth, int pHeight) { + return false; + } + + @Override + public ItemStack getResultItem() { + return output; + } + + @Override + public ResourceLocation getId() { + return id; + } + + @Override + public IRecipeSerializer getSerializer() { + return ActuallyRecipes.EMPOWERING_RECIPE.get(); + } + + @Override + public IRecipeType getType() { + return ActuallyRecipes.Types.EMPOWERING; + } + + public Ingredient getInput() { + return this.input; + } + + public ItemStack getOutput() { + return this.output; + } + + public Ingredient getStandOne() { + return this.modifier1; + } + + public Ingredient getStandTwo() { + return this.modifier2; + } + + public Ingredient getStandThree() { + return this.modifier3; + } + + public Ingredient getStandFour() { + return this.modifier4; + } + + public int getTime() { + return this.time; + } + + public int getEnergyPerStand() { + return this.energyPerStand; + } + + public int getParticleColors() { + return this.particleColor; + } + + public static class Serializer extends ForgeRegistryEntry> implements IRecipeSerializer { + @Override + public EmpowererRecipe fromJson(ResourceLocation pRecipeId, JsonObject pJson) { + ItemStack result = new ItemStack(JSONUtils.getAsItem(pJson, "result")); + Ingredient base = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "base")); + Ingredient mod1 = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "modifier1")); + Ingredient mod2 = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "modifier2")); + Ingredient mod3 = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "modifier3")); + Ingredient mod4 = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "modifier4")); + int energy = JSONUtils.getAsInt(pJson, "energy"); + int color = JSONUtils.getAsInt(pJson, "color"); + int time = JSONUtils.getAsInt(pJson, "time"); + + return new EmpowererRecipe(pRecipeId, result, base, mod1, mod2, mod3, mod4, energy, color, time); + } + + @Nullable + @Override + public EmpowererRecipe fromNetwork(ResourceLocation pRecipeId, PacketBuffer pBuffer) { + ItemStack result = pBuffer.readItem(); + Ingredient input = Ingredient.fromNetwork(pBuffer); + Ingredient mod1 = Ingredient.fromNetwork(pBuffer); + Ingredient mod2 = Ingredient.fromNetwork(pBuffer); + Ingredient mod3 = Ingredient.fromNetwork(pBuffer); + Ingredient mod4 = Ingredient.fromNetwork(pBuffer); + int energy = pBuffer.readInt(); + int color = pBuffer.readInt(); + int time = pBuffer.readInt(); + + return new EmpowererRecipe(pRecipeId, result, input, mod1, mod2, mod3, mod4, energy, color, time); + } + + @Override + public void toNetwork(PacketBuffer pBuffer, EmpowererRecipe pRecipe) { + pBuffer.writeItem(pRecipe.output); + pRecipe.input.toNetwork(pBuffer); + pRecipe.modifier1.toNetwork(pBuffer); + pRecipe.modifier2.toNetwork(pBuffer); + pRecipe.modifier3.toNetwork(pBuffer); + pRecipe.modifier4.toNetwork(pBuffer); + pBuffer.writeInt(pRecipe.energyPerStand); + pBuffer.writeInt(pRecipe.particleColor); + pBuffer.writeInt(pRecipe.time); + } + } + + public static class FinishedRecipe implements IFinishedRecipe { + private ResourceLocation id; + private Ingredient base; + private Ingredient mod1; + private Ingredient mod2; + private Ingredient mod3; + private Ingredient mod4; + private int energy; + private int color; + private int time; + private IItemProvider output; + + public FinishedRecipe(ResourceLocation id, IItemProvider output, Ingredient input, Ingredient modifier1, Ingredient modifier2, Ingredient modifier3, Ingredient modifier4, int energyPerStand, int particleColor, int time) { + this.id = id; + this.base = input; + this.output = output; + this.mod1 = modifier1; + this.mod2 = modifier2; + this.mod3 = modifier3; + this.mod4 = modifier4; + this.energy = energyPerStand; + this.color = particleColor; + this.time = time; + } + + @Override + public void serializeRecipeData(JsonObject pJson) { + pJson.add("base", base.toJson()); + pJson.add("modifier1", mod1.toJson()); + pJson.add("modifier2", mod2.toJson()); + pJson.add("modifier3", mod3.toJson()); + pJson.add("modifier4", mod4.toJson()); + pJson.addProperty("energy", energy); + pJson.addProperty("time", time); + pJson.addProperty("color", color); + pJson.addProperty("result", output.asItem().getRegistryName().toString()); + } + + @Override + public ResourceLocation getId() { + return id; + } + + @Override + public IRecipeSerializer getType() { + return ActuallyRecipes.EMPOWERING_RECIPE.get(); + } + + @Nullable + @Override + public JsonObject serializeAdvancement() { + return null; + } + + @Nullable + @Override + public ResourceLocation getAdvancementId() { + return null; + } + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/LaserRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/LaserRecipe.java index 8260c1ac6..dca84ef61 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/LaserRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/LaserRecipe.java @@ -9,7 +9,6 @@ import net.minecraft.network.PacketBuffer; import net.minecraft.util.IItemProvider; import net.minecraft.util.JSONUtils; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.registry.Registry; import net.minecraft.world.World; import net.minecraftforge.registries.ForgeRegistryEntry; @@ -47,7 +46,7 @@ public class LaserRecipe implements IRecipe { @Override public ItemStack assemble(IInventory pInv) { - return null; + return result.copy(); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/metalists/Crystals.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/metalists/Crystals.java index afeede08a..09dd3a5ee 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/metalists/Crystals.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/metalists/Crystals.java @@ -13,12 +13,12 @@ package de.ellpeck.actuallyadditions.mod.items.metalists; import net.minecraft.util.IStringSerializable; public enum Crystals implements IStringSerializable { - REDSTONE("red", 0xFF2F21, 158F / 255F, 43F / 255F, 39F / 255F), - LAPIS("blue", 0x5171FF, 37F / 255F, 49F / 255F, 147F / 255F), - DIAMOND("light_blue", 0x35F1FF, 99F / 255F, 135F / 255F, 210F / 255F), - COAL("black", 0x434442, 0.2F, 0.2F, 0.2F), - EMERALD("green", 0x44E033, 54F / 255F, 75F / 255F, 24F / 255F), - IRON("white", 0xCEDDD4, 0.8F, 0.8F, 0.8F); + REDSTONE("red", 0xFF2F21, 0x9e2b27), + LAPIS("blue", 0x5171FF, 0x253293), + DIAMOND("light_blue", 0x35F1FF, 0x6387d2), + COAL("black", 0x434442, 0x333333), + EMERALD("green", 0x44E033, 0x354a18), + IRON("white", 0xCEDDD4, 0xcccccc); public final String name; public final float[] conversionColorParticles; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java index 303e69ba3..6c3bd915b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java @@ -12,6 +12,9 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe; +import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; +import de.ellpeck.actuallyadditions.mod.crafting.ActuallyRecipes; +import de.ellpeck.actuallyadditions.mod.crafting.EmpowererRecipe; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover; import de.ellpeck.actuallyadditions.mod.util.StackUtil; @@ -28,6 +31,7 @@ import java.util.ArrayList; import java.util.List; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase.NBTType; +import net.minecraftforge.fml.server.ServerLifecycleHooks; public class TileEntityEmpowerer extends TileEntityInventoryBase { @@ -36,7 +40,7 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase { private int lastRecipe; public TileEntityEmpowerer() { - super(ActuallyTiles.EMPOWERER_TILE.get(), 1); + super(ActuallyBlocks.EMPOWERER.getTileEntityType(), 1); } @Deprecated //Use findMatchingRecipe @@ -65,7 +69,7 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase { @Nullable public static EmpowererRecipe findMatchingRecipe(ItemStack base, ItemStack stand1, ItemStack stand2, ItemStack stand3, ItemStack stand4) { - for (EmpowererRecipe r : ActuallyAdditionsAPI.EMPOWERER_RECIPES) { + for (EmpowererRecipe r : ServerLifecycleHooks.getCurrentServer().getRecipeManager().getAllRecipesFor(ActuallyRecipes.Types.EMPOWERING)) { if (r.matches(base, stand1, stand2, stand3, stand4)) { return r; }