From 462089b43aa7a1e0e56c0e20245b6e91e3f874a9 Mon Sep 17 00:00:00 2001 From: PepperBell <44146161+PepperCode1@users.noreply.github.com> Date: Wed, 26 May 2021 19:47:19 -0700 Subject: [PATCH] Clean up in world processing - Use static RecipeWrapper for finding recipes instead of making a new TileEntity every time - Move InWorldProcessing from logistics to contraptions/processing - Fix #799 by disallowing blasting processing on fireproof items --- .../deployer/BeltDeployerCallbacks.java | 2 +- .../components/fan/AirCurrent.java | 4 +- .../components/fan/SplashingRecipe.java | 8 +-- .../press/BeltPressingCallbacks.java | 2 +- .../press/MechanicalPressTileEntity.java | 2 +- .../particle/AirFlowParticle.java | 2 +- .../processing}/InWorldProcessing.java | 63 +++++++------------ .../belt/transport/TransportedItemStack.java | 2 +- .../logistics/item/filter/ItemAttribute.java | 2 +- .../advancement/AllAdvancements.java | 2 +- .../foundation/advancement/AllTriggers.java | 2 +- 11 files changed, 38 insertions(+), 53 deletions(-) rename src/main/java/com/simibubi/create/content/{logistics => contraptions/processing}/InWorldProcessing.java (86%) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/BeltDeployerCallbacks.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/BeltDeployerCallbacks.java index 6cfc09ede..7d007d11e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/BeltDeployerCallbacks.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/BeltDeployerCallbacks.java @@ -9,10 +9,10 @@ import com.simibubi.create.AllSoundEvents; import com.simibubi.create.Create; import com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.Mode; import com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.State; +import com.simibubi.create.content.contraptions.processing.InWorldProcessing; import com.simibubi.create.content.contraptions.relays.belt.BeltHelper; import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack; import com.simibubi.create.content.curiosities.tools.SandPaperPolishingRecipe; -import com.simibubi.create.content.logistics.InWorldProcessing; import com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult; import com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour.TransportedResult; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/AirCurrent.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/AirCurrent.java index 3b4d2ba91..72001c7ee 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/AirCurrent.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/AirCurrent.java @@ -8,8 +8,8 @@ import org.apache.commons.lang3.tuple.Pair; import com.simibubi.create.AllTags; import com.simibubi.create.content.contraptions.particle.AirFlowParticleData; -import com.simibubi.create.content.logistics.InWorldProcessing; -import com.simibubi.create.content.logistics.InWorldProcessing.Type; +import com.simibubi.create.content.contraptions.processing.InWorldProcessing; +import com.simibubi.create.content.contraptions.processing.InWorldProcessing.Type; import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/SplashingRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/SplashingRecipe.java index e6eafe17f..9bf446385 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/SplashingRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/SplashingRecipe.java @@ -3,22 +3,22 @@ package com.simibubi.create.content.contraptions.components.fan; import javax.annotation.ParametersAreNonnullByDefault; import com.simibubi.create.AllRecipeTypes; +import com.simibubi.create.content.contraptions.processing.InWorldProcessing; import com.simibubi.create.content.contraptions.processing.ProcessingRecipe; +import com.simibubi.create.content.contraptions.processing.InWorldProcessing.SplashingWrapper; import com.simibubi.create.content.contraptions.processing.ProcessingRecipeBuilder.ProcessingRecipeParams; -import com.simibubi.create.content.logistics.InWorldProcessing; -import com.simibubi.create.content.logistics.InWorldProcessing.SplashingInv; import net.minecraft.world.World; @ParametersAreNonnullByDefault -public class SplashingRecipe extends ProcessingRecipe { +public class SplashingRecipe extends ProcessingRecipe { public SplashingRecipe(ProcessingRecipeParams params) { super(AllRecipeTypes.SPLASHING, params); } @Override - public boolean matches(SplashingInv inv, World worldIn) { + public boolean matches(SplashingWrapper inv, World worldIn) { if (inv.isEmpty()) return false; return ingredients.get(0) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/BeltPressingCallbacks.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/BeltPressingCallbacks.java index 93f0d1cb4..3bc960959 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/BeltPressingCallbacks.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/BeltPressingCallbacks.java @@ -9,9 +9,9 @@ import java.util.stream.Collectors; import com.simibubi.create.Create; import com.simibubi.create.content.contraptions.components.press.MechanicalPressTileEntity.Mode; +import com.simibubi.create.content.contraptions.processing.InWorldProcessing; import com.simibubi.create.content.contraptions.relays.belt.BeltHelper; import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack; -import com.simibubi.create.content.logistics.InWorldProcessing; import com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult; import com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour.TransportedResult; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java index 36eabc127..36651a7d6 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java @@ -10,7 +10,7 @@ import com.simibubi.create.AllSoundEvents; import com.simibubi.create.Create; import com.simibubi.create.content.contraptions.processing.BasinOperatingTileEntity; import com.simibubi.create.content.contraptions.processing.BasinTileEntity; -import com.simibubi.create.content.logistics.InWorldProcessing; +import com.simibubi.create.content.contraptions.processing.InWorldProcessing; import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.advancement.ITriggerable; import com.simibubi.create.foundation.config.AllConfigs; diff --git a/src/main/java/com/simibubi/create/content/contraptions/particle/AirFlowParticle.java b/src/main/java/com/simibubi/create/content/contraptions/particle/AirFlowParticle.java index 3d5c41c8a..d4399cde7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/particle/AirFlowParticle.java +++ b/src/main/java/com/simibubi/create/content/contraptions/particle/AirFlowParticle.java @@ -4,7 +4,7 @@ import javax.annotation.Nonnull; import com.simibubi.create.Create; import com.simibubi.create.content.contraptions.components.fan.IAirCurrentSource; -import com.simibubi.create.content.logistics.InWorldProcessing; +import com.simibubi.create.content.contraptions.processing.InWorldProcessing; import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.VecHelper; diff --git a/src/main/java/com/simibubi/create/content/logistics/InWorldProcessing.java b/src/main/java/com/simibubi/create/content/contraptions/processing/InWorldProcessing.java similarity index 86% rename from src/main/java/com/simibubi/create/content/logistics/InWorldProcessing.java rename to src/main/java/com/simibubi/create/content/contraptions/processing/InWorldProcessing.java index 670f02cfc..0858c17ed 100644 --- a/src/main/java/com/simibubi/create/content/logistics/InWorldProcessing.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/InWorldProcessing.java @@ -1,4 +1,4 @@ -package com.simibubi.create.content.logistics; +package com.simibubi.create.content.contraptions.processing; import static com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.getHeatLevelOf; @@ -12,7 +12,6 @@ import javax.annotation.Nullable; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.content.contraptions.components.fan.SplashingRecipe; -import com.simibubi.create.content.contraptions.processing.ProcessingRecipe; import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock; import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack; import com.simibubi.create.foundation.config.AllConfigs; @@ -37,9 +36,6 @@ import net.minecraft.nbt.CompoundNBT; import net.minecraft.particles.ParticleTypes; import net.minecraft.particles.RedstoneParticleData; import net.minecraft.tags.BlockTags; -import net.minecraft.tileentity.BlastFurnaceTileEntity; -import net.minecraft.tileentity.FurnaceTileEntity; -import net.minecraft.tileentity.SmokerTileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.IBlockReader; @@ -50,13 +46,8 @@ import net.minecraftforge.items.wrapper.RecipeWrapper; public class InWorldProcessing { - public static class SplashingInv extends RecipeWrapper { - public SplashingInv() { - super(new ItemStackHandler(1)); - } - } - - public static SplashingInv splashingInv = new SplashingInv(); + private static final RecipeWrapper WRAPPER = new RecipeWrapper(new ItemStackHandler(1)); + private static final SplashingWrapper SPLASHING_WRAPPER = new SplashingWrapper(); public enum Type { SMOKING, BLASTING, SPLASHING, NONE @@ -103,17 +94,13 @@ public class InWorldProcessing { } private static boolean canProcess(ItemStack stack, Type type, World world) { - if (type == Type.BLASTING) { - return true; - } + if (type == Type.BLASTING) + return !stack.getItem().isFireproof(); if (type == Type.SMOKING) { - // FIXME this does not need to be a TE - SmokerTileEntity smoker = new SmokerTileEntity(); - smoker.setLocation(world, BlockPos.ZERO); - smoker.setInventorySlotContents(0, stack); + WRAPPER.setInventorySlotContents(0, stack); Optional recipe = world.getRecipeManager() - .getRecipe(IRecipeType.SMOKING, smoker, world); + .getRecipe(IRecipeType.SMOKING, WRAPPER, world); return recipe.isPresent(); } @@ -124,8 +111,8 @@ public class InWorldProcessing { } public static boolean isWashable(ItemStack stack, World world) { - splashingInv.setInventorySlotContents(0, stack); - Optional recipe = AllRecipeTypes.SPLASHING.find(splashingInv, world); + SPLASHING_WRAPPER.setInventorySlotContents(0, stack); + Optional recipe = AllRecipeTypes.SPLASHING.find(SPLASHING_WRAPPER, world); return recipe.isPresent(); } @@ -179,38 +166,29 @@ public class InWorldProcessing { private static List process(ItemStack stack, Type type, World world) { if (type == Type.SPLASHING) { - splashingInv.setInventorySlotContents(0, stack); - Optional recipe = AllRecipeTypes.SPLASHING.find(splashingInv, world); + SPLASHING_WRAPPER.setInventorySlotContents(0, stack); + Optional recipe = AllRecipeTypes.SPLASHING.find(SPLASHING_WRAPPER, world); if (recipe.isPresent()) return applyRecipeOn(stack, recipe.get()); return null; } - // FIXME this does not need to be a TE - SmokerTileEntity smoker = new SmokerTileEntity(); - smoker.setLocation(world, BlockPos.ZERO); - smoker.setInventorySlotContents(0, stack); + WRAPPER.setInventorySlotContents(0, stack); Optional smokingRecipe = world.getRecipeManager() - .getRecipe(IRecipeType.SMOKING, smoker, world); + .getRecipe(IRecipeType.SMOKING, WRAPPER, world); if (type == Type.BLASTING) { - // FIXME this does not need to be a TE - FurnaceTileEntity furnace = new FurnaceTileEntity(); - furnace.setLocation(world, BlockPos.ZERO); - furnace.setInventorySlotContents(0, stack); + WRAPPER.setInventorySlotContents(0, stack); Optional smeltingRecipe = world.getRecipeManager() - .getRecipe(IRecipeType.SMELTING, furnace, world); + .getRecipe(IRecipeType.SMELTING, WRAPPER, world); if (!smokingRecipe.isPresent()) { if (smeltingRecipe.isPresent()) return applyRecipeOn(stack, smeltingRecipe.get()); - // FIXME this does not need to be a TE - BlastFurnaceTileEntity blastFurnace = new BlastFurnaceTileEntity(); - blastFurnace.setLocation(world, BlockPos.ZERO); - blastFurnace.setInventorySlotContents(0, stack); + WRAPPER.setInventorySlotContents(0, stack); Optional blastingRecipe = world.getRecipeManager() - .getRecipe(IRecipeType.BLASTING, blastFurnace, world); + .getRecipe(IRecipeType.BLASTING, WRAPPER, world); if (blastingRecipe.isPresent()) return applyRecipeOn(stack, blastingRecipe.get()); @@ -299,6 +277,7 @@ public class InWorldProcessing { return stacks; } + public static void spawnParticlesForProcessing(@Nullable World world, Vector3d vec, Type type) { if (world == null || !world.isRemote) return; @@ -325,4 +304,10 @@ public class InWorldProcessing { } } + public static class SplashingWrapper extends RecipeWrapper { + public SplashingWrapper() { + super(new ItemStackHandler(1)); + } + } + } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/TransportedItemStack.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/TransportedItemStack.java index 5202ea1df..85cea6d9a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/TransportedItemStack.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/TransportedItemStack.java @@ -2,8 +2,8 @@ package com.simibubi.create.content.contraptions.relays.belt.transport; import java.util.Random; +import com.simibubi.create.content.contraptions.processing.InWorldProcessing; import com.simibubi.create.content.contraptions.relays.belt.BeltHelper; -import com.simibubi.create.content.logistics.InWorldProcessing; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java index 884156c60..7e7e1bb15 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java @@ -12,7 +12,7 @@ import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import com.simibubi.create.AllRecipeTypes; -import com.simibubi.create.content.logistics.InWorldProcessing; +import com.simibubi.create.content.contraptions.processing.InWorldProcessing; import com.simibubi.create.content.logistics.item.filter.attribute.BookAuthorAttribute; import com.simibubi.create.content.logistics.item.filter.attribute.BookCopyAttribute; import com.simibubi.create.content.logistics.item.filter.attribute.ColorAttribute; diff --git a/src/main/java/com/simibubi/create/foundation/advancement/AllAdvancements.java b/src/main/java/com/simibubi/create/foundation/advancement/AllAdvancements.java index 96392244e..18fcb1deb 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/AllAdvancements.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/AllAdvancements.java @@ -16,7 +16,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.AllFluids; import com.simibubi.create.AllItems; import com.simibubi.create.Create; -import com.simibubi.create.content.logistics.InWorldProcessing; +import com.simibubi.create.content.contraptions.processing.InWorldProcessing; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.Advancement.Builder; diff --git a/src/main/java/com/simibubi/create/foundation/advancement/AllTriggers.java b/src/main/java/com/simibubi/create/foundation/advancement/AllTriggers.java index 1e0c67527..959043354 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/AllTriggers.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/AllTriggers.java @@ -4,7 +4,7 @@ import java.util.LinkedList; import java.util.List; import java.util.function.Predicate; -import com.simibubi.create.content.logistics.InWorldProcessing; +import com.simibubi.create.content.contraptions.processing.InWorldProcessing; import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.block.Block;