Working on the railroad, I mean the player knowledge system, all the live long day
This commit is contained in:
parent
5f570fc576
commit
3e0907fa3e
|
@ -6,6 +6,7 @@ import com.pahimar.ee3.exchange.EnergyValueRegistry;
|
|||
import com.pahimar.ee3.handler.*;
|
||||
import com.pahimar.ee3.init.*;
|
||||
import com.pahimar.ee3.knowledge.AbilityRegistry;
|
||||
import com.pahimar.ee3.knowledge.PlayerKnowledgeRegistry;
|
||||
import com.pahimar.ee3.knowledge.TransmutationKnowledgeRegistry;
|
||||
import com.pahimar.ee3.network.PacketHandler;
|
||||
import com.pahimar.ee3.proxy.IProxy;
|
||||
|
@ -54,6 +55,8 @@ public class EquivalentExchange3
|
|||
@EventHandler
|
||||
public void onServerStarting(FMLServerStartingEvent event) {
|
||||
|
||||
Files.updateFileReferences();
|
||||
|
||||
SerializationHelper.initModDataDirectories();
|
||||
TransmutationKnowledgeRegistry.getInstance();
|
||||
AbilityRegistry.getInstance().loadAbilityRegistryFromFile(ConfigurationHandler.Settings.onlyLoadFile);
|
||||
|
@ -118,7 +121,10 @@ public class EquivalentExchange3
|
|||
|
||||
WorldEventHandler.hasInitilialized = false;
|
||||
EnergyValueRegistry.INSTANCE.save();
|
||||
|
||||
TransmutationKnowledgeRegistry.getInstance().clear();
|
||||
PlayerKnowledgeRegistry.INSTANCE.save();
|
||||
|
||||
AbilityRegistry.getInstance().save();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.pahimar.ee3.handler;
|
||||
|
||||
import com.pahimar.ee3.exchange.EnergyValueRegistry;
|
||||
import com.pahimar.ee3.knowledge.PlayerKnowledgeRegistry;
|
||||
import com.pahimar.ee3.recipe.AludelRecipeManager;
|
||||
import com.pahimar.ee3.recipe.RecipeRegistry;
|
||||
import com.pahimar.ee3.util.LogHelper;
|
||||
|
@ -25,6 +26,8 @@ public class WorldEventHandler {
|
|||
EnergyValueRegistry.INSTANCE.compute();
|
||||
LogHelper.info(EnergyValueRegistry.ENERGY_VALUE_MARKER, "Energy value system initialized {} values after {} ms", EnergyValueRegistry.INSTANCE.getEnergyValues().size(), (System.nanoTime() - startTime) / 100000);
|
||||
hasInitilialized = true;
|
||||
|
||||
PlayerKnowledgeRegistry.INSTANCE.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -270,7 +270,7 @@ public class AbilityRegistry implements JsonSerializer<AbilityRegistry>, JsonDes
|
|||
if (abilityDirectory != null)
|
||||
{
|
||||
abilityDirectory.mkdirs();
|
||||
writeToFile(new File(abilityDirectory, Files.ABILITIES_JSON_FILE));
|
||||
writeToFile(new File(abilityDirectory, Files.ABILITIES_JSON_FILENAME));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -299,7 +299,7 @@ public class AbilityRegistry implements JsonSerializer<AbilityRegistry>, JsonDes
|
|||
{
|
||||
if (abilityDirectory != null)
|
||||
{
|
||||
File abilitiesFile = new File(abilityDirectory, Files.ABILITIES_JSON_FILE);
|
||||
File abilitiesFile = new File(abilityDirectory, Files.ABILITIES_JSON_FILENAME);
|
||||
|
||||
if (abilitiesFile.exists())
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@ public class PlayerKnowledge {
|
|||
|
||||
if (itemStacks != null) {
|
||||
for (ItemStack itemStack : itemStacks) {
|
||||
knownItemStacks.add(ItemHelper.clone(itemStack, 1));
|
||||
learn(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
package com.pahimar.ee3.knowledge;
|
||||
|
||||
import com.pahimar.ee3.reference.Comparators;
|
||||
import com.pahimar.ee3.reference.Files;
|
||||
import com.pahimar.ee3.util.SerializationHelper;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class PlayerKnowledgeRegistry {
|
||||
|
||||
public static final PlayerKnowledgeRegistry INSTANCE = new PlayerKnowledgeRegistry();
|
||||
|
||||
private final TreeMap<String, PlayerKnowledge> playerKnowledgeMap;
|
||||
private final PlayerKnowledge templatePlayerKnowledge;
|
||||
|
||||
private static final String TEMPLATE_PLAYER_KNOWLEDGE_FILEPATH = "knowledge" + File.separator + "transmutation" + Files.TEMPLATE_JSON_FILENAME;
|
||||
public static File templatePlayerKnowledgeFile;
|
||||
|
||||
private PlayerKnowledgeRegistry() {
|
||||
|
||||
playerKnowledgeMap = new TreeMap<>(Comparators.STRING_COMPARATOR);
|
||||
templatePlayerKnowledge = new PlayerKnowledge();
|
||||
|
||||
// Init some data for testing
|
||||
PlayerKnowledge playerKnowledge = new PlayerKnowledge();
|
||||
playerKnowledge.learn(new ItemStack(Items.apple));
|
||||
playerKnowledge.learn(new ItemStack(Items.arrow));
|
||||
playerKnowledge.learn(new ItemStack(Items.baked_potato));
|
||||
playerKnowledge.learn(new ItemStack(Items.blaze_powder));
|
||||
playerKnowledge.learn(new ItemStack(Items.blaze_rod));
|
||||
playerKnowledge.learn(new ItemStack(Items.chainmail_boots));
|
||||
playerKnowledge.learn(new ItemStack(Items.carrot));
|
||||
playerKnowledge.learn(new ItemStack(Items.carrot_on_a_stick));
|
||||
playerKnowledge.learn(new ItemStack(Items.chainmail_boots));
|
||||
playerKnowledgeMap.put("pahimar", playerKnowledge);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* doesKnow
|
||||
* canLearn
|
||||
* teach
|
||||
* makeForget
|
||||
* makeForgetAll
|
||||
* load
|
||||
* save
|
||||
*/
|
||||
|
||||
public void save() {
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
||||
for (String playerName : playerKnowledgeMap.keySet()) {
|
||||
SerializationHelper.writeJsonFile(getPlayerKnowledgeFile(playerName), SerializationHelper.GSON.toJson(playerKnowledgeMap.get(playerName)));
|
||||
}
|
||||
}
|
||||
|
||||
SerializationHelper.writeJsonFile(templatePlayerKnowledgeFile, SerializationHelper.GSON.toJson(templatePlayerKnowledge));
|
||||
}
|
||||
|
||||
public void load() {
|
||||
|
||||
// Load template knowledge
|
||||
}
|
||||
|
||||
public void loadPlayer(EntityPlayer entityPlayer) {
|
||||
|
||||
}
|
||||
|
||||
public void loadPlayer(File file) {
|
||||
|
||||
}
|
||||
|
||||
private static File getPlayerKnowledgeFile(String playerName) {
|
||||
return new File(Files.playerDataDirectory, "knowledge" + File.separator + "transmutation" + File.separator + playerName + ".json");
|
||||
}
|
||||
}
|
|
@ -348,16 +348,16 @@ public class TransmutationKnowledgeRegistry
|
|||
{
|
||||
if (dataKnowledgeDirectory != null)
|
||||
{
|
||||
File templateFile = new File(dataKnowledgeDirectory, Files.TEMPLATE_JSON_FILE);
|
||||
File templateFile = new File(dataKnowledgeDirectory, Files.TEMPLATE_JSON_FILENAME);
|
||||
|
||||
if (!templateFile.exists())
|
||||
{
|
||||
templateKnowledge = new TransmutationKnowledge();
|
||||
SerializationHelper.writeTransmutationKnowledgeToFile(dataKnowledgeDirectory, Files.TEMPLATE_JSON_FILE, templateKnowledge);
|
||||
SerializationHelper.writeTransmutationKnowledgeToFile(dataKnowledgeDirectory, Files.TEMPLATE_JSON_FILENAME, templateKnowledge);
|
||||
}
|
||||
else
|
||||
{
|
||||
templateKnowledge = SerializationHelper.readTransmutationKnowledgeFromFile(dataKnowledgeDirectory, Files.TEMPLATE_JSON_FILE);
|
||||
templateKnowledge = SerializationHelper.readTransmutationKnowledgeFromFile(dataKnowledgeDirectory, Files.TEMPLATE_JSON_FILENAME);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -372,12 +372,12 @@ public class TransmutationKnowledgeRegistry
|
|||
{
|
||||
if (templateKnowledge != null)
|
||||
{
|
||||
SerializationHelper.writeTransmutationKnowledgeToFile(dataKnowledgeDirectory, Files.TEMPLATE_JSON_FILE, templateKnowledge);
|
||||
SerializationHelper.writeTransmutationKnowledgeToFile(dataKnowledgeDirectory, Files.TEMPLATE_JSON_FILENAME, templateKnowledge);
|
||||
}
|
||||
else
|
||||
{
|
||||
templateKnowledge = new TransmutationKnowledge();
|
||||
SerializationHelper.writeTransmutationKnowledgeToFile(dataKnowledgeDirectory, Files.TEMPLATE_JSON_FILE, templateKnowledge);
|
||||
SerializationHelper.writeTransmutationKnowledgeToFile(dataKnowledgeDirectory, Files.TEMPLATE_JSON_FILENAME, templateKnowledge);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,43 +1,52 @@
|
|||
package com.pahimar.ee3.reference;
|
||||
|
||||
import com.pahimar.ee3.exchange.EnergyValueRegistry;
|
||||
import com.pahimar.ee3.knowledge.PlayerKnowledgeRegistry;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Files {
|
||||
|
||||
public static File dataDirectory;
|
||||
public static File globalDataDirectory;
|
||||
public static File playerDataDirectory;
|
||||
|
||||
private static final String ENERGY_VALUES_JSON = "energy-values.json";
|
||||
private static final String PRE_CALCULATION_ENERGY_VALUES = "pre-calculation-energy-values.json";
|
||||
private static final String POST_CALCULATION_ENERGY_VALUES = "post-calculation-energy-values.json";
|
||||
private static final String ENERGY_VALUES_JSON_FILENAME = "energy-values.json";
|
||||
private static final String PRE_CALCULATION_ENERGY_VALUES_FILENAME = "pre-calculation-energy-values.json";
|
||||
private static final String POST_CALCULATION_ENERGY_VALUES_FILENAME = "post-calculation-energy-values.json";
|
||||
|
||||
public static final String TEMPLATE_JSON_FILE = "template.json";
|
||||
public static final String ABILITIES_JSON_FILE = "abilities.json";
|
||||
public static final String TEMPLATE_JSON_FILENAME = "template-player-knowledge.json";
|
||||
public static final String ABILITIES_JSON_FILENAME = "abilities.json";
|
||||
|
||||
public static File abilitiesDataDirectory;
|
||||
public static File knowledgeDataDirectory;
|
||||
|
||||
public static File abilitiesDataFile;
|
||||
public static File knowledgeDataFile;
|
||||
|
||||
public static void init(FMLPreInitializationEvent event) {
|
||||
|
||||
dataDirectory = new File(event.getModConfigurationDirectory().getParentFile(), "data" + File.separator + Reference.LOWERCASE_MOD_ID);
|
||||
globalDataDirectory = new File(event.getModConfigurationDirectory().getParentFile(), "data" + File.separator + Reference.LOWERCASE_MOD_ID);
|
||||
|
||||
EnergyValueRegistry.energyValuesDirectory = new File(dataDirectory, "energy-values");
|
||||
EnergyValueRegistry.energyValuesDirectory = new File(globalDataDirectory, "energy-values");
|
||||
EnergyValueRegistry.energyValuesDirectory.mkdirs();
|
||||
EnergyValueRegistry.energyValuesFile = new File(EnergyValueRegistry.energyValuesDirectory, ENERGY_VALUES_JSON);
|
||||
EnergyValueRegistry.preCalculationValuesFile = new File(EnergyValueRegistry.energyValuesDirectory, PRE_CALCULATION_ENERGY_VALUES);
|
||||
EnergyValueRegistry.postCalculationValuesFile = new File(EnergyValueRegistry.energyValuesDirectory, POST_CALCULATION_ENERGY_VALUES);
|
||||
EnergyValueRegistry.energyValuesFile = new File(EnergyValueRegistry.energyValuesDirectory, ENERGY_VALUES_JSON_FILENAME);
|
||||
EnergyValueRegistry.preCalculationValuesFile = new File(EnergyValueRegistry.energyValuesDirectory, PRE_CALCULATION_ENERGY_VALUES_FILENAME);
|
||||
EnergyValueRegistry.postCalculationValuesFile = new File(EnergyValueRegistry.energyValuesDirectory, POST_CALCULATION_ENERGY_VALUES_FILENAME);
|
||||
|
||||
abilitiesDataDirectory = new File(dataDirectory, "abilities");
|
||||
File templatePlayerKnowledgeDirectory = new File(globalDataDirectory, "knowledge" + File.separator + "transmutation");
|
||||
templatePlayerKnowledgeDirectory.mkdirs();
|
||||
PlayerKnowledgeRegistry.templatePlayerKnowledgeFile = new File(templatePlayerKnowledgeDirectory, TEMPLATE_JSON_FILENAME);
|
||||
|
||||
abilitiesDataDirectory = new File(globalDataDirectory, "abilities");
|
||||
abilitiesDataDirectory.mkdirs();
|
||||
abilitiesDataFile = new File(abilitiesDataDirectory, ABILITIES_JSON_FILE);
|
||||
abilitiesDataFile = new File(abilitiesDataDirectory, ABILITIES_JSON_FILENAME);
|
||||
}
|
||||
|
||||
knowledgeDataDirectory = new File(dataDirectory, "knowledge");
|
||||
knowledgeDataDirectory.mkdirs();
|
||||
knowledgeDataFile = new File(knowledgeDataDirectory, TEMPLATE_JSON_FILE);
|
||||
/**
|
||||
* Updates the references to the instance specific EE3 data directories, creating them if they don't already exist
|
||||
*/
|
||||
public static void updateFileReferences() {
|
||||
|
||||
playerDataDirectory = new File(FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getSaveHandler().getWorldDirectory(), "playerdata" + File.separator + Reference.LOWERCASE_MOD_ID);
|
||||
playerDataDirectory.mkdirs();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ public class SerializationHelper {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public static File getInstanceDataDirectory()
|
||||
{
|
||||
return instanceDataDirectory;
|
||||
|
@ -69,6 +70,7 @@ public class SerializationHelper {
|
|||
* Creates (if one does not exist already) and initializes a mod specific File reference inside of the current world's playerdata directory
|
||||
*/
|
||||
public static void initModDataDirectories() {
|
||||
|
||||
instanceDataDirectory = new File(FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getSaveHandler().getWorldDirectory(), "data" + File.separator + Reference.LOWERCASE_MOD_ID);
|
||||
instanceDataDirectory.mkdirs();
|
||||
|
||||
|
@ -236,7 +238,7 @@ public class SerializationHelper {
|
|||
writeJsonFile(file, GSON.toJson(valueMap, ENERGY_VALUE_MAP_TYPE));
|
||||
}
|
||||
|
||||
private static String readJsonFile(File file) throws FileNotFoundException {
|
||||
public static String readJsonFile(File file) throws FileNotFoundException {
|
||||
|
||||
StringBuilder jsonStringBuilder = new StringBuilder();
|
||||
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) {
|
||||
|
@ -259,7 +261,7 @@ public class SerializationHelper {
|
|||
return jsonStringBuilder.toString();
|
||||
}
|
||||
|
||||
private static void writeJsonFile(File file, String fileContents) {
|
||||
public static void writeJsonFile(File file, String fileContents) {
|
||||
|
||||
File tempFile = new File(file.getAbsolutePath() + "_tmp");
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.pahimar.ee3.util.serialize;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.pahimar.ee3.exchange.WrappedStack;
|
||||
import com.pahimar.ee3.knowledge.PlayerKnowledge;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
@ -21,7 +22,7 @@ public class PlayerKnowledgeSerializer implements JsonSerializer<PlayerKnowledge
|
|||
|
||||
if (src != null) {
|
||||
for (ItemStack itemStack : src.getKnownItemStacks()) {
|
||||
jsonArray.add(context.serialize(itemStack));
|
||||
jsonArray.add(context.serialize(WrappedStack.wrap(itemStack)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue