Added custom method for updating block state from TileEntity state changes.

This commit is contained in:
Sebastian Hartte
2020-06-07 12:41:32 +02:00
parent 53fc345e88
commit 6011b2dd49
3 changed files with 42 additions and 23 deletions
@@ -327,4 +327,28 @@ public abstract class AEBaseTileBlock<T extends AEBaseTile> extends AEBaseBlock
return this.getTileEntity( w, pos );
}
/**
* Returns the BlockState based on the given BlockState while considering the state of the given TileEntity.
*
* If the given TileEntity is not of the right type for this block, the state is returned unchanged,
* this is also the case if the given block state does not belong to this block.
*/
public final BlockState getTileEntityBlockState(BlockState current, TileEntity te) {
if (current.getBlock() != this || !tileEntityClass.isInstance(te)) {
return current;
}
return updateBlockStateFromTileEntity(current, tileEntityClass.cast(te));
}
/**
* Reimplement this in subclasses to allow tile-entities to update the state of their block when their own
* state changes.
*
* It is guaranteed that te is not-null and the block of the given block state is this exact block instance.
*/
protected BlockState updateBlockStateFromTileEntity(BlockState currentState, T te) {
return currentState;
}
}
@@ -62,27 +62,20 @@ public class BlockChest extends AEBaseTileBlock<TileChest>
}
@Override
public BlockState updatePostPlacement(BlockState state, Direction facing, BlockState facingState, IWorld worldIn, BlockPos pos, BlockPos facingPos) {
// FIXME Check tile-entity updated prop
protected BlockState updateBlockStateFromTileEntity(BlockState currentState, TileChest te) {
DriveSlotState slotState = DriveSlotState.EMPTY;
TileChest te = this.getTileEntity( worldIn, pos );
if( te != null )
if( te.getCellCount() >= 1 )
{
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;
}
slotState = DriveSlotState.fromCellStatus( te.getCellStatus( 0 ) );
}
// Power-state has to be checked separately
if( !te.isPowered() && slotState != DriveSlotState.EMPTY )
{
slotState = DriveSlotState.OFFLINE;
}
return state.with( SLOT_STATE, slotState );
return currentState.with( SLOT_STATE, slotState );
}
@Override