use of betterwithaddons.tileentity.TileEntityRopePost in project BetterWithAddons by DaedalusGame.
the class BlockRopePost method getExtendedState.
@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
TileEntity te = world instanceof ChunkCache ? ((ChunkCache) world).getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK) : world.getTileEntity(pos);
if (te instanceof TileEntityRopePost) {
TileEntityRopePost tile = (TileEntityRopePost) te;
IExtendedBlockState withplanks = ((IExtendedBlockState) state).withProperty(HELD_WORLD, world).withProperty(HELD_POS, pos).withProperty(HELD_STATE, tile.getFenceState()).withProperty(HELD_PLANKS, tile.getPlanks());
return withplanks;
} else {
return state;
}
}
use of betterwithaddons.tileentity.TileEntityRopePost in project BetterWithAddons by DaedalusGame.
the class BlockRopePost method breakBlock.
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
TileEntity te = worldIn.getTileEntity(pos);
if (te instanceof TileEntityRopePost) {
NonNullList<ItemStack> drops = NonNullList.create();
drops.add(((TileEntityRopePost) te).getPlanks());
IBlockState fenceState = ((TileEntityRopePost) te).getFenceState();
if (fenceState != null)
fenceState.getBlock().getDrops(drops, worldIn, pos, fenceState, 0);
for (ItemStack drop : drops) spawnAsEntity(worldIn, pos, drop);
}
super.breakBlock(worldIn, pos, state);
}
use of betterwithaddons.tileentity.TileEntityRopePost in project BetterWithAddons by DaedalusGame.
the class BlockRopePost method placeFencePost.
public void placeFencePost(World world, BlockPos pos) {
IBlockState state = world.getBlockState(pos);
world.setBlockState(pos, getDefaultState());
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileEntityRopePost)
((TileEntityRopePost) te).setFenceState(state);
}
use of betterwithaddons.tileentity.TileEntityRopePost in project BetterWithAddons by DaedalusGame.
the class BlockRopePost method removedByPlayer.
@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
if (state.getValue(HAS_PLANKS)) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileEntityRopePost && !world.isRemote) {
TileEntityRopePost tile = (TileEntityRopePost) te;
spawnAsEntity(world, pos, tile.getPlanks());
tile.setPlanks(ItemStack.EMPTY);
return false;
}
}
return super.removedByPlayer(state, world, pos, player, willHarvest);
}
use of betterwithaddons.tileentity.TileEntityRopePost in project BetterWithAddons by DaedalusGame.
the class BlockRopePost method onBlockActivated.
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (playerIn == null)
return false;
TileEntity te = worldIn.getTileEntity(pos);
ItemStack stack = playerIn.getHeldItem(hand);
if (te instanceof TileEntityRopePost && !playerIn.isSneaking() && ItemUtil.matchesOreDict(stack, "plankWood")) {
TileEntityRopePost tile = (TileEntityRopePost) te;
if (worldIn.isRemote)
return true;
else {
if (tile.getPlanks().isEmpty()) {
tile.setPlanks(stack.splitStack(1));
}
return true;
}
}
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
Aggregations