Skip to content

Commit

Permalink
Add recipes for clearing facades
Browse files Browse the repository at this point in the history
  • Loading branch information
kirjorjos committed Dec 31, 2024
1 parent 3faef4c commit 39050bc
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public int getRecipeDuration(RecipeMechanicalSqueezer recipe) {
protected boolean finalizeRecipe(RecipeMechanicalSqueezer recipe, boolean simulate) {
// Output items
NonNullList<ItemStack> 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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ protected void update(Level level, BlockPos pos, BlockState blockState, BlockEnt
Optional<RecipeSqueezer> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<IngredientChance> getOutputItems(ItemStack inputItem) {
ItemStack facadeItemStack = new ItemStack(RegistryEntries.ITEM_FACADE);

facadeItemStack.setTag(null);
Either<ItemStack, ItemStackFromIngredient> 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, ItemStackFromIngredient> itemStack = Either.left(new ItemStack(item));
IngredientChance combinedBlock = new IngredientChance(itemStack, 1.0F);

return NonNullList.of(facade, facade, combinedBlock);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public ItemStack assemble(Container inv) {
return this.outputItems.get(0).getIngredientFirst().copy();
}

public NonNullList<IngredientChance> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "integrateddynamics:crafting_special_nbt_clear",
"item": "integrateddynamics:facade"
}
Original file line number Diff line number Diff line change
@@ -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
}
]
}
}

0 comments on commit 39050bc

Please sign in to comment.