Jump to content

[1.10.2] [SOLVED] Problems with Player's Display name


Tschipp

Recommended Posts

I'm trying to make a Command that changes the Player's Display Name. It stores that name in the player's NBT.

When I use the command it sort of works, it only changes my name in chat and in death messages. When trying on a LAN world the display name is still Player...

I'm not sure why this is happening. I copy the data from the dead player to the new one fine, that can't be the problem. I also try refreshing the name using player.refreshDisplayName() but that doesn't seem to do anything. I've also tried manually firing the event, no luck there.

 

EDIT: I did some work and also added a Packet. I have little experience with packets so I'm probably doing something completely wrong, please don't blame me. In any case, whatever I did didn't seem to fix anything.

 

This is my main Class (My events are at the bottom):

package tschipp.fakename;

import tschipp.creativePlus.network.NoisePacket;
import tschipp.creativePlus.network.NoisePacketHandler;
import tschipp.creativePlus.network.RadiusPacket;
import tschipp.creativePlus.network.RadiusPacketHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerEvent;
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.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side;


@Mod(modid = "fakename", name = "Fake Name", version = "1.0")

public class FakeName {

@Instance(value = "fakename")
public static FakeName instance;

public static SimpleNetworkWrapper network;


@EventHandler
public void preInit(FMLPreInitializationEvent event) {

	network = NetworkRegistry.INSTANCE.newSimpleChannel("FakeNameChannel");

	network.registerMessage(FakeNamePacketHandler.class, FakeNamePacket.class, 0, Side.SERVER);

}



@EventHandler
public void init(FMLInitializationEvent event) {
	MinecraftForge.EVENT_BUS.register(this);	
}



@EventHandler
public void postInit(FMLPostInitializationEvent event) {


}



@EventHandler
public void serverLoad(FMLServerStartingEvent event)
{
	event.registerServerCommand(new CommandFakeName());

}



/*@SubscribeEvent
public void onChat(ServerChatEvent event) {
	EntityPlayerMP player = event.getPlayer();
	NBTTagCompound tag = player.getEntityData();
	String username = event.getUsername();
	String message = event.getMessage();
	String component = event.getComponent().getFormattedText();
	if(tag.hasKey("fakename") && !tag.hasKey("oldfakename")) {
		event.setComponent(new TextComponentString(event.getComponent().getUnformattedText().replace(username, tag.getString("fakename"))));
	}
	if(tag.hasKey("fakename") && tag.hasKey("oldfakename")) {
		event.setComponent(new TextComponentString(event.getComponent().getUnformattedText().replace(tag.getString("oldfakename"), tag.getString("fakename"))));
	}
	System.out.println(tag);

} */

@SubscribeEvent
public void renderName(PlayerEvent.NameFormat event) {
	NBTTagCompound tag = event.getEntityLiving().getEntityData();
	if(tag.hasKey("fakename")) {
		event.setDisplayname(tag.getString("fakename"));
		event.setDisplayname(tag.getString("fakename"));
	}
	else 
	{
		event.setDisplayname(event.getUsername());
	}


}  

//Makes Sure that the Data persists on Death
@SubscribeEvent
public void onClone(PlayerEvent.Clone event) 
{
	EntityPlayer oldPlayer = event.getOriginal();
	EntityPlayer newPlayer = event.getEntityPlayer();

	if(oldPlayer.getEntityData().hasKey("fakename")) 
	{
		String fakename = oldPlayer.getEntityData().getString("fakename");
		newPlayer.getEntityData().setString("fakename", fakename);
		PlayerEvent.NameFormat event2 = new PlayerEvent.NameFormat(newPlayer, fakename);
		MinecraftForge.EVENT_BUS.post(event2);
	}





}


}

 

This is my Command Class:

package tschipp.fakename;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerEvent;

public class CommandFakeName extends CommandBase implements ICommand {

private final List names;

public CommandFakeName()
{
	names = new ArrayList();
	names.add("fakename");
	names.add("fn");
}

@Override
public int compareTo(ICommand o)
{

	return 0;
}

@Override
public String getCommandName()
{

	return "fakename";
}

@Override
public String getCommandUsage(ICommandSender sender)
{

	return "/fakename <mode> <args...>";
}

public String getCommandUsageReal()
{
	return "/fakename real <fakename> ";
}

public String getCommandUsageClear()
{
	return "/fakename clear <player>";
}

public String getCommandUsageSet()
{
	return "/fakename set <player> <fakename> OR /fakename set <fakename>";
}

@Override
public List<String> getCommandAliases()
{

	return this.names;
}

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
	if(args.length > 0)
	{
	if (args[0].toLowerCase().equals("set"))
	{
		// Handling set <Playername> <Fakename>
		if (args.length == 3)
		{
			String playername = args[1];
			String fakename = args[2];
			EntityPlayerMP player = CommandBase.getPlayer(server, sender, playername);
			NBTTagCompound tag = player.getEntityData();
			fakename = fakename.replace("&", "§");
			tag.setString("fakename", fakename);
			if (sender.getCommandSenderEntity() != null && sender.getCommandSenderEntity() instanceof EntityPlayerMP && !playername.equals(((EntityPlayer) sender).getGameProfile().getName()))
			{
				sender.addChatMessage(new TextComponentString(playername + "'s name is now " + fakename));
			}
			player.addChatMessage(new TextComponentString("Your name is now " + fakename));
			FakeName.network.sendToAll(new FakeNamePacket(tag));
			player.refreshDisplayName();
		}
		// Handling set <Fakename>
		else if (args.length == 2)
		{
			String fakename = args[1];
			EntityPlayerMP player = CommandBase.getPlayer(server, sender, sender.getName());
			NBTTagCompound tag = player.getEntityData();
			fakename = fakename.replace("&", "§");
			tag.setString("fakename", fakename);
			player.addChatMessage(new TextComponentString("Your name is now " + fakename));
			FakeName.network.sendToAll(new FakeNamePacket(tag));
			player.refreshDisplayName();
		}

		else
		{
			throw new WrongUsageException(this.getCommandUsageSet());
		}

		// Handling real <Fakename>
	} else if (args[0].toLowerCase().equals("real"))
	{
		if (args.length == 2)
		{
			String fakename = args[1];
			String[] allNames = server.getAllUsernames();
			for (int i = 0; i < allNames.length; i++)
			{
				EntityPlayerMP testingPlayer = CommandBase.getPlayer(server, sender, allNames[i]);
				if (testingPlayer.getEntityData() != null && testingPlayer.getEntityData().hasKey("fakename"))
				{
					String fakeNamePlayer = testingPlayer.getEntityData().getString("fakename");
					String toRemove;
					while (fakeNamePlayer.contains("§"))
					{
						toRemove = fakeNamePlayer.substring((fakeNamePlayer.indexOf("§")), fakeNamePlayer.indexOf("§") + 2);
						fakeNamePlayer = fakeNamePlayer.replace(toRemove, "");
					}
					if(fakeNamePlayer.toLowerCase().equals(fakename.toLowerCase()))
					{
						sender.addChatMessage(new TextComponentString(fakeNamePlayer + "'s real name is " + testingPlayer.getGameProfile().getName()));
						return;
					}
				}

				if (i == allNames.length - 1)
				{
					sender.addChatMessage(new TextComponentString(TextFormatting.RED + "There is no Player with the Fake Name '" + fakename + "'"));
				}
			}

		} else
		{
			throw new WrongUsageException(this.getCommandUsageReal());
		}

	}
	//Handling clear <playername>
	else if (args[0].toLowerCase().equals("clear"))
	{
		if (args.length == 2)
		{
			String playername = args[1];
			EntityPlayerMP player = CommandBase.getPlayer(server, sender, playername);
			if(player.getEntityData() != null && player.getEntityData().hasKey("fakename"))
			{
				player.getEntityData().removeTag("fakename");
				sender.addChatMessage(new TextComponentString(playername+"'s Fake Name was removed"));
				player.refreshDisplayName();
			}
			else
			{
				sender.addChatMessage(new TextComponentString(TextFormatting.RED + "The provided Player does not have a Fake Name"));
			}
		}
		else
		{
			throw new WrongUsageException(this.getCommandUsageClear());
		}

	}

	}
	else
	{
		throw new WrongUsageException(this.getCommandUsage(sender));
	}

}

@Override
public boolean checkPermission(MinecraftServer server, ICommandSender sender)
{

	return true;
}

@Override
public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos)
{

	if (args.length > 0)
	{
		if (args.length == 1)
		{
			return CommandBase.getListOfStringsMatchingLastWord(args, "set", "real", "clear");
		}

		if (args.length == 2 && (args[0].equals("set") || args[0].equals("clear")))
		{
			return CommandBase.getListOfStringsMatchingLastWord(args, server.getAllUsernames());
		}

		else
		{
			return Collections.<String>emptyList();
		}

	}

	return Collections.<String>emptyList();

}

@Override
public boolean isUsernameIndex(String[] args, int index)
{

	return false;
}

@Override
public int getRequiredPermissionLevel()
{
	return 4;
}

}

 

Packet:

package tschipp.fakename;

import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;

public class FakeNamePacket implements IMessage {

public NBTTagCompound tag;

public FakeNamePacket() {

}

public FakeNamePacket(NBTTagCompound tag) {
	this.tag = tag;
}

@Override
public void fromBytes(ByteBuf buf) {
	this.tag = ByteBufUtils.readTag(buf);
}

@Override
public void toBytes(ByteBuf buf) {
	ByteBufUtils.writeTag(buf, this.tag);
}

}

 

Packet Handler:

package tschipp.fakename;

import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IThreadListener;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import tschipp.creativePlus.items.CustomItems;
import tschipp.creativePlus.network.NoisePacket;

public class FakeNamePacketHandler implements IMessageHandler<FakeNamePacket, IMessage>{

@Override
public IMessage onMessage(final FakeNamePacket message, final MessageContext ctx) {
	IThreadListener mainThread = (WorldServer)ctx.getServerHandler().playerEntity.worldObj;

	mainThread.addScheduledTask(new Runnable(){
		EntityPlayerMP player = ctx.getServerHandler().playerEntity;


		@Override
		public void run() {

			NBTTagCompound tag = message.tag;
			NBTTagCompound playerTag = player.getEntityData();
			playerTag.setString("fakename", tag.getString("fakename"));

		} 


	});

	return null;
}



}


 

This is all my code. There is no more.

 

 

 

Link to comment
Share on other sites

You send a custom packet to them and set the display name client side as well.

I can try that when I get home...

The weird thing is... when I just set the displaname by typing event.setDisplayname("TestName") in the NameFormat event, it seems to display fine...

Link to comment
Share on other sites

Apparently like this:

PlayerEvent.NameFormat event = new PlayerEvent.NameFormat(player, fakename);
MinecraftForge.EVENT_BUS.post(event);

 

That is not even close to the same thing.

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

Because I edited the main post.

 

And we'd know that from reading a post that says, "Bump" how?

Also, don't do that.  Just post the new problem with the updated code rather than saying "bump."

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

@Override

public int compareTo(ICommand o)

{

 

return 0;

}

Why? :o This breaks the
Comparable

interface contract and will crash servers under some circumstances.

 

What does this method do? What should I change it into?

Thanks for being very detailed in your post. I think I figured out how to do the packets, I just need to handle some more Events.

 

What does

Link to comment
Share on other sites

What does this method do? What should I change it into?

Thanks for being very detailed in your post. I think I figured out how to do the packets, I just need to handle some more Events.

 

Try looking at some other commands.

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

Right now I'm not sure when I should send the packet... I obviously send it when a player executes the command, but the problem there is that if the player rejoins the server, all the names for the other players will be lost for him. The other players do see the player's fake name though, as I send the packet also when a player joins the world. I originally wanted to send the packet when a player is rendered, but the RenderLivingEvent doesn't seem to be for that purpose, as I cannot detect if the player has any data stored on him. I now send it during LivingUpdateEvent, is that a bad idea performance wise? I'm not sure how the packets affect the performance. This is my packet at its current state. Is that any better, or am I still doing everything wrong?

 

Packet:

package tschipp.fakename;

import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;

public class FakeNamePacket implements IMessage {

public String fakename;
public int entityId;

public FakeNamePacket() {

}

public FakeNamePacket(String fakename, int entityID) {
	this.fakename = fakename;
	this.entityId = entityID;
}

@Override
public void fromBytes(ByteBuf buf) {
	this.fakename = ByteBufUtils.readUTF8String(buf);
	this.entityId = ByteBufUtils.readVarInt(buf, 4);
}

@Override
public void toBytes(ByteBuf buf) {
	ByteBufUtils.writeUTF8String(buf, this.fakename);
	ByteBufUtils.writeVarInt(buf, this.entityId, 4);
}

}

 

Packet Handler:

package tschipp.fakename;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IThreadListener;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import tschipp.creativePlus.items.CustomItems;
import tschipp.creativePlus.network.NoisePacket;

public class FakeNamePacketHandler implements IMessageHandler<FakeNamePacket, IMessage>{

@Override
public IMessage onMessage(final FakeNamePacket message, final MessageContext ctx) {


	EntityPlayer player = (ctx.side.isClient() ? Minecraft.getMinecraft().thePlayer : ctx.getServerHandler().playerEntity);

	EntityPlayer toSync = (EntityPlayer) player.worldObj.getEntityByID(message.entityId);
	if(toSync != null)
	{
		NBTTagCompound tag = toSync.getEntityData();
		tag.setString("fakename", message.fakename);
		toSync.refreshDisplayName();

	}
	return null;
}



}


 

Event:

@SubscribeEvent
public void onLivingUpdate(LivingUpdateEvent event)
{
	if(event.getEntity() instanceof EntityPlayer)
	{
		EntityPlayer player = (EntityPlayer) event.getEntity();
		if(player.getEntityData() != null && player.getEntityData().hasKey("fakename"))
		{
			FakeName.network.sendToAll(new FakeNamePacket(player.getEntityData().getString("fakename") , player.getEntityId()));
		}
	}
}

Link to comment
Share on other sites

Thanks for the feedback. How exactly do I get the player from my proxy?

And about the EntityID int: Why will it sometimes crash and what can I do against that? Should I not even send the EntityID?

 

Also, I added this event. It seems to work for the player hosting the lan world, players with a name get displayed correctly, but the joining player doesn't see the host's name.

@SubscribeEvent
public void onTracking(PlayerEvent.StartTracking event)
{
	if(event.getTarget() instanceof EntityPlayer)
	{
		EntityPlayer targetPlayer = (EntityPlayer) event.getTarget();
		System.out.println("The Targeted Player is " + targetPlayer);
		if(targetPlayer.getEntityData() != null && targetPlayer.getEntityData().hasKey("fakename"))
		{
			EntityPlayerMP toRecieve = (EntityPlayerMP) event.getEntityPlayer();
			System.out.println("The Recieving Player is " + toRecieve);

			FakeName.network.sendTo(new FakeNamePacket(targetPlayer.getEntityData().getString("fakename") , targetPlayer.getEntityId()), toRecieve);
		}
	}
} 

Link to comment
Share on other sites

I added this event:

@SubscribeEvent
public void onJoinWorld(net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent event) 
{
	EntityPlayer player = event.player;
	if(!player.worldObj.isRemote)
	{
		WorldServer serverWorld = (WorldServer) event.player.worldObj;
		Iterator<? extends EntityPlayer> playersTracking = serverWorld.getEntityTracker().getTrackingPlayers(player).iterator();
		if(player.getEntityData() != null && player.getEntityData().hasKey("fakename"))
		{
			while(playersTracking.hasNext())
			{
				FakeName.network.sendTo(new FakeNamePacket(player.getEntityData().getString("fakename") , player.getEntityId()), (EntityPlayerMP) playersTracking.next());
			}
		}
	}
}  

 

 

Packet Handler:

package tschipp.fakename;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IThreadListener;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import tschipp.creativePlus.items.CustomItems;
import tschipp.creativePlus.network.NoisePacket;

public class FakeNamePacketHandler implements IMessageHandler<FakeNamePacket, IMessage>{

@Override
public IMessage onMessage(final FakeNamePacket message, final MessageContext ctx) {



	EntityPlayer toSync = (EntityPlayer)FakeName.clientProxy.getClientWorld().getEntityByID(message.entityId);
	if(toSync != null)
	{
		NBTTagCompound tag = toSync.getEntityData();
		tag.setString("fakename", message.fakename);
		toSync.refreshDisplayName();

	}
	return null;
}



}


 

It still isn't working. What am I missing here?

Link to comment
Share on other sites

One thing, a little bit of topic, but you shouldn't use §, use TextFormatting.*

I don't really. I only use it internally for the player's name, and it's just easier to replace the '&' with a '§' than having to replace them all with some huge piece of code...

Link to comment
Share on other sites

Well, try that first then before I go through the trouble of debugging it on my machine...

Well, apparently that really was all it took O.o

It works fine now! Thank you so much!

I added the working version to github, in case I still find a bug...

Link to comment
Share on other sites

Welp, here I am again.

I found out the mod crashes servers instantly...  ::)

I'm pretty sure it's because of this here in my main mod class:

@SidedProxy(clientSide = CLIENT_PROXY, serverSide = COMMON_PROXY)
public static ClientProxy clientProxy;

 

In any case,here is the log: http://pastebin.com/xvTbWXQN

I have since removed it, but now there's an error in my PacketHandler class:

				EntityPlayer toSync = (EntityPlayer)FakeName.[color=red]clientProxy[/color].getClientWorld().getEntityByID(message.entityId);

 

So I changed it to this:

				EntityPlayer toSync = (EntityPlayer)FakeName.proxy.getClientWorld().getEntityByID(message.entityId);

 

but now it's erroring at getClientWorld(), because that is a method in my ClientProxy class.

Here it is:

package tschipp.fakename;

import net.minecraft.client.Minecraft;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

public class ClientProxy extends CommonProxy {

public void preInit(FMLPreInitializationEvent event) {

	super.preInit(event);



	}

	public void init(FMLInitializationEvent event) {

		super.init(event);

	}

	public void postInit(FMLPostInitializationEvent event) {

		super.postInit(event);

	}


	public World getClientWorld() 
	{
		return Minecraft.getMinecraft().theWorld;
	}

}


 

The problem now is, how do I get access to the getClientWorld method from my PacketHandler class?

Link to comment
Share on other sites

I'm pretty sure it's because of this here in my main mod class:

@SidedProxy(clientSide = CLIENT_PROXY, serverSide = COMMON_PROXY)
public static ClientProxy clientProxy;

 

Attempted to load a proxy type tschipp.fakename.CommonProxy into tschipp.fakename.FakeName.clientProxy, but the types don't match

 

You have to type your proxy as being a CommonProxy.

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/ores/OresBase.java#L88

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

You still can't do this:

@SidedProxy(clientSide = CLIENT_PROXY, serverSide = COMMON_PROXY)
public static ClientProxy clientProxy;

Because it will still try to load the common proxy into the variable which can only hold a client proxy.

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

Of course it does, I bet it's now crashing with a NullPointerException.

 

My question is, why do you have two proxy variables?

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

Of course it does, I bet it's now crashing with a NullPointerException.

 

My question is, why do you have two proxy variables?

Because I didn't know how else to access the getClientWorld() method from my client proxy.

How do I get the client proxy from my proxy variable?

Link to comment
Share on other sites

MainMod.proxy.getClientWorld();

 

This method will be in BOTH proxy classes.  That's the whole point of a proxy.  Look at all these deliciously empty methods that actually do something.

 

Your common proxy will return null.  Your client proxy will then do what it needs to.

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

    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
  • Topics

×
×
  • Create New...

Important Information

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