From 66df324ef097f5d3c8ef1e3de68febe308d4f941 Mon Sep 17 00:00:00 2001 From: shartte Date: Fri, 26 Aug 2016 11:09:49 +0200 Subject: [PATCH] Implemented interface states and models (#66) * Implemented interface states and models. --- .../appeng/block/misc/BlockInterface.java | 30 ++++++- .../java/appeng/tile/misc/TileInterface.java | 80 ++++++++++++------ .../blockstates/tile.BlockInterface.json | 6 ++ .../models/block/tile.BlockInterface.json | 6 ++ .../block/tile.BlockInterfaceOriented.json | 12 +++ .../models/item/tile.BlockInterface.json | 3 + .../textures/blocks/BlockInterface.png | Bin 0 -> 430 bytes .../blocks/BlockInterfaceAlternate.png | Bin 0 -> 350 bytes .../blocks/BlockInterfaceAlternateArrow.png | Bin 0 -> 301 bytes 9 files changed, 108 insertions(+), 29 deletions(-) create mode 100644 src/main/resources/assets/appliedenergistics2/blockstates/tile.BlockInterface.json create mode 100644 src/main/resources/assets/appliedenergistics2/models/block/tile.BlockInterface.json create mode 100644 src/main/resources/assets/appliedenergistics2/models/block/tile.BlockInterfaceOriented.json create mode 100644 src/main/resources/assets/appliedenergistics2/models/item/tile.BlockInterface.json create mode 100644 src/main/resources/assets/appliedenergistics2/textures/blocks/BlockInterface.png create mode 100644 src/main/resources/assets/appliedenergistics2/textures/blocks/BlockInterfaceAlternate.png create mode 100644 src/main/resources/assets/appliedenergistics2/textures/blocks/BlockInterfaceAlternateArrow.png diff --git a/src/main/java/appeng/block/misc/BlockInterface.java b/src/main/java/appeng/block/misc/BlockInterface.java index 01b49bf7b..8f963a3cd 100644 --- a/src/main/java/appeng/block/misc/BlockInterface.java +++ b/src/main/java/appeng/block/misc/BlockInterface.java @@ -20,15 +20,18 @@ package appeng.block.misc; import java.util.EnumSet; - import javax.annotation.Nullable; import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.properties.PropertyBool; +import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import appeng.api.util.AEPartLocation; @@ -43,6 +46,8 @@ import appeng.util.Platform; public class BlockInterface extends AEBaseTileBlock { + private static final PropertyBool OMNIDIRECTIONAL = PropertyBool.create( "omnidirectional" ); + public BlockInterface() { super( Material.IRON ); @@ -51,6 +56,26 @@ public class BlockInterface extends AEBaseTileBlock this.setFeature( EnumSet.of( AEFeature.Core ) ); } + @Override + protected IProperty[] getAEStates() + { + return new IProperty[] { AE_BLOCK_FORWARD, AE_BLOCK_UP, OMNIDIRECTIONAL }; + } + + @Override + public IBlockState getActualState( IBlockState state, IBlockAccess world, BlockPos pos ) + { + // Determine whether the interface is omni-directional or not + TileInterface te = getTileEntity( world, pos ); + boolean omniDirectional = true; // The default + if (te != null) { + omniDirectional = te.isOmniDirectional(); + } + + return super.getActualState( state, world, pos ) + .withProperty( OMNIDIRECTIONAL, omniDirectional ); + } + @Override public boolean onActivated( final World w, final BlockPos pos, final EntityPlayer p, final EnumHand hand, final @Nullable ItemStack heldItem, final EnumFacing side, final float hitX, final float hitY, final float hitZ ) { @@ -82,7 +107,8 @@ public class BlockInterface extends AEBaseTileBlock { if( rotatable instanceof TileInterface ) { - ( (TileInterface) rotatable ).setSide( AEPartLocation.fromFacing( axis ) ); + ( (TileInterface) rotatable ).setSide( axis ); } } + } diff --git a/src/main/java/appeng/tile/misc/TileInterface.java b/src/main/java/appeng/tile/misc/TileInterface.java index c5dc927f9..7c4a91a41 100644 --- a/src/main/java/appeng/tile/misc/TileInterface.java +++ b/src/main/java/appeng/tile/misc/TileInterface.java @@ -24,6 +24,8 @@ import java.util.List; import com.google.common.collect.ImmutableSet; +import io.netty.buffer.ByteBuf; + import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; @@ -70,7 +72,9 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, IT { private final DualityInterface duality = new DualityInterface( this.getProxy(), this ); - private AEPartLocation pointAt = AEPartLocation.INTERNAL; + + // Indicates that this interface has no specific direction set + private boolean omniDirectional = true; @MENetworkEventSubscribe public void stateChange( final MENetworkChannelsChanged c ) @@ -84,37 +88,45 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, IT this.duality.notifyNeighbors(); } - public void setSide( final AEPartLocation axis ) + public void setSide( final EnumFacing facing ) { if( Platform.isClient() ) { return; } - if( this.pointAt == axis.getOpposite() ) + EnumFacing newForward = facing; + + if( !omniDirectional && getForward() == facing.getOpposite() ) { - this.pointAt = axis; + newForward = facing; } - else if( this.pointAt == axis || this.pointAt == axis.getOpposite() ) + else if( !omniDirectional && ( getForward() == facing || getForward() == facing.getOpposite() ) ) { - this.pointAt = AEPartLocation.INTERNAL; + omniDirectional = true; } - else if( this.pointAt == AEPartLocation.INTERNAL ) + else if( omniDirectional ) { - this.pointAt = axis.getOpposite(); + newForward = facing.getOpposite(); + omniDirectional = false; } else { - this.pointAt = Platform.rotateAround( this.pointAt, axis ); + newForward = Platform.rotateAround( getForward(), facing ); } - if( AEPartLocation.INTERNAL == this.pointAt ) + if( omniDirectional ) { - this.setOrientation( EnumFacing.UP, EnumFacing.UP ); + this.setOrientation( EnumFacing.NORTH, EnumFacing.UP ); } else { - this.setOrientation( this.pointAt.yOffset != 0 ? EnumFacing.SOUTH : EnumFacing.UP, this.pointAt.getOpposite().getFacing() ); + EnumFacing newUp = EnumFacing.UP; + if( newForward == EnumFacing.UP || newForward == EnumFacing.DOWN ) + { + newUp = EnumFacing.NORTH; + } + this.setOrientation( newForward, newUp ); } this.configureNodeSides(); @@ -124,13 +136,13 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, IT private void configureNodeSides() { - if( this.pointAt == AEPartLocation.INTERNAL ) + if( omniDirectional ) { this.getProxy().setValidSides( EnumSet.allOf( EnumFacing.class ) ); } else { - this.getProxy().setValidSides( EnumSet.complementOf( EnumSet.of( this.pointAt.getFacing() ) ) ); + this.getProxy().setValidSides( EnumSet.complementOf( EnumSet.of( getForward() ) ) ); } } @@ -164,27 +176,32 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, IT @TileEvent( TileEventType.WORLD_NBT_WRITE ) public void writeToNBT_TileInterface( final NBTTagCompound data ) { - data.setInteger( "pointAt", this.pointAt.ordinal() ); + data.setBoolean( "omniDirectional", omniDirectional ); this.duality.writeToNBT( data ); } @TileEvent( TileEventType.WORLD_NBT_READ ) public void readFromNBT_TileInterface( final NBTTagCompound data ) { - final int val = data.getInteger( "pointAt" ); - - if( val >= 0 && val < AEPartLocation.values().length ) - { - this.pointAt = AEPartLocation.values()[val]; - } - else - { - this.pointAt = AEPartLocation.INTERNAL; - } + this.omniDirectional = data.getBoolean( "omniDirectional" ); this.duality.readFromNBT( data ); } + @TileEvent( TileEventType.NETWORK_READ ) + public boolean readFromStream_TileInterface( final ByteBuf data ) + { + boolean oldOmniDirectional = this.omniDirectional; + this.omniDirectional = data.readBoolean(); + return oldOmniDirectional != omniDirectional; + } + + @TileEvent( TileEventType.NETWORK_WRITE ) + public void writeToStream_TileInterface( final ByteBuf data ) + { + data.writeBoolean( omniDirectional ); + } + @Override public AECableType getCableConnectionType( final AEPartLocation dir ) { @@ -260,11 +277,11 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, IT @Override public EnumSet getTargets() { - if( this.pointAt == null || this.pointAt == AEPartLocation.INTERNAL ) + if( omniDirectional ) { return EnumSet.allOf( EnumFacing.class ); } - return EnumSet.of( this.pointAt.getFacing() ); + return EnumSet.of( getForward() ); } @Override @@ -338,4 +355,13 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, IT { this.duality.setPriority( newValue ); } + + /** + * @return True if this interface is omni-directional. + */ + public boolean isOmniDirectional() + { + return this.omniDirectional; + } + } diff --git a/src/main/resources/assets/appliedenergistics2/blockstates/tile.BlockInterface.json b/src/main/resources/assets/appliedenergistics2/blockstates/tile.BlockInterface.json new file mode 100644 index 000000000..f2fa4a97d --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/blockstates/tile.BlockInterface.json @@ -0,0 +1,6 @@ +{ + "variants": { + "omnidirectional=true": { "model": "appliedenergistics2:tile.BlockInterface" }, + "omnidirectional=false": { "model": "appliedenergistics2:tile.BlockInterfaceOriented", "x": 90 } + } +} diff --git a/src/main/resources/assets/appliedenergistics2/models/block/tile.BlockInterface.json b/src/main/resources/assets/appliedenergistics2/models/block/tile.BlockInterface.json new file mode 100644 index 000000000..26742fcd0 --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/block/tile.BlockInterface.json @@ -0,0 +1,6 @@ +{ + "parent": "block/cube_all", + "textures": { + "all": "appliedenergistics2:blocks/BlockInterface" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/appliedenergistics2/models/block/tile.BlockInterfaceOriented.json b/src/main/resources/assets/appliedenergistics2/models/block/tile.BlockInterfaceOriented.json new file mode 100644 index 000000000..9973a1aa7 --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/block/tile.BlockInterfaceOriented.json @@ -0,0 +1,12 @@ +{ + "parent": "block/cube", + "textures": { + "particle": "appliedenergistics2:blocks/BlockInterface", + "down": "appliedenergistics2:blocks/BlockInterfaceAlternate", + "up": "appliedenergistics2:blocks/BlockInterface", + "north": "appliedenergistics2:blocks/BlockInterfaceAlternateArrow", + "south": "appliedenergistics2:blocks/BlockInterfaceAlternateArrow", + "east": "appliedenergistics2:blocks/BlockInterfaceAlternateArrow", + "west": "appliedenergistics2:blocks/BlockInterfaceAlternateArrow" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/appliedenergistics2/models/item/tile.BlockInterface.json b/src/main/resources/assets/appliedenergistics2/models/item/tile.BlockInterface.json new file mode 100644 index 000000000..6a45ddc31 --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/item/tile.BlockInterface.json @@ -0,0 +1,3 @@ +{ + "parent": "appliedenergistics2:block/tile.BlockInterface" +} \ No newline at end of file diff --git a/src/main/resources/assets/appliedenergistics2/textures/blocks/BlockInterface.png b/src/main/resources/assets/appliedenergistics2/textures/blocks/BlockInterface.png new file mode 100644 index 0000000000000000000000000000000000000000..dccd04a41793bb1775960db6df4e14451bb1115b GIT binary patch literal 430 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd7G?$phPQVgfdp969eo`c7&i8E|4C$JU|>*4 z_6YK2V5m}KU}$JzVEDzrz|io5fuYoZf#FpG1B2BJ1_tqhIlBUF7#J9|0(?STwbkT} z^;FFb)iqRP8yXr+_0?9aSYf8G>fqpzl9HmODr=#yYNV_7|Nnm*bIooB1_s6?Z+92o zZ(9<-GB7Z37I;J!GcfQi17XJYJ1g@U7#JcwT^vI=t|upmgaieJ1O=r96f!cqw@olH zC`b=D`GTRzOr1@Tzopr0H_ps Aw*UYD literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/appliedenergistics2/textures/blocks/BlockInterfaceAlternate.png b/src/main/resources/assets/appliedenergistics2/textures/blocks/BlockInterfaceAlternate.png new file mode 100644 index 0000000000000000000000000000000000000000..b100ea882fe54de958f007e9664d29996bf433d4 GIT binary patch literal 350 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s7SkfJR9T^xl_H+M9WMyDr zP)PO&@?~JCQe$9fXklRZ#lXPO@PdJ%)PRBERRRNp)eHs(@q#(K0&N%=7&r?&B8wRq z_?Ce%WBZ+z`3wvUQYEetCBgY=CFO}lsSE*$nRz98ey$-3WyX4@dWHrDUy2qoFfgq1 zba4!^@LxJPny*(p_K`f?iI#6BRUPm7XxP>zubw!;awl`(-Y%Px zt#J}|Pa8M?eXh*S#hsliB(Qp)=86yZ;+bskrwJ7>LFLD^$NR zc{NxDEaC8b-yq#%$a1~fv7}{2gWHZ;_DkApW?$=I(sblAEE?sxKS;4N>@&WRfB*B&b=MxU3qG@+roH&eF$M+(22WQ%mvv4FO#qklc9;MF literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/appliedenergistics2/textures/blocks/BlockInterfaceAlternateArrow.png b/src/main/resources/assets/appliedenergistics2/textures/blocks/BlockInterfaceAlternateArrow.png new file mode 100644 index 0000000000000000000000000000000000000000..95fcd713c63e9f0d2d6307f1c988c793835b8843 GIT binary patch literal 301 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4kiW$h6xih%orFLBuiW)N`mv#O3D+9QW+dm z@{>{(JaZG%Q-e|yQz{EjrrIztFr4>vaSW-rH795z-ysE&8k-qDJ@x_SJ`p7^-yBOX zFD@&3d12%H1fOIU8`VtCjk+J(PB+Uvz4y_j)@p;mxydO)A}_cP@_e)N;NrXOqG5CK zuc3zO&xrXedA7fHJ$fo?_o}>EY-^gn7vA0Ww&|7xbK8u?cby#8Y+AeT{lVDlja#oh zShecddj041f9zIWPGS*yWcl@tl zZ%NJR)C8HS+?VI9X)?Uw_P+eKZ<@(x%WsxE=eIL3Gki`Ak$x-jc?kmp1B0ilpUXO@ GgeCwb1cE03 literal 0 HcmV?d00001