Posted April 4, 201510 yr I made a universal sword class to get rid of the stupid ToolMaterial stuff and let me make many different special swords using only one class. One of the features is setting a type when registering it so that if the weapon is of that type it has a certain effect. I'm trying to make type '1' set a mob on fire when it's hit with this weapon. But when I hit a mob, it just does normal damage, no fire. What am I doing wrong? Universal Sword Class: public class NewSword extends Item { public static float attackDamage; public static boolean isBreakable; public static String lore; public static int effectType; public NewSword(String description, int uses, float attack, boolean breakable, int type) { maxStackSize = 1; setMaxDamage(uses); attackDamage = attack; lore = description; effectType = type; } @Override @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, EntityPlayer playerIn, List tooltip, boolean advanced) { tooltip.add(EnumChatFormatting.GREEN + lore); } public float func_150931_i() { return attackDamage; } public float func_150893_a(ItemStack p_150893_1_, Block p_150893_2_) { if (p_150893_2_ == Blocks.web) { return 15.0F; } else { Material material = p_150893_2_.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. */ @Override public boolean hitEntity(ItemStack p_77644_1_, EntityLivingBase p_77644_2_, EntityLivingBase p_77644_3_) { if(isBreakable) { return true; } if(effectType == 1) { p_77644_2_.setFire(5); return true; } else return false; } @Override 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. */ @Override @SideOnly(Side.CLIENT) public boolean isFull3D() { return true; } /** * returns the action that specifies what animation to play when the items is being used */ @Override public EnumAction getItemUseAction(ItemStack p_77661_1_) { return EnumAction.BLOCK; } /** * How long it takes to use or consume an item */ public int getMaxItemUseDuration(ItemStack p_77626_1_) { return 72000; } /** * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer */ @Override public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_) { p_77659_3_.setItemInUse(p_77659_1_, this.getMaxItemUseDuration(p_77659_1_)); return p_77659_1_; } public boolean func_150897_b(Block p_150897_1_) { return p_150897_1_ == Blocks.web; } /** * Return whether this item is repairable in an anvil. */ @Override public boolean getIsRepairable(ItemStack p_82789_1_, ItemStack p_82789_2_) { return false; } /** * Gets a map of item attribute modifiers, used by ItemSword to increase hit damage. */ @Override public Multimap getItemAttributeModifiers() { Multimap multimap = super.getItemAttributeModifiers(); multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(itemModifierUUID, "Weapon modifier", (double)this.attackDamage, 0)); return multimap; } } Flaming Stick registration: flaming_stick = new NewSword("Miss_Apocalypse", 250, 5.5F, true, 1).setUnlocalizedName("flaming_stick").setCreativeTab(Main.tabPubliCraft); GameRegistry.registerItem(flaming_stick, flaming_stick.getUnlocalizedName().substring(5));
April 4, 201510 yr Item is a singleton - you cannot use static fields in it, unless thay are shared between all swords using this class. You need to use NBT to save ANY properties, or stop using static fields if you want to have shared props between instances. You probably registered second sword after 1st one and your static effectType field got changed. Sry my post doesnt make any sense after i read it again, basically post below. 1.7.10 is no longer supported by forge, you are on your own.
April 4, 201510 yr Static, because you don't know, is a field/method that is available anywhere even if you don't have an instance of that class. And NBT Is not necessary because all instances of that sword will set fire. However, if you want some swords to set fire and others to do lightning but use the same item, then you should use NBT. Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.
April 5, 201510 yr @Override public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) { target.setFire(4); stack.damageItem(1, attacker); return true; }
June 3, 201510 yr Can I please use this class to make my own swords? Also, could you display where you would add textures and everything? I'm sorta new to modding and I'm missing armor and swords. Thank you for your time
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.