JimiIT92 Posted August 30, 2015 Posted August 30, 2015 Hi guys I'm trying to make a Katana, wich will basically be a sword but faster, but i don't know how to change it's speed. This is the code for my katana (it's just a copy of the ItemSword class), how can i make it faster (i mean if you click with a sword it does an animation to attack, so you can't attack every second until the animation is over, how can i speed up this animation?) package blaze.items; import com.google.common.collect.Multimap; import com.sun.webkit.SharedBuffer; import blaze.core.BLItems; import blaze.core.BLTabs; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.EnumAction; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import sun.corba.SharedSecrets; public class ItemKatana extends Item { private float attackDamage; private final Item.ToolMaterial material; public ItemKatana(Item.ToolMaterial material) { this.material = material; this.maxStackSize = 1; this.setMaxDamage(material.getMaxUses()); this.setCreativeTab(BLTabs.tabCombat); this.attackDamage = 2.0F + material.getDamageVsEntity(); } /** * Returns the amount of damage this item will deal. One heart of damage is equal to 2 damage points. */ public float getDamageVsEntity() { return this.material.getDamageVsEntity(); } public float getStrVsBlock(ItemStack stack, Block block) { Material material = block.getMaterial(); return material != Material.plants && material != Material.vine && material != Material.coral && material != Material.leaves && material != Material.gourd ? 1.0F : 1.5F; } /** * Current implementations of this method in child classes do not use the entry argument beside ev. They just raise * the damage on the stack. * * @param target The Entity being hit * @param attacker the attacking entity */ public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) { stack.damageItem(1, attacker); return true; } /** * Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic. */ public boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLivingBase playerIn) { if ((double)blockIn.getBlockHardness(worldIn, pos) != 0.0D) { stack.damageItem(2, playerIn); } return true; } /** * Returns True is the item is renderer in full 3D when hold. */ @SideOnly(Side.CLIENT) public boolean isFull3D() { return true; } /** * returns the action that specifies what animation to play when the items is being used */ public EnumAction getItemUseAction(ItemStack stack) { return EnumAction.BLOCK; } /** * How long it takes to use or consume an item */ public int getMaxItemUseDuration(ItemStack stack) { return 72000; } /** * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer */ public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) { playerIn.setItemInUse(itemStackIn, this.getMaxItemUseDuration(itemStackIn)); return itemStackIn; } /** * Return the enchantability factor of the item, most of the time is based on material. */ public int getItemEnchantability() { return this.material.getEnchantability(); } /** * Return the name for this tool's material. */ public String getToolMaterialName() { return this.material.toString(); } public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) { if(this.material.equals("ruby") && repair.getItem().equals(BLItems.ruby)) return true; else return false; } /** * Gets a map of item attribute modifiers, used by ItemSword to increase hit damage. */ public Multimap getItemAttributeModifiers() { Multimap multimap = super.getItemAttributeModifiers(); multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(itemModifierUUID, "Weapon modifier", (double)this.attackDamage, 0)); return multimap; } } Don't blame me if i always ask for your help. I just want to learn to be better
Agravaine Posted August 30, 2015 Posted August 30, 2015 public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker){ target.hurtTime = 0; stack.damageItem(1, attacker); return true; }
Draco18s Posted August 30, 2015 Posted August 30, 2015 That doesn't speed up the animation, it just lets the target get hurt immediately. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
JimiIT92 Posted August 30, 2015 Author Posted August 30, 2015 That doesn't speed up the animation, it just lets the target get hurt immediately. I was just posting that it doesn't change the animation speed Don't blame me if i always ask for your help. I just want to learn to be better
JimiIT92 Posted August 31, 2015 Author Posted August 31, 2015 up Don't blame me if i always ask for your help. I just want to learn to be better
EverythingGames Posted August 31, 2015 Posted August 31, 2015 The potion effect Haste speeds up the animation for hitting, though it also does for block breaking. Try taking a look at it to see how you can achieve the same effect - remember to consider the speeding-up of block breaking. Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]
JimiIT92 Posted August 31, 2015 Author Posted August 31, 2015 I tried before looking the code for the Haste effect but i didn't find that Don't blame me if i always ask for your help. I just want to learn to be better
EverythingGames Posted August 31, 2015 Posted August 31, 2015 Use your IDE. In Eclipse, I found a couple pieces of code relating specifically to this. 1.) The Potion Effect Declaration - This is found in net.minecraft.potion.Potion //Potion effect is declared below public static final Potion digSpeed = (new Potion(3, new ResourceLocation("haste"), false, 14270531)).setPotionName("potion.digSpeed").setIconIndex(2, 0).setEffectiveness(1.5D); 2.) The Swing Animation Speed - This is found in net.minecraft.entity.EntityLivingBase //Modify the below method /** * Returns an integer indicating the end point of the swing animation, used by {@link #swingProgress} to provide a * progress indicator. Takes dig speed enchantments into account. */ private int getArmSwingAnimationEnd() { return this.isPotionActive(Potion.digSpeed) ? 6 - (1 + this.getActivePotionEffect(Potion.digSpeed).getAmplifier()) * 1 : (this.isPotionActive(Potion.digSlowdown) ? 6 + (1 + this.getActivePotionEffect(Potion.digSlowdown).getAmplifier()) * 2 : 6); } Looking at the above modified code found in the paths provided, the first example declares the effect. The second example is what you want to look at, as it returns an integer pertaining to the end of the "swing animation". Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]
EverythingGames Posted August 31, 2015 Posted August 31, 2015 After a bit more searching, I came across this field, which you can modify using reflection. Field SwingProgressInt - Found in net.minecraft.entity.EntityLivingBase //Change this to your needed speed - be sure to pay attention to the methods regarding this field below public int swingProgressInt; Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]
JimiIT92 Posted August 31, 2015 Author Posted August 31, 2015 Oh, that's why i didn't find the code, it was in the entity class. Also i tried do "Search in file" in eclipse but it gives me an error i don't know why I'll try working with that parameters and let you know, thanks Don't blame me if i always ask for your help. I just want to learn to be better
JimiIT92 Posted September 1, 2015 Author Posted September 1, 2015 Ok, so i've tried doing that, but i don't know how to refer that variable using reflection What is the instruction to do that? Don't blame me if i always ask for your help. I just want to learn to be better
JimiIT92 Posted September 1, 2015 Author Posted September 1, 2015 Ok, so i've overrited this method @Override public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) { player.swingProgressInt = 1; return this.hitEntity(stack, (EntityLivingBase) entity, player); } and my katana is faster (wich is what i want), BUT if i hit an entity it doesn't deal damage Don't blame me if i always ask for your help. I just want to learn to be better
LordMastodon Posted September 1, 2015 Posted September 1, 2015 Try adding super.onLeftClickEntity to the beginning of your method. Who are you? Why have you brought me here? And why are there so many PewDiePie fanboys surrounding meeeeeeeee....... *falls into pit and dies*. Also this. Check it out. http://i.imgur.com/J4rrGt6.png[/img]
JimiIT92 Posted September 1, 2015 Author Posted September 1, 2015 Ok, so i've looked into the super method wich is only a return false statement. So i changed my function to this and it worked @Override public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) { player.swingProgressInt = 3; return false; } Also fun fact: it seems that i can make my item only faster but not slower. Don't blame me if i always ask for your help. I just want to learn to be better
Recommended Posts