Jump to content

[SOLVED] Refresh name tag?


Zer0HD2

Recommended Posts

So I've created a levelling system where a user's level is displayed in their name. I have it working so that the user's display name is refreshed when they level up, but the name tag (above their head) does not refresh for other players. I'm assuming this has something to do with packets, but since I've not really worked with them much I was wondering if anyone could give me some pointers on how I need to do this?

Link to comment
Share on other sites

Still stuck on exactly how I would do this - as I said, this is the first time I've attempted anything that uses packet handling.

 

I tried sending the SyncPlayerPropsPacket to all players in the code I posted here (Changed the sendTo() to sentToAll()), but that had no effect.

Link to comment
Share on other sites

Thanks for that, I've changed most of the things you pointed out, but I'm unsure on one thing. What is an alternative to using the dataWatcher? Or, if that's not what you meant, what should I read the dataWatcher from? I haven't been able to find out much about it, so I only know the basics of how it works.

 

I'll update the code on Github once I've tested the nametag updating.

Link to comment
Share on other sites

Updated github with new code. Still using dataWatcher for now, and sending update packets to nearby players broke ALL the things, so I've removed that for now. Right now it just uses a nicer packet handling method than the horrific one I was using before.

 

I'm still not entirely sure, once I've sent the packet to nearby players telling them your level, how it is used in the nametag. Also tried to find where Minecraft renders the nametag above the player, failed miserably.

Link to comment
Share on other sites

Alright, so I have a packet which sends the entityId of the player and their level, but what exactly do you mean by updating the player properties? Sorry for all the questions, this is the only thing I don't quite understand ._.

Link to comment
Share on other sites

Yep, I've got the player from the ID, I'm just not sure where to go from here:

 

Packet:

 

public class LevelSyncMP implements IMessage {

public int level, entityId;

public LevelSyncMP() {}

public LevelSyncMP(int level, int entityId)
{
	this.level = level;
	this.entityId = entityId;
}

@Override
public void fromBytes(ByteBuf buf) 
{
	this.level = buf.readInt();
	this.entityId = buf.readInt();
}

@Override
public void toBytes(ByteBuf buf) 
{
	buf.writeInt(level);
	buf.writeInt(entityId);
}

}

 

MessageHandler:

 

public class LevelSyncHandlerMP implements IMessageHandler<LevelSyncMP, IMessage> {

private World world = Minecraft.getMinecraft().theWorld;
private int entityId, level;
private EntityPlayer player;
private String username;

@Override
public IMessage onMessage(LevelSyncMP message, MessageContext ctx) {
	this.level = message.level;
	this.entityId = message.entityId;
	this.player = (EntityPlayer)world.getEntityByID(this.entityId);
	this.username = this.player.getCommandSenderName();

	return null;
}

}

Link to comment
Share on other sites

Alright, so far my MessageHandler looks like this:

 

public class LevelSyncHandlerMP implements IMessageHandler<LevelSyncMP, IMessage> {

private World world = Minecraft.getMinecraft().theWorld;
private EntityPlayer player;


@Override
public IMessage onMessage(LevelSyncMP message, MessageContext ctx) {
	this.player = (EntityPlayer)world.getEntityByID(message.entityId);
	ExtendedPlayerProperties properties = ExtendedPlayerProperties.fetchProperties(player);

	return null;
}

}

 

Are you saying that I should set the level of the player who's ID I sent in the packet to the value that I sent? Because that seems sort of pointless. If not, sorry, I've been at work all day so I can't brain right now.

Link to comment
Share on other sites

Been working on this for a while, and any server I test it on now crashes with the following error:

 

 

 

Description: Exception in server tick loop

 

cpw.mods.fml.common.LoaderException: java.lang.NoClassDefFoundError: net/minecraft/client/multiplayer/WorldClient

at cpw.mods.fml.common.LoadController.transition(LoadController.java:162)

at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:511)

at cpw.mods.fml.server.FMLServerHandler.beginServerLoading(FMLServerHandler.java:88)

at cpw.mods.fml.common.FMLCommonHandler.onServerStart(FMLCommonHandler.java:313)

at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:114)

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:374)

at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:669)

Caused by: java.lang.NoClassDefFoundError: net/minecraft/client/multiplayer/WorldClient

at java.lang.Class.getDeclaredConstructors0(Native Method)

at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)

at java.lang.Class.getConstructor0(Unknown Source)

at java.lang.Class.newInstance(Unknown Source)

at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.<init>(SimpleChannelHandlerWrapper.java:21)

at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.getHandlerWrapper(SimpleNetworkWrapper.java:129)

at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.addClientHandlerAfter(SimpleNetworkWrapper.java:123)

at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.registerMessage(SimpleNetworkWrapper.java:111)

at com.zer0.hardcore.MCHardcore.preInit(MCHardcore.java:65)

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 cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:513)

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 com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)

at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)

at com.google.common.eventbus.EventBus.post(EventBus.java:267)

at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:208)

at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:187)

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 com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)

at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)

at com.google.common.eventbus.EventBus.post(EventBus.java:267)

at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:118)

at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:510)

... 5 more

Caused by: java.lang.ClassNotFoundException: net.minecraft.client.multiplayer.WorldClient

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:188)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

... 41 more

Caused by: java.lang.RuntimeException: Attempted to load class biz for invalid side SERVER

at cpw.mods.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:50)

at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:276)

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:174)

... 43 more

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- System Details --

Details:

Minecraft Version: 1.7.2

Operating System: Windows 8.1 (x86) version 6.3

Java Version: 1.7.0_55, Oracle Corporation

Java VM Version: Java HotSpot Client VM (mixed mode), Oracle Corporation

Memory: 23826232 bytes (22 MB) / 72310784 bytes (68 MB) up to 1037959168 bytes (989 MB)

JVM Flags: 1 total; -Xmx1024M

AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used

IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0

FML: MCP v9.03 FML v7.2.196.1082 Minecraft Forge 10.12.1.1082 4 mods loaded, 4 mods active

mcp{9.03} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized

FML{7.2.196.1082} [Forge Mod Loader] (mcfs.jar) Unloaded->Constructed->Pre-initialized

Forge{10.12.1.1082} [Minecraft Forge] (mcfs.jar) Unloaded->Constructed->Pre-initialized

mchardcore{1.1.9.4} [Minecraft Hardcore] (MCHardcore-1.7.2-1.1.9.4_PACKET.TEST_3.jar) Unloaded->Constructed->Errored

Profiler Position: N/A (disabled)

Is Modded: Definitely; Server brand changed to 'fml,forge'

Type: Dedicated Server (map_server.txt)

 

 

 

Line 65 is me registering the sync packet:

 

network.registerMessage(LevelSyncHandlerMP.class, LevelSyncMP.class, 1, Side.CLIENT);

 

Message: https://gist.github.com/Zer0HD/f0e535ca03f5201d1d9b

Handler: https://gist.github.com/Zer0HD/60aeb41dac86357dad44

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.