mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 07:13:28 +01:00
parent
32391142ed
commit
9bafff59d4
4 changed files with 38 additions and 19 deletions
|
@ -14,48 +14,50 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
//Yes, this is name based instead of UUID-based.
|
||||
//It just works better this way because of vanilla quirks. Don't judge me.
|
||||
public final class PlayerData{
|
||||
|
||||
public static PlayerSave getDataFromPlayer(EntityPlayer player){
|
||||
public static PlayerSave getDataFromPlayer(String name){
|
||||
ArrayList<PlayerSave> data = WorldData.PLAYER_SAVE_DATA;
|
||||
//Get Data from existing data
|
||||
for(PlayerSave save : data){
|
||||
if(save.thePlayerUUID.equals(player.getUniqueID())){
|
||||
if(save.theName != null && save.theName.equals(name)){
|
||||
return save;
|
||||
}
|
||||
}
|
||||
|
||||
//Add Data if none is existant
|
||||
PlayerSave aSave = new PlayerSave(player.getUniqueID(), new NBTTagCompound());
|
||||
PlayerSave aSave = new PlayerSave(name, new NBTTagCompound());
|
||||
data.add(aSave);
|
||||
return aSave;
|
||||
}
|
||||
|
||||
public static PlayerSave getDataFromPlayer(EntityPlayer player){
|
||||
return getDataFromPlayer(player.getName());
|
||||
}
|
||||
|
||||
public static class PlayerSave{
|
||||
|
||||
public final UUID thePlayerUUID;
|
||||
public final String theName;
|
||||
public NBTTagCompound theCompound;
|
||||
|
||||
public PlayerSave(UUID theUUID, NBTTagCompound theCompound){
|
||||
this.thePlayerUUID = theUUID;
|
||||
public PlayerSave(String name, NBTTagCompound theCompound){
|
||||
this.theName = name;
|
||||
this.theCompound = theCompound;
|
||||
}
|
||||
|
||||
public static PlayerSave fromNBT(NBTTagCompound compound){
|
||||
UUID theID = new UUID(compound.getLong("MostSignificant"), compound.getLong("LeastSignificant"));
|
||||
String name = compound.getString("Name");
|
||||
NBTTagCompound theCompound = compound.getCompoundTag("Tag");
|
||||
return new PlayerSave(theID, theCompound);
|
||||
return new PlayerSave(name, theCompound);
|
||||
}
|
||||
|
||||
public NBTTagCompound toNBT(){
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setLong("LeastSignificant", this.thePlayerUUID.getLeastSignificantBits());
|
||||
compound.setLong("MostSignificant", this.thePlayerUUID.getMostSignificantBits());
|
||||
|
||||
compound.setString("Name", this.theName);
|
||||
compound.setTag("Tag", this.theCompound);
|
||||
|
||||
return compound;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,7 +97,15 @@ public class CommonEvents{
|
|||
EntityPlayerMP player = (EntityPlayerMP)event.getEntity();
|
||||
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
|
||||
if(!data.theCompound.hasNoTags()){
|
||||
PacketHandler.theNetwork.sendTo(new PacketServerToClient(data.theCompound, PacketHandler.PLAYER_DATA_TO_CLIENT_HANDLER), player);
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setString("Name", player.getName());
|
||||
compound.setTag("Data", data.theCompound);
|
||||
compound.setBoolean("Log", true);
|
||||
PacketHandler.theNetwork.sendTo(new PacketServerToClient(compound, PacketHandler.PLAYER_DATA_TO_CLIENT_HANDLER), player);
|
||||
ModUtil.LOGGER.info("Sending Player Data to player "+player.getName()+" with info "+data.theCompound+".");
|
||||
}
|
||||
else{
|
||||
ModUtil.LOGGER.info("Not sending Player Data to player "+player.getName()+" because he doesn't have any.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
|
@ -93,7 +94,10 @@ public class ItemLaserWrench extends ItemBase{
|
|||
save.theCompound.setInteger("LaserWrenchMode", currMode);
|
||||
|
||||
if(player instanceof EntityPlayerMP){
|
||||
PacketHandler.theNetwork.sendTo(new PacketServerToClient(save.theCompound, PacketHandler.PLAYER_DATA_TO_CLIENT_HANDLER), (EntityPlayerMP)player);
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setString("Name", player.getName());
|
||||
compound.setTag("Data", save.theCompound);
|
||||
PacketHandler.theNetwork.sendTo(new PacketServerToClient(compound, PacketHandler.PLAYER_DATA_TO_CLIENT_HANDLER), (EntityPlayerMP)player);
|
||||
}
|
||||
|
||||
player.addChatComponentMessage(new TextComponentString("Mode changed to "+WrenchMode.values()[currMode].name+"!"));
|
||||
|
|
|
@ -98,9 +98,11 @@ public final class PacketHandler{
|
|||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void handleData(NBTTagCompound compound){
|
||||
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
||||
if(player != null){
|
||||
PlayerData.getDataFromPlayer(player).theCompound = compound;
|
||||
NBTTagCompound data = compound.getCompoundTag("Data");
|
||||
String name = compound.getString("Name");
|
||||
PlayerData.getDataFromPlayer(name).theCompound = data;
|
||||
if(compound.getBoolean("Log")){
|
||||
ModUtil.LOGGER.info("Receiving Player Data for player "+name+" with info "+data+".");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -133,7 +135,10 @@ public final class PacketHandler{
|
|||
PlayerData.PlayerSave playerData = PlayerData.getDataFromPlayer(player);
|
||||
playerData.theCompound.merge(data);
|
||||
if(player instanceof EntityPlayerMP){
|
||||
PacketHandler.theNetwork.sendTo(new PacketServerToClient(playerData.theCompound, PLAYER_DATA_TO_CLIENT_HANDLER), (EntityPlayerMP)player);
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setString("Name", player.getName());
|
||||
tag.setTag("Data", playerData.theCompound);
|
||||
PacketHandler.theNetwork.sendTo(new PacketServerToClient(tag, PLAYER_DATA_TO_CLIENT_HANDLER), (EntityPlayerMP)player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue