Skip to content

Commit

Permalink
Add a recipe for duplicating filled sample takers
Browse files Browse the repository at this point in the history
  • Loading branch information
OffsetMonkey538 committed Oct 15, 2023
1 parent a453b05 commit f47058d
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import top.offsetmonkey538.compactmobfarms.config.ModConfig;
import top.offsetmonkey538.compactmobfarms.item.ModItems;
import top.offsetmonkey538.compactmobfarms.item.group.ModItemGroups;
import top.offsetmonkey538.compactmobfarms.recipe.ModRecipes;
import top.offsetmonkey538.compactmobfarms.screen.ModScreenHandlers;
import top.offsetmonkey538.monkeyconfig538.ConfigManager;

Expand All @@ -34,6 +35,7 @@ public void onInitialize() {
ModItemGroups.register();
ModBlockEntityTypes.register();
ModScreenHandlers.register();
ModRecipes.register();

//noinspection UnstableApiUsage
ItemStorage.SIDED.registerForBlockEntity((block, direction) -> block.getDropInventory(), ModBlockEntityTypes.COMPACT_MOB_FARM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
import net.minecraft.advancement.criterion.InventoryChangedCriterion;
import net.minecraft.data.server.recipe.ComplexRecipeJsonBuilder;
import net.minecraft.data.server.recipe.RecipeJsonProvider;
import net.minecraft.data.server.recipe.ShapedRecipeJsonBuilder;
import net.minecraft.data.server.recipe.ShapelessRecipeJsonBuilder;
import net.minecraft.item.Items;
import net.minecraft.recipe.book.RecipeCategory;
import net.minecraft.registry.tag.ItemTags;
import top.offsetmonkey538.compactmobfarms.item.ModItems;
import top.offsetmonkey538.compactmobfarms.recipe.ModRecipes;

public class ModRecipeProvider extends FabricRecipeProvider {
public ModRecipeProvider(FabricDataOutput output) {
Expand All @@ -19,6 +21,10 @@ public ModRecipeProvider(FabricDataOutput output) {

@Override
public void generate(Consumer<RecipeJsonProvider> exporter) {
ComplexRecipeJsonBuilder
.create(ModRecipes.CLONE_FILLED_SAMPLE_TAKER)
.offerTo(exporter, "clone_filled_sample_taker");

ShapelessRecipeJsonBuilder
.create(RecipeCategory.MISC, ModItems.SPAWNER_SHARD)
.input(ModItems.SPIRIT_BOTTLE, 2)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package top.offsetmonkey538.compactmobfarms.recipe;

import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.recipe.SpecialCraftingRecipe;
import net.minecraft.recipe.book.CraftingRecipeCategory;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import top.offsetmonkey538.compactmobfarms.item.ModItems;
import top.offsetmonkey538.compactmobfarms.item.SampleTakerItem;

public class FilledSampleTakerCloningRecipe extends SpecialCraftingRecipe {
public FilledSampleTakerCloningRecipe(Identifier id, CraftingRecipeCategory category) {
super(id, category);
}

@Override
public boolean matches(RecipeInputInventory inventory, World world) {
boolean foundFilledSampleTaker = false;
boolean foundEmptySampleTaker = false;
boolean foundSpiritBottle = false;

for (int i = 0; i < inventory.getInputStacks().size(); i++) {
final ItemStack stack = inventory.getInputStacks().get(i);
if (stack.isEmpty()) continue;

if (stack.isOf(ModItems.FILLED_SAMPLE_TAKER)) {
if (foundFilledSampleTaker) return false;
foundFilledSampleTaker = true;
}

if (stack.isOf(ModItems.SAMPLE_TAKER)) {
if (SampleTakerItem.getSamplesCollected(stack).size() > 0) return false;

if (foundEmptySampleTaker) return false;
foundEmptySampleTaker = true;
}

if (stack.isOf(ModItems.SPIRIT_BOTTLE)) {
if (foundSpiritBottle) return false;
foundSpiritBottle = true;
}
}

return foundFilledSampleTaker &&
foundEmptySampleTaker &&
foundSpiritBottle;
}

@Override
public ItemStack craft(RecipeInputInventory inventory, DynamicRegistryManager registryManager) {
final ItemStack filledSampleTaker = inventory.getInputStacks().stream()
.filter(stack -> stack.isOf(ModItems.FILLED_SAMPLE_TAKER))
.toList().get(0);

return filledSampleTaker.copyWithCount(2);
}

@Override
public boolean fits(int width, int height) {
return (width * height >= 3);
}

@Override
public RecipeSerializer<?> getSerializer() {
return ModRecipes.CLONE_FILLED_SAMPLE_TAKER;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package top.offsetmonkey538.compactmobfarms.recipe;

import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.recipe.SpecialRecipeSerializer;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;

import static top.offsetmonkey538.compactmobfarms.CompactMobFarms.*;

public final class ModRecipes {
private ModRecipes() {

}

public static final SpecialRecipeSerializer<FilledSampleTakerCloningRecipe> CLONE_FILLED_SAMPLE_TAKER = register("clone_filled_sample_taker", new SpecialRecipeSerializer<>(FilledSampleTakerCloningRecipe::new));

private static <T extends RecipeSerializer<?>> T register(String name, T item) {
return Registry.register(Registries.RECIPE_SERIALIZER, id(name), item);
}

@SuppressWarnings("EmptyMethod")
public static void register() {
// Registers recipe serializers by loading the class.
}
}

0 comments on commit f47058d

Please sign in to comment.