Skip to content

Commit

Permalink
Added support for both squeezers, fixed crash with squeezing blank
Browse files Browse the repository at this point in the history
facade, made just return blank facade
  • Loading branch information
kirjorjos committed Dec 23, 2024
1 parent d72642a commit e5cfb01
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 57 deletions.
3 changes: 1 addition & 2 deletions src/main/java/org/cyclops/integrateddynamics/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.cyclops.integrateddynamics.inventory.container.*;
import org.cyclops.integrateddynamics.item.*;
import org.cyclops.integrateddynamics.recipe.ItemFacadeRecipeConfig;
import org.cyclops.integrateddynamics.recipe.ItemFacadeSqueezeRecipeConfig;
import org.cyclops.integrateddynamics.recipe.ItemVariableCopyRecipeConfig;
import org.cyclops.integrateddynamics.recipe.RecipeSerializerCraftingSpecialShapedOmniDirectional3Config;
import org.cyclops.integrateddynamics.recipe.RecipeSerializerCraftingSpecialShapedOmniDirectionalConfig;
Expand Down Expand Up @@ -191,7 +190,7 @@ public static void registerBlocks(ConfigHandler configHandler) {
configHandler.addConfigurable(new RecipeEnergyContainerCombinationConfig());
configHandler.addConfigurable(new ItemVariableCopyRecipeConfig());
configHandler.addConfigurable(new ItemFacadeRecipeConfig());
configHandler.addConfigurable(new ItemFacadeSqueezeRecipeConfig());
configHandler.addConfigurable(new RecipeFacadeSqueezeConfig());
configHandler.addConfigurable(new RecipeSerializerCraftingSpecialShapedOmniDirectionalConfig());
configHandler.addConfigurable(new RecipeSerializerCraftingSpecialShapedOmniDirectional3Config());
configHandler.addConfigurable(new RecipeSerializerCraftingSpecialShapelessOmniDirectionalConfig());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.cyclops.integrateddynamics.item.ItemFacade;
import org.cyclops.integrateddynamics.item.ItemVariable;
import org.cyclops.integrateddynamics.recipe.ItemFacadeRecipe;
import org.cyclops.integrateddynamics.recipe.ItemFacadeSqueezeRecipe;
import org.cyclops.integrateddynamics.recipe.ItemVariableCopyRecipe;
import org.cyclops.integrateddynamics.world.gen.foliageplacer.FoliagePlacerMenril;
import org.cyclops.integrateddynamics.world.gen.trunkplacer.TrunkPlacerMenril;
Expand Down Expand Up @@ -210,8 +209,8 @@ public class RegistryEntries {
public static final RecipeType<RecipeSqueezer> RECIPETYPE_SQUEEZER = null;
@ObjectHolder(registryName = "recipe_type", value = "integrateddynamics:mechanical_squeezer")
public static final RecipeType<RecipeMechanicalSqueezer> RECIPETYPE_MECHANICAL_SQUEEZER = null;
@ObjectHolder(registryName = "recipe_type", value = "integrateddynamics:squeeze_facade")
public static final RecipeType<ItemFacadeSqueezeRecipe> RECIPETYPE_SQUEEZE_FACADE = null;
@ObjectHolder(registryName = "recipe_type", value = "integrateddynamics:facade_squeeze")
public static final RecipeType<RecipeFacadeSqueeze> RECIPETYPE_FACADE_SQUEEZE = null;

@ObjectHolder(registryName = "recipe_serializer", value = "integrateddynamics:drying_basin")
public static final RecipeSerializer<RecipeDryingBasin> RECIPESERIALIZER_DRYING_BASIN = null;
Expand All @@ -225,8 +224,8 @@ public class RegistryEntries {
public static final RecipeSerializer<RecipeNbtClear> RECIPESERIALIZER_NBT_CLEAR = null;
@ObjectHolder(registryName = "recipe_serializer", value = "integrateddynamics:crafting_special_energycontainer_combination")
public static final RecipeSerializer<RecipeEnergyContainerCombination> RECIPESERIALIZER_ENERGY_CONTAINER_COMBINATION = null;
@ObjectHolder(registryName = "recipe_serializer", value = "integrateddynamics:squeeze_facade")
public static final RecipeSerializer<ItemFacadeSqueezeRecipe> RECIPESERIALIZER_FACADE_SQUEEZE = null;
@ObjectHolder(registryName = "recipe_serializer", value = "integrateddynamics:facade_squeeze")
public static final RecipeSerializer<RecipeFacadeSqueeze> RECIPESERIALIZER_FACADE_SQUEEZE = null;
@ObjectHolder(registryName = "recipe_serializer", value = "integrateddynamics:crafting_special_facade")
public static final SimpleRecipeSerializer<ItemFacadeRecipe> RECIPESERIALIZER_FACADE = null;
@ObjectHolder(registryName = "recipe_serializer", value = "integrateddynamics:crafting_special_variable_copy")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.cyclops.integrateddynamics.block.BlockMechanicalSqueezerConfig;
import org.cyclops.integrateddynamics.core.blockentity.BlockEntityMechanicalMachine;
import org.cyclops.integrateddynamics.core.recipe.handler.RecipeHandlerSqueezer;
import org.cyclops.integrateddynamics.core.recipe.type.RecipeFacadeSqueeze;
import org.cyclops.integrateddynamics.core.recipe.type.RecipeMechanicalSqueezer;
import org.cyclops.integrateddynamics.core.recipe.type.RecipeSqueezer;
import org.cyclops.integrateddynamics.inventory.container.ContainerMechanicalSqueezer;
Expand Down Expand Up @@ -76,7 +77,11 @@ protected SingleCache.ICacheUpdater<ItemStack, Optional<RecipeMechanicalSqueezer
@Override
public Optional<RecipeMechanicalSqueezer> getNewValue(ItemStack key) {
Container recipeInput = new SimpleContainer(key);
return CraftingHelpers.findServerRecipe(getRecipeRegistry(), recipeInput, getLevel());
Optional<RecipeMechanicalSqueezer> recipe = CraftingHelpers.findServerRecipe(getRecipeRegistry(), recipeInput, getLevel());
if (recipe.isEmpty() && key.getItem().getDescriptionId().equals("item.integrateddynamics.facade")) {
recipe = Optional.of(new RecipeFacadeSqueeze(null, 20)); //fake recipe
}
return recipe;
}

@Override
Expand Down Expand Up @@ -142,7 +147,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.getOutputItems(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 @@ -32,6 +32,7 @@
import org.cyclops.integrateddynamics.RegistryEntries;
import org.cyclops.integrateddynamics.block.BlockSqueezer;
import org.cyclops.integrateddynamics.core.recipe.handler.RecipeHandlerSqueezer;
import org.cyclops.integrateddynamics.core.recipe.type.RecipeFacadeSqueeze;
import org.cyclops.integrateddynamics.core.recipe.type.RecipeSqueezer;

import java.util.Arrays;
Expand Down Expand Up @@ -83,9 +84,13 @@ public void setItem(int slotId, ItemStack itemstack) {
recipeCache = new SingleCache<>(
new SingleCache.ICacheUpdater<ItemStack, Optional<RecipeSqueezer>>() {
@Override
public Optional<RecipeSqueezer> getNewValue(ItemStack key) {
public Optional getNewValue(ItemStack key) {
Container recipeInput = new SimpleContainer(key);
return CraftingHelpers.findServerRecipe(getRegistry(), recipeInput, getLevel());
Optional<?> recipe = CraftingHelpers.findServerRecipe(getRegistry(), recipeInput, getLevel());
if (recipe.isEmpty() && key.getItem().getDescriptionId().equals("item.integrateddynamics.facade")) {
recipe = Optional.of(new RecipeFacadeSqueeze(null, -1)); //fake recipe
}
return recipe;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.cyclops.integrateddynamics.recipe;
package org.cyclops.integrateddynamics.core.recipe.type;

import org.cyclops.integrateddynamics.core.recipe.type.RecipeSqueezerNBT;
import com.mojang.datafixers.util.Either;

import org.cyclops.cyclopscore.recipe.ItemStackFromIngredient;
import org.cyclops.integrateddynamics.RegistryEntries;
import org.cyclops.integrateddynamics.core.recipe.type.RecipeSqueezerOutputCalculator;

import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
Expand All @@ -14,22 +12,27 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.registries.ForgeRegistries;


public class ItemFacadeSqueezeRecipe extends RecipeSqueezerNBT {
public class RecipeFacadeSqueeze extends RecipeMechanicalSqueezer {

private final static ItemStack facadeItemStack = new ItemStack(ForgeRegistries.ITEMS.getValue((new ResourceLocation("integrateddynamics:facade"))));

public ItemFacadeSqueezeRecipe(ResourceLocation id) {
super(id, facadeItemStack, new ItemFacadeSqueezeRecipeCalculator(), FluidStack.EMPTY);
public RecipeFacadeSqueeze(ResourceLocation id, int duration) {
super(id, Ingredient.of(facadeItemStack), new ItemFacadeSqueezeRecipeCalculator().getItems(facadeItemStack), FluidStack.EMPTY, duration);
}

public RecipeSerializer<?> getSerializer() {
return RegistryEntries.RECIPESERIALIZER_FACADE_SQUEEZE;
}

public RecipeType<?> getType() {
return RegistryEntries.RECIPETYPE_FACADE_SQUEEZE;
}

@Override
public NonNullList<IngredientChance> getOutputItems(ItemStack inputItem) {
return new ItemFacadeSqueezeRecipeCalculator().getItems(inputItem);
Expand All @@ -39,15 +42,19 @@ static class ItemFacadeSqueezeRecipeCalculator extends RecipeSqueezerOutputCalcu

@Override
public NonNullList<IngredientChance> getItems(ItemStack inputItem) {
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);

Either<ItemStack, ItemStackFromIngredient> itemStack = Either.left(new ItemStack(item));
IngredientChance combinedBlock = new IngredientChance(itemStack, 100.0F);
IngredientChance combinedBlock = new IngredientChance(itemStack, 1.0F);

Either<ItemStack, ItemStackFromIngredient> facadeEither = Either.left(facadeItemStack);
IngredientChance facade = new IngredientChance(facadeEither, 100.0F);
return NonNullList.of(facade, facade, combinedBlock);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.cyclops.integrateddynamics.core.recipe.type;

import org.cyclops.cyclopscore.config.extendedconfig.RecipeConfig;
import org.cyclops.integrateddynamics.IntegratedDynamics;
import org.cyclops.integrateddynamics.recipe.ItemFacadeRecipe;

/**
* Config for {@link ItemFacadeRecipe}.
* @author rubensworks
*/
public class RecipeFacadeSqueezeConfig extends RecipeConfig<RecipeFacadeSqueeze> {

public RecipeFacadeSqueezeConfig() {
super(IntegratedDynamics._instance,
"squeeze_facade",
eConfig -> new RecipeSerializerFacadeSqueeze());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.cyclops.integrateddynamics.core.recipe.type;

import org.jetbrains.annotations.Nullable;

import com.google.gson.JsonObject;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.RecipeSerializer;

public class RecipeSerializerFacadeSqueeze implements RecipeSerializer<RecipeFacadeSqueeze>{

@Override
public RecipeFacadeSqueeze fromJson(ResourceLocation recipeID, JsonObject json) {
return new RecipeFacadeSqueeze(recipeID, 20);
}


@Nullable
@Override
public RecipeFacadeSqueeze fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) {
return new RecipeFacadeSqueeze(recipeId, 20);
}

@Override
public void toNetwork(FriendlyByteBuf buffer, RecipeFacadeSqueeze recipe) {}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.cyclops.integrateddynamics.core.recipe.type;

import org.cyclops.cyclopscore.config.extendedconfig.RecipeTypeConfig;
import org.cyclops.integrateddynamics.IntegratedDynamics;

public class RecipeTypeFacadeSqueezeConfig extends RecipeTypeConfig<RecipeFacadeSqueeze> {

public RecipeTypeFacadeSqueezeConfig() {
super(
IntegratedDynamics._instance,
"facade_squeeze"
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "integrateddynamics:facade_squeeze",
"duration": 10
}

This file was deleted.

0 comments on commit e5cfb01

Please sign in to comment.