Search in sources :

Example 26 with ItemBlock

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

the class GuiArcaneCompendium method mouseClicked.

@Override
protected void mouseClicked(int par1, int par2, int par3) {
    if (stackTip != null) {
        GuiArcaneCompendium newGuiToDisplay = null;
        if (stackTip.getItem() instanceof ItemBlock) {
            ItemBlock item = (ItemBlock) stackTip.getItem();
            Block block = item.field_150939_a;
            String name = block.getUnlocalizedName().replace("arsmagica2:", "").replace("tile.", "");
            String metaname = name + "@" + stackTip.getItemDamage();
            String searchName = metaname;
            CompendiumEntry entry = ArcaneCompendium.instance.getEntry(metaname);
            if (entry == null) {
                searchName = name;
                entry = ArcaneCompendium.instance.getEntry(searchName);
            }
            if (entry != null) {
                newGuiToDisplay = entry.getCompendiumGui(searchName);
            }
        } else if (stackTip.getItem() == ItemsCommonProxy.spell_component) {
            String name = SkillManager.instance.getSkillName(SkillManager.instance.getSkill(stackTip.getItemDamage()));
            CompendiumEntry entry = ArcaneCompendium.instance.getEntry(name);
            if (entry != null) {
                newGuiToDisplay = new GuiArcaneCompendium(name, stackTip.getItem(), stackTip.getItemDamage());
            }
        } else {
            String name = stackTip.getItem().getUnlocalizedName().replace("item.", "").replace("arsmagica2:", "");
            String metaname = name + "@" + stackTip.getItemDamage();
            String searchName = metaname;
            CompendiumEntry entry = ArcaneCompendium.instance.getEntry(metaname);
            if (entry == null) {
                searchName = name;
                entry = ArcaneCompendium.instance.getEntry(searchName);
            }
            if (entry != null) {
                newGuiToDisplay = entry.getCompendiumGui(searchName);
            }
        }
        if (newGuiToDisplay != null) {
            storeBreadcrumb();
            Minecraft.getMinecraft().displayGuiScreen(newGuiToDisplay);
        }
        return;
    } else if (entryEntity != null) {
        isDragging = true;
        lastMouseX = par1;
    }
    super.mouseClicked(par1, par2, par3);
}
Also used : Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemBlock(net.minecraft.item.ItemBlock)

Example 27 with ItemBlock

use of net.minecraft.item.ItemBlock in project OpenLights by PC-Logix.

the class DriverBlock method worksWith.

protected boolean worksWith(final Block referenceBlock, final int referenceMetadata) {
    for (ItemStack stack : blocks) {
        if (stack != null && stack.getItem() instanceof ItemBlock) {
            final ItemBlock item = (ItemBlock) stack.getItem();
            final Block supportedBlock = item.field_150939_a;
            final int supportedMetadata = item.getMetadata(stack.getItemDamage());
            if (referenceBlock == supportedBlock && (referenceMetadata == supportedMetadata || stack.getItemDamage() == OreDictionary.WILDCARD_VALUE)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock)

Example 28 with ItemBlock

use of net.minecraft.item.ItemBlock in project Railcraft by Railcraft.

the class ItemFirestoneRefined method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (player.canPlayerEdit(pos, side, stack)) {
        Block block = WorldPlugin.getBlock(world, pos);
        if (block != Blocks.STONE) {
            List<ItemStack> drops = block.getDrops(world, pos, WorldPlugin.getBlockState(world, pos), 0);
            if (drops.size() == 1 && drops.get(0) != null && drops.get(0).getItem() instanceof ItemBlock) {
                ItemStack cooked = FurnaceRecipes.instance().getSmeltingResult(drops.get(0));
                if (cooked != null && cooked.getItem() instanceof ItemBlock) {
                    IBlockState newState = InvTools.getBlockStateFromStack(cooked, world, pos);
                    if (newState != null) {
                        WorldPlugin.setBlockState(world, pos, newState);
                        SoundHelper.playSound(world, null, pos, SoundEvents.ITEM_FIRECHARGE_USE, SoundCategory.BLOCKS, 1.0F, itemRand.nextFloat() * 0.4F + 0.8F);
                        stack.damageItem(1, player);
                        return EnumActionResult.SUCCESS;
                    }
                }
            }
        }
    }
    pos = pos.offset(side);
    if (player.canPlayerEdit(pos, side, stack) && world.isAirBlock(pos)) {
        SoundHelper.playSound(world, null, pos, SoundEvents.ITEM_FIRECHARGE_USE, SoundCategory.BLOCKS, 1.0F, itemRand.nextFloat() * 0.4F + 0.8F);
        world.setBlockState(pos, Blocks.FIRE.getDefaultState());
        stack.damageItem(1, player);
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.FAIL;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock)

Example 29 with ItemBlock

use of net.minecraft.item.ItemBlock in project Railcraft by Railcraft.

the class EntityCartUndercutter method replaceWith.

private void replaceWith(BlockPos pos, int slotExist, int slotStock) {
    ItemStack exist = patternInv.getStackInSlot(slotExist);
    ItemStack stock = getStackInSlot(slotStock);
    if (!isValidBallast(stock))
        return;
    IBlockState oldState = WorldPlugin.getBlockState(worldObj, pos);
    if (oldState == null || !blockMatches(oldState, exist))
        return;
    if (safeToReplace(pos)) {
        Block stockBlock = InvTools.getBlockFromStack(stock);
        List<ItemStack> drops = oldState.getBlock().getDrops(worldObj, pos, oldState, 0);
        ItemBlock item = (ItemBlock) stock.getItem();
        int newMeta = 0;
        if (item.getHasSubtypes())
            newMeta = item.getMetadata(stock.getItemDamage());
        IBlockState newState;
        if (stockBlock != null && WorldPlugin.setBlockState(worldObj, pos, (newState = stockBlock.getStateFromMeta(newMeta)))) {
            SoundHelper.playBlockSound(worldObj, pos, stockBlock.getSoundType().getPlaceSound(), SoundCategory.NEUTRAL, (1f + 1.0F) / 2.0F, 1f * 0.8F, newState);
            decrStackSize(slotStock, 1);
            for (ItemStack stack : drops) {
                CartToolsAPI.transferHelper.offerOrDropItem(this, stack);
            }
            blink();
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock)

Example 30 with ItemBlock

use of net.minecraft.item.ItemBlock in project Railcraft by Railcraft.

the class EntityCartUndercutter method blockMatches.

private boolean blockMatches(IBlockState state, ItemStack stack) {
    if (InvTools.isEmpty(stack))
        return true;
    if (stack.getItem() instanceof ItemBlock) {
        ItemBlock existItem = (ItemBlock) stack.getItem();
        int existMeta = OreDictionary.WILDCARD_VALUE;
        if (existItem.getHasSubtypes())
            existMeta = existItem.getMetadata(stack.getItemDamage());
        Block stackBlock = InvTools.getBlockFromStack(stack);
        return (stackBlock == state.getBlock() && (existMeta == OreDictionary.WILDCARD_VALUE || state.getBlock().getMetaFromState(state) == existMeta)) || (stackBlock == Blocks.DIRT && stackBlock == Blocks.GRASS);
    }
    return false;
}
Also used : Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemBlock(net.minecraft.item.ItemBlock)

Aggregations

ItemBlock (net.minecraft.item.ItemBlock)69 Block (net.minecraft.block.Block)36 ItemStack (net.minecraft.item.ItemStack)34 Item (net.minecraft.item.Item)14 IBlockState (net.minecraft.block.state.IBlockState)7 EntityItem (net.minecraft.entity.item.EntityItem)4 TileEntity (net.minecraft.tileentity.TileEntity)4 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)3 RenderItem (net.minecraft.client.renderer.entity.RenderItem)3 EnumFacing (net.minecraft.util.EnumFacing)3 BlockPos (net.minecraft.util.math.BlockPos)3 AMVector3 (am2.api.math.AMVector3)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 CustomizableSCTE (net.geforcemods.securitycraft.api.CustomizableSCTE)2 IExplosive (net.geforcemods.securitycraft.api.IExplosive)2 IOwnable (net.geforcemods.securitycraft.api.IOwnable)2 Tessellator (net.minecraft.client.renderer.Tessellator)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 ChatComponentText (net.minecraft.util.ChatComponentText)2