Jump to content

Recommended Posts

Posted

Hi there, I'm Jake :). I'm pretty new to Forge Modding, although I've been coding in bukkit for several years. Anyway attempting a project I've run into a few issues. :(

 

Heres my code:

 

TabList.java

[embed=425,349]package com.jakenelson19.tablist;

 

import net.minecraftforge.fml.common.FMLCommonHandler;

import net.minecraftforge.fml.common.Mod;

import net.minecraftforge.fml.common.Mod.EventHandler;

import net.minecraftforge.fml.common.Mod.Instance;

import net.minecraftforge.fml.common.SidedProxy;

import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

 

@Mod(modid=Reference.MOD_ID, name=Reference.MOD_NAME, version=Reference.VERSION)

public class TabList {

 

@Instance(Reference.MOD_ID)

public static TabList instance;

 

 

@EventHandler

public void preInit(FMLPreInitializationEvent event)  {

 

        FMLCommonHandler.instance().bus().register(new DeathHandler());

       

        System.out.println("Event Handler Initialized");

 

}

 

@EventHandler

public void load(FMLInitializationEvent event)  {}

 

@EventHandler

public void postInit(FMLPostInitializationEvent event)  {}

 

}

[/embed]

 

DeathHandler.java

[embed=425,349]package com.jakenelson19.tablist;

 

import net.minecraft.client.Minecraft;

import net.minecraft.util.ResourceLocation;

import net.minecraft.util.text.ITextComponent;

import net.minecraft.util.text.TextComponentString;

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import net.minecraftforge.fml.common.gameevent.PlayerEvent;

 

public class DeathHandler {

 

    @SubscribeEvent

    public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) {

 

    //event.player.addChatMessage(new TextComponentString(event.player.getDisplayName() + " is testing chat messages"));

    event.player.addChatMessage(new TextComponentString("testing chat messages"));

    ResourceLocation text = Minecraft.getMinecraft().ingameGUI.getTabList().ICONS;

    event.player.addChatMessage(new TextComponentString(""+text));

    }

   

    @SubscribeEvent

    public void onPlayerLogin(PlayerEvent.PlayerRespawnEvent event) {

 

    //event.player.addChatMessage(new TextComponentString(event.player.getDisplayName() + " is testing chat messages"));

    event.player.addChatMessage(new TextComponentString("testing chat messages"));

    ResourceLocation text = Minecraft.getMinecraft().ingameGUI.getTabList().ICONS;

    event.player.addChatMessage(new TextComponentString(""+text));

    }

   

}[/embed]

 

Issues:

 

 

1) I want the mod to run client side only, so that i can connect to normal servers and have it running. Currently the mods don't work on normal servers :(

 

2) The main thing i'm trying to achieve is to take all the users in the tablist, and put them into a java hashmap / array

 

I'd greatly appreciate this help as I've been stuck here for ages.

 

Thanks!

Posted

2) The main thing i'm trying to achieve is to take all the users in the tablist, and put them into a java hashmap / array

 

You can fetch an array of all the player's usernames via the PlayerList like so:

 

FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getAllUsernames()

.

Posted

2) The main thing i'm trying to achieve is to take all the users in the tablist, and put them into a java hashmap / array

 

You can fetch an array of all the player's usernames via the PlayerList like so:

 

FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getAllUsernames()

.

He wants it to be client side only...

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.

Posted

You should look at how

GuiPlayerTabOverlay#renderPlayerlist

retrieves the data that it renders.

 

In future, please use [nobbc]


[/nobbc] tags when posting code.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Sorry im a bit of a noob how would that work  :-X

 

Open the

GuiPlayerTabOverlay

class and navigate to the

renderPlayerlist

method. The first two lines retrieve the

List<NetworkPlayerInfo>

used to render the overlay.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Sorry im a bit of a noob how would that work  :-X

 

Open the

GuiPlayerTabOverlay

class and navigate to the

renderPlayerlist

method. The first two lines retrieve the

List<NetworkPlayerInfo>

used to render the overlay.

 

Thanks a lot  ;D, I think i can work with that. The only problem I have now is how do I make the mod client side?

 

(Allowing it to access Bukkit/Spigot/vanilla servers while running the mod).

Posted

The only problem I have now is how do I make the mod client side?

 

(Allowing it to access Bukkit/Spigot/vanilla servers while running the mod).

 

In your

@Mod

annotation, set

clientSideOnly

to

true

so it's only loaded by the client and set

acceptableRemoteVersions

to

"*"

so any remote version (including none) is accepted.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • 2 months later...
Posted

Thanks a lot Choonster!

 

This is the code I wrote from Choonster's answer if anyone needs it

 

Collection<NetworkPlayerInfo> InfoMap = Minecraft.getMinecraft().getConnection().getPlayerInfoMap();


	for (final NetworkPlayerInfo networkplayerinfo : InfoMap) {
		System.out.println(networkplayerinfo.getGameProfile().getName())
	}

 

It logs all currently online players usernames.

 

 

 

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.