Jump to content

[solved] [1.12.2] getting offline player capability on different online client


Recommended Posts

Posted (edited)

First of all I have been modding for just over a year now, but this is my first post.  With that out of the way, on to the problem.

 

I have a gui that lists players that have joined in a team with you (the teams are saved in a world capability), and it displays their aura (saved as a capability on the player).  This works fine as long as every member of the team is on the server, however if there is a member of the team that is not on the server, opening this gui will cause a crash because the client can not find the player.

the current offending line of code (line 254 of Team Capability class)

this.world.getPlayerEntityByUUID(UUID.fromString(teamnbt.getString(teamkey)))

when the team capability is being deserialized from nbt (after being sent from the server to the client)

(world can be either a client world or server world)

 

so my main question is, can you get an EntityPlayer instance of an offline player on the client?  Can you get the data of an offline player on a client (similar to using player.dat on a server)?  Is there another way to display the capability data on the client of the offline player?

 

Team Capability class

Spoiler

package be.bluexin.rwbym.capabilities.team;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import be.bluexin.rwbym.utility.network.MessageConfirmRequest;
import be.bluexin.rwbym.utility.network.MessageDenyRequest;
import be.bluexin.rwbym.utility.network.MessageLeaveTeam;
import be.bluexin.rwbym.utility.network.MessageSendRequest;
import be.bluexin.rwbym.utility.network.RWBYNetworkHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;

public class Team implements ITeam {
	
	private List<List<EntityPlayer>> teams = new ArrayList<>();
	
	private List<Request> requests = new ArrayList<>();
	
	private World world;
	
	private boolean dirty = false;
	
	@Override
	public EntityPlayer[] getTeam(EntityPlayer player) {
		
		for (List<EntityPlayer> team : teams) {
			List<EntityPlayer> teamCopy = new ArrayList<>(team);
			if (teamCopy.removeIf(member -> member.equals(player))) {
				return teamCopy.toArray(new EntityPlayer[3]);
			}
		}
		
		return new EntityPlayer[3];
	}
	
	@Override
	public boolean hasRoom(EntityPlayer player) {
		
		for (List<EntityPlayer> team : teams) {
			if (team.contains(player)) {
				return team.size() < 4;
			}
		}
		
		return true;
		
	}
	
	@Override
	public boolean isSolo(EntityPlayer player) {
		return this.getTeamList(player).size() == 1;
	}
	
	@Override
	public List<Request> getSentRequests(EntityPlayer player) {
		
		List<Request> sent = new ArrayList<>();
		
		for (Request request : requests) {
			if (request.getSender().equals(player)) {
				sent.add(request);
			}
		}
		
		return sent;
		
	}
	
	@Override
	public List<Request> getReceivedRequests(EntityPlayer player) {
		
		List<Request> received = new ArrayList<>();
		
		for (Request request : requests) {
			if (request.getReceiver().equals(player)) {
				received.add(request);
			}
		}
		
		return received;
		
	}
	
	@Override
	public Request getRequest(EntityPlayer sender, EntityPlayer receiver) {
		
		for (Request request : requests) {
			
			if (request.getSender().equals(sender) && request.getReceiver().equals(receiver)) {
				return request;
			}
			
		}
		
		return null;
	}
	
	@Override
	public void sendRequest(String sender, String receiver) {
		this.sendRequest(world.getPlayerEntityByUUID(UUID.fromString(sender)), world.getPlayerEntityByUUID(UUID.fromString(receiver)));
	}
	
	@Override
	public void sendRequest(EntityPlayer sender, EntityPlayer receiver) {
		if (sender == null || receiver == null) {
			return ;
		}
		if (this.world.isRemote) {
			RWBYNetworkHandler.sendToServer(new MessageSendRequest(sender, receiver));
		}
		else {
			this.markDirty();
		}
		if (this.hasRoom(sender) && this.isSolo(receiver)) {
			this.requests.add(new Request(sender, receiver));
		}
	}
	
	@Override
	public void confirmRequest(String sender, String receiver) {
		this.confirmRequest(world.getPlayerEntityByUUID(UUID.fromString(sender)), world.getPlayerEntityByUUID(UUID.fromString(receiver)));
	}
	
	@Override
	public void confirmRequest(EntityPlayer sender, EntityPlayer receiver) {
		if (sender == null || receiver == null) {
			return ;
		}
		if (this.world.isRemote) {
			RWBYNetworkHandler.sendToServer(new MessageConfirmRequest(sender, receiver));
		}
		else {
			this.markDirty();
		}
		Request request = this.getRequest(sender, receiver);
		if (request != null && this.hasRoom(sender) && this.isSolo(receiver)) {
			List<EntityPlayer> team = this.getTeamList(sender);
			team.add(receiver);
			if (this.isSolo(sender)) {
				teams.add(team);
			}
			requests.remove(request);
		}
	}
	
	@Override
	public void denyRequest(String sender, String receiver) {
		this.denyRequest(world.getPlayerEntityByUUID(UUID.fromString(sender)), world.getPlayerEntityByUUID(UUID.fromString(receiver)));
	}
	
	@Override
	public void denyRequest(EntityPlayer sender, EntityPlayer receiver) {
		if (sender == null || receiver == null) {
			return ;
		}
		if (this.world.isRemote) {
			RWBYNetworkHandler.sendToServer(new MessageDenyRequest(sender, receiver));
		}
		else {
			this.markDirty();
		}
		Request request = this.getRequest(sender, receiver);
		if (request != null) {
			requests.remove(request);
		}
	}
	
	@Override
	public void leaveTeam(String player) {
		this.leaveTeam(world.getPlayerEntityByUUID(UUID.fromString(player)));
	}
	
	@Override
	public void leaveTeam(EntityPlayer player) {
		if (player == null) {
			return;
		}
		if (this.world.isRemote) {
			RWBYNetworkHandler.sendToServer(new MessageLeaveTeam(player));
		}
		else {
			this.markDirty();
		}
		this.getTeamList(player).remove(player);
		if (this.isSolo(player)) {
			List<EntityPlayer> team = this.getTeamList(player);
			this.teams.remove(team);
		}
	}
	
	@Override
	public void setWorld(World world) {
		this.world = world;
	}

	@Override
	public NBTTagCompound serialize() {
		
		requests.removeIf(request -> (request.getSender() == null || request.getReceiver() == null));
		teams.removeIf(team -> team.size() < 2);
		
		NBTTagCompound nbt = new NBTTagCompound();
		NBTTagCompound teamsnbt = new NBTTagCompound();
		NBTTagCompound requestsnbt = new NBTTagCompound();
		
		Integer i = 0;
		for (List<EntityPlayer> team : teams) {
			NBTTagCompound teamnbt = new NBTTagCompound();
			Integer j = 0;
			for (EntityPlayer player : team) {
				if (player != null) {
					teamnbt.setString(j.toString(), player.getCachedUniqueIdString());
				}
				j++;
			}
			teamsnbt.setTag(i.toString(), teamnbt);
			i++;
		}
		
		i = 0;
		for (Request request : requests) {
			requestsnbt.setString(i.toString() + "sender", request.getSender().getCachedUniqueIdString());
			requestsnbt.setString(i.toString() + "receiver", request.getReceiver().getCachedUniqueIdString());
			i++;
		}
		
		nbt.setTag("teams", teamsnbt);
		nbt.setTag("requests", requestsnbt);
		nbt.setInteger("requestSize", i);
		
		return nbt;
		
	}

	@Override
	public void deserialize(NBTTagCompound nbt) {
		
		teams.clear();
		requests.clear();
		
		NBTTagCompound teamsnbt = nbt.getCompoundTag("teams");
		NBTTagCompound requestsnbt = nbt.getCompoundTag("requests");
		
		for (String key : teamsnbt.getKeySet()) {
			
			NBTTagCompound teamnbt = teamsnbt.getCompoundTag(key);
			List<EntityPlayer> team = new ArrayList<>();
			
			for (String teamkey : teamnbt.getKeySet()) {
				team.add(this.world.getPlayerEntityByUUID(UUID.fromString(teamnbt.getString(teamkey))));
			}
			
			teams.add(team);
			
		}
		
		int i1 = nbt.getInteger("requestSize");
		
		for (Integer i = 0; i < i1; i++) {
			
			EntityPlayer sender = world.getPlayerEntityByUUID(UUID.fromString(requestsnbt.getString(i.toString() + "sender")));
			EntityPlayer receiver = world.getPlayerEntityByUUID(UUID.fromString(requestsnbt.getString(i.toString() + "receiver")));
			
			requests.add(new Request(sender, receiver));
			
		}
		
	}
	
	@Override
	public void markDirty() {
		this.dirty = true;
	}
	
	@Override
	public boolean isDirty() {
		boolean flag = this.dirty;
		this.dirty = false;
		return flag;
	}
	
	private List<EntityPlayer> getTeamList(EntityPlayer player) {
		
		for (List<EntityPlayer> team : teams) {
			if (team.contains(player)) {
				return team;
			}
		}
		
		List<EntityPlayer> team = new ArrayList<>(4);
		team.add(player);
		
		return team;
		
	}

}

 

 

Gui class

Spoiler



package be.bluexin.rwbym.gui.scroll;

import java.io.IOException;

import javax.annotation.Nullable;

import org.lwjgl.input.Keyboard;

import be.bluexin.rwbym.RWBYModels;
import be.bluexin.rwbym.capabilities.CapabilityHandler;
import be.bluexin.rwbym.capabilities.ISemblance;
import be.bluexin.rwbym.capabilities.Aura.AuraProvider;
import be.bluexin.rwbym.capabilities.Aura.IAura;
import be.bluexin.rwbym.capabilities.team.ITeam;
import be.bluexin.rwbym.capabilities.team.TeamProvider;
import be.bluexin.rwbym.gui.GuiButtonScroll;
import be.bluexin.rwbym.utility.network.MessageSendPlayerDataToServer;
import be.bluexin.rwbym.utility.network.MessagePlayerEXP;
import be.bluexin.rwbym.utility.network.RWBYNetworkHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiButtonImage;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiScreenBook;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

public class GuiScreenScrollTeam extends GuiScreen {

	private static final ResourceLocation SCROLL_GUI_TEXTURE = new ResourceLocation(RWBYModels.MODID, "textures/gui/scroll.png");

	private final int texturex = 128;
	private final int texturey = 210;
	
	private int x;
	private int y;

	private final int barx = 81;
	private final int bary = 9;

	private Minecraft mc;

	private EntityPlayer players[] = new EntityPlayer[4];

	private ItemStack heads[] = {ItemStack.EMPTY, ItemStack.EMPTY, ItemStack.EMPTY, ItemStack.EMPTY};
	
	private GuiButton leaveButton;

	public GuiScreenScrollTeam(EntityPlayer player) {
		
		this.addPlayer(player, 0);
		
		if (Minecraft.getMinecraft().world.hasCapability(TeamProvider.TEAM_CAP, null)) {
			
			ITeam team = Minecraft.getMinecraft().world.getCapability(TeamProvider.TEAM_CAP, null);
			int i = 1;
			for (EntityPlayer member : team.getTeam(player)) {
				this.addPlayer(member, i);
				i++;
			}
			
		}
		
	}

	@Override
	public void initGui() {
		super.initGui();
		
		x = (this.width - texturex) / 2;
		y = (this.height - 21 - texturey) / 2;
		
		this.mc = Minecraft.getMinecraft();

		this.allowUserInput = true;

		this.buttonList.clear();
		this.addButton(new GuiButtonScroll(0, x+2, y+2, 9, 9, 0, 227, 9, 9, 0, ""));
		this.addButton(new GuiButtonScroll(1, x+2 + 8, y+2, 9, 9, 8, 227, 9, 9, 0, ""));
		this.addButton(new GuiButtonScroll(2, x+2 + 16, y+2, 9, 9, 16, 227, 9, 9, 0, ""));
		this.addButton(new GuiButtonScroll(3, x+2 + 24, y+2, 9, 9, 24, 227, 9, 9, 0, ""));
		
		leaveButton = this.addButton(new GuiButtonScroll(4, x + (texturex - 70) / 2, y + 90, 70, 14, texturex, 0, 90, 14, 12, "Leave Team"));
		leaveButton.visible = false;

	}

	@Override
	public boolean doesGuiPauseGame() {
		return false;
	}

	@Override
	protected void actionPerformed(GuiButton button) throws IOException {
		
		if (button.id == 0) {
			Minecraft.getMinecraft().displayGuiScreen(new GuiScreenScrollTeam(this.players[0]));
		}
		else if (button.id == 2) {
			Minecraft.getMinecraft().displayGuiScreen(new GuiScreenScrollRequests(this.players[0]));
		}
		else if (button.id == 3) {
			Minecraft.getMinecraft().displayGuiScreen(new GuiScreenScrollLevel(this.players[0]));
		}
		else if (button.id == 4) {
			if (Minecraft.getMinecraft().world.hasCapability(TeamProvider.TEAM_CAP, null)) {
				Minecraft.getMinecraft().world.getCapability(TeamProvider.TEAM_CAP, null).leaveTeam(this.players[0]);
			}
		}
		
	}

	@Override
	protected void keyTyped(char typedChar, int keyCode) throws IOException {
		super.keyTyped(typedChar, keyCode);
		if (keyCode == this.mc.gameSettings.keyBindInventory.getKeyCode()) {
			this.mc.displayGuiScreen(null);
		}
	}

	@Override
	public void updateScreen() {
		leaveButton.visible = players[1] != null || players[2] != null || players[3] != null;
	}

	@Override
	public void drawScreen(int mouseX, int mouseY, float partialTicks) {
		GlStateManager.enableAlpha();
		GlStateManager.enableBlend();

		mc.getTextureManager().bindTexture(SCROLL_GUI_TEXTURE);
		int sizex = this.width;
		int sizey = this.height - 21;
		this.drawTexturedModalRect(x, y, 0, 0, texturex, texturey);
		
		this.drawTexturedModalRect(x + 42, y + 11, texturex, 38, 43, 42);

		this.renderBar((sizex - barx) / 2, sizey / 2 - texturey * 9 / 40, players[0]);

		this.renderItemModelIntoGUI(heads[0], sizex / 2, sizey / 2 - texturey * 7 / 20, 4);

		this.renderPlayer(1);
		this.renderPlayer(2);
		this.renderPlayer(3);

		super.drawScreen(mouseX, mouseY, partialTicks);

		GlStateManager.disableBlend();
		GlStateManager.disableAlpha();
	}

