Search in sources :

Example 6 with ItemTool

use of net.minecraft.item.ItemTool in project SilentGems by SilentChaos512.

the class EquipmentTooltips method renderForWeapon.

private void renderForWeapon(RenderTooltipEvent.PostText event, ItemStack stack) {
    Minecraft mc = Minecraft.getMinecraft();
    FontRenderer fontRenderer = event.getFontRenderer();
    ItemStack currentEquip = mc.player.getHeldItemMainhand();
    double scale = 0.75;
    int x = (int) (event.getX() / scale);
    int y = (int) ((event.getY() - 16) / scale);
    int durability = getDurability(stack, 0);
    int equippedDurability = getDurability(currentEquip, durability);
    float meleeDamage = getMeleeDamage(stack, 0);
    float equippedMeleeDamage = getMeleeDamage(currentEquip, meleeDamage);
    float magicDamage = getMagicDamage(stack, 0);
    float equippedMagicDamage = getMagicDamage(currentEquip, magicDamage);
    float meleeSpeed = getMeleeSpeed(stack, 0);
    float equippedMeleeSpeed = getMeleeSpeed(currentEquip, meleeSpeed);
    GlStateManager.pushMatrix();
    GlStateManager.color(1f, 1f, 1f, 1f);
    GlStateManager.scale(scale, scale, scale);
    mc.renderEngine.bindTexture(TEXTURE);
    boolean bothWeapons = (isWeapon(stack) || stack.getItem() instanceof ItemTool) && (isWeapon(currentEquip) || currentEquip.getItem() instanceof ItemTool);
    boolean eitherIsCaster = bothWeapons && (isCaster(stack) || isCaster(currentEquip));
    // Durability
    x = renderStat(mc, fontRenderer, 0, x, y, durability, equippedDurability, StackHelper.isValid(currentEquip));
    // Melee Damage
    x = renderStat(mc, fontRenderer, 3, x, y, meleeDamage, equippedMeleeDamage, bothWeapons);
    // Magic Damage
    if (magicDamage > 0 || equippedMagicDamage > 0)
        x = renderStat(mc, fontRenderer, 4, x, y, magicDamage, equippedMagicDamage, eitherIsCaster);
    // Melee Speed
    x = renderStat(mc, fontRenderer, 5, x, y, meleeSpeed, equippedMeleeSpeed, bothWeapons);
    lastWidth = (int) (x * scale - event.getX());
    GlStateManager.popMatrix();
}
Also used : ItemTool(net.minecraft.item.ItemTool) FontRenderer(net.minecraft.client.gui.FontRenderer) ItemStack(net.minecraft.item.ItemStack) Minecraft(net.minecraft.client.Minecraft)

Example 7 with ItemTool

use of net.minecraft.item.ItemTool in project SilentGems by SilentChaos512.

the class EquipmentTooltips method renderForTool.

