Added Rotatable Interfaces.
This commit is contained in:
parent
4fde370d7f
commit
c4a7d5b480
6 changed files with 136 additions and 11 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<? 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
|
||||
public boolean onActivated(World w, int x, int y, int z, EntityPlayer p, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
|
|
39
client/render/blocks/RenderBlockInterface.java
Normal file
39
client/render/blocks/RenderBlockInterface.java
Normal 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;
|
||||
}
|
||||
}
|
|
@ -22,6 +22,8 @@ public enum ExtraTextures
|
|||
|
||||
BlockChargerInside("BlockChargerInside"),
|
||||
|
||||
BlockInterfaceAlternate("BlockInterfaceAlternate"), BlockInterfaceAlternateArrow("BlockInterfaceAlternateArrow"),
|
||||
|
||||
MEStorageCellTextures("MEStorageCellTextures"), White("White"),
|
||||
|
||||
BlockMatterCannonParticle("BlockMatterCannonParticle"), BlockEnergyParticle("BlockEnergyParticle"),
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue