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

  • Author

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.

  • Author

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!

  • Author

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!

  • Author

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?

  • Author

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.

For getting the player who died, you can use LivingDeathEvent.

this has the entity and his coordinates.

Than you only have to remove the old death message using event.setCanceled(true); in ServerChatEvent

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.