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();
}
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();
}
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));
}
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();
}
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);
}
Aggregations