Re-jigging how modders can set things as being learnable/not learnable, and recoverable/not recoverable
This commit is contained in:
parent
f77b24278a
commit
de22edc3eb
|
@ -7,8 +7,8 @@ import com.pahimar.ee3.command.CommandSyncValues;
|
|||
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.KnowledgeRegistry;
|
||||
import com.pahimar.ee3.knowledge.SkillRegistry;
|
||||
import com.pahimar.ee3.network.PacketHandler;
|
||||
import com.pahimar.ee3.proxy.IProxy;
|
||||
import com.pahimar.ee3.recipe.RecipeRegistry;
|
||||
|
@ -146,9 +146,9 @@ public class EquivalentExchange3
|
|||
return RecipeRegistry.getInstance();
|
||||
}
|
||||
|
||||
public SkillRegistry getSkillRegistry()
|
||||
public AbilityRegistry getAbilityRegistry()
|
||||
{
|
||||
return SkillRegistry.getInstance();
|
||||
return AbilityRegistry.getInstance();
|
||||
}
|
||||
|
||||
public AlchemyArrayRegistry getAlchemyArrayRegistry()
|
||||
|
|
122
src/main/java/com/pahimar/ee3/api/AbilityRegistryProxy.java
Normal file
122
src/main/java/com/pahimar/ee3/api/AbilityRegistryProxy.java
Normal file
|
@ -0,0 +1,122 @@
|
|||
package com.pahimar.ee3.api;
|
||||
|
||||
import com.pahimar.ee3.EquivalentExchange3;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public final class AbilityRegistryProxy {
|
||||
@Mod.Instance("EE3")
|
||||
private static Object ee3Mod;
|
||||
|
||||
public static boolean isLearnable(Block block) {
|
||||
return isLearnable(new ItemStack(block));
|
||||
}
|
||||
|
||||
public static boolean isLearnable(Item item) {
|
||||
return isLearnable(new ItemStack(item));
|
||||
}
|
||||
|
||||
public static boolean isLearnable(ItemStack itemStack) {
|
||||
init();
|
||||
|
||||
if (ee3Mod != null) {
|
||||
return EE3Wrapper.ee3mod.getAbilityRegistry().isLearnable(itemStack);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void setAsLearnable(Block block) {
|
||||
setAsLearnable(new ItemStack(block));
|
||||
}
|
||||
|
||||
public static void setAsLearnable(Item item) {
|
||||
setAsLearnable(new ItemStack(item));
|
||||
}
|
||||
|
||||
public static void setAsLearnable(ItemStack itemStack) {
|
||||
init();
|
||||
|
||||
if (ee3Mod != null) {
|
||||
EE3Wrapper.ee3mod.getAbilityRegistry().setAsLearnable(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setAsNotLearnable(Block block) {
|
||||
setAsNotLearnable(new ItemStack(block));
|
||||
}
|
||||
|
||||
public static void setAsNotLearnable(Item item) {
|
||||
setAsNotLearnable(new ItemStack(item));
|
||||
}
|
||||
|
||||
public static void setAsNotLearnable(ItemStack itemStack) {
|
||||
init();
|
||||
|
||||
if (ee3Mod != null) {
|
||||
EE3Wrapper.ee3mod.getAbilityRegistry().setAsNotLearnable(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isRecoverable(Block block) {
|
||||
return isRecoverable(new ItemStack(block));
|
||||
}
|
||||
|
||||
public static boolean isRecoverable(Item item) {
|
||||
return isRecoverable(new ItemStack(item));
|
||||
}
|
||||
|
||||
public static boolean isRecoverable(ItemStack itemStack) {
|
||||
init();
|
||||
|
||||
if (ee3Mod != null) {
|
||||
return EE3Wrapper.ee3mod.getAbilityRegistry().isRecoverable(itemStack);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void setAsRecoverable(Block block) {
|
||||
setAsRecoverable(new ItemStack(block));
|
||||
}
|
||||
|
||||
public static void setAsRecoverable(Item item) {
|
||||
setAsRecoverable(new ItemStack(item));
|
||||
}
|
||||
|
||||
public static void setAsRecoverable(ItemStack itemStack) {
|
||||
init();
|
||||
|
||||
if (ee3Mod != null) {
|
||||
EE3Wrapper.ee3mod.getAbilityRegistry().setAsRecoverable(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setAsNotRecoverable(Block block) {
|
||||
setAsNotRecoverable(new ItemStack(block));
|
||||
}
|
||||
|
||||
public static void setAsNotRecoverable(Item item) {
|
||||
setAsNotRecoverable(new ItemStack(item));
|
||||
}
|
||||
|
||||
public static void setAsNotRecoverable(ItemStack itemStack) {
|
||||
init();
|
||||
|
||||
if (ee3Mod != null) {
|
||||
EE3Wrapper.ee3mod.getAbilityRegistry().setAsNotRecoverable(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
private static class EE3Wrapper {
|
||||
private static EquivalentExchange3 ee3mod;
|
||||
}
|
||||
|
||||
private static void init() {
|
||||
if (ee3Mod != null) {
|
||||
EE3Wrapper.ee3mod = (EquivalentExchange3) ee3Mod;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,13 +24,10 @@ public final class EnergyValueRegistryProxy
|
|||
{
|
||||
init();
|
||||
|
||||
// NOOP if EquivalentExchange3 is not present
|
||||
if (ee3Mod == null)
|
||||
if (ee3Mod != null)
|
||||
{
|
||||
return;
|
||||
EE3Wrapper.ee3mod.getEnergyValueRegistry().addPreAssignedEnergyValue(object, energyValue);
|
||||
}
|
||||
|
||||
EE3Wrapper.ee3mod.getEnergyValueRegistry().addPreAssignedEnergyValue(object, energyValue);
|
||||
}
|
||||
|
||||
public static void addPostAssignedEnergyValue(Object object, int energyValue)
|
||||
|
@ -47,13 +44,10 @@ public final class EnergyValueRegistryProxy
|
|||
{
|
||||
init();
|
||||
|
||||
// NOOP if EquivalentExchange3 is not present
|
||||
if (ee3Mod == null)
|
||||
if (ee3Mod != null)
|
||||
{
|
||||
return;
|
||||
EE3Wrapper.ee3mod.getEnergyValueRegistry().addPostAssignedEnergyValue(object, energyValue);
|
||||
}
|
||||
|
||||
EE3Wrapper.ee3mod.getEnergyValueRegistry().addPostAssignedEnergyValue(object, energyValue);
|
||||
}
|
||||
|
||||
public static boolean hasEnergyValue(Object object)
|
||||
|
@ -65,13 +59,12 @@ public final class EnergyValueRegistryProxy
|
|||
{
|
||||
init();
|
||||
|
||||
// NOOP if EquivalentExchange3 is not present
|
||||
if (ee3Mod == null)
|
||||
if (ee3Mod != null)
|
||||
{
|
||||
return false;
|
||||
return EE3Wrapper.ee3mod.getEnergyValueRegistry().hasEnergyValue(object, strict);
|
||||
}
|
||||
|
||||
return EE3Wrapper.ee3mod.getEnergyValueRegistry().hasEnergyValue(object, strict);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static EnergyValue getEnergyValue(Object object)
|
||||
|
@ -83,13 +76,12 @@ public final class EnergyValueRegistryProxy
|
|||
{
|
||||
init();
|
||||
|
||||
// NOOP if EquivalentExchange3 is not present
|
||||
if (ee3Mod == null)
|
||||
if (ee3Mod != null)
|
||||
{
|
||||
return null;
|
||||
return EE3Wrapper.ee3mod.getEnergyValueRegistry().getEnergyValue(object, strict);
|
||||
}
|
||||
|
||||
return EE3Wrapper.ee3mod.getEnergyValueRegistry().getEnergyValue(object, strict);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List getStacksInRange(int start, int finish)
|
||||
|
@ -106,13 +98,12 @@ public final class EnergyValueRegistryProxy
|
|||
{
|
||||
init();
|
||||
|
||||
// NOOP if EquivalentExchange3 is not present
|
||||
if (ee3Mod == null)
|
||||
if (ee3Mod != null)
|
||||
{
|
||||
return null;
|
||||
return EE3Wrapper.ee3mod.getEnergyValueRegistry().getStacksInRange(start, finish);
|
||||
}
|
||||
|
||||
return EE3Wrapper.ee3mod.getEnergyValueRegistry().getStacksInRange(start, finish);
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class EE3Wrapper
|
||||
|
|
|
@ -1,138 +0,0 @@
|
|||
package com.pahimar.ee3.api;
|
||||
|
||||
import com.pahimar.ee3.EquivalentExchange3;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public final class SkillRegistryProxy
|
||||
{
|
||||
@Mod.Instance("EE3")
|
||||
private static Object ee3Mod;
|
||||
|
||||
public static void addSkill(Block block)
|
||||
{
|
||||
addSkill(new ItemStack(block));
|
||||
}
|
||||
|
||||
public static void addSkill(Block block, boolean isLearnable, boolean isRecoverable)
|
||||
{
|
||||
addSkill(new ItemStack(block), isLearnable, isRecoverable);
|
||||
}
|
||||
|
||||
public static void addSkill(Item item)
|
||||
{
|
||||
addSkill(new ItemStack(item));
|
||||
}
|
||||
|
||||
public static void addSkill(Item item, boolean isLearnable, boolean isRecoverable)
|
||||
{
|
||||
addSkill(new ItemStack(item), isLearnable, isRecoverable);
|
||||
}
|
||||
|
||||
public static void addSkill(ItemStack itemStack)
|
||||
{
|
||||
addSkill(itemStack, true, true);
|
||||
}
|
||||
|
||||
public static void addSkill(ItemStack itemStack, boolean isLearnable, boolean isRecovereable)
|
||||
{
|
||||
addSkill(itemStack, isLearnable, isRecovereable, 0);
|
||||
}
|
||||
|
||||
public static void addSkill(ItemStack itemStack, boolean isLearnable, boolean isRecovereable, int knowledgeTier)
|
||||
{
|
||||
init();
|
||||
|
||||
// NOOP if EquivalentExchange3 is not present
|
||||
if (ee3Mod == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EE3Wrapper.ee3mod.getSkillRegistry().addSkill(itemStack, isLearnable, isRecovereable, knowledgeTier);
|
||||
}
|
||||
|
||||
public static boolean isLearnable(Block block)
|
||||
{
|
||||
return isLearnable(new ItemStack(block));
|
||||
}
|
||||
|
||||
public static boolean isLearnable(Item item)
|
||||
{
|
||||
return isLearnable(new ItemStack(item));
|
||||
}
|
||||
|
||||
public static boolean isLearnable(ItemStack itemStack)
|
||||
{
|
||||
init();
|
||||
|
||||
// NOOP if EquivalentExchange3 is not present
|
||||
if (ee3Mod == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return EE3Wrapper.ee3mod.getSkillRegistry().canBeLearned(itemStack);
|
||||
}
|
||||
|
||||
public static boolean isRecoverable(Block block)
|
||||
{
|
||||
return isRecoverable(new ItemStack(block));
|
||||
}
|
||||
|
||||
public static boolean isRecoverable(Item item)
|
||||
{
|
||||
return isRecoverable(new ItemStack(item));
|
||||
}
|
||||
|
||||
public static boolean isRecoverable(ItemStack itemStack)
|
||||
{
|
||||
init();
|
||||
|
||||
// NOOP if EquivalentExchange3 is not present
|
||||
if (ee3Mod == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return EE3Wrapper.ee3mod.getSkillRegistry().isRecoverable(itemStack);
|
||||
}
|
||||
|
||||
public static int getKnowledgeTier(Block block)
|
||||
{
|
||||
return getKnowledgeTier(new ItemStack(block));
|
||||
}
|
||||
|
||||
public static int getKnowledgeTier(Item item)
|
||||
{
|
||||
return getKnowledgeTier(new ItemStack(item));
|
||||
}
|
||||
|
||||
public static int getKnowledgeTier(ItemStack itemStack)
|
||||
{
|
||||
init();
|
||||
|
||||
// NOOP if EquivalentExchange3 is not present
|
||||
if (ee3Mod == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return EE3Wrapper.ee3mod.getSkillRegistry().getKnowledgeTier(itemStack);
|
||||
}
|
||||
|
||||
private static class EE3Wrapper
|
||||
{
|
||||
private static EquivalentExchange3 ee3mod;
|
||||
}
|
||||
|
||||
private static void init()
|
||||
{
|
||||
if (ee3Mod != null)
|
||||
{
|
||||
EE3Wrapper.ee3mod = (EquivalentExchange3) ee3Mod;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,9 +28,6 @@ public class ConfigurationHandler
|
|||
{
|
||||
// TODO Come back and do these constants in logical locations and names
|
||||
Settings.General.syncThreshold = configuration.getInt(Messages.Configuration.GENERAL_SYNC_THRESHOLD, Configuration.CATEGORY_GENERAL, 5, 0, Short.MAX_VALUE, StatCollector.translateToLocal(Messages.Configuration.GENERAL_SYNC_THRESHOLD_COMMENT), Messages.Configuration.GENERAL_SYNC_THRESHOLD_LABEL);
|
||||
Settings.Transmutation.knowledgeMode = ConfigurationHelper.getString(configuration, Messages.Configuration.TRANSMUTATION_KNOWLEDGE_MODE, Messages.Configuration.CATEGORY_TRANSMUTATION, "All", StatCollector.translateToLocal(Messages.Configuration.TRANSMUTATION_KNOWLEDGE_MODE_COMMENT), new String[]{"All", "Select", "Tier", "Restricted", "None"}, Messages.Configuration.TRANSMUTATION_KNOWLEDGE_MODE_LABEL);
|
||||
Settings.Transmutation.maxKnowledgeTier = configuration.getInt(Messages.Configuration.TRANSMUTATION_KNOWLEDGE_MAX_TIER, Messages.Configuration.CATEGORY_TRANSMUTATION, 0, 0, Short.MAX_VALUE, StatCollector.translateToLocal(Messages.Configuration.TRANSMUTATION_KNOWLEDGE_MAX_TIER_COMMENT), Messages.Configuration.TRANSMUTATION_KNOWLEDGE_MAX_TIER_LABEL);
|
||||
Settings.Transmutation.useTemplateFile = configuration.getBoolean(Messages.Configuration.TRANSMUTATION_KNOWLEDGE_TEMPLATE, Messages.Configuration.CATEGORY_TRANSMUTATION, true, StatCollector.translateToLocal(Messages.Configuration.TRANSMUTATION_KNOWLEDGE_TEMPLATE_COMMENT), Messages.Configuration.TRANSMUTATION_KNOWLEDGE_TEMPLATE_LABEL);
|
||||
Settings.Sounds.soundMode = ConfigurationHelper.getString(configuration, Messages.Configuration.SOUND_MODE, Configuration.CATEGORY_GENERAL, "All", StatCollector.translateToLocal(Messages.Configuration.SOUND_MODE_COMMENT), new String[]{"All", "Self", "None"}, Messages.Configuration.SOUND_MODE_LABEL);
|
||||
|
||||
if (configuration.hasChanged())
|
||||
|
|
|
@ -1,262 +0,0 @@
|
|||
package com.pahimar.ee3.handler;
|
||||
|
||||
import com.pahimar.ee3.knowledge.TransmutationKnowledge;
|
||||
import com.pahimar.ee3.reference.Reference;
|
||||
import com.pahimar.ee3.reference.Settings;
|
||||
import com.pahimar.ee3.util.LogHelper;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
// TODO Remove
|
||||
public class TransmutationKnowledgeHandler
|
||||
{
|
||||
public static File playerDataDirectory;
|
||||
public static File transmutationKnowledgeDirectory;
|
||||
|
||||
private static TransmutationKnowledge allowedTransmutationKnowledge;
|
||||
private static TransmutationKnowledge templateTransmutationKnowledge;
|
||||
// TODO Look into caching TransmutationKnowledge for currently logged in players, rather than going to disk constantly
|
||||
|
||||
public static void lazyInitKnowledgeSystem(PlayerEvent.LoadFromFile event)
|
||||
{
|
||||
// Grab the correct directory to be reading/writing player knowledge data to
|
||||
if (playerDataDirectory == null || !playerDataDirectory.getAbsolutePath().equalsIgnoreCase(event.playerDirectory.getAbsolutePath()))
|
||||
{
|
||||
playerDataDirectory = new File(event.playerDirectory, Reference.MOD_ID.toLowerCase());
|
||||
|
||||
if (!playerDataDirectory.exists())
|
||||
{
|
||||
playerDataDirectory.mkdir();
|
||||
}
|
||||
|
||||
transmutationKnowledgeDirectory = new File(playerDataDirectory, "knowledge");
|
||||
|
||||
if (!transmutationKnowledgeDirectory.exists())
|
||||
{
|
||||
transmutationKnowledgeDirectory.mkdir();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static NBTTagCompound getPlayerKnowledge(EntityPlayer entityPlayer)
|
||||
{
|
||||
if (playerDataDirectory != null && playerDataDirectory.isDirectory())
|
||||
{
|
||||
File playerDataFile = new File(playerDataDirectory, entityPlayer.getUniqueID().toString() + KNOWLEDGE_FILE_EXTENSION);
|
||||
|
||||
if (playerDataFile.exists() && playerDataFile.isFile())
|
||||
{
|
||||
try
|
||||
{
|
||||
return CompressedStreamTools.readCompressed(new FileInputStream(playerDataFile));
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
||||
new TransmutationKnowledge().writeToNBT(nbtTagCompound);
|
||||
return nbtTagCompound;
|
||||
}
|
||||
|
||||
public static void savePlayerKnowledge(EntityPlayer entityPlayer)
|
||||
{
|
||||
savePlayerKnowledge(entityPlayer, null);
|
||||
}
|
||||
|
||||
public static void savePlayerKnowledge(EntityPlayer entityPlayer, TransmutationKnowledge transmutationKnowledge)
|
||||
{
|
||||
if (playerDataDirectory != null && playerDataDirectory.isDirectory() && transmutationKnowledgeDirectory != null && transmutationKnowledgeDirectory.isDirectory())
|
||||
{
|
||||
NBTTagCompound transmutationKnowledgeCompound = null;
|
||||
|
||||
if (transmutationKnowledge == null)
|
||||
{
|
||||
if (Settings.Transmutation.useTemplateFile)
|
||||
{
|
||||
transmutationKnowledgeCompound = getTemplateKnowledgeCompound();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
transmutationKnowledge.writeToNBT(transmutationKnowledgeCompound);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
File file1 = new File(transmutationKnowledgeDirectory, entityPlayer.getUniqueID().toString() + KNOWLEDGE_FILE_EXTENSION + ".tmp");
|
||||
File file2 = new File(transmutationKnowledgeDirectory, entityPlayer.getUniqueID().toString() + KNOWLEDGE_FILE_EXTENSION);
|
||||
CompressedStreamTools.writeCompressed(transmutationKnowledgeCompound, new FileOutputStream(file1));
|
||||
|
||||
if (file2.exists())
|
||||
{
|
||||
file2.delete();
|
||||
}
|
||||
|
||||
file1.renameTo(file2);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
LogHelper.warn("Failed to save transmutation knowledge for player '" + entityPlayer.getCommandSenderName() + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static TransmutationKnowledge getTemplateKnowledge()
|
||||
{
|
||||
if (templateTransmutationKnowledge == null)
|
||||
{
|
||||
// TODO Init
|
||||
}
|
||||
|
||||
return templateTransmutationKnowledge;
|
||||
}
|
||||
|
||||
private static void initializeTemplateKnowledge(TransmutationKnowledge templatePlayerKnowledge)
|
||||
{
|
||||
if (playerDataDirectory != null && playerDataDirectory.isDirectory())
|
||||
{
|
||||
File templatePlayerKnowledgeFile = new File(playerDataDirectory, TEMPLATE_FILENAME);
|
||||
|
||||
if (templatePlayerKnowledge == null)
|
||||
{
|
||||
templatePlayerKnowledge = new TransmutationKnowledge();
|
||||
}
|
||||
|
||||
if (!templatePlayerKnowledgeFile.exists())
|
||||
{
|
||||
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
||||
templatePlayerKnowledge.writeToNBT(nbtTagCompound);
|
||||
|
||||
try
|
||||
{
|
||||
CompressedStreamTools.writeCompressed(nbtTagCompound, new FileOutputStream(templatePlayerKnowledgeFile));
|
||||
} catch (Exception exception)
|
||||
{
|
||||
LogHelper.warn("Failed to initialize player knowledge template file");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static NBTTagCompound getTemplateKnowledgeCompound()
|
||||
{
|
||||
if (playerDataDirectory != null && playerDataDirectory.isDirectory())
|
||||
{
|
||||
File templateKnowledgeFile = new File(playerDataDirectory, TEMPLATE_FILENAME);
|
||||
|
||||
if (templateKnowledgeFile.exists() && templateKnowledgeFile.isFile())
|
||||
{
|
||||
try
|
||||
{
|
||||
return CompressedStreamTools.readCompressed(new FileInputStream(templateKnowledgeFile));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
initializeTemplateKnowledge(null);
|
||||
}
|
||||
}
|
||||
|
||||
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
||||
new TransmutationKnowledge().writeToNBT(nbtTagCompound);
|
||||
return nbtTagCompound;
|
||||
}
|
||||
|
||||
public static void saveTemplateKnowledge()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static TransmutationKnowledge getAllowedTransmutations()
|
||||
{
|
||||
if (allowedTransmutationKnowledge == null)
|
||||
{
|
||||
// TODO Init
|
||||
}
|
||||
|
||||
return allowedTransmutationKnowledge;
|
||||
// return new TransmutationKnowledge(getAllowedKnowledgeFile());
|
||||
}
|
||||
|
||||
private static void initializeAllowedKnowledgeFile(TransmutationKnowledge allowedKnowledgeFile)
|
||||
{
|
||||
if (playerDataDirectory != null && playerDataDirectory.isDirectory())
|
||||
{
|
||||
File templatePlayerKnowledgeFile = new File(playerDataDirectory, ALLOWED_KNOWLEDGE_FILENAME);
|
||||
|
||||
if (allowedKnowledgeFile == null)
|
||||
{
|
||||
allowedKnowledgeFile = new TransmutationKnowledge();
|
||||
}
|
||||
|
||||
if (!templatePlayerKnowledgeFile.exists())
|
||||
{
|
||||
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
||||
allowedKnowledgeFile.writeToNBT(nbtTagCompound);
|
||||
|
||||
try
|
||||
{
|
||||
CompressedStreamTools.writeCompressed(nbtTagCompound, new FileOutputStream(templatePlayerKnowledgeFile));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
LogHelper.warn("Failed to initialize transmutation knowledge template file");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static NBTTagCompound getAllowedKnowledgeFile()
|
||||
{
|
||||
if (playerDataDirectory != null && playerDataDirectory.isDirectory())
|
||||
{
|
||||
File allowedKnowledgeFile = new File(playerDataDirectory, ALLOWED_KNOWLEDGE_FILENAME);
|
||||
|
||||
if (allowedKnowledgeFile.exists() && allowedKnowledgeFile.isFile())
|
||||
{
|
||||
try
|
||||
{
|
||||
return CompressedStreamTools.readCompressed(new FileInputStream(allowedKnowledgeFile));
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} finally
|
||||
{
|
||||
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
||||
new TransmutationKnowledge().writeToNBT(nbtTagCompound);
|
||||
return nbtTagCompound;
|
||||
}
|
||||
} else
|
||||
{
|
||||
initializeAllowedKnowledgeFile(null);
|
||||
}
|
||||
}
|
||||
|
||||
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
||||
new TransmutationKnowledge().writeToNBT(nbtTagCompound);
|
||||
return nbtTagCompound;
|
||||
}
|
||||
|
||||
public static void saveAllowedKnowledge()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static final String KNOWLEDGE_FILE_EXTENSION = ".transmutation";
|
||||
private static final String TEMPLATE_FILENAME = "template" + KNOWLEDGE_FILE_EXTENSION;
|
||||
private static final String ALLOWED_KNOWLEDGE_FILENAME = "allowed" + KNOWLEDGE_FILE_EXTENSION;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.pahimar.ee3.init;
|
||||
|
||||
import com.pahimar.ee3.api.SkillRegistryProxy;
|
||||
import com.pahimar.ee3.api.AbilityRegistryProxy;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
|
@ -14,9 +14,9 @@ public class Skills
|
|||
{
|
||||
for (ItemStack oreStack : OreDictionary.getOres(oreName))
|
||||
{
|
||||
SkillRegistryProxy.addSkill(oreStack, false, true);
|
||||
AbilityRegistryProxy.setAsNotLearnable(oreStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
71
src/main/java/com/pahimar/ee3/knowledge/AbilityRegistry.java
Normal file
71
src/main/java/com/pahimar/ee3/knowledge/AbilityRegistry.java
Normal file
|
@ -0,0 +1,71 @@
|
|||
package com.pahimar.ee3.knowledge;
|
||||
|
||||
import com.pahimar.ee3.exchange.WrappedStack;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
// TODO Serialize the sets to separate JSON for map makers, cause you know, I love them
|
||||
public class AbilityRegistry {
|
||||
private static AbilityRegistry AbilityRegistry = null;
|
||||
private Set<WrappedStack> notLearnableSet;
|
||||
private Set<WrappedStack> notRecoverableSet;
|
||||
|
||||
private AbilityRegistry() {
|
||||
}
|
||||
|
||||
public static AbilityRegistry getInstance() {
|
||||
if (AbilityRegistry == null) {
|
||||
AbilityRegistry = new AbilityRegistry();
|
||||
AbilityRegistry.init();
|
||||
}
|
||||
|
||||
return AbilityRegistry;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
notLearnableSet = new TreeSet<WrappedStack>();
|
||||
notRecoverableSet = new TreeSet<WrappedStack>();
|
||||
}
|
||||
|
||||
public boolean isLearnable(Object object) {
|
||||
if (WrappedStack.canBeWrapped(object)) {
|
||||
WrappedStack wrappedObject = new WrappedStack(object);
|
||||
return !notLearnableSet.contains(wrappedObject);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setAsLearnable(Object object) {
|
||||
if (WrappedStack.canBeWrapped(object)) {
|
||||
notLearnableSet.remove(new WrappedStack(object));
|
||||
}
|
||||
}
|
||||
|
||||
public void setAsNotLearnable(Object object) {
|
||||
if (WrappedStack.canBeWrapped(object)) {
|
||||
notLearnableSet.add(new WrappedStack(object));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRecoverable(Object object) {
|
||||
if (WrappedStack.canBeWrapped(object)) {
|
||||
return !notRecoverableSet.contains(new WrappedStack(object));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setAsRecoverable(Object object) {
|
||||
if (WrappedStack.canBeWrapped(object)) {
|
||||
notRecoverableSet.remove(new WrappedStack(object));
|
||||
}
|
||||
}
|
||||
|
||||
public void setAsNotRecoverable(Object object) {
|
||||
if (WrappedStack.canBeWrapped(object)) {
|
||||
notRecoverableSet.add(new WrappedStack(object));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package com.pahimar.ee3.knowledge;
|
||||
|
||||
public class Skill
|
||||
{
|
||||
private final boolean learnable;
|
||||
private final boolean recoverable;
|
||||
private final int knowledgeTier;
|
||||
|
||||
public Skill()
|
||||
{
|
||||
this(true, true, 0);
|
||||
}
|
||||
|
||||
public Skill(boolean learnable, boolean recoverable)
|
||||
{
|
||||
this(learnable, recoverable, 0);
|
||||
}
|
||||
|
||||
public Skill(boolean learnable, boolean recoverable, int tier)
|
||||
{
|
||||
this.learnable = learnable;
|
||||
this.recoverable = recoverable;
|
||||
|
||||
if (tier >= 0)
|
||||
{
|
||||
this.knowledgeTier = tier;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.knowledgeTier = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isLearnable()
|
||||
{
|
||||
return learnable;
|
||||
}
|
||||
|
||||
public boolean isRecoverable()
|
||||
{
|
||||
return recoverable;
|
||||
}
|
||||
|
||||
public int getKnowledgeTier()
|
||||
{
|
||||
return knowledgeTier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object)
|
||||
{
|
||||
return object instanceof Skill && (this.learnable == ((Skill) object).learnable && this.recoverable == ((Skill) object).recoverable && this.knowledgeTier == ((Skill) object).knowledgeTier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("Skill[learnable: %s, recoverable: %s, knowledgeTier: %s]", learnable, recoverable, knowledgeTier);
|
||||
}
|
||||
}
|
|
@ -1,153 +0,0 @@
|
|||
package com.pahimar.ee3.knowledge;
|
||||
|
||||
import com.pahimar.ee3.exchange.EnergyValueRegistry;
|
||||
import com.pahimar.ee3.exchange.WrappedStack;
|
||||
import com.pahimar.ee3.handler.TransmutationKnowledgeHandler;
|
||||
import com.pahimar.ee3.reference.Settings;
|
||||
import com.pahimar.ee3.util.ItemHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
// TODO Change up so that we only track what is not learnable, and what is not recoverable
|
||||
// Everything that has an EnergyValue is learnable and recoverable unless there is an entry for it in either of these lists
|
||||
public class SkillRegistry
|
||||
{
|
||||
private static SkillRegistry SkillRegistry = null;
|
||||
private SortedMap<ItemStack, Skill> transmutationSkills;
|
||||
private Set<WrappedStack> notLearnableSet;
|
||||
private Set<WrappedStack> notRecoverableSet;
|
||||
|
||||
private SkillRegistry()
|
||||
{
|
||||
}
|
||||
|
||||
public static SkillRegistry getInstance()
|
||||
{
|
||||
if (SkillRegistry == null)
|
||||
{
|
||||
SkillRegistry = new SkillRegistry();
|
||||
SkillRegistry.init();
|
||||
}
|
||||
|
||||
return SkillRegistry;
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
transmutationSkills = new TreeMap<ItemStack, Skill>(ItemHelper.comparator);
|
||||
notLearnableSet = new TreeSet<WrappedStack>();
|
||||
notRecoverableSet = new TreeSet<WrappedStack>();
|
||||
}
|
||||
|
||||
public void addSkill(ItemStack itemStack, boolean learnable, boolean recoverable)
|
||||
{
|
||||
addSkill(itemStack, new Skill(learnable, recoverable, 0));
|
||||
}
|
||||
|
||||
public void addSkill(ItemStack itemStack, boolean learnable, boolean recoverable, int tier)
|
||||
{
|
||||
addSkill(itemStack, new Skill(learnable, recoverable, tier));
|
||||
}
|
||||
|
||||
private void addSkill(ItemStack itemStack, Skill skill)
|
||||
{
|
||||
ItemStack unitItemStack = itemStack.copy();
|
||||
unitItemStack.stackSize = 1;
|
||||
|
||||
if (!transmutationSkills.containsKey(unitItemStack))
|
||||
{
|
||||
transmutationSkills.put(unitItemStack, skill);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasSkillMapping(ItemStack itemStack)
|
||||
{
|
||||
ItemStack unitItemStack = itemStack.copy();
|
||||
unitItemStack.stackSize = 1;
|
||||
|
||||
return transmutationSkills.containsKey(unitItemStack);
|
||||
}
|
||||
|
||||
public boolean canBeLearned(ItemStack itemStack)
|
||||
{
|
||||
ItemStack unitItemStack = itemStack.copy();
|
||||
unitItemStack.stackSize = 1;
|
||||
|
||||
if (transmutationSkills.containsKey(unitItemStack))
|
||||
{
|
||||
return transmutationSkills.get(unitItemStack).isLearnable();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean canLearnItemStack(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack == null || itemStack.getItem() == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Settings.Transmutation.knowledgeMode.equalsIgnoreCase("All"))
|
||||
{
|
||||
if (SkillRegistry.getInstance().hasSkillMapping(itemStack))
|
||||
{
|
||||
return EnergyValueRegistry.getInstance().hasEnergyValue(itemStack) && SkillRegistry.getInstance().canBeLearned(itemStack);
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnergyValueRegistry.getInstance().hasEnergyValue(itemStack);
|
||||
}
|
||||
}
|
||||
else if (Settings.Transmutation.knowledgeMode.equalsIgnoreCase("Select"))
|
||||
{
|
||||
return EnergyValueRegistry.getInstance().hasEnergyValue(itemStack) && SkillRegistry.getInstance().canBeLearned(itemStack);
|
||||
}
|
||||
else if (Settings.Transmutation.knowledgeMode.equalsIgnoreCase("Tier"))
|
||||
{
|
||||
int itemStackKnowledgeTier = SkillRegistry.getInstance().getKnowledgeTier(itemStack);
|
||||
|
||||
return EnergyValueRegistry.getInstance().hasEnergyValue(itemStack) && SkillRegistry.getInstance().canBeLearned(itemStack) && itemStackKnowledgeTier >= 0 && itemStackKnowledgeTier <= Settings.Transmutation.maxKnowledgeTier;
|
||||
}
|
||||
else if (Settings.Transmutation.knowledgeMode.equalsIgnoreCase("Restricted"))
|
||||
{
|
||||
TransmutationKnowledge allowedKnowledge = TransmutationKnowledgeHandler.getAllowedTransmutations();
|
||||
|
||||
return EnergyValueRegistry.getInstance().hasEnergyValue(itemStack) && SkillRegistry.getInstance().canBeLearned(itemStack) && allowedKnowledge.isKnown(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isRecoverable(ItemStack itemStack)
|
||||
{
|
||||
ItemStack unitItemStack = itemStack.copy();
|
||||
unitItemStack.stackSize = 1;
|
||||
|
||||
if (transmutationSkills.containsKey(unitItemStack))
|
||||
{
|
||||
return transmutationSkills.get(unitItemStack).isRecoverable();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getKnowledgeTier(ItemStack itemStack)
|
||||
{
|
||||
ItemStack unitItemStack = itemStack.copy();
|
||||
unitItemStack.stackSize = 1;
|
||||
|
||||
if (transmutationSkills.containsKey(unitItemStack))
|
||||
{
|
||||
return transmutationSkills.get(unitItemStack).getKnowledgeTier();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
|
@ -15,20 +15,6 @@ public final class Messages
|
|||
public static final String GENERAL_SYNC_THRESHOLD_LABEL = "general.sync.threshold.label";
|
||||
public static final String GENERAL_SYNC_THRESHOLD_COMMENT = "general.sync.threshold.comment";
|
||||
|
||||
public static final String CATEGORY_TRANSMUTATION = "general.transmutation";
|
||||
|
||||
public static final String TRANSMUTATION_KNOWLEDGE_MODE = "knowledgeMode";
|
||||
public static final String TRANSMUTATION_KNOWLEDGE_MODE_LABEL = "general.transmutation.knowledge.mode.label";
|
||||
public static final String TRANSMUTATION_KNOWLEDGE_MODE_COMMENT = "general.transmutation.knowledge.mode.comment";
|
||||
|
||||
public static final String TRANSMUTATION_KNOWLEDGE_MAX_TIER = "maxTier";
|
||||
public static final String TRANSMUTATION_KNOWLEDGE_MAX_TIER_LABEL = "general.transmutation.knowledge.maxTier.label";
|
||||
public static final String TRANSMUTATION_KNOWLEDGE_MAX_TIER_COMMENT = "general.transmutation.knowledge.maxTier.comment";
|
||||
|
||||
public static final String TRANSMUTATION_KNOWLEDGE_TEMPLATE = "useTemplateFile";
|
||||
public static final String TRANSMUTATION_KNOWLEDGE_TEMPLATE_LABEL = "general.transmutation.knowledge.template.label";
|
||||
public static final String TRANSMUTATION_KNOWLEDGE_TEMPLATE_COMMENT = "general.transmutation.knowledge.template.comment";
|
||||
|
||||
public static final String SOUND_MODE = "soundMode";
|
||||
public static final String SOUND_MODE_LABEL = "general.sound.soundMode.label";
|
||||
public static final String SOUND_MODE_COMMENT = "general.sound.soundMode.comment";
|
||||
|
|
|
@ -7,13 +7,6 @@ public class Settings
|
|||
public static int syncThreshold;
|
||||
}
|
||||
|
||||
public static class Transmutation
|
||||
{
|
||||
public static String knowledgeMode;
|
||||
public static int maxKnowledgeTier;
|
||||
public static boolean useTemplateFile;
|
||||
}
|
||||
|
||||
public static class Sounds
|
||||
{
|
||||
public static String soundMode;
|
||||
|
|
Loading…
Reference in a new issue