Search in sources :

Example 56 with ItemBlock

use of net.minecraft.item.ItemBlock in project ArsMagica2 by Mithion.

the class BlockEverstone method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
    if (player.getHeldItem() != null) {
        Block block = null;
        int meta = -1;
        TileEntityEverstone everstone = getTE(world, x, y, z);
        if (everstone == null)
            return false;
        if (player.getHeldItem().getItem() == ItemsCommonProxy.crystalWrench) {
            if (!world.isRemote) {
                if (everstone.getFacade() != null) {
                    everstone.setFacade(null, -1);
                    return true;
                } else {
                    world.setBlockToAir(x, y, z);
                    this.dropBlockAsItem(world, x, y, z, new ItemStack(BlocksCommonProxy.everstone));
                    return true;
                }
            }
        } else if (player.getHeldItem().getItem() instanceof ItemBlock) {
            ItemBlock itemblock = (ItemBlock) player.getHeldItem().getItem();
            block = itemblock.field_150939_a;
            if (block.isOpaqueCube()) {
                meta = itemblock.getMetadata(player.getHeldItem().getItemDamage());
            }
        }
        if (everstone.getFacade() == null && block != null) {
            everstone.setFacade(block, meta);
            world.notifyBlockChange(x, y, z, this);
            return true;
        }
    }
    return false;
}
Also used : Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) TileEntityEverstone(am2.blocks.tileentities.TileEntityEverstone) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock)

Example 57 with ItemBlock

use of net.minecraft.item.ItemBlock in project Pearcel-Mod by MiningMark48.

the class ModBlocks method registerBlock.

private static void registerBlock(Block block) {
    GameRegistry.register(block);
    ItemBlock item = new ItemBlock(block);
    item.setRegistryName(block.getRegistryName());
    GameRegistry.register(item);
}
Also used : ItemBlock(net.minecraft.item.ItemBlock)

Example 58 with ItemBlock

use of net.minecraft.item.ItemBlock in project Overloaded by CJ-MC-Mods.

the class PlayerInteractionUtil method placeBlock.

public static boolean placeBlock(@Nonnull ItemStack searchStack, @Nonnull EntityPlayerMP player, @Nonnull World worldIn, @Nonnull BlockPos newPosition, @Nonnull EnumFacing facing, @Nonnull IEnergyStorage energy, float hitX, float hitY, float hitZ) {
    // Can we place a block at this Pos
    ItemBlock itemBlock = ((ItemBlock) searchStack.getItem());
    if (!worldIn.mayPlace(itemBlock.getBlock(), newPosition, false, facing, null)) {
        return false;
    }
    BlockEvent.PlaceEvent event = ForgeEventFactory.onPlayerBlockPlace(player, new BlockSnapshot(worldIn, newPosition, worldIn.getBlockState(newPosition)), facing, EnumHand.MAIN_HAND);
    if (event.isCanceled())
        return false;
    long distance = Math.round(player.getPosition().getDistance(newPosition.getX(), newPosition.getY(), newPosition.getZ()));
    long cost = OverloadedConfig.multiToolConfig.placeBaseCost + OverloadedConfig.multiToolConfig.costPerMeterAway * distance;
    if (cost > Integer.MAX_VALUE || cost < 0 || energy.getEnergyStored() < cost)
        return false;
    IItemHandler inventory = player.getCapability(ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
    int foundStackSlot = findItemStack(searchStack, inventory);
    if (foundStackSlot == -1) {
        System.out.println("Stack not found");
        return false;
    }
    System.out.println("Stack found at index: " + foundStackSlot);
    ItemStack foundStack = inventory.extractItem(foundStackSlot, 1, player.capabilities.isCreativeMode);
    int i = itemBlock.getMetadata(foundStack.getMetadata());
    IBlockState iblockstate1 = itemBlock.block.getStateForPlacement(worldIn, newPosition, facing, hitX, hitY, hitZ, i, player, EnumHand.MAIN_HAND);
    if (itemBlock.placeBlockAt(foundStack, player, worldIn, newPosition, facing, hitX, hitY, hitZ, iblockstate1)) {
        SoundType soundtype = worldIn.getBlockState(newPosition).getBlock().getSoundType(worldIn.getBlockState(newPosition), worldIn, newPosition, player);
        worldIn.playSound(null, newPosition, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
        energy.extractEnergy((int) cost, false);
        System.out.println("Place Block Successs");
        return true;
    }
    System.out.println("Place Block Failed");
    inventory.insertItem(foundStackSlot, foundStack, player.capabilities.isCreativeMode);
    return false;
}
Also used : SoundType(net.minecraft.block.SoundType) IBlockState(net.minecraft.block.state.IBlockState) IItemHandler(net.minecraftforge.items.IItemHandler) BlockSnapshot(net.minecraftforge.common.util.BlockSnapshot) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) BlockEvent(net.minecraftforge.event.world.BlockEvent)

Example 59 with ItemBlock

use of net.minecraft.item.ItemBlock in project minecolonies by Minecolonies.

the class BlockSolidSubstitution method initBlock.

/**
     * initialize the block
     * sets the creative tab, as well as the resistance and the hardness.
     */
private void initBlock() {
    setRegistryName(BLOCK_NAME);
    setUnlocalizedName(String.format("%s.%s", Constants.MOD_ID.toLowerCase(), BLOCK_NAME));
    setCreativeTab(ModCreativeTabs.MINECOLONIES);
    GameRegistry.register(this);
    GameRegistry.register((new ItemBlock(this)).setRegistryName(this.getRegistryName()));
    setHardness(BLOCK_HARDNESS);
    setResistance(RESISTANCE);
}
Also used : ItemBlock(net.minecraft.item.ItemBlock)

Example 60 with ItemBlock

use of net.minecraft.item.ItemBlock in project minecolonies by Minecolonies.

the class BlockSubstitution method initBlock.

/**
     * initialize the block
     * sets the creative tab, as well as the resistance and the hardness.
     */
private void initBlock() {
    setRegistryName(BLOCK_NAME);
    setUnlocalizedName(String.format("%s.%s", Constants.MOD_ID.toLowerCase(), BLOCK_NAME));
    setCreativeTab(ModCreativeTabs.MINECOLONIES);
    GameRegistry.register(this);
    GameRegistry.register((new ItemBlock(this)).setRegistryName(this.getRegistryName()));
    setHardness(BLOCK_HARDNESS);
    setResistance(RESISTANCE);
}
Also used : ItemBlock(net.minecraft.item.ItemBlock)

Aggregations

ItemBlock (net.minecraft.item.ItemBlock)78 Block (net.minecraft.block.Block)41 ItemStack (net.minecraft.item.ItemStack)37 Item (net.minecraft.item.Item)20 IBlockState (net.minecraft.block.state.IBlockState)11 EntityItem (net.minecraft.entity.item.EntityItem)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 TileEntity (net.minecraft.tileentity.TileEntity)4 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)3 IProperty (net.minecraft.block.properties.IProperty)3 RenderItem (net.minecraft.client.renderer.entity.RenderItem)3 EnumFacing (net.minecraft.util.EnumFacing)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 BlockPos (net.minecraft.util.math.BlockPos)3 AMVector3 (am2.api.math.AMVector3)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Tessellator (net.minecraft.client.renderer.Tessellator)2 ChatComponentText (net.minecraft.util.ChatComponentText)2