From d94a7faaa5b3a078f876dee42c00c3ec9def86d7 Mon Sep 17 00:00:00 2001 From: reidbhuntley Date: Mon, 14 Jun 2021 17:26:00 -0400 Subject: [PATCH] Tweaks n' configs - Fixed ejectors stacking unstackable items - Tweaked infinite fluid source size configuration - Fixed a Schematicannon crash my code from a previous commit caused - Added config for disabling large Firework Rocket recipes - Added config for disabling movable Spawners --- .../components/crafter/RecipeGridHandler.java | 16 ++++++++++++++++ .../structureMovement/BlockMovementChecks.java | 5 +++++ .../actors/FluidManipulationBehaviour.java | 13 ++++++------- .../logistics/block/depot/DepotBehaviour.java | 5 +++-- .../block/SchematicannonTileEntity.java | 8 ++++---- .../create/foundation/config/CKinetics.java | 4 +++- .../create/foundation/config/CRecipes.java | 4 ++++ 7 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/RecipeGridHandler.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/RecipeGridHandler.java index 3f32854de..0dd0d5991 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/RecipeGridHandler.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/RecipeGridHandler.java @@ -9,6 +9,10 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Predicate; +import java.util.stream.IntStream; + +import net.minecraft.item.crafting.FireworkRocketRecipe; +import net.minecraft.item.crafting.ICraftingRecipe; import org.apache.commons.lang3.tuple.Pair; @@ -145,6 +149,7 @@ public class RecipeGridHandler { if (AllConfigs.SERVER.recipes.allowRegularCraftingInCrafter.get()) result = world.getRecipeManager() .getRecipe(IRecipeType.CRAFTING, craftinginventory, world) + .filter(r -> isRecipeAllowed(r, craftinginventory)) .map(r -> r.getCraftingResult(craftinginventory)) .orElse(null); if (result == null) @@ -154,6 +159,17 @@ public class RecipeGridHandler { return result; } + public static boolean isRecipeAllowed(ICraftingRecipe recipe, CraftingInventory inventory) { + if (!AllConfigs.SERVER.recipes.allowBiggerFireworksInCrafter.get() && recipe instanceof FireworkRocketRecipe) { + int numItems = IntStream.range(0, inventory.getSizeInventory()) + .map(i -> inventory.getStackInSlot(i).isEmpty() ? 0 : 1) + .sum(); + if (numItems > 9) + return false; + } + return true; + } + public static class GroupedItems { Map, ItemStack> grid = new HashMap<>(); int minX, minY, maxX, maxY, width, height; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/BlockMovementChecks.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/BlockMovementChecks.java index 8e2a8fc7c..c0889389a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/BlockMovementChecks.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/BlockMovementChecks.java @@ -29,6 +29,8 @@ import com.simibubi.create.content.contraptions.fluids.tank.FluidTankBlock; import com.simibubi.create.content.contraptions.fluids.tank.FluidTankConnectivityHandler; import com.simibubi.create.content.logistics.block.redstone.RedstoneLinkBlock; +import com.simibubi.create.foundation.config.AllConfigs; + import net.minecraft.block.AbstractPressurePlateBlock; import net.minecraft.block.AbstractRailBlock; import net.minecraft.block.AbstractSignBlock; @@ -47,6 +49,7 @@ import net.minecraft.block.LadderBlock; import net.minecraft.block.RedstoneDiodeBlock; import net.minecraft.block.RedstoneWallTorchBlock; import net.minecraft.block.RedstoneWireBlock; +import net.minecraft.block.SpawnerBlock; import net.minecraft.block.StandingSignBlock; import net.minecraft.block.TorchBlock; import net.minecraft.block.WallSignBlock; @@ -189,6 +192,8 @@ public class BlockMovementChecks { return false; if (AllBlockTags.NON_MOVABLE.matches(state)) return false; + if (!AllConfigs.SERVER.kinetics.movableSpawners.get() && block instanceof SpawnerBlock) + return false; // Move controllers only when they aren't moving if (block instanceof MechanicalPistonBlock && state.get(MechanicalPistonBlock.STATE) != PistonState.MOVING) diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/FluidManipulationBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/FluidManipulationBehaviour.java index 02e3182e3..a3c70ed09 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/FluidManipulationBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/FluidManipulationBehaviour.java @@ -50,6 +50,7 @@ public abstract class FluidManipulationBehaviour extends TileEntityBehaviour { // Search static final int searchedPerTick = 256; + static final int validationTimerMin = 160; List frontier; Set visited; @@ -67,12 +68,10 @@ public abstract class FluidManipulationBehaviour extends TileEntityBehaviour { counterpartActed = true; } - private int validationTimer() { + protected int validationTimer() { int maxBlocks = maxBlocks(); - return infinite || maxBlocks < 0 - ? 160 - // Allow enough time for the server's infinite block threshold to be reached - : maxBlocks / searchedPerTick; + // Allow enough time for the server's infinite block threshold to be reached + return maxBlocks < 0 ? validationTimerMin : Math.max(validationTimerMin, maxBlocks / searchedPerTick + 1); } protected int setValidationTimer() { @@ -184,7 +183,7 @@ public abstract class FluidManipulationBehaviour extends TileEntityBehaviour { frontier.add(new BlockPosEntry(offsetPos, entry.distance + 1)); } } - + return fluid; } @@ -204,7 +203,7 @@ public abstract class FluidManipulationBehaviour extends TileEntityBehaviour { if (world instanceof ServerWorld) AllPackets.sendToNear(world, splooshPos, 10, new FluidSplashPacket(splooshPos, new FluidStack(fluid, 1))); } - + protected boolean canDrainInfinitely(Fluid fluid) { return maxBlocks() != -1; // && !AllFluidTags.NO_INFINITE_DRAINING.matches(fluid); } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/depot/DepotBehaviour.java b/src/main/java/com/simibubi/create/content/logistics/block/depot/DepotBehaviour.java index 02748a50d..ecac9759c 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/depot/DepotBehaviour.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/depot/DepotBehaviour.java @@ -11,6 +11,7 @@ import com.simibubi.create.AllSoundEvents; 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.block.funnel.AbstractFunnelBlock; +import com.simibubi.create.foundation.item.ItemHelper; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.BehaviourType; @@ -86,7 +87,7 @@ public class DepotBehaviour extends TileEntityBehaviour { if (heldItem == null) { heldItem = ts; } else { - if (!ItemHandlerHelper.canItemStacksStack(heldItem.stack, ts.stack)) { + if (!ItemHelper.canItemStackAmountsStack(heldItem.stack, ts.stack)) { Vector3d vec = VecHelper.getCenterOf(tileEntity.getPos()); InventoryHelper.spawnItemStack(tileEntity.getWorld(), vec.x, vec.y + .5f, vec.z, ts.stack); } else { @@ -250,7 +251,7 @@ public class DepotBehaviour extends TileEntityBehaviour { ItemStack inserted = heldItem.stack; if (remainingSpace <= 0) return inserted; - if (this.heldItem != null && !ItemHandlerHelper.canItemStacksStack(this.heldItem.stack, inserted)) + if (this.heldItem != null && !ItemHelper.canItemStackAmountsStack(this.heldItem.stack, inserted)) return inserted; ItemStack returned = ItemStack.EMPTY; diff --git a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonTileEntity.java b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonTileEntity.java index 94d50415e..b45867c13 100644 --- a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonTileEntity.java +++ b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonTileEntity.java @@ -150,7 +150,7 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC inventory = new SchematicannonInventory(this); statusMsg = "idle"; state = State.STOPPED; - printingEntityIndex = 0; + printingEntityIndex = -1; printStage = PrintStage.BLOCKS; deferredBlocks = new LinkedList<>(); replaceMode = 2; @@ -594,7 +594,7 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC schematicLoaded = true; state = State.PAUSED; statusMsg = "ready"; - printingEntityIndex = 0; + printingEntityIndex = -1; printStage = PrintStage.BLOCKS; deferredBlocks.clear(); updateChecklist(); @@ -699,9 +699,9 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC } if (printStage == PrintStage.ENTITIES) { - if (printingEntityIndex < entities.size()) { - currentPos = entities.get(printingEntityIndex).getBlockPos().subtract(schematicAnchor); + if (printingEntityIndex + 1 < entities.size()) { printingEntityIndex++; + currentPos = entities.get(printingEntityIndex).getBlockPos().subtract(schematicAnchor); } else { finishedPrinting(); } diff --git a/src/main/java/com/simibubi/create/foundation/config/CKinetics.java b/src/main/java/com/simibubi/create/foundation/config/CKinetics.java index ec9218eb1..f97a88318 100644 --- a/src/main/java/com/simibubi/create/foundation/config/CKinetics.java +++ b/src/main/java/com/simibubi/create/foundation/config/CKinetics.java @@ -33,6 +33,7 @@ public class CKinetics extends ConfigBase { public ConfigInt maxPistonPoles = i(64, 1, "maxPistonPoles", Comments.maxPistonPoles); public ConfigInt maxRopeLength = i(128, 1, "maxRopeLength", Comments.maxRopeLength); public ConfigInt maxCartCouplingLength = i(32, 1, "maxCartCouplingLength", Comments.maxCartCouplingLength); + public ConfigBool movableSpawners = b(true, "movableSpawners", Comments.movableSpawners); public CStress stressValues = nested(1, CStress::new, Comments.stress); @@ -92,9 +93,10 @@ public class CKinetics extends ConfigBase { static String maxEjectorDistance = "Max Distance in blocks a Weighted Ejector can throw"; static String ejectorScanInterval = "Time in ticks until the next item launched by an ejector scans blocks for potential collisions"; + static String movableSpawners = "When true, allows Spawner blocks to be moved by contraptions."; } - public static enum DeployerAggroSetting { + public enum DeployerAggroSetting { ALL, CREEPERS, NONE } diff --git a/src/main/java/com/simibubi/create/foundation/config/CRecipes.java b/src/main/java/com/simibubi/create/foundation/config/CRecipes.java index eec2389e7..ec1b46489 100644 --- a/src/main/java/com/simibubi/create/foundation/config/CRecipes.java +++ b/src/main/java/com/simibubi/create/foundation/config/CRecipes.java @@ -7,6 +7,8 @@ public class CRecipes extends ConfigBase { public ConfigBool allowShapedSquareInPress = b(true, "allowShapedSquareInPress", Comments.allowShapedSquareInPress); public ConfigBool allowRegularCraftingInCrafter = b(true, "allowRegularCraftingInCrafter", Comments.allowRegularCraftingInCrafter); + public ConfigBool allowBiggerFireworksInCrafter = + b(false, "allowBiggerFireworksInCrafter", Comments.allowBiggerFireworksInCrafter); public ConfigBool allowStonecuttingOnSaw = b(true, "allowStonecuttingOnSaw", Comments.allowStonecuttingOnSaw); public ConfigBool allowWoodcuttingOnSaw = b(true, "allowWoodcuttingOnSaw", Comments.allowWoodcuttingOnSaw); public ConfigInt lightSourceCountForRefinedRadiance = @@ -28,6 +30,8 @@ public class CRecipes extends ConfigBase { "When true, allows any single-ingredient 2x2 or 3x3 crafting recipes to be processed by a Mechanical Press + Basin."; static String allowRegularCraftingInCrafter = "When true, allows any standard crafting recipes to be processed by Mechanical Crafters."; + static String allowBiggerFireworksInCrafter = + "When true, allows Firework Rockets with more than 9 ingredients to be crafted using Mechanical Crafters."; static String allowStonecuttingOnSaw = "When true, allows any stonecutting recipes to be processed by a Mechanical Saw."; static String allowWoodcuttingOnSaw =