From 39050bc5f569e192b465f90a914d84888525935f Mon Sep 17 00:00:00 2001 From: kirjorjos Date: Tue, 31 Dec 2024 11:28:18 -0500 Subject: [PATCH] Add recipes for clearing facades --- .../BlockEntityMechanicalSqueezer.java | 2 +- .../blockentity/BlockEntitySqueezer.java | 5 +-- .../recipe/type/FacadeSqueezeCalculator.java | 36 +++++++++++++++++++ .../core/recipe/type/RecipeSqueezer.java | 5 +++ .../mechanical_facade_squeeze.json | 19 ++++++++++ .../recipes/special/facade_clear.json | 4 +++ .../squeezer/convenience/facade_squeeze.json | 18 ++++++++++ 7 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/cyclops/integrateddynamics/core/recipe/type/FacadeSqueezeCalculator.java create mode 100644 src/main/resources/data/integrateddynamics/recipes/mechanical_squeezer/convenience/mechanical_facade_squeeze.json create mode 100644 src/main/resources/data/integrateddynamics/recipes/special/facade_clear.json create mode 100644 src/main/resources/data/integrateddynamics/recipes/squeezer/convenience/facade_squeeze.json diff --git a/src/main/java/org/cyclops/integrateddynamics/blockentity/BlockEntityMechanicalSqueezer.java b/src/main/java/org/cyclops/integrateddynamics/blockentity/BlockEntityMechanicalSqueezer.java index f04354ec78d..6f2ca2fa400 100644 --- a/src/main/java/org/cyclops/integrateddynamics/blockentity/BlockEntityMechanicalSqueezer.java +++ b/src/main/java/org/cyclops/integrateddynamics/blockentity/BlockEntityMechanicalSqueezer.java @@ -142,7 +142,7 @@ public int getRecipeDuration(RecipeMechanicalSqueezer recipe) { protected boolean finalizeRecipe(RecipeMechanicalSqueezer recipe, boolean simulate) { // Output items NonNullList outputStacks = NonNullList.create(); - for (RecipeSqueezer.IngredientChance itemStackChance : recipe.getOutputItems()) { + for (RecipeSqueezer.IngredientChance itemStackChance : recipe.assemble(getInventory().getItem(SLOT_INPUT))) { ItemStack outputStack = itemStackChance.getIngredientFirst().copy(); if (!outputStack.isEmpty() && (simulate || itemStackChance.getChance() == 1.0F || itemStackChance.getChance() >= getLevel().random.nextFloat())) { diff --git a/src/main/java/org/cyclops/integrateddynamics/blockentity/BlockEntitySqueezer.java b/src/main/java/org/cyclops/integrateddynamics/blockentity/BlockEntitySqueezer.java index a45badcb914..184eb2e8973 100644 --- a/src/main/java/org/cyclops/integrateddynamics/blockentity/BlockEntitySqueezer.java +++ b/src/main/java/org/cyclops/integrateddynamics/blockentity/BlockEntitySqueezer.java @@ -161,9 +161,10 @@ protected void update(Level level, BlockPos pos, BlockState blockState, BlockEnt Optional recipeOptional = blockEntity.getCurrentRecipe(); if (recipeOptional.isPresent()) { RecipeSqueezer recipe = recipeOptional.get(); + ItemStack oldItem = blockEntity.getInventory().getItem(0); blockEntity.getInventory().setItem(0, ItemStack.EMPTY); - for (RecipeSqueezer.IngredientChance itemStackChance : recipe.getOutputItems()) { - if (itemStackChance.getChance() == 1.0F || itemStackChance.getChance() >= level.random.nextFloat()) { + for (RecipeSqueezer.IngredientChance itemStackChance : recipe.assemble(oldItem)) { + if (itemStackChance.getChance() == 1.0F || itemStackChance.getChance() >= level.random.nextFloat()) { ItemStack resultStack = itemStackChance.getIngredientFirst().copy(); for (Direction side : Direction.values()) { if (!resultStack.isEmpty() && side != Direction.UP) { diff --git a/src/main/java/org/cyclops/integrateddynamics/core/recipe/type/FacadeSqueezeCalculator.java b/src/main/java/org/cyclops/integrateddynamics/core/recipe/type/FacadeSqueezeCalculator.java new file mode 100644 index 00000000000..aca9d4a97f6 --- /dev/null +++ b/src/main/java/org/cyclops/integrateddynamics/core/recipe/type/FacadeSqueezeCalculator.java @@ -0,0 +1,36 @@ +package org.cyclops.integrateddynamics.core.recipe.type; + +import org.cyclops.cyclopscore.recipe.ItemStackFromIngredient; +import org.cyclops.integrateddynamics.RegistryEntries; +import org.cyclops.integrateddynamics.core.recipe.type.RecipeSqueezer.IngredientChance; + +import com.mojang.datafixers.util.Either; + +import net.minecraft.core.NonNullList; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.registries.ForgeRegistries; + +public class FacadeSqueezeCalculator { + + public static NonNullList getOutputItems(ItemStack inputItem) { + ItemStack facadeItemStack = new ItemStack(RegistryEntries.ITEM_FACADE); + + facadeItemStack.setTag(null); + Either facadeEither = Either.left(facadeItemStack); + IngredientChance facade = new IngredientChance(facadeEither, 1.0F); + + CompoundTag nbt = inputItem.getOrCreateTag(); + ResourceLocation resourceLocation = new ResourceLocation(nbt.getCompound("block").getString("Name")); + Item item = ForgeRegistries.ITEMS.getValue(resourceLocation); + + if (resourceLocation.toString().equals("minecraft:")) return NonNullList.of(facade, facade); // NBT is either malformed or non-existent + + Either itemStack = Either.left(new ItemStack(item)); + IngredientChance combinedBlock = new IngredientChance(itemStack, 1.0F); + + return NonNullList.of(facade, facade, combinedBlock); + } +} diff --git a/src/main/java/org/cyclops/integrateddynamics/core/recipe/type/RecipeSqueezer.java b/src/main/java/org/cyclops/integrateddynamics/core/recipe/type/RecipeSqueezer.java index 27c6d2f54ed..ba82cb63d52 100644 --- a/src/main/java/org/cyclops/integrateddynamics/core/recipe/type/RecipeSqueezer.java +++ b/src/main/java/org/cyclops/integrateddynamics/core/recipe/type/RecipeSqueezer.java @@ -61,6 +61,11 @@ public ItemStack assemble(Container inv) { return this.outputItems.get(0).getIngredientFirst().copy(); } + public NonNullList assemble(ItemStack inputItem) { + if (!inputItem.is(RegistryEntries.ITEM_FACADE.asItem())) return getOutputItems(); + return FacadeSqueezeCalculator.getOutputItems(inputItem); + } + @Override public boolean canCraftInDimensions(int width, int height) { return width * height <= 1; diff --git a/src/main/resources/data/integrateddynamics/recipes/mechanical_squeezer/convenience/mechanical_facade_squeeze.json b/src/main/resources/data/integrateddynamics/recipes/mechanical_squeezer/convenience/mechanical_facade_squeeze.json new file mode 100644 index 00000000000..cd756306f18 --- /dev/null +++ b/src/main/resources/data/integrateddynamics/recipes/mechanical_squeezer/convenience/mechanical_facade_squeeze.json @@ -0,0 +1,19 @@ +{ + "type": "integrateddynamics:mechanical_squeezer", + "item": "integrateddynamics:facade", + "result": { + "items": [ + { + "item": "integrateddynamics:facade", + "chance": 1, + "count": 1 + }, + { + "item": "integrateddynamics:facade", + "chance": 1, + "count": 1 + } + ] + }, + "duration": 20 +} \ No newline at end of file diff --git a/src/main/resources/data/integrateddynamics/recipes/special/facade_clear.json b/src/main/resources/data/integrateddynamics/recipes/special/facade_clear.json new file mode 100644 index 00000000000..800a2b5b830 --- /dev/null +++ b/src/main/resources/data/integrateddynamics/recipes/special/facade_clear.json @@ -0,0 +1,4 @@ +{ + "type": "integrateddynamics:crafting_special_nbt_clear", + "item": "integrateddynamics:facade" +} \ No newline at end of file diff --git a/src/main/resources/data/integrateddynamics/recipes/squeezer/convenience/facade_squeeze.json b/src/main/resources/data/integrateddynamics/recipes/squeezer/convenience/facade_squeeze.json new file mode 100644 index 00000000000..d68dfa42d40 --- /dev/null +++ b/src/main/resources/data/integrateddynamics/recipes/squeezer/convenience/facade_squeeze.json @@ -0,0 +1,18 @@ +{ + "type": "integrateddynamics:squeezer", + "item": "integrateddynamics:facade", + "result": { + "items": [ + { + "item": "integrateddynamics:facade", + "chance": 1, + "count": 1 + }, + { + "item": "integrateddynamics:facade", + "chance": 1, + "count": 1 + } + ] + } +} \ No newline at end of file