Houses and beds
Making your own familiar house and familiar bed.
Creating your own familiar house
Extend AbstractFamiliarStorageBlock for the block:
public class FamiliarHouseExampleBlock extends AbstractFamiliarStorageBlock {
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public static final MapCodec<FamiliarHouseExampleBlock> CODEC = simpleCodec(FamiliarHouseExampleBlock::new);
public FamiliarHouseExampleBlock(Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
}
@Override
public MapCodec<FamiliarHouseExampleBlock> codec() {
return CODEC;
}
@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new FamiliarHouseExampleBlockEntity(pos, state);
}
//How many familiar houses are allowed per chunk
@Override
protected int getAmountPerChunk() {
return 2;
}
@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> blockEntityType) {
return level.isClientSide ? null : createTickerHelper(blockEntityType, BlockEntityRegistry.FAMILIAR_HOUSE_EXAMPLE.get(), AbstractFamiliarStorageBlockEntity::serverTick);
}
//Rest of the implementation...
}The block entity is a normal modded block entity extending AbstractFamiliarStorageBlockEntity.
Creating your own familiar bed
Extend AbstractFamiliarBedBlock for the block and AbstractFamiliarBedBlockEntity for the block entity, and implement them like any other modded block and block entity.
Beds hatch Familiar Eggs with no extra code. If the egg doesn't sit right on your bed's model, override these on the block entity:
@Override
public Vec3 getEggRenderOffset() { // bottom center of the egg, from the block's corner, for a bed facing north
return new Vec3(0.5, 0.3125, 0.5);
}
@Override
public float getEggRenderScale() { // 1 = a full block tall
return 0.5F;
}The egg turns with the bed's HORIZONTAL_FACING property (the standard FACING of horizontal blocks), offset included. For other facing properties, override getEggRenderFacing().
Call super in saveAdditional and getUpdateTag if your block entity overrides them: the bed's taken flag and its egg are saved and synced there, and an egg on the bed would vanish on reload without them.