private void renderForTool(RenderTooltipEvent.PostText event, ItemStack stack) {
    Minecraft mc = Minecraft.getMinecraft();
    FontRenderer fontRenderer = event.getFontRenderer();
    ItemStack currentEquip = mc.player.getHeldItemMainhand();
    boolean isAxe = stack.getItem() instanceof ItemAxe;
    boolean isDurabilityOnly = !(stack.getItem() instanceof ItemTool);
    // boolean isHoe = stack.getItem() instanceof ItemHoe;
    // boolean isSickle = stack.getItem() instanceof ItemGemSickle;
    // boolean isShears = stack.getItem() instanceof ItemShears;
    // boolean isFishingRod = stack.getItem() instanceof ItemFishingRod;
    double scale = 0.75;
    int x = (int) (event.getX() / scale);
    int y = (int) ((event.getY() - 16) / scale);
    int durability = getDurability(stack, 0);
    int equippedDurability = getDurability(currentEquip, durability);
    int harvestLevel = getHarvestLevel(stack, 0);
    int equippedHarvestLevel = getHarvestLevel(currentEquip, harvestLevel);
    float harvestSpeed = getHarvestSpeed(stack, 0);
    float equippedHarvestSpeed = getHarvestSpeed(currentEquip, harvestSpeed);
    float meleeDamage = getMeleeDamage(stack, 0);
    float equippedMeleeDamage = getMeleeDamage(currentEquip, meleeDamage);
    float meleeSpeed = getMeleeSpeed(stack, 0);
    float equippedMeleeSpeed = getMeleeSpeed(currentEquip, meleeSpeed);
    GlStateManager.pushMatrix();
    GlStateManager.color(1f, 1f, 1f, 1f);
    GlStateManager.scale(scale, scale, scale);
    mc.renderEngine.bindTexture(TEXTURE);
    boolean currentIsDurabilityOnly = currentEquip.getItem() instanceof ItemHoe || currentEquip.getItem() instanceof ItemGemSickle || currentEquip.getItem() instanceof ItemFishingRod;
    boolean bothWeapons = (isWeapon(stack) || stack.getItem() instanceof ItemTool) && (isWeapon(currentEquip) || currentEquip.getItem() instanceof ItemTool);
    // Durability
    x = renderStat(mc, fontRenderer, 0, x, y, durability, equippedDurability, StackHelper.isValid(currentEquip));
    // Harvest Level
    if (!isAxe && !isDurabilityOnly && harvestLevel > -1) {
        x = renderStat(mc, fontRenderer, 1, x, y, harvestLevel, equippedHarvestLevel, !currentIsDurabilityOnly && currentEquip.getItem() instanceof ItemTool);
    }
    // Harvest Speed
    if (!isDurabilityOnly && harvestSpeed > 0)
        x = renderStat(mc, fontRenderer, 2, x, y, harvestSpeed, equippedHarvestSpeed, !currentIsDurabilityOnly && currentEquip.getItem() instanceof ItemTool);
    // Melee Damage and Speed
    if (isAxe) {
        x = renderStat(mc, fontRenderer, 3, x, y, meleeDamage, equippedMeleeDamage, bothWeapons);
        x = renderStat(mc, fontRenderer, 5, x, y, meleeSpeed, equippedMeleeSpeed, bothWeapons);
    }
    lastWidth = (int) (x * scale - event.getX());
    GlStateManager.popMatrix();
}
Also used : ItemAxe(net.minecraft.item.ItemAxe) ItemHoe(net.minecraft.item.ItemHoe) ItemTool(net.minecraft.item.ItemTool) ItemFishingRod(net.minecraft.item.ItemFishingRod) FontRenderer(net.minecraft.client.gui.FontRenderer) ItemStack(net.minecraft.item.ItemStack) Minecraft(net.minecraft.client.Minecraft) ItemGemSickle(net.silentchaos512.gems.item.tool.ItemGemSickle)

Example 8 with ItemTool

use of net.minecraft.item.ItemTool in project SpongeCommon by SpongePowered.

the class HarvestingPropertyStore method getFor.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected Optional<HarvestingProperty> getFor(ItemStack itemStack) {
    final Item item = itemStack.getItem();
    if (item instanceof ItemTool && !(item instanceof ItemPickaxe)) {
        final ImmutableSet<BlockType> blocks = ImmutableSet.copyOf((Set) ((ItemTool) item).effectiveBlocks);
        return Optional.of(new HarvestingProperty(blocks));
    }
    final Collection<BlockType> blockTypes = SpongeImpl.getRegistry().getAllOf(BlockType.class);
    final ImmutableSet.Builder<BlockType> builder = ImmutableSet.builder();
    blockTypes.stream().filter(blockType -> item.canHarvestBlock((IBlockState) blockType.getDefaultState())).forEach(builder::add);
    final ImmutableSet<BlockType> blocks = builder.build();
    if (blocks.isEmpty()) {
        return Optional.empty();
    }
    return Optional.of(new HarvestingProperty(blocks));
}
Also used : SpongeImpl(org.spongepowered.common.SpongeImpl) ImmutableSet(com.google.common.collect.ImmutableSet) ItemTool(net.minecraft.item.ItemTool) Item(net.minecraft.item.Item) ItemPickaxe(net.minecraft.item.ItemPickaxe) Collection(java.util.Collection) Set(java.util.Set) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) BlockType(org.spongepowered.api.block.BlockType) Optional(java.util.Optional) AbstractItemStackPropertyStore(org.spongepowered.common.data.property.store.common.AbstractItemStackPropertyStore) HarvestingProperty(org.spongepowered.api.data.property.item.HarvestingProperty) Item(net.minecraft.item.Item) ItemTool(net.minecraft.item.ItemTool) ImmutableSet(com.google.common.collect.ImmutableSet) BlockType(org.spongepowered.api.block.BlockType) ItemPickaxe(net.minecraft.item.ItemPickaxe) HarvestingProperty(org.spongepowered.api.data.property.item.HarvestingProperty)

