mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-14 16:03:49 +01:00
Implement #4577 for Encased Pipes
This commit is contained in:
parent
8a4190fcf5
commit
9e3140938b
3 changed files with 93 additions and 3 deletions
|
@ -13,6 +13,8 @@ import java.util.function.Supplier;
|
|||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllTileEntities;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableBlock;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.StructureTransform;
|
||||
import com.simibubi.create.content.contraptions.fluids.FluidPropagator;
|
||||
import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour;
|
||||
import com.simibubi.create.content.contraptions.relays.elementary.EncasedBlock;
|
||||
|
@ -36,7 +38,9 @@ import net.minecraft.world.item.context.UseOnContext;
|
|||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Mirror;
|
||||
import net.minecraft.world.level.block.PipeBlock;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
@ -46,7 +50,8 @@ import net.minecraft.world.phys.BlockHitResult;
|
|||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.ticks.TickPriority;
|
||||
|
||||
public class EncasedPipeBlock extends Block implements IWrenchable, ISpecialBlockItemRequirement, ITE<FluidPipeTileEntity>, EncasedBlock {
|
||||
public class EncasedPipeBlock extends Block
|
||||
implements IWrenchable, ISpecialBlockItemRequirement, ITE<FluidPipeTileEntity>, EncasedBlock, ITransformableBlock {
|
||||
public static final Map<Direction, BooleanProperty> FACING_TO_PROPERTY_MAP = PipeBlock.PROPERTY_BY_DIRECTION;
|
||||
|
||||
private final Supplier<Block> casing;
|
||||
|
@ -173,4 +178,20 @@ public class EncasedPipeBlock extends Block implements IWrenchable, ISpecialBloc
|
|||
EncasedPipeBlock.transferSixWayProperties(state, defaultBlockState()));
|
||||
FluidTransportBehaviour.loadFlows(level, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState pState, Rotation pRotation) {
|
||||
return FluidPipeBlockRotation.rotate(pState, pRotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState mirror(BlockState pState, Mirror pMirror) {
|
||||
return FluidPipeBlockRotation.mirror(pState, pMirror);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState transform(BlockState state, StructureTransform transform) {
|
||||
return FluidPipeBlockRotation.transform(state, transform);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ import javax.annotation.Nullable;
|
|||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllTileEntities;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableBlock;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.StructureTransform;
|
||||
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;
|
||||
|
@ -36,7 +38,9 @@ import net.minecraft.world.level.BlockGetter;
|
|||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Mirror;
|
||||
import net.minecraft.world.level.block.PipeBlock;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
@ -50,8 +54,8 @@ import net.minecraft.world.phys.Vec3;
|
|||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraft.world.ticks.TickPriority;
|
||||
|
||||
public class FluidPipeBlock extends PipeBlock
|
||||
implements SimpleWaterloggedBlock, IWrenchableWithBracket, ITE<FluidPipeTileEntity>, EncasableBlock {
|
||||
public class FluidPipeBlock extends PipeBlock implements SimpleWaterloggedBlock, IWrenchableWithBracket,
|
||||
ITE<FluidPipeTileEntity>, EncasableBlock, ITransformableBlock {
|
||||
|
||||
private static final VoxelShape OCCLUSION_BOX = Block.box(4, 4, 4, 12, 12, 12);
|
||||
|
||||
|
@ -337,4 +341,20 @@ public class FluidPipeBlock extends PipeBlock
|
|||
public VoxelShape getOcclusionShape(BlockState pState, BlockGetter pLevel, BlockPos pPos) {
|
||||
return OCCLUSION_BOX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState pState, Rotation pRotation) {
|
||||
return FluidPipeBlockRotation.rotate(pState, pRotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState mirror(BlockState pState, Mirror pMirror) {
|
||||
return FluidPipeBlockRotation.mirror(pState, pMirror);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState transform(BlockState state, StructureTransform transform) {
|
||||
return FluidPipeBlockRotation.transform(state, transform);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package com.simibubi.create.content.contraptions.fluids.pipes;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.StructureTransform;
|
||||
import com.simibubi.create.foundation.utility.Iterate;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.block.Mirror;
|
||||
import net.minecraft.world.level.block.PipeBlock;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
|
||||
public class FluidPipeBlockRotation {
|
||||
|
||||
public static final Map<Direction, BooleanProperty> FACING_TO_PROPERTY_MAP = PipeBlock.PROPERTY_BY_DIRECTION;
|
||||
|
||||
public static BlockState rotate(BlockState state, Rotation rotation) {
|
||||
BlockState rotated = state;
|
||||
for (Direction direction : Iterate.horizontalDirections)
|
||||
rotated = rotated.setValue(FACING_TO_PROPERTY_MAP.get(rotation.rotate(direction)),
|
||||
state.getValue(FACING_TO_PROPERTY_MAP.get(direction)));
|
||||
return rotated;
|
||||
}
|
||||
|
||||
public static BlockState mirror(BlockState state, Mirror mirror) {
|
||||
BlockState mirrored = state;
|
||||
for (Direction direction : Iterate.horizontalDirections)
|
||||
mirrored = mirrored.setValue(FACING_TO_PROPERTY_MAP.get(mirror.mirror(direction)),
|
||||
state.getValue(FACING_TO_PROPERTY_MAP.get(direction)));
|
||||
return mirrored;
|
||||
}
|
||||
|
||||
public static BlockState transform(BlockState state, StructureTransform transform) {
|
||||
if (transform.mirror != null)
|
||||
state = mirror(state, transform.mirror);
|
||||
|
||||
if (transform.rotationAxis == Direction.Axis.Y)
|
||||
return rotate(state, transform.rotation);
|
||||
|
||||
BlockState rotated = state;
|
||||
for (Direction direction : Iterate.directions)
|
||||
rotated = rotated.setValue(FACING_TO_PROPERTY_MAP.get(transform.rotateFacing(direction)),
|
||||
state.getValue(FACING_TO_PROPERTY_MAP.get(direction)));
|
||||
return rotated;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue