Jump to content

Gui on enitiy killed


darkfire123

Recommended Posts

im tying to have a GUI appear when ever a player kills a Entity, but i don't want it to pause the game and player moment  kinda like the GUI from rwTema's Monk mod when the player achieve the quest it give them.

 

currently i have a class  DFMEventHandler which Add the Event onEntityDeath to the event buss (it is regiter in my main class...

MinecraftForge.EVENT_BUS.register(new DFMEventHandler() );

  in the init  faze  )

Spoiler

package com.df.dfmod.Utils;



import com.df.dfmod.Gui.DFMGui;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.DamageSource;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.client.event.RenderGameOverlayEvent.Post;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;


@EventBusSubscriber
public class DFMEventHandler {
	
	private DFMGui gui;
	private RenderGameOverlayEvent post;
	public static boolean isDead = false;
	
//	 public void kill(DamageSource source) {
//		
//		if (source.getTrueSource() instanceof EntityPlayer) {
//			EntityPlayer player = (EntityPlayer) source.getTrueSource();
//			
//			player.sendMessage(new TextComponentString("you killed SomeThing!!!"));
//			Utils.getlogger().info("You killed Something!!!");
//		}
//	}
	
	@SubscribeEvent
	 public void onEntityDeath(LivingDeathEvent event) {   	 
		
		 // test weather or not player has kill an enitiy
		if (event.getSource().getTrueSource() instanceof EntityPlayer) {
			
			EntityPlayer player = (EntityPlayer) event.getSource().getTrueSource();
			isDead = true;
			player.sendMessage(new TextComponentString("you killed SomeThing!!!"));
				
		}

	 }
	

}

 

 

 

 

and i have the Gui that uses the RenderGameOverlayEvent  to have a GUI Appear

Spoiler

package com.df.dfmod.Gui;

import org.lwjgl.opengl.GL11;

import com.df.dfmod.Utils.DFMEventHandler;
import com.df.dfmod.Utils.Reference;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.DamageSource;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class DFMGui extends Gui{

	private Minecraft mc;
	
	public final ResourceLocation texture = new ResourceLocation(Reference.MODID, "textures/gui/dfmgui.png");
	int guiWidth = 160;
	int guiHight = 132;

	 @SubscribeEvent
	 public void onRenderGameOverlayEvent(RenderGameOverlayEvent.Post event) 
	 {		
			GL11.glPushMatrix();
					
					mc.renderEngine.bindTexture(texture);
					drawTexturedModalRect(0, 0, 0, 0, guiWidth, guiHight);
				
						GL11.glPopMatrix();
	 }
	
}

 

 

my only problem i cant seem to figure out and google doesn't help with  is  getting the overlay to appear when the entity is killed!

1) should i merge the two event together ??

2) can i call my onRenderGameOverlayEvent with-in onEntityDeath

3) right now im not looking for the most efficient way to run the Gui and so forth just trying to get it started

 

Edited by darkfire123
fixing a mistake
Link to comment
Share on other sites

11 minutes ago, darkfire123 said:

should i merge the two event together ??

You can't do this.

 

11 minutes ago, darkfire123 said:

can i call my onRenderGameOverlayEvent with-in onEntityDeath

No.

11 minutes ago, darkfire123 said:

right now im not looking for the most efficient way to run the Gui and so forth just trying to get it started

Cool.

12 minutes ago, darkfire123 said:

currently i have a class  DFMEventHandler which Add the Event onEntityDeath to the event buss (it is regiter in my main class...

Create a capability attach it to the player and it needs to contain at least an int for a timer. You will set the timer to the amount of ticks that you want the overlay to be rendered when the player kills an entity. And in the overlay event render it as long as the timer value is greater than 0. And in a client tick event decrement the timer variable in the client player. You may need to send a packet to the client when you detect that the player has killed an entity(not sure if it fires on both client and server).

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

I'm confused. Why can't you use the already available LivingDeathEvent? I think it is fired on both sides, but if not just send a packet to the client. In any case, as mentioned you can then start a timer for how long you want it displayed on the client. I personally would just do it as a static int field in a ClientTickEvent handler. 

 

However, you can also consider making the message use an existing temporary GUI like a toast message.

 

Furthermore, your GUI doesn't have to pause the game -- that is just a setting in the GUI. Most GUIs do not actually pause the game.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.