1414import gregtech .api .pipenet .tile .PipeCoverableImplementation ;
1515import gregtech .api .pipenet .tile .TileEntityPipeBase ;
1616import gregtech .api .util .GTUtility ;
17+ import gregtech .client .renderer .pipe .PipeRenderProperties ;
18+ import gregtech .client .renderer .pipe .cover .CoverRendererPackage ;
1719import gregtech .common .ConfigHolder ;
1820import gregtech .common .blocks .BlockFrame ;
1921import gregtech .common .blocks .MetaBlocks ;
2325import net .minecraft .block .Block ;
2426import net .minecraft .block .ITileEntityProvider ;
2527import net .minecraft .block .SoundType ;
28+ import net .minecraft .block .properties .PropertyBool ;
2629import net .minecraft .block .state .BlockFaceShape ;
30+ import net .minecraft .block .state .BlockStateContainer ;
2731import net .minecraft .block .state .IBlockState ;
2832import net .minecraft .client .Minecraft ;
33+ import net .minecraft .client .renderer .texture .TextureAtlasSprite ;
2934import net .minecraft .creativetab .CreativeTabs ;
3035import net .minecraft .entity .Entity ;
3136import net .minecraft .entity .EntityLivingBase ;
4651import net .minecraft .util .math .Vec3d ;
4752import net .minecraft .world .IBlockAccess ;
4853import net .minecraft .world .World ;
54+ import net .minecraftforge .common .property .IExtendedBlockState ;
4955import net .minecraftforge .fml .relauncher .Side ;
5056import net .minecraftforge .fml .relauncher .SideOnly ;
5157
5258import codechicken .lib .raytracer .CuboidRayTraceResult ;
5359import codechicken .lib .raytracer .IndexedCuboid6 ;
5460import codechicken .lib .raytracer .RayTracer ;
5561import codechicken .lib .vec .Cuboid6 ;
62+ import org .apache .commons .lang3 .tuple .Pair ;
5663import org .jetbrains .annotations .NotNull ;
5764import org .jetbrains .annotations .Nullable ;
5865
5966import java .util .ArrayList ;
6067import java .util .Collections ;
68+ import java .util .EnumMap ;
6169import java .util .List ;
6270import java .util .Random ;
6371
@@ -68,6 +76,28 @@ public abstract class BlockPipe<PipeType extends Enum<PipeType> & IPipeType<Node
6876 WorldPipeNetType extends WorldPipeNet <NodeDataType , ? extends PipeNet <NodeDataType >>> extends BuiltInRenderBlock
6977 implements ITileEntityProvider , IFacadeWrapper , IBlockAppearance {
7078
79+ public static final PropertyBool NORTH = PropertyBool .create ("north" );
80+ public static final PropertyBool EAST = PropertyBool .create ("east" );
81+ public static final PropertyBool SOUTH = PropertyBool .create ("south" );
82+ public static final PropertyBool WEST = PropertyBool .create ("west" );
83+ public static final PropertyBool UP = PropertyBool .create ("up" );
84+ public static final PropertyBool DOWN = PropertyBool .create ("down" );
85+
86+ public static final EnumMap <EnumFacing , PropertyBool > FACINGS = buildFacings ();
87+
88+ private static @ NotNull EnumMap <EnumFacing , PropertyBool > buildFacings () {
89+ EnumMap <EnumFacing , PropertyBool > map = new EnumMap <>(EnumFacing .class );
90+ map .put (EnumFacing .NORTH , NORTH );
91+ map .put (EnumFacing .EAST , EAST );
92+ map .put (EnumFacing .SOUTH , SOUTH );
93+ map .put (EnumFacing .WEST , WEST );
94+ map .put (EnumFacing .UP , UP );
95+ map .put (EnumFacing .DOWN , DOWN );
96+ return map ;
97+ }
98+
99+ public static final PropertyBool FRAMED = PropertyBool .create ("framed" );
100+
71101 protected final ThreadLocal <IPipeTile <PipeType , NodeDataType >> tileEntities = new ThreadLocal <>();
72102
73103 public BlockPipe () {
@@ -146,7 +176,7 @@ public ItemStack getItem(@NotNull World world, @NotNull BlockPos pos, @NotNull I
146176 protected abstract NodeDataType getFallbackType ();
147177
148178 // TODO this has no reason to need an ItemStack parameter
149- public abstract PipeType getItemPipeType ( ItemStack itemStack );
179+ public abstract PipeType getPipeType ( );
150180
151181 public abstract void setTileEntityData (TileEntityPipeBase <PipeType , NodeDataType > pipeTile , ItemStack itemStack );
152182
@@ -352,7 +382,7 @@ public boolean onPipeActivated(World world, IBlockState state, BlockPos pos, Ent
352382 IBlockState blockStateAtSide = world .getBlockState (pos .offset (side ));
353383 if (blockStateAtSide .getBlock () instanceof BlockFrame ) {
354384 ItemBlockPipe <?, ?> itemBlockPipe = (ItemBlockPipe <?, ?>) itemStack .getItem ();
355- if (itemBlockPipe .blockPipe .getItemPipeType ( itemStack ) == getItemPipeType ( itemStack )) {
385+ if (itemBlockPipe .blockPipe .getPipeType ( ) == getPipeType ( )) {
356386 BlockFrame frameBlock = (BlockFrame ) blockStateAtSide .getBlock ();
357387 boolean wasPlaced = frameBlock .replaceWithFramedPipe (world , pos .offset (side ), blockStateAtSide ,
358388 entityPlayer , itemStack , side );
@@ -734,4 +764,68 @@ public PipeConnectionData(EnumFacing side) {
734764 this .side = side ;
735765 }
736766 }
767+
768+ @ Override
769+ public int getMetaFromState (@ NotNull IBlockState state ) {
770+ return 0 ;
771+ }
772+
773+ @ Override
774+ protected @ NotNull BlockStateContainer createBlockState () {
775+ return constructState (new BlockStateContainer .Builder (this ))
776+ .add (NORTH , SOUTH , EAST , WEST , UP , DOWN , FRAMED )
777+ .build ();
778+ }
779+
780+ protected @ NotNull BlockStateContainer .Builder constructState (BlockStateContainer .@ NotNull Builder builder ) {
781+ return builder .add (PipeRenderProperties .THICKNESS_PROPERTY ).add (PipeRenderProperties .CLOSED_MASK_PROPERTY )
782+ .add (PipeRenderProperties .BLOCKED_MASK_PROPERTY ).add (PipeRenderProperties .COLOR_PROPERTY )
783+ .add (PipeRenderProperties .FRAME_MATERIAL_PROPERTY ).add (PipeRenderProperties .FRAME_MASK_PROPERTY )
784+ .add (CoverRendererPackage .CRP_PROPERTY );
785+ }
786+
787+ @ SuppressWarnings ("deprecation" )
788+ @ Override
789+ public @ NotNull IBlockState getActualState (@ NotNull IBlockState state , @ NotNull IBlockAccess worldIn ,
790+ @ NotNull BlockPos pos ) {
791+ var tile = getPipeTileEntity (worldIn , pos );
792+ if (tile == null ) return state ;
793+ state = writeConnectionMask (state , tile .getCoverAdjustedConnectionMask ());
794+ return state .withProperty (FRAMED , tile .getFrameMaterial () != null );
795+ }
796+
797+ public static IBlockState writeConnectionMask (@ NotNull IBlockState state , byte connectionMask ) {
798+ for (EnumFacing facing : EnumFacing .VALUES ) {
799+ state = state .withProperty (FACINGS .get (facing ), GTUtility .evalMask (facing , connectionMask ));
800+ }
801+ return state ;
802+ }
803+
804+ public static byte readConnectionMask (@ NotNull IBlockState state ) {
805+ byte mask = 0 ;
806+ for (EnumFacing facing : EnumFacing .VALUES ) {
807+ if (state .getValue (FACINGS .get (facing ))) {
808+ mask |= (byte ) (1 << facing .ordinal ());
809+ }
810+ }
811+ return mask ;
812+ }
813+
814+ @ Override
815+ public @ NotNull IBlockState getExtendedState (@ NotNull IBlockState state , @ NotNull IBlockAccess world ,
816+ @ NotNull BlockPos pos ) {
817+ var tile = getPipeTileEntity (world , pos );
818+ if (tile == null ) return state ;
819+ else return tile .getRenderInformation ((IExtendedBlockState ) state .getActualState (world , pos ));
820+ }
821+
822+ @ SideOnly (Side .CLIENT )
823+ @ Override
824+ protected Pair <TextureAtlasSprite , Integer > getParticleTexture (World world , BlockPos blockPos ) {
825+ var tile = getPipeTileEntity (world , blockPos );
826+ if (tile != null ) {
827+ return getPipeType ().getModel ().getParticleTexture (tile .getPaintingColor (), null );
828+ }
829+ return null ;
830+ }
737831}
0 commit comments