mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-14 23:53:42 +01:00
Flow transfer
- Fluid pipes no longer reset their contained flows when changed to/from their windowed or encased variant
This commit is contained in:
parent
ee3d359a9a
commit
bf1c86ed87
5 changed files with 41 additions and 3 deletions
|
@ -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<Map<BlockPos, Map<Direction, PipeConnection>>> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue