Implemented interface states and models (#66)

* Implemented interface states and models.
This commit is contained in:
shartte 2016-08-26 11:09:49 +02:00 committed by Elix_x
parent 999401c50c
commit 66df324ef0
9 changed files with 108 additions and 29 deletions

View file

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

View file

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

View file

@ -0,0 +1,6 @@
{
"variants": {
"omnidirectional=true": { "model": "appliedenergistics2:tile.BlockInterface" },
"omnidirectional=false": { "model": "appliedenergistics2:tile.BlockInterfaceOriented", "x": 90 }
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "block/cube_all",
"textures": {
"all": "appliedenergistics2:blocks/BlockInterface"
}
}

View file

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

View file

@ -0,0 +1,3 @@
{
"parent": "appliedenergistics2:block/tile.BlockInterface"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 430 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 B