Jump to content

[1.9.4] Trying to make a certain effect happen with a specific material


Recommended Posts

Posted

Hello,

I'm trying to make a custom material apply wither, and set the target on fire if the entity it hits is undead. However, it doesn't seem to apply this effect on hit.

Here's my code:

[spoiler=Sword Class]

package com.t10a.minedran.item.weapons;

import com.t10a.minedran.reference.Reference;
import com.t10a.minedran.init.ModItems;
import com.t10a.minedran.item.MaterialEffects;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;

public class ItemCustomSword extends ItemSword {

public ItemCustomSword(ToolMaterial material) {
	super(material);
	setMaxStackSize(1);

	setCreativeTab(CreativeTabs.COMBAT);
	setUnlocalizedName(Reference.ItemBase.MODSWORD.getUnlocalizedName() + "_" + getToolMaterialName().toLowerCase());
	setRegistryName(Reference.ItemBase.MODSWORD.getRegistryName()  + "_" + getToolMaterialName().toLowerCase());
}

    public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker, ToolMaterial material)
    {
    	MaterialEffects.effectsOnAttack(material, stack, target, attacker);
        stack.damageItem(1, attacker);
        return true;
    }
}

 

[spoiler=Material Effects Class]

package com.t10a.minedran.item;

import com.t10a.minedran.init.ModItems;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.init.MobEffects;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.potion.PotionEffect;
import net.minecraft.item.ItemStack;

public abstract class MaterialEffects 
{

public static void effectsOnAttack(final ToolMaterial material, final ItemStack stack, final EntityLivingBase target, final EntityLivingBase attacker)
{
    	if (material.equals(ModItems.TUTORIAL))
    	{
    		if(target.getCreatureAttribute() == EnumCreatureAttribute.UNDEAD)
    		{
    			target.addPotionEffect(new PotionEffect(MobEffects.WITHER, 60, 3));
    			target.setFire(10);
    		}
    	}
}
}

 

Thanks if you can help.

If I'm asking a whole bunch of questions, please don't get angry. I'm trying to learn.

Posted

Your

hitEntity

method doesn't override a super method, you can't just add random parameters to a method and expect it to be called.

 

If you'd used the

@Override

annotation, you would have already known this was the problem.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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