From f9d48386cafe39ac9fa0d764c0cf5c7b8317ac52 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Thu, 15 Apr 2021 14:43:34 +0200 Subject: [PATCH] Scanning the Far Lands for Rails - Fixed basins not continuing their processing when items are extracted by funnel #1416 - Basins now accept full stacks for items thrown into the top manually - Fixed Smart Chutes not dropping filter items - Fixed Smart Chutes not updating attached diagonal chutes properly when removed - Fixed Server-side crash when coupling two minecarts from a glitched self-colliding pile --- .../deployer/DeployerMovementBehaviour.java | 2 ++ .../train/CouplingPhysics.java | 3 +++ .../train/MinecartSim2020.java | 3 ++- .../contraptions/processing/BasinBlock.java | 5 +++++ .../processing/BasinInventory.java | 11 ++++++++++ .../processing/BasinTileEntity.java | 3 ++- .../block/chute/AbstractChuteBlock.java | 21 ++++++++++++------- .../block/chute/SmartChuteBlock.java | 2 ++ .../filtering/SchematicInstances.java | 14 +++++++------ .../foundation/item/SmartInventory.java | 8 +++++++ 10 files changed, 57 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovementBehaviour.java index 209144e81..a146a6c3e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovementBehaviour.java @@ -101,6 +101,8 @@ public class DeployerMovementBehaviour extends MovementBehaviour { if (!tag.getBoolean("Deployed")) return; SchematicWorld schematicWorld = SchematicInstances.get(world, filter); + if (schematicWorld == null) + return; if (!schematicWorld.getBounds() .isVecInside(pos.subtract(schematicWorld.anchor))) return; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingPhysics.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingPhysics.java index 74becf2da..e16ea5263 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingPhysics.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingPhysics.java @@ -93,7 +93,10 @@ public class CouplingPhysics { public static void softCollisionStep(World world, Couple carts, double couplingLength) { Couple maxSpeed = carts.map(AbstractMinecartEntity::getMaxCartSpeedOnRail); Couple canAddmotion = carts.map(MinecartSim2020::canAddMotion); + + // Assuming Minecarts will never move faster than 1 block/tick Couple motions = carts.map(Entity::getMotion); + motions.replaceWithParams(VecHelper::clamp, Couple.create(1f, 1f)); Couple nextPositions = carts.map(MinecartSim2020::predictNextPositionOf); Couple shapes = carts.mapWithContext((cart, current) -> { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/MinecartSim2020.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/MinecartSim2020.java index aebbd074c..0a8f00f41 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/MinecartSim2020.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/MinecartSim2020.java @@ -8,6 +8,7 @@ import com.google.common.collect.Maps; import com.mojang.datafixers.util.Pair; import com.simibubi.create.content.contraptions.components.structureMovement.train.capability.CapabilityMinecartController; import com.simibubi.create.content.contraptions.components.structureMovement.train.capability.MinecartController; +import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.block.AbstractRailBlock; import net.minecraft.block.BlockState; @@ -47,7 +48,7 @@ public class MinecartSim2020 { public static Vector3d predictNextPositionOf(AbstractMinecartEntity cart) { Vector3d position = cart.getPositionVec(); - Vector3d motion = cart.getMotion(); + Vector3d motion = VecHelper.clamp(cart.getMotion(), 1f); return position.add(motion); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinBlock.java b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinBlock.java index 3b42e8a32..16548ca6f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinBlock.java @@ -131,8 +131,13 @@ public class BasinBlock extends Block implements ITE, IWrenchab return; ItemEntity itemEntity = (ItemEntity) entityIn; withTileEntityDo(worldIn, entityIn.getBlockPos(), te -> { + + // Tossed items bypass the quarter-stack limit + te.inputInventory.withMaxStackSize(64); ItemStack insertItem = ItemHandlerHelper.insertItem(te.inputInventory, itemEntity.getItem() .copy(), false); + te.inputInventory.withMaxStackSize(16); + if (insertItem.isEmpty()) { itemEntity.remove(); if (!itemEntity.world.isRemote) diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinInventory.java b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinInventory.java index 3e3ac469a..70e5bce70 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinInventory.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinInventory.java @@ -7,8 +7,11 @@ import net.minecraftforge.items.ItemHandlerHelper; public class BasinInventory extends SmartInventory { + private BasinTileEntity te; + public BasinInventory(int slots, BasinTileEntity te) { super(slots, te, 16, true); + this.te = te; } @Override @@ -19,5 +22,13 @@ public class BasinInventory extends SmartInventory { return stack; return super.insertItem(slot, stack, simulate); } + + @Override + public ItemStack extractItem(int slot, int amount, boolean simulate) { + ItemStack extractItem = super.extractItem(slot, amount, simulate); + if (!simulate && !extractItem.isEmpty()) + te.notifyChangeOfContents(); + return extractItem; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java index 6f61259dd..9601477f0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java @@ -96,7 +96,8 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor super(type); inputInventory = new BasinInventory(9, this); inputInventory.whenContentsChanged($ -> contentsChanged = true); - outputInventory = new BasinInventory(9, this).forbidInsertion(); + outputInventory = new BasinInventory(9, this).forbidInsertion() + .withMaxStackSize(64); areFluidsMoving = false; itemCapability = LazyOptional.of(() -> new CombinedInvWrapper(inputInventory, outputInventory)); contentsChanged = true; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/chute/AbstractChuteBlock.java b/src/main/java/com/simibubi/create/content/logistics/block/chute/AbstractChuteBlock.java index 33c5c818b..60970e62d 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/chute/AbstractChuteBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/chute/AbstractChuteBlock.java @@ -6,6 +6,7 @@ import com.simibubi.create.content.contraptions.wrench.IWrenchable; import com.simibubi.create.foundation.block.ITE; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour; +import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour; import com.simibubi.create.foundation.utility.BlockHelper; import com.simibubi.create.foundation.utility.Iterate; @@ -49,7 +50,7 @@ public abstract class AbstractChuteBlock extends Block implements IWrenchable, I public static boolean isOpenChute(BlockState state) { return isChute(state) && ((AbstractChuteBlock) state.getBlock()).isOpen(state); } - + public static boolean isTransparentChute(BlockState state) { return isChute(state) && ((AbstractChuteBlock) state.getBlock()).isTransparent(state); } @@ -66,7 +67,7 @@ public abstract class AbstractChuteBlock extends Block implements IWrenchable, I public boolean isOpen(BlockState state) { return true; } - + public boolean isTransparent(BlockState state) { return false; } @@ -128,6 +129,7 @@ public abstract class AbstractChuteBlock extends Block implements IWrenchable, I public void onReplaced(BlockState state, World world, BlockPos pos, BlockState p_196243_4_, boolean p_196243_5_) { boolean differentBlock = state.getBlock() != p_196243_4_.getBlock(); if (state.hasTileEntity() && (differentBlock || !p_196243_4_.hasTileEntity())) { + TileEntityBehaviour.destroy(world, pos, FilteringBehaviour.TYPE); withTileEntityDo(world, pos, c -> c.onRemoved(state)); world.removeTileEntity(pos); } @@ -140,7 +142,10 @@ public abstract class AbstractChuteBlock extends Block implements IWrenchable, I BlockPos toUpdate = pos.up() .offset(direction); BlockState stateToUpdate = world.getBlockState(toUpdate); - BlockState updated = updateChuteState(stateToUpdate, world.getBlockState(toUpdate.up()), world, toUpdate); + if (!isChute(stateToUpdate)) + continue; + BlockState updated = ((AbstractChuteBlock) stateToUpdate.getBlock()).updateChuteState(stateToUpdate, + world.getBlockState(toUpdate.up()), world, toUpdate); if (stateToUpdate != updated && !world.isRemote) world.setBlockState(toUpdate, updated); } @@ -157,9 +162,11 @@ public abstract class AbstractChuteBlock extends Block implements IWrenchable, I @Override public void neighborChanged(BlockState p_220069_1_, World world, BlockPos pos, Block p_220069_4_, BlockPos neighbourPos, boolean p_220069_6_) { - if (pos.down().equals(neighbourPos)) + if (pos.down() + .equals(neighbourPos)) withTileEntityDo(world, pos, ChuteTileEntity::blockBelowChanged); - else if (pos.up().equals(neighbourPos)) + else if (pos.up() + .equals(neighbourPos)) withTileEntityDo(world, pos, chute -> chute.capAbove = LazyOptional.empty()); } @@ -171,13 +178,13 @@ public abstract class AbstractChuteBlock extends Block implements IWrenchable, I BlockHelper.addReducedDestroyEffects(state, world, pos, manager); return true; } - + @Override public VoxelShape getShape(BlockState p_220053_1_, IBlockReader p_220053_2_, BlockPos p_220053_3_, ISelectionContext p_220053_4_) { return ChuteShapes.getShape(p_220053_1_); } - + @Override public VoxelShape getCollisionShape(BlockState p_220071_1_, IBlockReader p_220071_2_, BlockPos p_220071_3_, ISelectionContext p_220071_4_) { diff --git a/src/main/java/com/simibubi/create/content/logistics/block/chute/SmartChuteBlock.java b/src/main/java/com/simibubi/create/content/logistics/block/chute/SmartChuteBlock.java index 55b0b2d52..a27f1a92a 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/chute/SmartChuteBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/chute/SmartChuteBlock.java @@ -3,6 +3,8 @@ package com.simibubi.create.content.logistics.block.chute; import java.util.Random; import com.simibubi.create.AllTileEntities; +import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; +import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour; import net.minecraft.block.Block; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/simibubi/create/content/schematics/filtering/SchematicInstances.java b/src/main/java/com/simibubi/create/content/schematics/filtering/SchematicInstances.java index 5f92377ca..90a184ddb 100644 --- a/src/main/java/com/simibubi/create/content/schematics/filtering/SchematicInstances.java +++ b/src/main/java/com/simibubi/create/content/schematics/filtering/SchematicInstances.java @@ -35,12 +35,14 @@ public class SchematicInstances { public static SchematicWorld get(World world, ItemStack schematic) { Cache map = loadedSchematics.get(world); int hash = getHash(schematic); - try { - return map.get(hash, () -> loadWorld(world, schematic)); - } catch (ExecutionException e) { - e.printStackTrace(); - } - return null; + SchematicWorld ifPresent = map.getIfPresent(hash); + if (ifPresent != null) + return ifPresent; + SchematicWorld loadWorld = loadWorld(world, schematic); + if (loadWorld == null) + return null; + map.put(hash, loadWorld); + return loadWorld; } private static SchematicWorld loadWorld(World wrapped, ItemStack schematic) { diff --git a/src/main/java/com/simibubi/create/foundation/item/SmartInventory.java b/src/main/java/com/simibubi/create/foundation/item/SmartInventory.java index 95be9e73e..7be383918 100644 --- a/src/main/java/com/simibubi/create/foundation/item/SmartInventory.java +++ b/src/main/java/com/simibubi/create/foundation/item/SmartInventory.java @@ -18,6 +18,7 @@ public class SmartInventory extends RecipeWrapper protected boolean extractionAllowed; protected boolean insertionAllowed; protected boolean stackNonStackables; + protected SyncedStackHandler wrapped; protected int stackSize; public SmartInventory(int slots, SyncedTileEntity te) { @@ -30,6 +31,13 @@ public class SmartInventory extends RecipeWrapper insertionAllowed = true; extractionAllowed = true; this.stackSize = stackSize; + wrapped = (SyncedStackHandler) inv; + } + + public SmartInventory withMaxStackSize(int maxStackSize) { + stackSize = maxStackSize; + wrapped.stackSize = maxStackSize; + return this; } public SmartInventory whenContentsChanged(Consumer updateCallback) {