diff --git a/block/AEBaseBlock.java b/block/AEBaseBlock.java index 9d7e4746..f9e54f3e 100644 --- a/block/AEBaseBlock.java +++ b/block/AEBaseBlock.java @@ -288,6 +288,16 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature return null; } + protected boolean hasCustomRotation() + { + return false; + } + + protected void customRotateBlock(IOrientable rotateable, ForgeDirection axis) + { + + } + @Override final public boolean rotateBlock(World w, int x, int y, int z, ForgeDirection axis) { @@ -304,18 +314,26 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature if ( rotateable != null && rotateable.canBeRotated() ) { - ForgeDirection forward = rotateable.getForward(); - ForgeDirection up = rotateable.getUp(); - - for (int rs = 0; rs < 4; rs++) + if ( hasCustomRotation() ) { - forward = Platform.rotateAround( forward, axis ); - up = Platform.rotateAround( up, axis ); + customRotateBlock( rotateable, axis ); + return true; + } + else + { + ForgeDirection forward = rotateable.getForward(); + ForgeDirection up = rotateable.getUp(); - if ( this.isValidOrientation( w, x, y, z, forward, up ) ) + for (int rs = 0; rs < 4; rs++) { - rotateable.setOrientation( forward, up ); - return true; + forward = Platform.rotateAround( forward, axis ); + up = Platform.rotateAround( up, axis ); + + if ( this.isValidOrientation( w, x, y, z, forward, up ) ) + { + rotateable.setOrientation( forward, up ); + return true; + } } } } diff --git a/block/AEBaseItemBlock.java b/block/AEBaseItemBlock.java index 3d37e18c..ec82e74e 100644 --- a/block/AEBaseItemBlock.java +++ b/block/AEBaseItemBlock.java @@ -123,7 +123,7 @@ public class AEBaseItemBlock extends ItemBlock if ( super.placeBlockAt( stack, player, w, x, y, z, side, hitX, hitY, hitZ, metadata ) ) { - if ( blockType.hasBlockTileEntity() ) + if ( blockType.hasBlockTileEntity() && !blockType.hasCustomRotation() ) { AEBaseTile tile = blockType.getTileEntity( w, x, y, z ); ori = tile; diff --git a/block/misc/BlockInterface.java b/block/misc/BlockInterface.java index 45bb6806..9674f1fd 100644 --- a/block/misc/BlockInterface.java +++ b/block/misc/BlockInterface.java @@ -6,7 +6,10 @@ import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.util.IOrientable; import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; +import appeng.client.render.blocks.RenderBlockInterface; import appeng.core.features.AEFeature; import appeng.core.sync.GuiBridge; import appeng.tile.misc.TileInterface; @@ -21,6 +24,27 @@ public class BlockInterface extends AEBaseBlock setTileEntiy( TileInterface.class ); } + @Override + protected Class getRenderer() + { + return RenderBlockInterface.class; + } + + @Override + protected boolean hasCustomRotation() + { + return true; + } + + @Override + protected void customRotateBlock(IOrientable rotateable, ForgeDirection axis) + { + if ( rotateable instanceof TileInterface ) + { + ((TileInterface) rotateable).setSide( axis ); + } + } + @Override public boolean onActivated(World w, int x, int y, int z, EntityPlayer p, int side, float hitX, float hitY, float hitZ) { diff --git a/client/render/blocks/RenderBlockInterface.java b/client/render/blocks/RenderBlockInterface.java new file mode 100644 index 00000000..d0e25b74 --- /dev/null +++ b/client/render/blocks/RenderBlockInterface.java @@ -0,0 +1,39 @@ +package appeng.client.render.blocks; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; +import appeng.client.render.BlockRenderInfo; +import appeng.client.texture.ExtraTextures; +import appeng.tile.misc.TileInterface; + +public class RenderBlockInterface extends BaseBlockRender +{ + + public RenderBlockInterface() { + super( false, 20 ); + } + + @Override + public boolean renderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + { + TileInterface ti = block.getTileEntity( world, x, y, z ); + + BlockRenderInfo info = block.getRendererInstance(); + + if ( ti.getForward() != ForgeDirection.UNKNOWN ) + { + IIcon side = ExtraTextures.BlockInterfaceAlternateArrow.getIcon(); + info.setTemporaryRenderIcons( ExtraTextures.BlockInterfaceAlternate.getIcon(), block.getIcon( 0, 0 ), side, side, side, side ); + } + + boolean fz = super.renderInWorld( block, world, x, y, z, renderer ); + + info.setTemporaryRenderIcon( null ); + + return fz; + } +} diff --git a/client/texture/ExtraTextures.java b/client/texture/ExtraTextures.java index 3178ed37..404bf5e6 100644 --- a/client/texture/ExtraTextures.java +++ b/client/texture/ExtraTextures.java @@ -22,6 +22,8 @@ public enum ExtraTextures BlockChargerInside("BlockChargerInside"), + BlockInterfaceAlternate("BlockInterfaceAlternate"), BlockInterfaceAlternateArrow("BlockInterfaceAlternateArrow"), + MEStorageCellTextures("MEStorageCellTextures"), White("White"), BlockMatterCannonParticle("BlockMatterCannonParticle"), BlockEnergyParticle("BlockEnergyParticle"), diff --git a/tile/misc/TileInterface.java b/tile/misc/TileInterface.java index 039e39b4..e466ccab 100644 --- a/tile/misc/TileInterface.java +++ b/tile/misc/TileInterface.java @@ -1,5 +1,7 @@ package appeng.tile.misc; +import java.util.EnumSet; + import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -25,14 +27,40 @@ import appeng.tile.events.AETileEventHandler; import appeng.tile.events.TileEventType; import appeng.tile.grid.AENetworkInvTile; import appeng.tile.inventory.InvOperation; +import appeng.util.Platform; import appeng.util.inv.IInventoryDestination; public class TileInterface extends AENetworkInvTile implements IGridTickable, ISegmentedInventory, ITileStorageMonitorable, IStorageMonitorable, IInventoryDestination, IInterfaceHost, IConfigureableObject { + ForgeDirection pointAt = ForgeDirection.UNKNOWN; DualityInterface duality = new DualityInterface( gridProxy, this ); + public void setSide(ForgeDirection axis) + { + if ( Platform.isClient() ) + return; + + if ( pointAt == axis.getOpposite() ) + pointAt = axis; + else if ( pointAt == axis || pointAt == axis.getOpposite() ) + pointAt = ForgeDirection.UNKNOWN; + else if ( pointAt == ForgeDirection.UNKNOWN ) + pointAt = axis.getOpposite(); + else + pointAt = Platform.rotateAround( pointAt, axis ); + + if ( ForgeDirection.UNKNOWN == pointAt ) + setOrientation( pointAt, pointAt ); + else + setOrientation( pointAt.offsetY != 0 ? ForgeDirection.SOUTH : ForgeDirection.UP, pointAt.getOpposite() ); + + gridProxy.setValidSides( EnumSet.complementOf( EnumSet.of( pointAt ) ) ); + markForUpdate(); + markDirty(); + } + @Override public void gridChanged() { @@ -49,21 +77,35 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, IS @Override public void writeToNBT(NBTTagCompound data) { + data.setInteger( "pointAt", pointAt.ordinal() ); duality.writeToNBT( data ); } @Override public void readFromNBT(NBTTagCompound data) { + int val = data.getInteger( "pointAt" ); + + if ( val >= 0 && val < ForgeDirection.values().length ) + pointAt = ForgeDirection.values()[val]; + else + pointAt = ForgeDirection.UNKNOWN; + duality.readFromNBT( data ); } - }; public TileInterface() { addNewHandler( new TileInterfaceHandler() ); } + @Override + public void onReady() + { + gridProxy.setValidSides( EnumSet.complementOf( EnumSet.of( pointAt ) ) ); + super.onReady(); + } + @Override public AECableType getCableConnectionType(ForgeDirection dir) {