Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

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.

  • Author

Oops. Silly me. Thanks

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.