First pass of implementing rendering for crafting cubes (#7)

This commit is contained in:
Sebastian Hartte
2016-09-12 01:11:38 +02:00
parent f35a951b09
commit 5b6ed0cfd0
57 changed files with 980 additions and 173 deletions
@@ -21,23 +21,64 @@ package appeng.block.crafting;
import java.util.List;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.util.AEColor;
import appeng.client.UnlistedProperty;
import appeng.tile.crafting.TileCraftingMonitorTile;
public class BlockCraftingMonitor extends BlockCraftingUnit
{
public static final UnlistedProperty<AEColor> COLOR = new UnlistedProperty<>( "color", AEColor.class );
public static final UnlistedProperty<EnumFacing> FORWARD = new UnlistedProperty<>( "forward", EnumFacing.class );
public BlockCraftingMonitor()
{
super( CraftingUnitType.MONITOR );
this.setTileEntity( TileCraftingMonitorTile.class );
}
@Override
protected BlockStateContainer createBlockState()
{
return new ExtendedBlockState( this, getAEStates(), new IUnlistedProperty[] {
STATE,
COLOR,
FORWARD
} );
}
@Override
public IExtendedBlockState getExtendedState( IBlockState state, IBlockAccess world, BlockPos pos )
{
AEColor color = AEColor.Transparent;
EnumFacing forward = EnumFacing.NORTH;
TileCraftingMonitorTile te = getTileEntity( world, pos );
if( te != null )
{
color = te.getColor();
forward = te.getForward();
}
return super.getExtendedState( state, world, pos ).withProperty( COLOR, color ).withProperty( FORWARD, forward );
}
@Override
@SideOnly( Side.CLIENT )
public void getCheckedSubBlocks( final Item item, final CreativeTabs tabs, final List<ItemStack> itemStacks )
@@ -19,12 +19,14 @@
package appeng.block.crafting;
import java.util.EnumSet;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -32,10 +34,16 @@ import net.minecraft.util.BlockRenderLayer;
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 net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import appeng.api.util.AEPartLocation;
import appeng.block.AEBaseTileBlock;
import appeng.client.UnlistedProperty;
import appeng.client.render.crafting.CraftingCubeState;
import appeng.core.sync.GuiBridge;
import appeng.tile.crafting.TileCraftingTile;
import appeng.util.Platform;
@@ -43,8 +51,9 @@ import appeng.util.Platform;
public class BlockCraftingUnit extends AEBaseTileBlock
{
public static final PropertyBool POWERED = PropertyBool.create( "powered" );
public static final PropertyBool FORMED = PropertyBool.create( "formed" );
public static final PropertyBool POWERED = PropertyBool.create( "powered" );
public static final UnlistedProperty<CraftingCubeState> STATE = new UnlistedProperty<>( "state", CraftingCubeState.class );
public final CraftingUnitType type;
@@ -61,7 +70,38 @@ public class BlockCraftingUnit extends AEBaseTileBlock
{
return new IProperty[] { POWERED, FORMED };
}
@Override
public IExtendedBlockState getExtendedState( IBlockState state, IBlockAccess world, BlockPos pos )
{
EnumSet<EnumFacing> connections = EnumSet.noneOf( EnumFacing.class );
for( EnumFacing facing : EnumFacing.values() )
{
if( isConnected( world, pos, facing ) )
{
connections.add( facing );
}
}
IExtendedBlockState extState = (IExtendedBlockState) state;
return extState.withProperty( STATE, new CraftingCubeState( connections ) );
}
private boolean isConnected( IBlockAccess world, BlockPos pos, EnumFacing side )
{
BlockPos adjacentPos = pos.offset( side );
return world.getBlockState( adjacentPos ).getBlock() instanceof BlockCraftingUnit;
}
@Override
protected BlockStateContainer createBlockState()
{
return new ExtendedBlockState( this, getAEStates(), new IUnlistedProperty[] { STATE } );
}
@Override
public IBlockState getStateFromMeta( final int meta )
{
@@ -71,8 +111,8 @@ public class BlockCraftingUnit extends AEBaseTileBlock
@Override
public int getMetaFromState( final IBlockState state )
{
final boolean p = (boolean) state.getValue( POWERED );
final boolean f = (boolean) state.getValue( FORMED );
boolean p = state.getValue( POWERED );
boolean f = state.getValue( FORMED );
return ( p ? 1 : 0 ) | ( f ? 2 : 0 );
}