diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidTransportBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidTransportBehaviour.java index 1d5d087fa..9cb460344 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidTransportBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidTransportBehaviour.java @@ -1,6 +1,7 @@ package com.simibubi.create.content.contraptions.fluids; import java.util.Collection; +import java.util.HashMap; import java.util.IdentityHashMap; import java.util.Map; import java.util.function.Predicate; @@ -13,12 +14,14 @@ import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.BehaviourType; import com.simibubi.create.foundation.utility.Iterate; +import com.simibubi.create.foundation.utility.WorldAttached; import net.minecraft.block.BlockState; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockDisplayReader; +import net.minecraft.world.IWorld; import net.minecraft.world.World; import net.minecraftforge.fluids.FluidStack; @@ -266,4 +269,23 @@ public abstract class FluidTransportBehaviour extends TileEntityBehaviour { return TYPE; } + // for switching TEs, but retaining flows + + public static final WorldAttached>> interfaceTransfer = + new WorldAttached<>(HashMap::new); + + public static void cacheFlows(IWorld world, BlockPos pos) { + FluidTransportBehaviour pipe = TileEntityBehaviour.get(world, pos, FluidTransportBehaviour.TYPE); + if (pipe != null) + interfaceTransfer.get(world) + .put(pos, pipe.interfaces); + } + + public static void loadFlows(IWorld world, BlockPos pos) { + FluidTransportBehaviour newPipe = TileEntityBehaviour.get(world, pos, FluidTransportBehaviour.TYPE); + if (newPipe != null) + newPipe.interfaces = interfaceTransfer.get(world) + .remove(pos); + } + } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/AxisPipeBlock.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/AxisPipeBlock.java index dde62b1ff..d9410ff54 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/AxisPipeBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/AxisPipeBlock.java @@ -7,6 +7,7 @@ import java.util.Random; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllShapes; import com.simibubi.create.content.contraptions.fluids.FluidPropagator; +import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour; import com.simibubi.create.content.contraptions.relays.elementary.BracketedTileEntityBehaviour; import com.simibubi.create.content.contraptions.wrench.IWrenchableWithBracket; import com.simibubi.create.foundation.advancement.AllTriggers; @@ -63,7 +64,9 @@ public class AxisPipeBlock extends RotatedPillarBlock implements IWrenchableWith BlockState newState = AllBlocks.ENCASED_FLUID_PIPE.getDefaultState(); for (Direction d : Iterate.directionsInAxis(getAxis(state))) newState = newState.with(EncasedPipeBlock.FACING_TO_PROPERTY_MAP.get(d), true); + FluidTransportBehaviour.cacheFlows(world, pos); world.setBlockState(pos, newState); + FluidTransportBehaviour.loadFlows(world, pos); } AllTriggers.triggerFor(AllTriggers.CASING_PIPE, player); return ActionResultType.SUCCESS; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/EncasedPipeBlock.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/EncasedPipeBlock.java index fe75a7c28..6c59b77a7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/EncasedPipeBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/EncasedPipeBlock.java @@ -13,6 +13,7 @@ import java.util.Random; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllTileEntities; import com.simibubi.create.content.contraptions.fluids.FluidPropagator; +import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour; import com.simibubi.create.content.contraptions.wrench.IWrenchable; import com.simibubi.create.content.schematics.ISpecialBlockItemRequirement; import com.simibubi.create.content.schematics.ItemRequirement; @@ -126,8 +127,10 @@ public class EncasedPipeBlock extends Block implements IWrenchable, ISpecialBloc break; } + FluidTransportBehaviour.cacheFlows(world, pos); world.setBlockState(pos, AllBlocks.FLUID_PIPE.get() .updateBlockState(equivalentPipe, firstFound, null, world, pos)); + FluidTransportBehaviour.loadFlows(world, pos); return ActionResultType.SUCCESS; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlock.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlock.java index df762a72d..d906e294e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlock.java @@ -66,9 +66,13 @@ public class FluidPipeBlock extends SixWayBlock implements IWaterLoggable, IWren if (context.getFace() .getAxis() == axis) return ActionResultType.PASS; - if (!world.isRemote) + if (!world.isRemote) { + FluidTransportBehaviour.cacheFlows(world, pos); world.setBlockState(pos, AllBlocks.GLASS_FLUID_PIPE.getDefaultState() - .with(GlassFluidPipeBlock.AXIS, axis).with(BlockStateProperties.WATERLOGGED, state.get(BlockStateProperties.WATERLOGGED))); + .with(GlassFluidPipeBlock.AXIS, axis) + .with(BlockStateProperties.WATERLOGGED, state.get(BlockStateProperties.WATERLOGGED))); + FluidTransportBehaviour.loadFlows(world, pos); + } return ActionResultType.SUCCESS; } @@ -78,9 +82,12 @@ public class FluidPipeBlock extends SixWayBlock implements IWaterLoggable, IWren if (!AllBlocks.COPPER_CASING.isIn(player.getHeldItem(hand))) return ActionResultType.PASS; AllTriggers.triggerFor(AllTriggers.CASING_PIPE, player); - if (!world.isRemote) + if (!world.isRemote) { + FluidTransportBehaviour.cacheFlows(world, pos); world.setBlockState(pos, EncasedPipeBlock.transferSixWayProperties(state, AllBlocks.ENCASED_FLUID_PIPE.getDefaultState())); + FluidTransportBehaviour.loadFlows(world, pos); + } return ActionResultType.SUCCESS; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/GlassFluidPipeBlock.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/GlassFluidPipeBlock.java index fffa566df..d85e25e8f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/GlassFluidPipeBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/GlassFluidPipeBlock.java @@ -4,6 +4,7 @@ import javax.annotation.ParametersAreNonnullByDefault; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllTileEntities; +import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour; import com.simibubi.create.content.schematics.ISpecialBlockItemRequirement; import com.simibubi.create.content.schematics.ItemRequirement; @@ -59,8 +60,10 @@ public class GlassFluidPipeBlock extends AxisPipeBlock implements IWaterLoggable BlockState newState; World world = context.getWorld(); BlockPos pos = context.getPos(); + FluidTransportBehaviour.cacheFlows(world, pos); newState = toRegularPipe(world, pos, state).with(BlockStateProperties.WATERLOGGED, state.get(BlockStateProperties.WATERLOGGED)); world.setBlockState(pos, newState, 3); + FluidTransportBehaviour.loadFlows(world, pos); return ActionResultType.SUCCESS; }