	/**
	 * Draws an entity on the screen.
	 */
	public static void drawEntityOnScreen(int posX, int posY, int scale, EntityLivingBase ent)
	{
		GlStateManager.enableColorMaterial();
		GlStateManager.pushMatrix();
		GlStateManager.translate((float)posX, (float)posY, 50.0F);
		GlStateManager.scale((float)(-scale), (float)scale, (float)scale);
		GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F);
		float f = ent.renderYawOffset;
		float f1 = ent.rotationYaw;
		float f2 = ent.rotationPitch;
		float f3 = ent.prevRotationYawHead;
		float f4 = ent.rotationYawHead;
		GlStateManager.rotate(135.0F, 0.0F, 1.0F, 0.0F);
		RenderHelper.enableStandardItemLighting();
		GlStateManager.rotate(-135.0F, 0.0F, 1.0F, 0.0F);
		ent.renderYawOffset = 0;
		ent.rotationYaw = 0;
		ent.rotationPitch = 0;
		ent.rotationYawHead = ent.rotationYaw;
		ent.prevRotationYawHead = ent.rotationYaw;
		GlStateManager.translate(0.0F, 0.0F, 0.0F);
		RenderManager rendermanager = Minecraft.getMinecraft().getRenderManager();
		rendermanager.setPlayerViewY(180.0F);
		rendermanager.setRenderShadow(false);
		rendermanager.renderEntity(ent, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, false);
		rendermanager.setRenderShadow(true);
		ent.renderYawOffset = f;
		ent.rotationYaw = f1;
		ent.rotationPitch = f2;
		ent.prevRotationYawHead = f3;
		ent.rotationYawHead = f4;
		GlStateManager.popMatrix();
		RenderHelper.disableStandardItemLighting();
		GlStateManager.disableRescaleNormal();
		GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit);
		GlStateManager.disableTexture2D();
		GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
	}

	protected void renderItemModelIntoGUI(ItemStack stack, int x, int y, int scale)
	{

		IBakedModel bakedmodel = mc.getRenderItem().getItemModelWithOverrides(stack, (World)null, (EntityLivingBase)null);

		GlStateManager.pushMatrix();
		mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
		mc.getTextureManager().getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).setBlurMipmap(false, false);
		GlStateManager.enableRescaleNormal();
		GlStateManager.enableAlpha();
		GlStateManager.alphaFunc(516, 0.1F);
		GlStateManager.enableBlend();
		GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
		GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
		this.setupGuiTransform(x, y, bakedmodel.isGui3d());
		GlStateManager.translate(0, 0.25F * scale, 0);
		GlStateManager.scale(scale, scale, scale);
		GlStateManager.disableLighting();
		bakedmodel = net.minecraftforge.client.ForgeHooksClient.handleCameraTransforms(bakedmodel, ItemCameraTransforms.TransformType.HEAD, false);
		mc.getRenderItem().renderItem(stack, bakedmodel);
		GlStateManager.disableAlpha();
		GlStateManager.disableRescaleNormal();
		GlStateManager.popMatrix();
		mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
		mc.getTextureManager().getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).restoreLastBlurMipmap();
		mc.getTextureManager().bindTexture(SCROLL_GUI_TEXTURE);
	}

	private void setupGuiTransform(int xPosition, int yPosition, boolean isGui3d)
	{
		GlStateManager.translate((float)xPosition, (float)yPosition, 100.0F + this.zLevel);
		GlStateManager.scale(1.0F, -1.0F, 1.0F);
		GlStateManager.scale(16.0F, 16.0F, 16.0F);

		if (isGui3d)
		{
			GlStateManager.enableLighting();
		}
		else
		{
			GlStateManager.disableLighting();
		}
	}

	private void renderBar(int posx, int posy, EntityPlayer player) {

		int width = 0;

		IAura aura = player.getCapability(AuraProvider.AURA_CAP, null);

		if (aura != null) {
			width = (int) (aura.getPercentage() * (barx - 2));
		}

		this.drawTexturedModalRect(posx + 1, posy + 1, 0, texturey + 10, width, bary - 2);

		float color[] = new float[3];

		ISemblance semblance = CapabilityHandler.getCurrentSemblance(player);

		if (semblance != null) {
			color = semblance.getColor();
			GlStateManager.color(color[0], color[1], color[2]);
		}

		this.drawTexturedModalRect(posx, posy, 0, texturey, barx, bary);

		if (aura != null) {

			//this.drawCenteredString(fontRenderer, "0", posx, posy - texturey * 2 / 40, 255<<16|0<<8|0);

			//this.drawCenteredString(fontRenderer, Integer.toString(aura.getMaxAura()), posx + barx, posy - texturey * 2 / 40, 255<<16|255<<8|0);

			//this.drawCenteredString(fontRenderer, Integer.toString((int) (aura.getMaxAura() * aura.getPercentage())), posx + width, posy + texturey * 2 / 40, 255<<16|(int)(255 * aura.getPercentage())<<8|0);

			this.drawCenteredString(fontRenderer, Integer.toString((int)(aura.getMaxAura() * aura.getPercentage())) + " / " + Integer.toString((int)aura.getMaxAura()), posx + barx / 2, posy + texturey * 2 / 40, 255<<16|255<<8|255);
		}
	}

	private void addPlayer(@Nullable EntityPlayer playerIn, int index) {

		this.players[index] = playerIn;

		if (playerIn != null) {
			heads[index] = new ItemStack(Items.SKULL, 1, 3);

			NBTTagCompound nbt = heads[index].getTagCompound();

			if (nbt == null) {
				nbt = new NBTTagCompound();
				heads[index].setTagCompound(nbt);
			}

			nbt.setString("SkullOwner", playerIn.getName());
		}
		else {
			heads[index] = ItemStack.EMPTY;
		}

	}

	private void renderPlayer(int index) {
		int sizex = this.width;
		int sizey = this.height - 21;

		if (players[index] != null) {

			this.renderBar((sizex - barx) / 2 + 10, sizey / 2 - texturey * (1 - 3*index) / 20 - 5, players[index]);

			this.renderItemModelIntoGUI(heads[index], sizex / 2 - 45, sizey / 2 - texturey * (1 - 3*index) / 20, 2);

		}
	}
	
}

 

 

