From 881b18a47db94b93a6976b69ce99c490e72e5752 Mon Sep 17 00:00:00 2001 From: P3pp3rF1y Date: Sat, 9 Nov 2024 02:02:41 +0100 Subject: [PATCH] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20Remove=20unuse?= =?UTF-8?q?d=20recipe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ShulkerBoxFromVanillaShapedRecipe.java | 83 ------------------- .../sophisticatedstorage/init/ModBlocks.java | 1 - 2 files changed, 84 deletions(-) delete mode 100644 src/main/java/net/p3pp3rf1y/sophisticatedstorage/crafting/ShulkerBoxFromVanillaShapedRecipe.java diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/crafting/ShulkerBoxFromVanillaShapedRecipe.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/crafting/ShulkerBoxFromVanillaShapedRecipe.java deleted file mode 100644 index b8bdc9e4..00000000 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/crafting/ShulkerBoxFromVanillaShapedRecipe.java +++ /dev/null @@ -1,83 +0,0 @@ -package net.p3pp3rf1y.sophisticatedstorage.crafting; - -import net.minecraft.core.HolderLookup; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.CraftingInput; -import net.minecraft.world.item.crafting.RecipeSerializer; -import net.minecraft.world.item.crafting.ShapedRecipe; -import net.minecraft.world.level.Level; -import net.neoforged.neoforge.capabilities.Capabilities; -import net.neoforged.neoforge.items.IItemHandler; -import net.p3pp3rf1y.sophisticatedcore.crafting.IWrapperRecipe; -import net.p3pp3rf1y.sophisticatedcore.crafting.RecipeWrapperSerializer; -import net.p3pp3rf1y.sophisticatedcore.util.InventoryHelper; -import net.p3pp3rf1y.sophisticatedstorage.init.ModBlocks; -import net.p3pp3rf1y.sophisticatedstorage.item.StackStorageWrapper; -import net.p3pp3rf1y.sophisticatedstorage.item.WoodStorageBlockItem; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class ShulkerBoxFromVanillaShapedRecipe extends ShapedRecipe implements IWrapperRecipe { - private final ShapedRecipe compose; - - public ShulkerBoxFromVanillaShapedRecipe(ShapedRecipe compose) { - super(compose.getGroup(), compose.category(), compose.pattern, compose.result); - this.compose = compose; - } - - @Override - public boolean matches(CraftingInput input, Level level) { - return super.matches(input, level) && getVanillaShulkerBox(input).map(storage -> !(storage.getItem() instanceof WoodStorageBlockItem) || !WoodStorageBlockItem.isPacked(storage)).orElse(false); - } - - @Override - public ShapedRecipe getCompose() { - return compose; - } - - @Override - public ItemStack assemble(CraftingInput input, HolderLookup.Provider registries) { - ItemStack upgradedStorage = super.assemble(input, registries); - getVanillaShulkerBox(input).ifPresent(vanillaShulkerBox -> { - @Nullable IItemHandler itemCap = vanillaShulkerBox.getCapability(Capabilities.ItemHandler.ITEM); - if (itemCap != null) { - StackStorageWrapper wrapper = StackStorageWrapper.fromStack(registries, upgradedStorage); - InventoryHelper.iterate(itemCap, (slot, stack) -> { - if (!stack.isEmpty()) { - wrapper.getInventoryHandler().insertItem(stack, false); - } - }); - } - }); - return upgradedStorage; - } - - @Override - public boolean isSpecial() { - return true; - } - - private Optional getVanillaShulkerBox(CraftingInput input) { - for (int slot = 0; slot < input.size(); slot++) { - ItemStack slotStack = input.getItem(slot); - if (slotStack.getItem() instanceof BlockItem blockItem && blockItem.getBlock() instanceof net.minecraft.world.level.block.ShulkerBoxBlock) { - return Optional.of(slotStack); - } - } - - return Optional.empty(); - } - - @Override - public RecipeSerializer getSerializer() { - return ModBlocks.SHULKER_BOX_FROM_VANILLA_SHAPED_RECIPE_SERIALIZER.get(); - } - - public static class Serializer extends RecipeWrapperSerializer { - public Serializer() { - super(ShulkerBoxFromVanillaShapedRecipe::new, RecipeSerializer.SHAPED_RECIPE); - } - } -} diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/init/ModBlocks.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/init/ModBlocks.java index 9ea3891f..79eca902 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/init/ModBlocks.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/init/ModBlocks.java @@ -281,7 +281,6 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { private static final DeferredRegister> RECIPE_SERIALIZERS = DeferredRegister.create(BuiltInRegistries.RECIPE_SERIALIZER, SophisticatedStorage.MOD_ID); public static final Supplier> STORAGE_DYE_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("storage_dye", () -> new SimpleCraftingRecipeSerializer<>(StorageDyeRecipe::new)); public static final Supplier> STORAGE_TIER_UPGRADE_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("storage_tier_upgrade", StorageTierUpgradeRecipe.Serializer::new); - public static final Supplier> SHULKER_BOX_FROM_VANILLA_SHAPED_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("shulker_box_from_vanilla_shaped", ShulkerBoxFromVanillaShapedRecipe.Serializer::new); public static final Supplier> SHULKER_BOX_FROM_VANILLA_SHAPELESS_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("shulker_box_from_vanilla_shapeless", ShulkerBoxFromVanillaShapelessRecipe.Serializer::new); public static final Supplier> STORAGE_TIER_UPGRADE_SHAPELESS_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("storage_tier_upgrade_shapeless", StorageTierUpgradeShapelessRecipe.Serializer::new); public static final Supplier> SHULKER_BOX_FROM_CHEST_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("shulker_box_from_chest", ShulkerBoxFromChestRecipe.Serializer::new);