Search in sources :

Example 71 with IBlockState

use of net.minecraft.block.state.IBlockState in project Overloaded by CJ-MC-Mods.

the class PlayerInteractionUtil method removeBlock.

private static boolean removeBlock(World world, BlockPos pos, EntityPlayer player, boolean canHarvest) {
    IBlockState iblockstate = world.getBlockState(pos);
    boolean flag = iblockstate.getBlock().removedByPlayer(iblockstate, world, pos, player, canHarvest);
    if (flag) {
        iblockstate.getBlock().onBlockDestroyedByPlayer(world, pos, iblockstate);
    }
    return flag;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState)

Example 72 with IBlockState

use of net.minecraft.block.state.IBlockState in project AgriCraft by AgriCraft.

the class MethodGetGrowthStage method onMethodCalled.

@Override
protected Object[] onMethodCalled(TileEntityCrop crop) {
    IBlockState state = crop.getWorld().getBlockState(crop.getPos());
    Block block = state.getBlock();
    int meta = block.getMetaFromState(state);
    double growthStage = (100.00 * meta) / 7;
    return new Object[] { growthStage };
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block)

Example 73 with IBlockState

use of net.minecraft.block.state.IBlockState in project AgriCraft by AgriCraft.

the class MethodGetCurrentSoil method onMethodCalled.

@Override
protected Object[] onMethodCalled(TileEntityCrop crop) {
    IBlockState state = crop.getWorld().getBlockState(crop.getPos().add(0, -1, 0));
    Block block = state.getBlock();
    int meta = block.getMetaFromState(state);
    return new Object[] { (new ItemStack(block, 1, meta)).getDisplayName() };
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 74 with IBlockState

use of net.minecraft.block.state.IBlockState in project AgriCraft by AgriCraft.

the class ItemMagnifyingGlass method onItemUseFirst.

//this is called when you right click with this item in hand
@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    if (world.isRemote) {
        List<String> list = new ArrayList<>();
        IBlockState state = world.getBlockState(pos);
        Block block = state.getBlock();
        TileEntity te = world.getTileEntity(pos);
        // Add a separator.
        list.add("========== " + AgriCore.getTranslator().translate("item.agricraft:magnifying_glass.name") + " ==========");
        // Add lighting information.
        list.add("Brightness: (" + world.getLightFromNeighbors(pos.up()) + "/15)");
        // Add block information.
        if (block instanceof IAgriDisplayable) {
            ((IAgriDisplayable) block).addDisplayInfo(list::add);
        }
        // Add tile information.
        if (te instanceof IAgriDisplayable) {
            ((IAgriDisplayable) te).addDisplayInfo(list::add);
        }
        // Display information.
        for (String msg : list) {
            player.addChatComponentMessage(new TextComponentString(msg));
        }
    }
    return EnumActionResult.SUCCESS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) ArrayList(java.util.ArrayList) IAgriDisplayable(com.infinityraider.agricraft.api.v1.misc.IAgriDisplayable) Block(net.minecraft.block.Block) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 75 with IBlockState

use of net.minecraft.block.state.IBlockState in project ConvenientAdditions by Necr0.

the class ItemCompost method tryCompostApply.

public boolean tryCompostApply(ItemStack compost, World world, BlockPos pos) {
    IBlockState state = world.getBlockState(pos);
    Block b = state.getBlock();
    //change to support applying compost on the plant instead of the soil
    if (b != null && (b instanceof IPlantable)) {
        pos = pos.down();
        state = world.getBlockState(pos);
        b = state.getBlock();
    }
    if (!(b == Blocks.DIRT || b == Blocks.FARMLAND || b == Blocks.GRASS || ((b == ModBlocks.compostSoilBlock || b == ModBlocks.compostSoilTilledBlock) && b.getMetaFromState(state) != 0)))
        return false;
    if (!world.isRemote) {
        if (b == Blocks.DIRT)
            world.setBlockState(pos, ModBlocks.compostSoilBlock.getDefaultState());
        else if (b == Blocks.FARMLAND)
            world.setBlockState(pos, ModBlocks.compostSoilTilledBlock.getDefaultState());
        else if (b == Blocks.GRASS) {
            if (compost.getItemDamage() == 1 && world.rand.nextFloat() < ModConfigMisc.composter_sporesMyceliumChance)
                world.setBlockState(pos, Blocks.MYCELIUM.getDefaultState());
            else
                world.setBlockState(pos, ModBlocks.compostSoilBlock.getDefaultState(), 3);
        } else if (b == ModBlocks.compostSoilBlock || b == ModBlocks.compostSoilTilledBlock) {
            world.setBlockState(pos, b.getDefaultState(), 3 + 4);
        }
        compost.shrink(1);
    }
    world.playSound(null, pos, Blocks.GRASS.getSoundType().getHitSound(), SoundCategory.BLOCKS, Blocks.GRASS.getSoundType().getVolume(), Blocks.GRASS.getSoundType().getPitch());
    return true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block)

Aggregations

IBlockState (net.minecraft.block.state.IBlockState)2979 BlockPos (net.minecraft.util.math.BlockPos)1194 Block (net.minecraft.block.Block)797 ItemStack (net.minecraft.item.ItemStack)517 EnumFacing (net.minecraft.util.EnumFacing)420 TileEntity (net.minecraft.tileentity.TileEntity)339 World (net.minecraft.world.World)255 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)171 EntityPlayer (net.minecraft.entity.player.EntityPlayer)136 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)126 ArrayList (java.util.ArrayList)125 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)121 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)95 Entity (net.minecraft.entity.Entity)94 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)93 ItemBlock (net.minecraft.item.ItemBlock)89 BlockPos (net.minecraft.util.BlockPos)84 Random (java.util.Random)82 Vec3d (net.minecraft.util.math.Vec3d)81 RayTraceResult (net.minecraft.util.math.RayTraceResult)76