Jump to content

[1.7.10]Newbie needs help w/ death messages


cw84

Recommended Posts

Hello,

 

I'm new to the modding community and this is my first post on minecraftforge.net...

 

Basically I've followed a few starter tutorials and have a minor understanding of Java. I've approximately 6 years of coding under my belt so this seemed like a fun side project to try and learn.

 

I have many questions as it seems the tutorials only cover the very basics (and so many people seem to be redoing those basic tuts). My first question is, how does one alter the death message displayed to the player? Simple enough, I'm looking to just add the coordinates the player has died at.

 

I believe there are a varying level of things that need to happen.. Stop me if I'm on the wrong track:

1. I need to listened to Forge events.

2. There is more than one event I must be listening too.

3. I need to have some kind of message handler to capture the out message, append to it, and complete sending the message.

 

So how does one go about accomplishing something so small?

 

I'm using latest Forge (I couldn't get FML1.8 to run).

I'm using MC 1.7.10.

I'm using Eclipse latest.

Link to comment
Share on other sites

The idea is that when the player dies, it will generate the death message and I would simply add to the end the coordinates the player has died at. I don't know that I need to modify the original message... just append to the end of it.

Link to comment
Share on other sites

Okay,

 

In my main class I have:

 

@EventHandler
public void loadMod(FMLInitializationEvent event)
{
MinecraftForge.EVENT_BUS.register(new DMEventHandler());
}

 

In my DMEventHandler class I have:

import net.minecraftforge.event.ServerChatEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class DMEventHandler
{
@SubscribeEvent
public void onServerChatEvent(ServerChatEvent event)
{
	System.out.print("Player =" + event.player);
	System.out.print("Message =" + event.message);
	System.out.print("Username =" + event.username);
	System.out.print("Component =" + event.component);
}
}

 

When I use the chat function it works perfectly. However, when I kill myself...

"[19:31:46] [server thread/INFO]: Player62 fell from a high place

[19:31:46] [Client thread/INFO]: [CHAT] Player62 fell from a high place"

or

"[19:32:22] [server thread/INFO]: Player62 was slain by Zombie

[19:32:22] [Client thread/INFO]: [CHAT] Player62 was slain by Zombie"

 

... I don't get any output. Is there something I am missing here?  ???

Thanks for the pointers!

Link to comment
Share on other sites

So I can now append the location to chat message sent.. I'm really looking to send the coordinates to the player upon their death. How do I get the death event?

 

Here is what I currently have:

import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.event.ServerChatEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class DMEventHandler
{
@SubscribeEvent
public void onServerChatEvent(ServerChatEvent event)
{		
	// Cancel Event...
	event.setCanceled(true);

	// Round position...
	double posX = Math.round(event.player.posX * 100.0) / 100.0;
	double posY = Math.round(event.player.posY * 100.0) / 100.0;
	double posZ = Math.round(event.player.posZ * 100.0) / 100.0;

	// Set string to be sent...
	String chattxt = event.message + " " + EnumChatFormatting.RED + "[" + EnumChatFormatting.YELLOW + "X:" + posX + " Y:" + posY + " Z:" + posZ + EnumChatFormatting.RED + "]";

	// Send text
	event.player.addChatMessage(new ChatComponentTranslation(chattxt));
}
}

 

Thanks guys!

Link to comment
Share on other sites

So I tried a different path...

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class DMEventHandler
{
@SubscribeEvent
public void onDeath(LivingDeathEvent event)
{
	// Get the killed entity...
	Entity killed = event.entityLiving;

	// If the entity is a player...
	if(killed instanceof EntityPlayer)
	{
		EntityPlayer player = (EntityPlayer) event.entityLiving;
		// Round position...
		double posX = Math.round(event.entity.posX * 100.0) / 100.0;
		double posY = Math.round(event.entity.posY * 100.0) / 100.0;
		double posZ = Math.round(event.entity.posZ * 100.0) / 100.0;

		// Set the string to be sent...
		String chattxt = EnumChatFormatting.RED + "[" + EnumChatFormatting.YELLOW + "X:" + posX + " Y:" + posY + " Z:" + posZ + EnumChatFormatting.RED + "]";

		// Send text
		player.addChatMessage(new ChatComponentTranslation(chattxt));
	}
}
}

 

This allows me to send the coordinates to the user at death. It doesn't, however, allow me to append to the message! Any help with this would be great. What's the right way to accomplish this?

Link to comment
Share on other sites

I couldn't capture when a death event happened using ServerChatEvent.. what is it I am looking for exactly?

 

At this point, I was able to get what I needed using the LivingDeathEvent. My only downside to it was that I can't cancel the server message and append the coordinates to it.

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.

Announcements



×
×
  • Create New...

Important Information

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