Jump to content

Custom death message when killed with custom sword.


dude22072

Recommended Posts

I have a custom weapon and was wondering if their is any way to have a unique death message when killed by it?

Legend of Zelda Mod[updated September 20th to 3.1.1]

Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0]

Fancy Cheeses[updated May 8th to 0.5.0]

Link to comment
Share on other sites

If you make a new instance of a DamageSource, you can add a custom death message for it via the LanguageRegistry.

 

DamageSourceSword class:

 

package you.modname;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ChatMessageComponent;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EntityDamageSourceIndirect;
import net.minecraft.util.StatCollector;

public class DamageSourceSword extends DamageSource
{

protected DamageSourceSword(String par1Str) 
{
	super(par1Str);
}

public static DamageSource causeSwordDamage(Entity par0Entity, Entity par1Entity)
{
	return (new EntityDamageSourceIndirect("sword", par0Entity, par1Entity));
}

@Override
public ChatMessageComponent func_111181_b(EntityLivingBase par1EntityLivingBase)
    {
	EntityLivingBase entitylivingbase1 = par1EntityLivingBase.func_94060_bK();
        String s = "death.attack." + this.damageType;
        String s1 = s + ".player";
        return entitylivingbase1 != null && StatCollector.func_94522_b(s1) ? ChatMessageComponent.func_111082_b(s1, new Object[] {par1EntityLivingBase.getTranslatedEntityName(), entitylivingbase1.getTranslatedEntityName()}): ChatMessageComponent.func_111082_b(s, new Object[] {par1EntityLivingBase.getTranslatedEntityName()});
    }
}

 

 

In your mod file, preferably in @PreInit():

 

LanguageRegistry.instance().addStringLocalization("death.attack.sword", "%1$s was sliced to death"); //This shouldn't happen, but add anyway.
LanguageRegistry.instance().addStringLocalization("death.attack.sword.player", "%1$s was sliced to death by %2$s"); //Death from the damagesource, because of a player. Should always be this.
LanguageRegistry.instance().addStringLocalization("death.attack.sword.item", "%1$s was sliced to death by %2$s using %3$s"); //Death from the damagesource of they renamed the sword

 

 

The enders are everywhere. You can't escape...

Link to comment
Share on other sites

If you make a new instance of a DamageSource, you can add a custom death message for it via the LanguageRegistry.

 

DamageSourceSword class:

 

package you.modname;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ChatMessageComponent;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EntityDamageSourceIndirect;
import net.minecraft.util.StatCollector;

public class DamageSourceSword extends DamageSource
{

protected DamageSourceSword(String par1Str) 
{
	super(par1Str);
}

public static DamageSource causeSwordDamage(Entity par0Entity, Entity par1Entity)
{
	return (new EntityDamageSourceIndirect("sword", par0Entity, par1Entity));
}

@Override
public ChatMessageComponent func_111181_b(EntityLivingBase par1EntityLivingBase)
    {
	EntityLivingBase entitylivingbase1 = par1EntityLivingBase.func_94060_bK();
        String s = "death.attack." + this.damageType;
        String s1 = s + ".player";
        return entitylivingbase1 != null && StatCollector.func_94522_b(s1) ? ChatMessageComponent.func_111082_b(s1, new Object[] {par1EntityLivingBase.getTranslatedEntityName(), entitylivingbase1.getTranslatedEntityName()}): ChatMessageComponent.func_111082_b(s, new Object[] {par1EntityLivingBase.getTranslatedEntityName()});
    }
}

 

 

In your mod file, preferably in @PreInit():

 

LanguageRegistry.instance().addStringLocalization("death.attack.sword", "%1$s was sliced to death"); //This shouldn't happen, but add anyway.
LanguageRegistry.instance().addStringLocalization("death.attack.sword.player", "%1$s was sliced to death by %2$s"); //Death from the damagesource, because of a player. Should always be this.
LanguageRegistry.instance().addStringLocalization("death.attack.sword.item", "%1$s was sliced to death by %2$s using %3$s"); //Death from the damagesource of they renamed the sword

 

 

It says the following imports don't exist:

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ChatMessageComponent;

Legend of Zelda Mod[updated September 20th to 3.1.1]

Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0]

Fancy Cheeses[updated May 8th to 0.5.0]

Link to comment
Share on other sites

If you're using Eclipse on Windows, use this key combo:

CTRL + SHIFT + O

It should sort your imports.

That does not solve my issue...

it actually makes it worse.

Legend of Zelda Mod[updated September 20th to 3.1.1]

Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0]

Fancy Cheeses[updated May 8th to 0.5.0]

Link to comment
Share on other sites

  • 3 weeks later...

ctrl+shift+o will never make it worst, if you're getting more error because of it it means that the fix you were trying to do is actuallly wayyy worst then the result after ctrol sihft o

 

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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