Added Rotatable Interfaces.

This commit is contained in:
AlgorithmX2 2014-03-19 22:28:53 -05:00
parent 4fde370d7f
commit c4a7d5b480
6 changed files with 136 additions and 11 deletions

View file

@ -288,6 +288,16 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
return null; return null;
} }
protected boolean hasCustomRotation()
{
return false;
}
protected void customRotateBlock(IOrientable rotateable, ForgeDirection axis)
{
}
@Override @Override
final public boolean rotateBlock(World w, int x, int y, int z, ForgeDirection axis) 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() ) if ( rotateable != null && rotateable.canBeRotated() )
{ {
ForgeDirection forward = rotateable.getForward(); if ( hasCustomRotation() )
ForgeDirection up = rotateable.getUp();
for (int rs = 0; rs < 4; rs++)
{ {
forward = Platform.rotateAround( forward, axis ); customRotateBlock( rotateable, axis );
up = Platform.rotateAround( up, 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 ); forward = Platform.rotateAround( forward, axis );
return true; up = Platform.rotateAround( up, axis );
if ( this.isValidOrientation( w, x, y, z, forward, up ) )
{
rotateable.setOrientation( forward, up );
return true;
}
} }
} }
} }

View file

@ -123,7 +123,7 @@ public class AEBaseItemBlock extends ItemBlock
if ( super.placeBlockAt( stack, player, w, x, y, z, side, hitX, hitY, hitZ, metadata ) ) 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 ); AEBaseTile tile = blockType.getTileEntity( w, x, y, z );
ori = tile; ori = tile;

View file

@ -6,7 +6,10 @@ import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.util.IOrientable;
import appeng.block.AEBaseBlock; import appeng.block.AEBaseBlock;
import appeng.client.render.BaseBlockRender;
import appeng.client.render.blocks.RenderBlockInterface;
import appeng.core.features.AEFeature; import appeng.core.features.AEFeature;
import appeng.core.sync.GuiBridge; import appeng.core.sync.GuiBridge;
import appeng.tile.misc.TileInterface; import appeng.tile.misc.TileInterface;
@ -21,6 +24,27 @@ public class BlockInterface extends AEBaseBlock
setTileEntiy( TileInterface.class ); setTileEntiy( TileInterface.class );
} }
@Override
protected Class<? extends BaseBlockRender> 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 @Override
public boolean onActivated(World w, int x, int y, int z, EntityPlayer p, int side, float hitX, float hitY, float hitZ) public boolean onActivated(World w, int x, int y, int z, EntityPlayer p, int side, float hitX, float hitY, float hitZ)
{ {

View file

@ -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;
}
}

View file

@ -22,6 +22,8 @@ public enum ExtraTextures
BlockChargerInside("BlockChargerInside"), BlockChargerInside("BlockChargerInside"),
BlockInterfaceAlternate("BlockInterfaceAlternate"), BlockInterfaceAlternateArrow("BlockInterfaceAlternateArrow"),
MEStorageCellTextures("MEStorageCellTextures"), White("White"), MEStorageCellTextures("MEStorageCellTextures"), White("White"),
BlockMatterCannonParticle("BlockMatterCannonParticle"), BlockEnergyParticle("BlockEnergyParticle"), BlockMatterCannonParticle("BlockMatterCannonParticle"), BlockEnergyParticle("BlockEnergyParticle"),

View file

@ -1,5 +1,7 @@
package appeng.tile.misc; package appeng.tile.misc;
import java.util.EnumSet;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -25,14 +27,40 @@ import appeng.tile.events.AETileEventHandler;
import appeng.tile.events.TileEventType; import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkInvTile; import appeng.tile.grid.AENetworkInvTile;
import appeng.tile.inventory.InvOperation; import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.inv.IInventoryDestination; import appeng.util.inv.IInventoryDestination;
public class TileInterface extends AENetworkInvTile implements IGridTickable, ISegmentedInventory, ITileStorageMonitorable, IStorageMonitorable, public class TileInterface extends AENetworkInvTile implements IGridTickable, ISegmentedInventory, ITileStorageMonitorable, IStorageMonitorable,
IInventoryDestination, IInterfaceHost, IConfigureableObject IInventoryDestination, IInterfaceHost, IConfigureableObject
{ {
ForgeDirection pointAt = ForgeDirection.UNKNOWN;
DualityInterface duality = new DualityInterface( gridProxy, this ); 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 @Override
public void gridChanged() public void gridChanged()
{ {
@ -49,21 +77,35 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, IS
@Override @Override
public void writeToNBT(NBTTagCompound data) public void writeToNBT(NBTTagCompound data)
{ {
data.setInteger( "pointAt", pointAt.ordinal() );
duality.writeToNBT( data ); duality.writeToNBT( data );
} }
@Override @Override
public void readFromNBT(NBTTagCompound data) 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 ); duality.readFromNBT( data );
} }
}; };
public TileInterface() { public TileInterface() {
addNewHandler( new TileInterfaceHandler() ); addNewHandler( new TileInterfaceHandler() );
} }
@Override
public void onReady()
{
gridProxy.setValidSides( EnumSet.complementOf( EnumSet.of( pointAt ) ) );
super.onReady();
}
@Override @Override
public AECableType getCableConnectionType(ForgeDirection dir) public AECableType getCableConnectionType(ForgeDirection dir)
{ {