Jump to content

[1.12] Modify the 'player list'


Toinou9120

Recommended Posts

Hello,

I'm making a client-sided mod where I need to write some infos about a player in the player list, like the level of the player ect.

But I don't know how to modify the content of the player list. I looked in the RenderGameOverlayEvent class and thought about reflection but I don't know what I should get and modify in this class. Can someone help me ? 

Link to comment
Share on other sites

Thank for your answer.

When I meant level, I didn't mean xp level, I mean a server minigame level, that I get from a statistics website.

When you say "draw", are you talking about the draw fonction in OpenGL ?

And another question, I need to draw the level of the player after his name in the player liste, so how do I get the actual content of the player list to know where to draw the level of the player ?

Link to comment
Share on other sites

Thank for your really complete answer,

I'm not a native english speaker so I have some difficulties to understand the step.

What i have understand is that :

 

- I must create a class that extends GuiPlayerTabOverlay and override the getPlayerName method so I can modify what it return

- Then I should get an instance of the GuiIngame

 

But after, I can't grab the overlayPlayerList beacause it's protected, so I don't understand how to do this. Can you explain ?

I'm sorry if it's simple and I just have a lack of vocabulary to understand what you said.

Edited by Toinou9120
mistake
Link to comment
Share on other sites

So I tried to do this, but it does not work. I think there are errors in my code.

 

This is my TabOverlay class :

 

public class TabOverlay extends GuiPlayerTabOverlay {

	public TabOverlay(Minecraft mcIn, GuiIngame guiIngameIn) {
		super(mcIn, guiIngameIn);
	}
	
	GuiPlayerTabOverlay gui;
	
	 /**
     * Returns the name that should be renderd for the player supplied
     */
	@Override
    public String getPlayerName(NetworkPlayerInfo networkPlayerInfoIn)
    {	
		return gui.getPlayerName(networkPlayerInfoIn) + "a";
    }
}

 

And this is my EventHandler class where I handle the TickEvent :

 

@SubscribeEvent
public void onTickEvent(TickEvent.ClientTickEvent e) {
    	
    if(e.phase == Phase.START) {
    		
    	TabOverlay tab = new TabOverlay(Minecraft.getMinecraft(), Minecraft.getMinecraft().ingameGUI);
    		
    	try {
				
    		Field overlay = GuiIngame.class.getDeclaredField("overlayPlayerList");
			overlay.setAccessible(true);
			overlay.set(Minecraft.getMinecraft().ingameGUI, tab);
				
				
		} catch (NoSuchFieldException | SecurityException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IllegalArgumentException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IllegalAccessException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
    }	
}

 

There is a layout problem with the code integration, but I don't know why.

I rarely use reflection so maybe I don't use it correctly or maybe this is the TabOverlay class that is false.

Can you help me ?

Edited by Toinou9120
Mistakes
Link to comment
Share on other sites

Use the ReflectionHelper class instead of doing it yourself. When built and released, the field will not be called "overlayPlayerList" but something like field_89034_b

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

So I used the ReflectionHelper class, so this is my new EventHandler class :

@SubscribeEvent
	public void onTickEvent(TickEvent.ClientTickEvent e) {
    	
    	if(e.phase == Phase.START) {
    		
    		TabOverlay tab = new TabOverlay(Minecraft.getMinecraft(), Minecraft.getMinecraft().ingameGUI);
    		
    		try {
				
    			ReflectionHelper ref = new ReflectionHelper();
    			
    			ref.setPrivateValue(GuiIngame.class, Minecraft.getMinecraft().ingameGUI, tab, "field_175196_v");
				
				
			} catch (SecurityException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (IllegalArgumentException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
    	}	
    }

 

But it throws a NoSuchFieldException, this is the crash report :

 

net.minecraftforge.fml.relauncher.ReflectionHelper$UnableToAccessFieldException: net.minecraftforge.fml.relauncher.ReflectionHelper$UnableToFindFieldException: java.lang.NoSuchFieldException: field_175196_v
	at net.minecraftforge.fml.relauncher.ReflectionHelper.setPrivateValue(ReflectionHelper.java:170)
	at com.example.examplemod.Event.onTickEvent(Event.java:32)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_9_Event_onTickEvent_ClientTickEvent.invoke(.dynamic)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179)
	at net.minecraftforge.fml.common.FMLCommonHandler.onPreClientTick(FMLCommonHandler.java:342)
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1815)
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1171)
	at net.minecraft.client.Minecraft.run(Minecraft.java:436)
	at net.minecraft.client.main.Main.main(Main.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:26)
Caused by: net.minecraftforge.fml.relauncher.ReflectionHelper$UnableToFindFieldException: java.lang.NoSuchFieldException: field_175196_v
	at net.minecraftforge.fml.relauncher.ReflectionHelper.findField(ReflectionHelper.java:117)
	at net.minecraftforge.fml.relauncher.ReflectionHelper.setPrivateValue(ReflectionHelper.java:166)
	... 21 more
Caused by: java.lang.NoSuchFieldException: field_175196_v
	at java.lang.Class.getDeclaredField(Unknown Source)
	at net.minecraftforge.fml.relauncher.ReflectionHelper.findField(ReflectionHelper.java:108)
	... 22 more

Do you know what is the issue ?

Link to comment
Share on other sites

java.lang.NoSuchFieldException: field_175196_v

You need to pass in both names.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I am not using hardcoded recipes, I'm using Vanilla's already existing code for leather armor dying. (via extending and implementing DyeableArmorItem / DyeableLeatherItem respectively) I have actually figured out that it's something to do with registering item colors to the ItemColors instance, but I'm trying to figure out where exactly in my mod's code I would be placing a call to the required event handler. Unfortunately the tutorial is criminally undescriptive. The most I've found is that it has to be done during client initialization. I'm currently trying to do the necessary setup via hijacking the item registry since trying to modify the item classes directly (via using SubscribeEvent in the item's constructor didn't work. Class so far: // mrrp mrow - mcmod item painter v1.0 - catzrule ch package catzadvitems.init; import net.minecraft.client.color.item.ItemColors; import net.minecraft.world.item.Item; import net.minecraftforge.registries.ObjectHolder; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.client.event.ColorHandlerEvent; import catzadvitems.item.DyeableWoolArmorItem; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public class Painter { @ObjectHolder("cai:dyeable_wool_chestplate") public static final Item W_CHEST = null; @ObjectHolder("cai:dyeable_wool_leggings") public static final Item W_LEGS = null; @ObjectHolder("cai:dyeable_wool_boots") public static final Item W_SOCKS = null; public Painter() { // left blank, idk if forge throws a fit if constructors are missing, not taking the chance of it happening. } @SubscribeEvent public static void init(FMLClientSetupEvent event) { new Painter(); } @Mod.EventBusSubscriber private static class ForgeBusEvents { @SubscribeEvent public static void registerItemColors(ColorHandlerEvent.Item event) { ItemColors col = event.getItemColors(); col.register(DyeableUnderArmorItem::getItemDyedColor, W_CHEST, W_LEGS, W_SOCKS); //placeholder for other dye-able items here later.. } } } (for those wondering, i couldn't think of a creative wool helmet name)
    • nvm found out it was because i had create h and not f
    • Maybe there's something happening in the 'leather armor + dye' recipe itself that would be updating the held item texture?
    • @SubscribeEvent public static void onRenderPlayer(RenderPlayerEvent.Pre e) { e.setCanceled(true); model.renderToBuffer(e.getPoseStack(), pBuffer, e.getPackedLight(), 0f, 0f, 0f, 0f, 0f); //ToaPlayerRenderer.render(); } Since getting the render method from a separate class is proving to be bit of a brick wall for me (but seems to be the solution in older versions of minecraft/forge) I've decided to try and pursue using the renderToBuffer method directly from the model itself. I've tried this route before but can't figure out what variables to feed it for the vertexConsumer and still can't seem to figure it out; if this is even a path to pursue.  The vanilla model files do not include any form of render methods, and seem to be fully constructed from their layer definitions? Their renderer files seem to take their layers which are used by the render method in the vanilla MobRenderer class. But for modded entities we @Override this function and don't have to feed the method variables because of that? I assume that the render method in the extended renderer takes the layer definitions from the renderer classes which take those from the model files. Or maybe instead of trying to use a render method I should be calling the super from the renderer like   new ToaPlayerRenderer(context, false); Except I'm not sure what I would provide for context? There's a context method in the vanilla EntityRendererProvider class which doesn't look especially helpful. I've been trying something like <e.getEntity(), model<e.getEntity()>> since that generally seems to be what is provided to the renderers for context, but I don't know if it's THE context I'm looking for? Especially since the method being called doesn't want to take this or variations of this.   In short; I feel like I'm super super close but I have to be missing something obvious? Maybe this insane inane ramble post will provide some insight into this puzzle?
  • Topics

×
×
  • Create New...

Important Information

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