Search in sources :

Example 1 with TileEntityRopePost

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;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ChunkCache(net.minecraft.world.ChunkCache) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) TileEntityRopePost(betterwithaddons.tileentity.TileEntityRopePost)

Example 2 with TileEntityRopePost

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);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) TileEntityRopePost(betterwithaddons.tileentity.TileEntityRopePost)

Example 3 with TileEntityRopePost

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);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) TileEntityRopePost(betterwithaddons.tileentity.TileEntityRopePost)

Example 4 with TileEntityRopePost

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);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRopePost(betterwithaddons.tileentity.TileEntityRopePost)

Example 5 with TileEntityRopePost

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);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ItemStack(net.minecraft.item.ItemStack) TileEntityRopePost(betterwithaddons.tileentity.TileEntityRopePost)

Aggregations

TileEntityRopePost (betterwithaddons.tileentity.TileEntityRopePost)5 TileEntity (net.minecraft.tileentity.TileEntity)5 IBlockState (net.minecraft.block.state.IBlockState)2 ItemStack (net.minecraft.item.ItemStack)2 ChunkCache (net.minecraft.world.ChunkCache)1 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)1