Add in Augmentation Table GUI xcf, add some more NBT name constants, implement a basic PlayerKnowledge object for storing transmutation data, and add in a basic save handler for the PlayerKnowledge
This commit is contained in:
parent
31e9085145
commit
b82bb5b4b0
|
@ -1,11 +1,9 @@
|
|||
package com.pahimar.ee3.handler;
|
||||
|
||||
import com.pahimar.ee3.reference.Settings;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PlayerEventHandler
|
||||
{
|
||||
|
@ -14,22 +12,17 @@ public class PlayerEventHandler
|
|||
{
|
||||
if (!event.entityPlayer.worldObj.isRemote)
|
||||
{
|
||||
if (Settings.PLAYER_DAT_LOCATION == null || Settings.PLAYER_DAT_LOCATION.length() == 0 || !Settings.PLAYER_DAT_LOCATION.equalsIgnoreCase(event.playerDirectory.getPath()))
|
||||
// Grab the correct directory to be reading/writing player knowledge data to
|
||||
if (PlayerKnowledgeHandler.playerDataDirectory == null || !PlayerKnowledgeHandler.playerDataDirectory.getAbsolutePath().equalsIgnoreCase(event.playerDirectory.getAbsolutePath()))
|
||||
{
|
||||
Settings.PLAYER_DAT_LOCATION = event.playerDirectory.getPath();
|
||||
PlayerKnowledgeHandler.playerDataDirectory = event.playerDirectory;
|
||||
}
|
||||
|
||||
File playerFile = event.getPlayerFile("ee3");
|
||||
if (!playerFile.exists())
|
||||
// If player knowledge data doesn't exist, initialize a file for the player
|
||||
File playerDataFile = event.getPlayerFile("ee3");
|
||||
if (!playerDataFile.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
playerFile.createNewFile();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
PlayerKnowledgeHandler.writeKnowledgeData(event.entityPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
package com.pahimar.ee3.handler;
|
||||
|
||||
import com.pahimar.ee3.skill.PlayerKnowledge;
|
||||
import com.pahimar.ee3.util.ItemHelper;
|
||||
import com.pahimar.ee3.util.LogHelper;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PlayerKnowledgeHandler
|
||||
{
|
||||
public static File playerDataDirectory;
|
||||
|
||||
public static void writeKnowledgeData(EntityPlayer entityPlayer)
|
||||
{
|
||||
if (playerDataDirectory != null && playerDataDirectory.isDirectory())
|
||||
{
|
||||
try
|
||||
{
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
new PlayerKnowledge(entityPlayer).writeToNBT(nbttagcompound);
|
||||
File file1 = new File(playerDataDirectory, entityPlayer.getUniqueID().toString() + ".ee3.tmp");
|
||||
File file2 = new File(playerDataDirectory, entityPlayer.getUniqueID().toString() + ".ee3");
|
||||
CompressedStreamTools.writeCompressed(nbttagcompound, new FileOutputStream(file1));
|
||||
|
||||
if (file2.exists())
|
||||
{
|
||||
file2.delete();
|
||||
}
|
||||
|
||||
file1.renameTo(file2);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
LogHelper.warn("Failed to save player knowledge for " + entityPlayer.getCommandSenderName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static PlayerKnowledge readKnowledgeData(EntityPlayer entityPlayer)
|
||||
{
|
||||
if (playerDataDirectory != null && playerDataDirectory.isDirectory())
|
||||
{
|
||||
File playerDataFile = new File(playerDataDirectory, entityPlayer.getUniqueID().toString() + ".ee3");
|
||||
|
||||
if (playerDataFile.exists() && playerDataFile.isFile())
|
||||
{
|
||||
LogHelper.info(playerDataFile.getAbsolutePath());
|
||||
try
|
||||
{
|
||||
PlayerKnowledge playerKnowledge = PlayerKnowledge.readPlayerKnowledgeFromNBT(CompressedStreamTools.readCompressed(new FileInputStream(playerDataFile)));
|
||||
|
||||
LogHelper.info(playerKnowledge.getPlayerUUID());
|
||||
|
||||
for (ItemStack itemStack : playerKnowledge.getKnownItemStacks())
|
||||
{
|
||||
LogHelper.info(ItemHelper.toString(itemStack));
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -201,12 +201,12 @@ public class InventoryAlchemicalBag implements IInventory, INBTTaggable
|
|||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbtTagCompound)
|
||||
{
|
||||
if (nbtTagCompound != null && nbtTagCompound.hasKey("Items"))
|
||||
if (nbtTagCompound != null && nbtTagCompound.hasKey(Names.NBT.ITEMS))
|
||||
{
|
||||
// Read in the ItemStacks in the inventory from NBT
|
||||
if (nbtTagCompound.hasKey("Items"))
|
||||
if (nbtTagCompound.hasKey(Names.NBT.ITEMS))
|
||||
{
|
||||
NBTTagList tagList = nbtTagCompound.getTagList("Items", 10);
|
||||
NBTTagList tagList = nbtTagCompound.getTagList(Names.NBT.ITEMS, 10);
|
||||
inventory = new ItemStack[this.getSizeInventory()];
|
||||
for (int i = 0; i < tagList.tagCount(); ++i)
|
||||
{
|
||||
|
@ -245,7 +245,7 @@ public class InventoryAlchemicalBag implements IInventory, INBTTaggable
|
|||
tagList.appendTag(tagCompound);
|
||||
}
|
||||
}
|
||||
nbtTagCompound.setTag("Items", tagList);
|
||||
nbtTagCompound.setTag(Names.NBT.ITEMS, tagList);
|
||||
}
|
||||
|
||||
public boolean hasCustomName()
|
||||
|
|
|
@ -75,6 +75,8 @@ public class Names
|
|||
|
||||
public static final class NBT
|
||||
{
|
||||
public static final String ITEMS = "Items";
|
||||
public static final String KNOWLEDGE = "Knowledge";
|
||||
public static final String CHARGE_LEVEL = "chargeLevel";
|
||||
public static final String MODE = "mode";
|
||||
public static final String CRAFTING_GUI_OPEN = "craftingGuiOpen";
|
||||
|
|
|
@ -2,5 +2,5 @@ package com.pahimar.ee3.reference;
|
|||
|
||||
public class Settings
|
||||
{
|
||||
public static String PLAYER_DAT_LOCATION = "";
|
||||
|
||||
}
|
||||
|
|
136
src/main/java/com/pahimar/ee3/skill/PlayerKnowledge.java
Normal file
136
src/main/java/com/pahimar/ee3/skill/PlayerKnowledge.java
Normal file
|
@ -0,0 +1,136 @@
|
|||
package com.pahimar.ee3.skill;
|
||||
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import com.pahimar.ee3.util.INBTTaggable;
|
||||
import com.pahimar.ee3.util.ItemHelper;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagLong;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerKnowledge implements INBTTaggable
|
||||
{
|
||||
private UUID playerUUID;
|
||||
private Set<ItemStack> knownItemStacks;
|
||||
|
||||
private PlayerKnowledge()
|
||||
{
|
||||
this.playerUUID = null;
|
||||
this.knownItemStacks = null;
|
||||
}
|
||||
|
||||
public PlayerKnowledge(EntityPlayer entityPlayer)
|
||||
{
|
||||
this.playerUUID = entityPlayer.getUniqueID();
|
||||
this.knownItemStacks = new TreeSet<ItemStack>(ItemHelper.comparator);
|
||||
}
|
||||
|
||||
public UUID getPlayerUUID()
|
||||
{
|
||||
return this.playerUUID;
|
||||
}
|
||||
|
||||
public boolean isItemStackKnown(ItemStack itemStack)
|
||||
{
|
||||
ItemStack unitItemStack = itemStack.copy();
|
||||
itemStack.stackSize = 1;
|
||||
return this.knownItemStacks.contains(unitItemStack);
|
||||
}
|
||||
|
||||
public Set<ItemStack> getKnownItemStacks()
|
||||
{
|
||||
return this.knownItemStacks;
|
||||
}
|
||||
|
||||
public boolean learnItemStack(ItemStack itemStack)
|
||||
{
|
||||
ItemStack unitItemStack = itemStack.copy();
|
||||
itemStack.stackSize = 1;
|
||||
|
||||
if (!this.knownItemStacks.contains(unitItemStack))
|
||||
{
|
||||
return this.knownItemStacks.add(unitItemStack);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean forgetItemStack(ItemStack itemStack)
|
||||
{
|
||||
ItemStack unitItemStack = itemStack.copy();
|
||||
itemStack.stackSize = 1;
|
||||
|
||||
if (this.knownItemStacks.contains(unitItemStack))
|
||||
{
|
||||
return this.knownItemStacks.remove(unitItemStack);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void resetKnownItemStacks()
|
||||
{
|
||||
this.knownItemStacks.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbtTagCompound)
|
||||
{
|
||||
if (nbtTagCompound != null && nbtTagCompound.hasKey(Names.NBT.UUID_MOST_SIG) && nbtTagCompound.hasKey(Names.NBT.UUID_LEAST_SIG) && nbtTagCompound.hasKey("Knowledge"))
|
||||
{
|
||||
// Read in the player's UUID from NBT
|
||||
if (nbtTagCompound.hasKey(Names.NBT.UUID_MOST_SIG) && nbtTagCompound.hasKey(Names.NBT.UUID_LEAST_SIG))
|
||||
{
|
||||
playerUUID = new UUID(nbtTagCompound.getLong(Names.NBT.UUID_MOST_SIG), nbtTagCompound.getLong(Names.NBT.UUID_LEAST_SIG));
|
||||
}
|
||||
|
||||
// Read in the ItemStacks in the inventory from NBT
|
||||
if (nbtTagCompound.hasKey(Names.NBT.KNOWLEDGE))
|
||||
{
|
||||
NBTTagList tagList = nbtTagCompound.getTagList(Names.NBT.KNOWLEDGE, 10);
|
||||
knownItemStacks = new TreeSet<ItemStack>(ItemHelper.comparator);
|
||||
for (int i = 0; i < tagList.tagCount(); ++i)
|
||||
{
|
||||
NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
|
||||
ItemStack itemStack = ItemStack.loadItemStackFromNBT(tagCompound);
|
||||
knownItemStacks.add(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbtTagCompound)
|
||||
{
|
||||
// Write the player's UUID to NBT
|
||||
if (playerUUID != null)
|
||||
{
|
||||
nbtTagCompound.setTag(Names.NBT.UUID_MOST_SIG, new NBTTagLong(playerUUID.getMostSignificantBits()));
|
||||
nbtTagCompound.setTag(Names.NBT.UUID_LEAST_SIG, new NBTTagLong(playerUUID.getLeastSignificantBits()));
|
||||
}
|
||||
|
||||
// Write the ItemStacks in the set to NBT
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
for (ItemStack itemStack : knownItemStacks)
|
||||
{
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
itemStack.writeToNBT(tagCompound);
|
||||
tagList.appendTag(tagCompound);
|
||||
}
|
||||
nbtTagCompound.setTag(Names.NBT.KNOWLEDGE, tagList);
|
||||
}
|
||||
|
||||
public static PlayerKnowledge readPlayerKnowledgeFromNBT(NBTTagCompound nbtTagCompound)
|
||||
{
|
||||
PlayerKnowledge playerKnowledge = new PlayerKnowledge();
|
||||
|
||||
playerKnowledge.readFromNBT(nbtTagCompound);
|
||||
|
||||
return playerKnowledge;
|
||||
}
|
||||
}
|
|
@ -62,7 +62,7 @@ public class TileEntityAlchemicalChest extends TileEntityEE implements IInventor
|
|||
super.readFromNBT(nbtTagCompound);
|
||||
|
||||
// Read in the ItemStacks in the inventory from NBT
|
||||
NBTTagList tagList = nbtTagCompound.getTagList("Items", 10);
|
||||
NBTTagList tagList = nbtTagCompound.getTagList(Names.NBT.ITEMS, 10);
|
||||
inventory = new ItemStack[this.getSizeInventory()];
|
||||
for (int i = 0; i < tagList.tagCount(); ++i)
|
||||
{
|
||||
|
@ -205,7 +205,7 @@ public class TileEntityAlchemicalChest extends TileEntityEE implements IInventor
|
|||
tagList.appendTag(tagCompound);
|
||||
}
|
||||
}
|
||||
nbtTagCompound.setTag("Items", tagList);
|
||||
nbtTagCompound.setTag(Names.NBT.ITEMS, tagList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -74,7 +74,7 @@ public class TileEntityAludel extends TileEntityEE implements ISidedInventory
|
|||
super.readFromNBT(nbtTagCompound);
|
||||
|
||||
// Read in the ItemStacks in the inventory from NBT
|
||||
NBTTagList tagList = nbtTagCompound.getTagList("Items", 10);
|
||||
NBTTagList tagList = nbtTagCompound.getTagList(Names.NBT.ITEMS, 10);
|
||||
inventory = new ItemStack[this.getSizeInventory()];
|
||||
for (int i = 0; i < tagList.tagCount(); ++i)
|
||||
{
|
||||
|
@ -225,7 +225,7 @@ public class TileEntityAludel extends TileEntityEE implements ISidedInventory
|
|||
tagList.appendTag(tagCompound);
|
||||
}
|
||||
}
|
||||
nbtTagCompound.setTag("Items", tagList);
|
||||
nbtTagCompound.setTag(Names.NBT.ITEMS, tagList);
|
||||
nbtTagCompound.setInteger("deviceCookTime", deviceCookTime);
|
||||
nbtTagCompound.setInteger("fuelBurnTime", fuelBurnTime);
|
||||
nbtTagCompound.setInteger("itemCookTime", itemCookTime);
|
||||
|
|
|
@ -73,7 +73,7 @@ public class TileEntityCalcinator extends TileEntityEE implements ISidedInventor
|
|||
super.readFromNBT(nbtTagCompound);
|
||||
|
||||
// Read in the ItemStacks in the inventory from NBT
|
||||
NBTTagList tagList = nbtTagCompound.getTagList("Items", 10);
|
||||
NBTTagList tagList = nbtTagCompound.getTagList(Names.NBT.ITEMS, 10);
|
||||
inventory = new ItemStack[this.getSizeInventory()];
|
||||
for (int i = 0; i < tagList.tagCount(); ++i)
|
||||
{
|
||||
|
@ -258,7 +258,7 @@ public class TileEntityCalcinator extends TileEntityEE implements ISidedInventor
|
|||
tagList.appendTag(tagCompound);
|
||||
}
|
||||
}
|
||||
nbtTagCompound.setTag("Items", tagList);
|
||||
nbtTagCompound.setTag(Names.NBT.ITEMS, tagList);
|
||||
nbtTagCompound.setInteger("deviceCookTime", deviceCookTime);
|
||||
nbtTagCompound.setInteger("fuelBurnTime", fuelBurnTime);
|
||||
nbtTagCompound.setInteger("itemCookTime", itemCookTime);
|
||||
|
|
|
@ -34,7 +34,7 @@ public class TileEntityGlassBell extends TileEntityEE implements IInventory
|
|||
super.readFromNBT(nbtTagCompound);
|
||||
|
||||
// Read in the ItemStacks in the inventory from NBT
|
||||
NBTTagList tagList = nbtTagCompound.getTagList("Items", 10);
|
||||
NBTTagList tagList = nbtTagCompound.getTagList(Names.NBT.ITEMS, 10);
|
||||
inventory = new ItemStack[this.getSizeInventory()];
|
||||
for (int i = 0; i < tagList.tagCount(); ++i)
|
||||
{
|
||||
|
@ -179,7 +179,7 @@ public class TileEntityGlassBell extends TileEntityEE implements IInventory
|
|||
tagList.appendTag(tagCompound);
|
||||
}
|
||||
}
|
||||
nbtTagCompound.setTag("Items", tagList);
|
||||
nbtTagCompound.setTag(Names.NBT.ITEMS, tagList);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -138,7 +138,7 @@ public class TileEntityResearchStation extends TileEntityEE implements IInventor
|
|||
tagList.appendTag(tagCompound);
|
||||
}
|
||||
}
|
||||
nbtTagCompound.setTag("Items", tagList);
|
||||
nbtTagCompound.setTag(Names.NBT.ITEMS, tagList);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -147,7 +147,7 @@ public class TileEntityResearchStation extends TileEntityEE implements IInventor
|
|||
super.readFromNBT(nbtTagCompound);
|
||||
|
||||
// Read in the ItemStacks in the inventory from NBT
|
||||
NBTTagList tagList = nbtTagCompound.getTagList("Items", 10);
|
||||
NBTTagList tagList = nbtTagCompound.getTagList(Names.NBT.ITEMS, 10);
|
||||
inventory = new ItemStack[this.getSizeInventory()];
|
||||
for (int i = 0; i < tagList.tagCount(); ++i)
|
||||
{
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue