From 26343b77c16f22f2f9fd8d98184b5246a4864569 Mon Sep 17 00:00:00 2001 From: Flanks255 <32142731+Flanks255@users.noreply.github.com> Date: Tue, 12 Oct 2021 22:08:31 -0500 Subject: [PATCH] Implemented LaserRecipe... Hopefully... --- .../data/ActuallyAdditionsData.java | 2 + .../data/LaserRecipeGenerator.java | 35 +++++ .../mod/crafting/ActuallyRecipes.java | 18 ++- .../mod/crafting/LaserRecipe.java | 147 ++++++++++++++++++ 4 files changed, 199 insertions(+), 3 deletions(-) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/data/LaserRecipeGenerator.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/crafting/LaserRecipe.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java b/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java index 564137a39..b52409e1d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java @@ -29,6 +29,8 @@ public class ActuallyAdditionsData { generator.addProvider(new ItemRecipeGenerator(generator)); generator.addProvider(generatorBlockTags); generator.addProvider(new ItemTagsGenerator(generator, generatorBlockTags, helper)); + + generator.addProvider(new LaserRecipeGenerator(generator)); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/LaserRecipeGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/LaserRecipeGenerator.java new file mode 100644 index 000000000..0d4cd22c9 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/data/LaserRecipeGenerator.java @@ -0,0 +1,35 @@ +package de.ellpeck.actuallyadditions.data; + +import com.google.gson.JsonObject; +import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; +import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; +import de.ellpeck.actuallyadditions.mod.crafting.LaserRecipe; +import net.minecraft.data.DataGenerator; +import net.minecraft.data.DirectoryCache; +import net.minecraft.data.IFinishedRecipe; +import net.minecraft.data.RecipeProvider; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.Ingredient; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.Tags; + +import java.nio.file.Path; +import java.util.function.Consumer; + +public class LaserRecipeGenerator extends RecipeProvider { + public LaserRecipeGenerator(DataGenerator p_i48262_1_) { + super(p_i48262_1_); + } + + @Override + protected void saveAdvancement(DirectoryCache pCache, JsonObject pAdvancementJson, Path pPath) { + } + + @Override + protected void buildShapelessRecipes(Consumer consumer) { + + + consumer.accept(new LaserRecipe.FinishedRecipe(new ResourceLocation(ActuallyAdditions.MODID, "laser_restonia_block"), + Ingredient.of(Tags.Items.STORAGE_BLOCKS_REDSTONE), 400, new ItemStack(ActuallyBlocks.RESTONIA_CRYSTAL.getItem()))); + } +} 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 6aea6f7a2..181c56130 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ActuallyRecipes.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ActuallyRecipes.java @@ -2,17 +2,29 @@ package de.ellpeck.actuallyadditions.mod.crafting; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import net.minecraft.item.crafting.IRecipeSerializer; +import net.minecraft.item.crafting.IRecipeType; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; public class ActuallyRecipes { - public static final DeferredRegister> RECIPE_TYPES = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, ActuallyAdditions.MODID); + public static final DeferredRegister> SERIALIZERS = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, ActuallyAdditions.MODID); public static void init(IEventBus bus) { - RECIPE_TYPES.register(bus); + SERIALIZERS.register(bus); } - public static final RegistryObject> KEEP_DATA_SHAPED_RECIPE = RECIPE_TYPES.register(RecipeKeepDataShaped.NAME, RecipeKeepDataShaped.Serializer::new); + 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 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 CRUSHING = IRecipeType.register(ActuallyAdditions.MODID + ":crush"); + public static final IRecipeType COALGEN = IRecipeType.register(ActuallyAdditions.MODID + ":coal_power"); + public static final IRecipeType OILGEN = IRecipeType.register(ActuallyAdditions.MODID + ":oil_power"); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/LaserRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/LaserRecipe.java new file mode 100644 index 000000000..5c9121284 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/LaserRecipe.java @@ -0,0 +1,147 @@ +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.*; +import net.minecraft.network.PacketBuffer; +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; + +import javax.annotation.Nullable; + + +public class LaserRecipe implements IRecipe { + public static String NAME = "laser"; + private ItemStack result; + private Ingredient itemIngredient; + private int energy; + private ResourceLocation id; + + public LaserRecipe(ResourceLocation id, ItemStack result, Ingredient itemIngredient, int energy) { + this.result = result; + this.itemIngredient = itemIngredient; + this.energy = energy; + this.id = id; + } + + public int getEnergy() { + return energy; + } + + public boolean matches(ItemStack itemStack, int energyIn) { + + return itemIngredient.test(itemStack) && (energyIn >= energy); + } + + //nah + @Override + public boolean matches(IInventory pInv, World pLevel) { + return false; + } + + @Override + public ItemStack assemble(IInventory pInv) { + return null; + } + + @Override + public boolean canCraftInDimensions(int pWidth, int pHeight) { + return false; + } + + @Override + public ItemStack getResultItem() { + return result; + } + + @Override + public ResourceLocation getId() { + return id; + } + + @Override + public IRecipeSerializer getSerializer() { + return ActuallyRecipes.LASER_RECIPE.get(); + } + + @Override + public IRecipeType getType() { + return ActuallyRecipes.Types.LASER; + } + + public static class Serializer extends ForgeRegistryEntry> implements IRecipeSerializer { + + @Override + public LaserRecipe fromJson(ResourceLocation pRecipeId, JsonObject pJson) { + Ingredient ingredient = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "ingredient")); + int energy = JSONUtils.getAsInt(pJson, "energy"); + ItemStack result = new ItemStack(JSONUtils.getAsItem(pJson, "result")); + + return new LaserRecipe(pRecipeId, result, ingredient, energy); + } + + @Nullable + @Override + public LaserRecipe fromNetwork(ResourceLocation pRecipeId, PacketBuffer pBuffer) { + Ingredient ingredient = Ingredient.fromNetwork(pBuffer); + int energy = pBuffer.readInt(); + ItemStack result = pBuffer.readItem(); + return new LaserRecipe(pRecipeId, result, ingredient, energy); + } + + @Override + public void toNetwork(PacketBuffer pBuffer, LaserRecipe pRecipe) { + pRecipe.itemIngredient.toNetwork(pBuffer); + pBuffer.writeInt(pRecipe.energy); + pBuffer.writeItem(pRecipe.result); + } + } + + public static class FinishedRecipe implements IFinishedRecipe { + private ResourceLocation id; + private Ingredient itemIngredient; + private int energy; + private ItemStack output; + + public FinishedRecipe(ResourceLocation id, Ingredient itemIngredient, int energy, ItemStack output) { + this.id = id; + this.itemIngredient = itemIngredient; + this.energy = energy; + this.output = output; + } + + @Override + public void serializeRecipeData(JsonObject pJson) { + pJson.add("input", itemIngredient.toJson()); + pJson.addProperty("energy", energy); + pJson.addProperty("output", Registry.ITEM.getKey(output.getItem()).toString()); + } + + @Override + public ResourceLocation getId() { + return id; + } + + @Override + public IRecipeSerializer getType() { + return ActuallyRecipes.LASER_RECIPE.get(); + } + + @Nullable + @Override + public JsonObject serializeAdvancement() { + return null; + } + + @Nullable + @Override + public ResourceLocation getAdvancementId() { + return null; + } + } +}