Jump to content

[SOLVED] [1.8] Making a Sword hit faster


JimiIT92

Recommended Posts

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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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. xD

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Ngamenslot adalah pilihan terbaik bagi Anda yang mencari situs terpercaya untuk bermain slot dan taruhan bola. Berikut adalah beberapa alasan mengapa Anda harus memilih Ngamenslot: Kombinasi Slot & Bola Kami menyajikan kombinasi terbaik antara permainan slot yang seru dan taruhan bola yang menegangkan. Dengan pilihan permainan yang beragam, setiap pemain dapat menikmati pengalaman bermain yang unik dan menyenangkan. Transaksi Mudah melalui Bank Ekonomi Kami menyediakan layanan transaksi yang mudah dan aman melalui Bank Ekonomi. Dengan dukungan dari sistem pembayaran yang terpercaya, Anda dapat melakukan deposit dan penarikan dana dengan cepat dan tanpa hambatan. Terpercaya dan Terjamin Ngamenslot telah terbukti sebagai situs terpercaya dengan ribuan pemain yang puas. Kami mengutamakan keamanan dan kenyamanan para pemain, sehingga Anda dapat bermain dengan tenang dan fokus pada permainan.  
    • Tambang88 adalah pilihan terbaik bagi Anda yang mencari pengalaman bermain slot gacor dengan transaksi mudah menggunakan Bank Sinarmas. Berikut adalah beberapa alasan mengapa Anda harus memilih Tambang88: Raja Slot Gacor Kami merupakan raja slot gacor dengan koleksi permainan terbaik yang menawarkan kesenangan bermain dan peluang kemenangan besar. Dengan fitur-fitur unggulan dan tema-tema menarik, setiap putaran permainan akan memberikan Anda pengalaman yang tak terlupakan. Transaksi Mudah dengan Bank Sinarmas Kami menyediakan layanan transaksi mudah melalui Bank Sinarmas untuk kenyamanan dan keamanan Anda. Dengan proses yang cepat dan efisien, Anda dapat melakukan deposit dan penarikan dana dengan lancar dan tanpa hambatan. Profesional dan Menguntungkan Tambang88 mengutamakan profesionalitas dalam memberikan layanan kepada para pemainnya. Kami juga menawarkan kesempatan untuk meraih keuntungan yang besar dengan jackpot dan hadiah-hadiah menarik lainnya.    
    • TRIK POLA SL0T GAC0R MAHJONG WAYS 1 DAN 2 HARI INI Sekarang Anda dapat meningkatkan peluang Bermain dengan langsung menggunakan situs resmi dari permainan Mahjong (PG SOFT). Cukup daftar dan siapkan hanya mulai dari 50K hingga 200K, Anda sudah memiliki peluang untuk memenangkan hadiah besar. Jika tidak memiliki dana sebanyak itu, Anda dapat mencoba dengan dana 50K dan memanfaatkan bonus member baru untuk menambah modal. Berikut adalah Situs Resmi Mahjong yang dapat Anda kunjungi: >> SITUS RESMI MAHJONG YANG TERBUKTI << >> SITUS RESMI MAHJONG YANG TERBUKTI << Setelah mendaftar, Anda dapat menggunakan pola yang sering saya gunakan: 🔥 25 Manual TURBO OFF 🔥 15 Manual TURBO ON 🔥 30 Auto TURBO OFF 🔥 10 Manual TURBO ON Pola ini biasanya memberikan hasil yang konsisten.
    • OLO4D adalah pilihan terbaik bagi Anda yang mencari pengalaman bermain slot gacor dengan transaksi mudah menggunakan Bank Bukopin. Berikut adalah beberapa alasan mengapa Anda harus memilih OLO4D: Slot Gacor Terbaik Kami menyajikan koleksi slot gacor terbaik yang menawarkan kesenangan bermain dan peluang kemenangan besar. Dengan fitur-fitur unggulan dan tema-tema menarik, setiap putaran permainan akan memberikan Anda pengalaman yang tak terlupakan. Transaksi Mudah dengan Bank Bukopin Kami menyediakan layanan transaksi mudah melalui Bank Bukopin untuk kenyamanan dan keamanan Anda. Dengan proses yang cepat dan efisien, Anda dapat melakukan deposit dan penarikan dana dengan lancar dan tanpa hambatan. Pasti Jackpot OLO4D memberikan jaminan bahwa setiap pemain pasti mendapatkan jackpot. Dengan peluang kemenangan yang tinggi, setiap putaran permainan bisa menjadi peluang untuk meraih keberuntungan besar.  
    • Balon168: Gampang Banjir Scatter Hitam Malam Ini Balon168 telah menjadi sorotan dalam dunia perjudian online, dan ada alasan kuat mengapa pemain semakin tertarik. Salah satu permainan unggulannya, yang dikenal dengan tingkat kemenangan yang tinggi, adalah varian "Gampang Banjir Scatter Hitam Malam Ini". Mari kita selami lebih dalam mengenai fenomena ini. Balon168: Destinasi Utama bagi Pecinta Slot     DAFTAR SEKARANG LINK VIP MAXWIN  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.