Example 9 with ItemTool

use of net.minecraft.item.ItemTool in project SpongeCommon by SpongePowered.

the class ToolTypePropertyStore method getFor.

@Override
protected Optional<ToolTypeProperty> getFor(ItemStack itemStack) {
    if (itemStack.getItem() instanceof ItemTool) {
        final ItemTool tool = (ItemTool) itemStack.getItem();
        final Item.ToolMaterial toolMaterial = tool.toolMaterial;
        return Optional.of(new ToolTypeProperty((ToolType) (Object) toolMaterial));
    } else if (itemStack.getItem() instanceof ItemSword) {
        final ItemSword itemSword = (ItemSword) itemStack.getItem();
        final Item.ToolMaterial swordMaterial = itemSword.material;
        return Optional.of(new ToolTypeProperty((ToolType) (Object) swordMaterial));
    } else if (itemStack.getItem() instanceof ItemHoe) {
        final ItemHoe itemHoe = (ItemHoe) itemStack.getItem();
        final Item.ToolMaterial hoeMaterial = itemHoe.toolMaterial;
        return Optional.of(new ToolTypeProperty((ToolType) (Object) hoeMaterial));
    }
    return Optional.empty();
}
Also used : ItemSword(net.minecraft.item.ItemSword) Item(net.minecraft.item.Item) ItemHoe(net.minecraft.item.ItemHoe) ItemTool(net.minecraft.item.ItemTool) ToolType(org.spongepowered.api.data.type.ToolType) ToolTypeProperty(org.spongepowered.api.data.property.item.ToolTypeProperty)

Example 10 with ItemTool

use of net.minecraft.item.ItemTool in project Wurst-MC-1.12 by Wurst-Imperium.

the class AutoSwordMod method setSlot.

public void setSlot() {
    // check if active
    if (!isActive())
        return;
    // wait for AutoEat
    if (wurst.mods.autoEatMod.isEating())
        return;
    // find best weapon
    float bestDamage = 0;
    int bestSlot = -1;
    for (int i = 0; i < 9; i++) {
        // skip empty slots
        if (InventoryUtils.isSlotEmpty(i))
            continue;
        Item item = WMinecraft.getPlayer().inventory.getStackInSlot(i).getItem();
        // get damage
        float damage = 0;
        if (item instanceof ItemSword)
            damage = ((ItemSword) item).attackDamage;
        else if (item instanceof ItemTool)
            damage = ((ItemTool) item).damageVsEntity;
        // compare with previous best weapon
        if (damage > bestDamage) {
            bestDamage = damage;
            bestSlot = i;
        }
    }
    // check if any weapon was found
    if (bestSlot == -1)
        return;
    // save old slot
    if (oldSlot == -1)
        oldSlot = WMinecraft.getPlayer().inventory.currentItem;
    // set slot
    WMinecraft.getPlayer().inventory.currentItem = bestSlot;
    // start timer
    timer = 4;
    wurst.events.add(UpdateListener.class, this);
}
Also used : ItemSword(net.minecraft.item.ItemSword) Item(net.minecraft.item.Item) ItemTool(net.minecraft.item.ItemTool)

Aggregations

ItemTool (net.minecraft.item.ItemTool)11 Item (net.minecraft.item.Item)9 ItemStack (net.minecraft.item.ItemStack)6 ItemSword (net.minecraft.item.ItemSword)5 ItemHoe (net.minecraft.item.ItemHoe)4 IBlockState (net.minecraft.block.state.IBlockState)3 Minecraft (net.minecraft.client.Minecraft)2 FontRenderer (net.minecraft.client.gui.FontRenderer)2 ItemArmor (net.minecraft.item.ItemArmor)2 ItemAxe (net.minecraft.item.ItemAxe)2 ItemBow (net.minecraft.item.ItemBow)2 ItemFishingRod (net.minecraft.item.ItemFishingRod)2 ItemPickaxe (net.minecraft.item.ItemPickaxe)2 WeightedItemStack (cavern.util.WeightedItemStack)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Collection (java.util.Collection)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1