(this is an old screenshot with the same player in all four slots, but it serves it's purpose of showing why I want the capability data exposed)
2019-04-18_17_56_56.png.5728e004b87d2d1b2fae4438960719f3.png

 

similar thread (but this only works on the server instead of the client I think)

 

 

also completely unrelated but
Player404

(which is a random player generated by the IDE) is actually registered to a real player
https://mcuuid.net/?q=Player404

Edited by Pi Man
solved
Posted
2 minutes ago, Pi Man said:

can you get an EntityPlayer instance of an offline player on the client?

Not really.

2 minutes ago, Pi Man said:

Can you get the data of an offline player on a client (similar to using player.dat on a server)?

Yes you can do this. I've done it recently you need to create an EntityPlayerMP instance on the server and load it's nbt. With a little digging you'll find where the nbt is loaded. Then you need to send the data to the client via a packet. Then store the data until the client player no longer needs it.

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

alright, so I got a solution
 

so what I did was when trying to save a client I've been just sending the UUID, now when the client is offline and trying to be saved, I also send the nbt data of the client as well as the username.

then on the receiving side, if the player is not found with the UUID, I call a proxy method to generate a "fake player" to take it's place.

Common Proxy:

	public EntityPlayer loadPlayer(NBTTagCompound teamnbt, String key, World world) {
		
		GameProfile profile = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerProfileCache().getProfileByUUID(UUID.fromString(teamnbt.getString(key)));
		EntityPlayerMP member = new EntityPlayerMP(FMLCommonHandler.instance().getMinecraftServerInstance(), (WorldServer) world, profile , new PlayerInteractionManager(world));
		FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().setPlayerManager(new WorldServer[] {(WorldServer) world});
		member.deserializeNBT(FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerNBT(member));
		member.mountEntityAndWakeUp();
		
		return member;

	}

 

Client Proxy:

	@Override
	public EntityPlayer loadPlayer(NBTTagCompound teamnbt, String key, World world) {
		EntityPlayer member;
		if (world.isRemote) {
			GameProfile profile = new GameProfile(UUID.fromString(teamnbt.getString(key)), teamnbt.getString(key + "name"));
			TileEntitySkull.updateGameprofile(profile);
			member = new EntityOtherPlayerMP(world, profile);
			member.deserializeNBT(teamnbt.getCompoundTag(key + "data"));
			member.setEntityId(teamnbt.getInteger(key + "id"));
		}
		else {
			member = super.loadPlayer(teamnbt, key, world);
		}
		
		return member;
	}

 

Serializing:

	@Override
	public NBTTagCompound serialize() {
		
		requests.removeIf(request -> (request.getSender() == null || request.getReceiver() == null));
		teams.removeIf(team -> team.size() < 2);
		
		NBTTagCompound nbt = new NBTTagCompound();
		NBTTagCompound teamsnbt = new NBTTagCompound();
		NBTTagCompound requestsnbt = new NBTTagCompound();
		
		Integer i = 0;
		for (List<EntityPlayer> team : teams) {
			NBTTagCompound teamnbt = new NBTTagCompound();
			Integer j = 0;
			for (EntityPlayer player : team) {
				if (player != null) {
					teamnbt.setString(j.toString(), player.getCachedUniqueIdString());
					if (player instanceof EntityPlayerMP && ((EntityPlayerMP)player).hasDisconnected()) {
						teamnbt.setTag(j.toString() + "data", player.writeToNBT(new NBTTagCompound()));
						teamnbt.setInteger(j.toString() + "id", player.getEntityId());
						teamnbt.setString(j.toString() + "name", player.getName());
					}
					j++;
				}
			}
			teamnbt.setInteger("size", j);
			teamsnbt.setTag(i.toString(), teamnbt);
			i++;
		}
		
		i = 0;
		for (Request request : requests) {
			requestsnbt.setString(i.toString() + "sender", request.getSender().getCachedUniqueIdString());
			requestsnbt.setString(i.toString() + "receiver", request.getReceiver().getCachedUniqueIdString());
			i++;
		}
		
		nbt.setTag("teams", teamsnbt);
		nbt.setTag("requests", requestsnbt);
		nbt.setInteger("requestSize", i);
		
		System.out.println(nbt);
		
		return nbt;
		
	}

 

Deserializing:

	@Override
	public void deserialize(NBTTagCompound nbt) {
		
		teams.clear();
		requests.clear();
		
		NBTTagCompound teamsnbt = nbt.getCompoundTag("teams");
		NBTTagCompound requestsnbt = nbt.getCompoundTag("requests");
		
		for (String key : teamsnbt.getKeySet()) {
			
			NBTTagCompound teamnbt = teamsnbt.getCompoundTag(key);
			List<EntityPlayer> team = new ArrayList<>();
			int i2 = teamnbt.getInteger("size");
			for (Integer i = 0; i < i2; i++) {
				EntityPlayer member = this.world.getPlayerEntityByUUID(UUID.fromString(teamnbt.getString(i.toString())));
				if (member == null) {
					member = RWBYModels.proxy.loadPlayer(teamnbt, i.toString(), world);
				}
				team.add(member);
			}
			
			teams.add(team);
			
		}
		
		int i1 = nbt.getInteger("requestSize");
		
		for (Integer i = 0; i < i1; i++) {
			
			EntityPlayer sender = world.getPlayerEntityByUUID(UUID.fromString(requestsnbt.getString(i.toString() + "sender")));
			EntityPlayer receiver = world.getPlayerEntityByUUID(UUID.fromString(requestsnbt.getString(i.toString() + "receiver")));
			
			requests.add(new Request(sender, receiver));
			
		}
		
	}

 

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.