diff --git a/src/main/java/appeng/block/misc/BlockInterface.java b/src/main/java/appeng/block/misc/BlockInterface.java index 01b49bf7..8f963a3c 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 c5dc927f..7c4a91a4 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 00000000..f2fa4a97 --- /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 00000000..26742fcd --- /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 00000000..9973a1aa --- /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 00000000..6a45ddc3 --- /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 00000000..dccd04a4 Binary files /dev/null and b/src/main/resources/assets/appliedenergistics2/textures/blocks/BlockInterface.png differ 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 00000000..b100ea88 Binary files /dev/null and b/src/main/resources/assets/appliedenergistics2/textures/blocks/BlockInterfaceAlternate.png differ 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 00000000..95fcd713 Binary files /dev/null and b/src/main/resources/assets/appliedenergistics2/textures/blocks/BlockInterfaceAlternateArrow.png differ