use of net.minecraft.item.ItemSword in project Hyperium by HyperiumClient.
the class HyperiumItemRenderer method renderItemInFirstPerson.
public void renderItemInFirstPerson(float partialTicks, float prevEquippedProgress, float equippedProgress, ItemStack itemToRender) {
float f = 1.0F - (prevEquippedProgress + (equippedProgress - prevEquippedProgress) * partialTicks);
EntityPlayerSP entityPlayerSP = mc.thePlayer;
float f1 = entityPlayerSP.getSwingProgress(partialTicks);
float f2 = entityPlayerSP.prevRotationPitch + (entityPlayerSP.rotationPitch - entityPlayerSP.prevRotationPitch) * partialTicks;
float f3 = entityPlayerSP.prevRotationYaw + (entityPlayerSP.rotationYaw - entityPlayerSP.prevRotationYaw) * partialTicks;
((IMixinItemRenderer) parent).callRotateArroundXAndY(f2, f3);
((IMixinItemRenderer) parent).callSetLightMapFromPlayer(entityPlayerSP);
((IMixinItemRenderer) parent).callRotateWithPlayerRotations(entityPlayerSP, partialTicks);
GlStateManager.enableRescaleNormal();
GlStateManager.pushMatrix();
if (itemToRender != null) {
if (itemToRender.getItem() == Items.filled_map) {
((IMixinItemRenderer) parent).callRenderItemMap(entityPlayerSP, f2, f, f1);
} else if ((itemToRender.getItem() instanceof ItemSword) && !mc.thePlayer.isBlocking() && Settings.CUSTOM_SWORD_ANIMATION) {
transformFirstPersonItem(f, f1);
} else if (entityPlayerSP.getItemInUseCount() > 0) {
EnumAction enumaction = itemToRender.getItemUseAction();
switch(enumaction) {
case NONE:
transformFirstPersonItem(f, 0.0F);
break;
case EAT:
case DRINK:
((IMixinItemRenderer) parent).callPerformDrinking(entityPlayerSP, partialTicks);
if (Settings.OLD_EATING) {
transformFirstPersonItem(f, f1);
} else {
transformFirstPersonItem(f, 0.0F);
}
break;
case BLOCK:
if (Settings.OLD_BLOCKHIT) {
transformFirstPersonItem(f, f1);
((IMixinItemRenderer) parent).callDoBlockTransformations();
GlStateManager.scale(0.83f, 0.88f, 0.85f);
GlStateManager.translate(-0.3f, 0.1f, 0.0f);
} else {
transformFirstPersonItem(f, 0f);
((IMixinItemRenderer) parent).callDoBlockTransformations();
}
break;
case BOW:
if (Settings.OLD_BOW) {
transformFirstPersonItem(f, f1);
((IMixinItemRenderer) parent).callDoBowTransformations(partialTicks, entityPlayerSP);
GlStateManager.translate(0.0F, 0.1F, -0.15F);
} else {
transformFirstPersonItem(f, 0.0F);
((IMixinItemRenderer) parent).callDoBowTransformations(partialTicks, entityPlayerSP);
}
}
} else {
((IMixinItemRenderer) parent).callDoItemUsedTransformations(f1);
transformFirstPersonItem(f, f1);
}
parent.renderItem(entityPlayerSP, itemToRender, ItemCameraTransforms.TransformType.FIRST_PERSON);
} else if (!entityPlayerSP.isInvisible()) {
((IMixinItemRenderer) parent).callRenderPlayerArm(entityPlayerSP, f, f1);
}
GlStateManager.popMatrix();
GlStateManager.disableRescaleNormal();
RenderHelper.disableStandardItemLighting();
}
use of net.minecraft.item.ItemSword in project Charset by CharsetMC.
the class TweakDisableVanillaTools method enable.
@Override
public void enable() {
Set<Item> itemSet = new HashSet<Item>();
for (ResourceLocation l : Item.itemRegistry.getKeys()) {
Item i = Item.itemRegistry.getObject(l);
if (i instanceof ItemPickaxe || i instanceof ItemAxe || i instanceof ItemSpade || i instanceof ItemSword) {
i.setMaxDamage(1);
itemSet.add(i);
}
}
if (getMode() >= 2) {
Iterator<IRecipe> iterator = CraftingManager.getInstance().getRecipeList().iterator();
while (iterator.hasNext()) {
ItemStack output = iterator.next().getRecipeOutput();
if (output != null && itemSet.contains(output.getItem())) {
iterator.remove();
itemSet.remove(output.getItem());
ModCharsetLib.logger.info("Disabled " + Item.itemRegistry.getNameForObject(output.getItem()).toString() + " (removed recipe)");
}
}
}
for (Item i : itemSet) {
ModCharsetLib.logger.info("Disabled " + Item.itemRegistry.getNameForObject(i).toString());
}
}
use of net.minecraft.item.ItemSword in project minecolonies by Minecolonies.
the class EntityAIMeleeGuard method attackEntity.
private boolean attackEntity(@NotNull final EntityLivingBase entityToAttack, final float baseDamage) {
double damgeToBeDealt = baseDamage;
if (worker.getHealth() <= 2) {
damgeToBeDealt *= 2;
}
damgeToBeDealt += ((AbstractBuildingGuards) getOwnBuilding()).getOffenceBonus();
final ItemStack heldItem = worker.getHeldItem(EnumHand.MAIN_HAND);
if (heldItem != null) {
if (ItemStackUtils.doesItemServeAsWeapon(heldItem)) {
if (heldItem.getItem() instanceof ItemSword) {
damgeToBeDealt += ((ItemSword) heldItem.getItem()).getAttackDamage();
} else {
damgeToBeDealt += TinkersWeaponHelper.getDamage(heldItem);
}
}
damgeToBeDealt += EnchantmentHelper.getModifierForCreature(heldItem, targetEntity.getCreatureAttribute());
}
targetEntity.attackEntityFrom(new DamageSource(worker.getName()), (float) damgeToBeDealt);
targetEntity.setRevengeTarget(worker);
final int fireAspectModifier = EnchantmentHelper.getFireAspectModifier(worker);
if (fireAspectModifier > 0) {
targetEntity.setFire(fireAspectModifier * FIRE_CHANCE_MULTIPLIER);
}
boolean killedEnemy = false;
if (targetEntity.getHealth() <= 0.0F) {
this.onKilledEntity(targetEntity);
killedEnemy = true;
}
worker.faceEntity(entityToAttack, (float) TURN_AROUND, (float) TURN_AROUND);
worker.getLookHelper().setLookPositionWithEntity(entityToAttack, (float) TURN_AROUND, (float) TURN_AROUND);
final double xDiff = targetEntity.posX - worker.posX;
final double zDiff = targetEntity.posZ - worker.posZ;
final double goToX = xDiff > 0 ? MOVE_MINIMAL : -MOVE_MINIMAL;
final double goToZ = zDiff > 0 ? MOVE_MINIMAL : -MOVE_MINIMAL;
worker.move(MoverType.SELF, goToX, 0, goToZ);
worker.swingArm(EnumHand.MAIN_HAND);
worker.playSound(SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, (float) BASIC_VOLUME, (float) getRandomPitch());
worker.damageItemInHand(1);
return killedEnemy;
}
use of net.minecraft.item.ItemSword in project Adventurers-Toolbox by the-realest-stu.
the class SpecialToolAbilityHandler method onTooltip.
@SideOnly(Side.CLIENT)
@SubscribeEvent(priority = EventPriority.HIGH)
public void onTooltip(ItemTooltipEvent event) {
if (event.getItemStack() != null && event.getEntityPlayer() != null) {
ItemStack stack = event.getItemStack();
Item item = stack.getItem();
if (item instanceof ItemATAxe || item instanceof ItemATDagger || item instanceof ItemATHammer || item instanceof ItemATHandpick || item instanceof ItemATHoe || item instanceof ItemATMace || item instanceof ItemATPickaxe || item instanceof ItemATShovel || item instanceof ItemATSword) {
boolean shift = GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindSneak);
boolean advanced = event.getFlags().isAdvanced();
List<String> tooltip = event.getToolTip();
tooltip.clear();
String s = stack.getDisplayName();
s = s + TextFormatting.RESET;
if (advanced) {
String s1 = "";
if (!s.isEmpty()) {
s = s + " (";
s1 = ")";
}
int i = Item.getIdFromItem(item);
if (stack.getHasSubtypes()) {
s = s + String.format("#%04d/%d%s", i, stack.getItemDamage(), s1);
} else {
s = s + String.format("#%04d%s", i, s1);
}
}
tooltip.add(s);
int i1 = 0;
if (shift) {
tooltip.add("");
if (item instanceof IHeadTool) {
HeadMaterial mat = IHeadTool.getHeadMat(stack);
tooltip.add(TextFormatting.YELLOW + " " + I18n.translateToLocal("desc.head.name") + ": " + I18n.translateToLocal("guide.mat." + mat.getName() + ".name"));
}
if (item instanceof IBladeTool) {
HeadMaterial mat = IBladeTool.getBladeMat(stack);
tooltip.add(TextFormatting.YELLOW + " " + I18n.translateToLocal("desc.blade.name") + ": " + I18n.translateToLocal("guide.mat." + mat.getName() + ".name"));
}
if (item instanceof ICrossguardTool) {
HeadMaterial mat = ICrossguardTool.getCrossguardMat(stack);
tooltip.add(TextFormatting.YELLOW + " " + I18n.translateToLocal("desc.crossguard.name") + ": " + I18n.translateToLocal("guide.mat." + mat.getName() + ".name"));
}
if (item instanceof IHaftTool) {
HaftMaterial mat = IHaftTool.getHaftMat(stack);
tooltip.add(TextFormatting.YELLOW + " " + I18n.translateToLocal("desc.haft.name") + ": " + I18n.translateToLocal("guide.mat." + mat.getName() + ".name"));
}
if (item instanceof IHandleTool) {
HandleMaterial mat = IHandleTool.getHandleMat(stack);
tooltip.add(TextFormatting.YELLOW + " " + I18n.translateToLocal("desc.handle.name") + ": " + I18n.translateToLocal("guide.mat." + mat.getName() + ".name"));
}
if (item instanceof IAdornedTool) {
AdornmentMaterial mat = IAdornedTool.getAdornmentMat(stack);
if (!mat.getName().equals("null")) {
tooltip.add(TextFormatting.YELLOW + " " + I18n.translateToLocal("desc.adornment.name") + ": " + I18n.translateToLocal("guide.mat." + mat.getName() + ".name"));
}
}
tooltip.add("");
}
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("HideFlags", 99)) {
i1 = stack.getTagCompound().getInteger("HideFlags");
}
if ((i1 & 32) == 0) {
item.addInformation(stack, event.getEntityPlayer() == null ? null : event.getEntityPlayer().world, tooltip, event.getFlags());
}
if (item instanceof ItemSword && isVoidTool(stack) && CommonProxy.thaumcraftLoaded) {
tooltip.add(TextFormatting.GOLD + I18n.translateToLocal("enchantment.special.sapless"));
}
if (stack.hasTagCompound()) {
if ((i1 & 1) == 0) {
NBTTagList nbttaglist = stack.getEnchantmentTagList();
for (int j = 0; j < nbttaglist.tagCount(); ++j) {
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(j);
int k = nbttagcompound.getShort("id");
int l = nbttagcompound.getShort("lvl");
Enchantment enchantment = Enchantment.getEnchantmentByID(k);
if (enchantment != null) {
tooltip.add(enchantment.getTranslatedName(l));
}
}
}
if (stack.getTagCompound().hasKey("display", 10)) {
NBTTagCompound nbttagcompound1 = stack.getTagCompound().getCompoundTag("display");
if (nbttagcompound1.getTagId("Lore") == 9) {
NBTTagList nbttaglist3 = nbttagcompound1.getTagList("Lore", 8);
if (!nbttaglist3.hasNoTags()) {
for (int l1 = 0; l1 < nbttaglist3.tagCount(); ++l1) {
tooltip.add(TextFormatting.DARK_PURPLE + "" + TextFormatting.ITALIC + nbttaglist3.getStringTagAt(l1));
}
}
}
}
}
Multimap<String, AttributeModifier> multimap = stack.getAttributeModifiers(EntityEquipmentSlot.MAINHAND);
if ((i1 & 2) == 0) {
if (!tooltip.get(tooltip.size() - 1).isEmpty()) {
tooltip.add("");
}
if (item instanceof ItemATPickaxe || item instanceof ItemATHandpick || item instanceof ItemATHammer || item instanceof ItemATAxe || item instanceof ItemATShovel) {
int harvestLvl = -1;
float efficiency = 0F;
if (item instanceof ItemATPickaxe) {
harvestLvl = ((ItemATPickaxe) item).getHarvestLevel(stack);
efficiency = ((ItemATPickaxe) item).getEfficiency(stack);
} else if (item instanceof ItemATHandpick) {
harvestLvl = ((ItemATHandpick) item).getHarvestLevel(stack);
efficiency = ((ItemATHandpick) item).getEfficiency(stack);
} else if (item instanceof ItemATHammer) {
harvestLvl = ((ItemATHammer) item).getHarvestLevel(stack);
efficiency = ((ItemATHammer) item).getEfficiency(stack);
} else if (item instanceof ItemATAxe) {
harvestLvl = ((ItemATAxe) item).getHarvestLevel(stack);
efficiency = ((ItemATAxe) item).getEfficiency(stack);
} else if (item instanceof ItemATShovel) {
harvestLvl = ((ItemATShovel) item).getHarvestLevel(stack);
efficiency = ((ItemATShovel) item).getEfficiency(stack);
}
tooltip.add(I18n.translateToLocal("desc.harvest_level.name") + ": " + harvestLvl);
tooltip.add(I18n.translateToLocal("desc.efficiency.name") + ": " + ItemStack.DECIMALFORMAT.format(efficiency));
}
for (Entry<String, AttributeModifier> entry : multimap.entries()) {
AttributeModifier attributemodifier = entry.getValue();
double d0 = attributemodifier.getAmount();
if (event.getEntityPlayer() != null && (shift || item instanceof ItemSword)) {
if (attributemodifier.getID() == ItemBase.getAttackDamageUUID()) {
d0 = d0 + event.getEntityPlayer().getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getBaseValue();
d0 = d0 + (double) EnchantmentHelper.getModifierForCreature(stack, EnumCreatureAttribute.UNDEFINED);
double d1 = d0 * 100.0D;
;
if (attributemodifier.getOperation() != 1 && attributemodifier.getOperation() != 2) {
d1 = d0;
}
tooltip.add(I18n.translateToLocal("desc.attack_damage.name") + ": " + ItemStack.DECIMALFORMAT.format(d1));
} else if (attributemodifier.getID() == ItemBase.getAttackSpeedUUID()) {
d0 += event.getEntityPlayer().getEntityAttribute(SharedMonsterAttributes.ATTACK_SPEED).getBaseValue();
double d1 = d0 * 100.0D;
;
if (attributemodifier.getOperation() != 1 && attributemodifier.getOperation() != 2) {
d1 = d0;
}
tooltip.add(I18n.translateToLocal("desc.attack_speed.name") + ": " + ItemStack.DECIMALFORMAT.format(d1));
}
}
}
if (shift) {
tooltip.add(I18n.translateToLocal("desc.enchantability.name") + ": " + item.getItemEnchantability(stack));
}
if (stack.isItemDamaged() && stack.isItemStackDamageable()) {
tooltip.add(I18n.translateToLocal("desc.durability.name") + ": " + (stack.getMaxDamage() - stack.getItemDamage()) + " / " + ItemStack.DECIMALFORMAT.format(stack.getMaxDamage()));
} else if (stack.isItemStackDamageable()) {
tooltip.add(I18n.translateToLocal("desc.durability.name") + ": " + stack.getMaxDamage());
}
}
if (stack.hasTagCompound() && stack.getTagCompound().getBoolean("Unbreakable") && (i1 & 4) == 0) {
tooltip.add(TextFormatting.BLUE + I18n.translateToLocal("item.unbreakable"));
}
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("CanDestroy", 9) && (i1 & 8) == 0) {
NBTTagList nbttaglist1 = stack.getTagCompound().getTagList("CanDestroy", 8);
if (!nbttaglist1.hasNoTags()) {
tooltip.add("");
tooltip.add(TextFormatting.GRAY + I18n.translateToLocal("item.canBreak"));
for (int j1 = 0; j1 < nbttaglist1.tagCount(); ++j1) {
Block block = Block.getBlockFromName(nbttaglist1.getStringTagAt(j1));
if (block != null) {
tooltip.add(TextFormatting.DARK_GRAY + block.getLocalizedName());
} else {
tooltip.add(TextFormatting.DARK_GRAY + "missingno");
}
}
}
}
if (advanced) {
tooltip.add(TextFormatting.DARK_GRAY + ((ResourceLocation) Item.REGISTRY.getNameForObject(item)).toString());
tooltip.add(TextFormatting.DARK_GRAY + I18n.translateToLocalFormatted("item.nbt_tags", stack.hasTagCompound() ? stack.getTagCompound().getKeySet().size() : 0));
}
}
}
}
use of net.minecraft.item.ItemSword in project Wurst-MC-1.12 by Wurst-Imperium.
the class AutoToolMod method equipBestTool.
public void equipBestTool(BlockPos pos, boolean useSwords, boolean useHands) {
EntityPlayer player = WMinecraft.getPlayer();
if (player.capabilities.isCreativeMode)
return;
IBlockState state = WBlock.getState(pos);
ItemStack heldItem = player.getHeldItemMainhand();
float bestSpeed = getDestroySpeed(heldItem, state);
int bestSlot = -1;
boolean useFallback = useHands && isDamageable(heldItem);
int fallbackSlot = -1;
for (int slot = 0; slot < 9; slot++) {
if (slot == player.inventory.currentItem)
continue;
ItemStack stack = player.inventory.getStackInSlot(slot);
if (fallbackSlot == -1 && !isDamageable(stack))
fallbackSlot = slot;
float speed = getDestroySpeed(stack, state);
if (speed <= bestSpeed)
continue;
if (!useSwords && stack.getItem() instanceof ItemSword)
continue;
bestSpeed = speed;
bestSlot = slot;
}
if (bestSlot != -1)
player.inventory.currentItem = bestSlot;
else if (useFallback && bestSpeed <= 1 && fallbackSlot != -1)
player.inventory.currentItem = fallbackSlot;
}
Aggregations