Implemented ME chest item + block model.

This commit is contained in:
Sebastian Hartte
2016-08-27 18:12:54 +02:00
parent 5465527ea0
commit 81984b3ad7
31 changed files with 330 additions and 23 deletions
@@ -22,12 +22,16 @@ package appeng.block.storage;
import javax.annotation.Nullable;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
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 appeng.api.AEApi;
@@ -43,10 +47,19 @@ import appeng.util.Platform;
public class BlockChest extends AEBaseTileBlock
{
private final static PropertyEnum<DriveSlotState> SLOT_STATE = PropertyEnum.create( "slot_state", DriveSlotState.class );
public BlockChest()
{
super( Material.IRON );
this.setTileEntity( TileChest.class );
this.setDefaultState( getDefaultState().withProperty( SLOT_STATE, DriveSlotState.EMPTY ) );
}
@Override
protected IProperty[] getAEStates()
{
return new IProperty[] { SLOT_STATE };
}
@Override
@@ -55,6 +68,30 @@ public class BlockChest extends AEBaseTileBlock
return BlockRenderLayer.CUTOUT;
}
@Override
public IBlockState getActualState( IBlockState state, IBlockAccess worldIn, BlockPos pos )
{
DriveSlotState slotState = DriveSlotState.EMPTY;
TileChest te = getTileEntity( worldIn, pos );
if( te != null )
{
if( te.getCellCount() >= 1 )
{
slotState = DriveSlotState.fromCellStatus( te.getCellStatus( 0 ) );
}
// Power-state has to be checked separately
if( !te.isPowered() && slotState != DriveSlotState.EMPTY )
{
slotState = DriveSlotState.OFFLINE;
}
}
return super.getActualState( state, worldIn, pos )
.withProperty( SLOT_STATE, slotState );
}
@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 )
{
@@ -0,0 +1,23 @@
package appeng.block.storage;
import appeng.api.util.AEColor;
import appeng.bootstrap.BlockRenderingCustomizer;
import appeng.bootstrap.IBlockRendering;
import appeng.bootstrap.IItemRendering;
import appeng.client.render.ColorableTileBlockColor;
import appeng.client.render.StaticItemColor;
public class ChestRendering extends BlockRenderingCustomizer
{
@Override
public void customize( IBlockRendering rendering, IItemRendering itemRendering )
{
// I checked, the ME chest doesn't keep its color in item form
itemRendering.color( new StaticItemColor( AEColor.Transparent ) );
rendering.blockColor( new ColorableTileBlockColor() );
}
}
@@ -19,25 +19,57 @@
package appeng.block.storage;
import net.minecraft.util.IStringSerializable;
/**
* Describes the different states a single slot of a BlockDrive can be in in terms of rendering.
*/
public enum DriveSlotState
public enum DriveSlotState implements IStringSerializable
{
// No cell in slot
EMPTY,
EMPTY( "empty" ),
// Cell in slot, but unpowered
OFFLINE,
OFFLINE( "offline" ),
// Online and free space
ONLINE,
ONLINE( "online" ),
// Types full, space left
TYPES_FULL,
TYPES_FULL( "types_full" ),
// Completely full
FULL
FULL( "full" );
private final String name;
DriveSlotState( String name )
{
this.name = name;
}
@Override
public String getName()
{
return name;
}
public static DriveSlotState fromCellStatus( int cellStatus )
{
switch( cellStatus )
{
default:
case 0:
return DriveSlotState.EMPTY;
case 1:
return DriveSlotState.ONLINE;
case 2:
return DriveSlotState.TYPES_FULL;
case 3:
return DriveSlotState.FULL;
}
}
}
@@ -70,22 +70,7 @@ public class DriveSlotsState
}
else
{
switch( chestOrDrive.getCellStatus( i ) )
{
default:
case 0:
slots[i] = DriveSlotState.EMPTY;
break;
case 1:
slots[i] = DriveSlotState.ONLINE;
break;
case 2:
slots[i] = DriveSlotState.TYPES_FULL;
break;
case 3:
slots[i] = DriveSlotState.FULL;
break;
}
slots[i] = DriveSlotState.fromCellStatus( chestOrDrive.getCellStatus( i ) );
}
}
return new DriveSlotsState( slots );
@@ -75,6 +75,7 @@ import appeng.block.storage.BlockDrive;
import appeng.block.storage.BlockIOPort;
import appeng.block.storage.BlockSkyChest;
import appeng.block.storage.BlockSkyChest.SkyChestType;
import appeng.block.storage.ChestRendering;
import appeng.block.storage.DriveRendering;
import appeng.block.storage.SkyChestRenderingCustomizer;
import appeng.bootstrap.BlockRenderingCustomizer;
@@ -288,7 +289,11 @@ public final class ApiBlocks implements IBlocks
.useCustomItemModel()
.rendering( new DriveRendering() )
.build();
this.chest = registry.block( "chest", BlockChest::new ).features( AEFeature.StorageCells, AEFeature.MEChest ).build();
this.chest = registry.block( "chest", BlockChest::new )
.features( AEFeature.StorageCells, AEFeature.MEChest )
.useCustomItemModel()
.rendering( new ChestRendering() )
.build();
this.iface = registry.block( "interface", BlockInterface::new ).build();
this.cellWorkbench = registry.block( "cell_workbench", BlockCellWorkbench::new ).features( AEFeature.StorageCells ).build();
this.iOPort = registry.block( "ioport", BlockIOPort::new ).features( AEFeature.StorageCells, AEFeature.IOPort ).build();