Rewrote the Ability system to be what it was really trying to be, a blacklist registry. Also fixed writing the data to a global area, and made it one file per blacklist. Fixes #898 and #991
This commit is contained in:
parent
160a923ef4
commit
2046edf3fb
|
@ -1,11 +1,11 @@
|
|||
package com.pahimar.ee3;
|
||||
|
||||
import com.pahimar.ee3.array.AlchemyArrayRegistry;
|
||||
import com.pahimar.ee3.blacklist.BlacklistRegistry;
|
||||
import com.pahimar.ee3.command.CommandEE;
|
||||
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.network.PacketHandler;
|
||||
import com.pahimar.ee3.proxy.IProxy;
|
||||
|
@ -55,7 +55,6 @@ public class EquivalentExchange3
|
|||
Files.updateFileReferences();
|
||||
|
||||
SerializationHelper.initModDataDirectories();
|
||||
AbilityRegistry.getInstance().loadAbilityRegistryFromFile(ConfigurationHandler.Settings.onlyLoadFile);
|
||||
event.registerServerCommand(new CommandEE());
|
||||
}
|
||||
|
||||
|
@ -79,6 +78,8 @@ public class EquivalentExchange3
|
|||
EnergyValues.init();
|
||||
|
||||
AlchemyArrays.registerAlchemyArrays();
|
||||
|
||||
BlacklistRegistry.INSTANCE.load();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -118,8 +119,7 @@ public class EquivalentExchange3
|
|||
WorldEventHandler.hasInitilialized = false;
|
||||
EnergyValueRegistry.INSTANCE.save();
|
||||
PlayerKnowledgeRegistry.INSTANCE.saveAll();
|
||||
|
||||
AbilityRegistry.getInstance().save();
|
||||
BlacklistRegistry.INSTANCE.saveAll();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -149,9 +149,8 @@ public class EquivalentExchange3
|
|||
return AludelRecipeManager.getInstance();
|
||||
}
|
||||
|
||||
public AbilityRegistry getAbilityRegistry()
|
||||
{
|
||||
return AbilityRegistry.getInstance();
|
||||
public BlacklistRegistry getBlacklistRegistry() {
|
||||
return BlacklistRegistry.INSTANCE;
|
||||
}
|
||||
|
||||
public AlchemyArrayRegistry getAlchemyArrayRegistry()
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
package com.pahimar.ee3.api.blacklist;
|
||||
|
||||
import com.pahimar.ee3.EquivalentExchange3;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
|
||||
public class BlacklistRegistryProxy {
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*
|
||||
* @param object
|
||||
* @return
|
||||
*/
|
||||
public static boolean isLearnable(Object object) {
|
||||
|
||||
init();
|
||||
|
||||
if (ee3Mod != null) {
|
||||
return EE3Wrapper.ee3mod.getBlacklistRegistry().isLearnable(object);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*
|
||||
* @param object
|
||||
* @return
|
||||
*/
|
||||
public static boolean isExchangeable(Object object) {
|
||||
|
||||
init();
|
||||
|
||||
if (ee3Mod != null) {
|
||||
return EE3Wrapper.ee3mod.getBlacklistRegistry().isExchangeable(object);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*
|
||||
* @param object
|
||||
*/
|
||||
public static void setAsLearnable(Object object) {
|
||||
removeFromBlacklist(object, Blacklist.KNOWLEDGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*
|
||||
* @param object
|
||||
*/
|
||||
public static void setAsNotLearnable(Object object) {
|
||||
addToBlacklist(object, Blacklist.KNOWLEDGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*
|
||||
* @param object
|
||||
*/
|
||||
public static void setAsExchangeable(Object object) {
|
||||
removeFromBlacklist(object, Blacklist.EXCHANGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*
|
||||
* @param object
|
||||
*/
|
||||
public static void setAsNotExchangeable(Object object) {
|
||||
addToBlacklist(object, Blacklist.EXCHANGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*
|
||||
* @param object
|
||||
* @param blacklist
|
||||
*/
|
||||
public static void addToBlacklist(Object object, Blacklist blacklist) {
|
||||
|
||||
init();
|
||||
|
||||
if (ee3Mod != null) {
|
||||
EE3Wrapper.ee3mod.getBlacklistRegistry().addToBlacklist(object, blacklist);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*
|
||||
* @param object
|
||||
* @param blacklist
|
||||
*/
|
||||
public static void removeFromBlacklist(Object object, Blacklist blacklist) {
|
||||
|
||||
init();
|
||||
|
||||
if (ee3Mod != null) {
|
||||
EE3Wrapper.ee3mod.getBlacklistRegistry().removeFromBlacklist(object, blacklist);
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.Instance("EE3")
|
||||
private static Object ee3Mod;
|
||||
|
||||
private static class EE3Wrapper {
|
||||
private static EquivalentExchange3 ee3mod;
|
||||
}
|
||||
|
||||
private static void init() {
|
||||
|
||||
if (ee3Mod != null) {
|
||||
BlacklistRegistryProxy.EE3Wrapper.ee3mod = (EquivalentExchange3) ee3Mod;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Blacklist {
|
||||
KNOWLEDGE,
|
||||
EXCHANGE
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
@API(owner = "EE3", apiVersion = "@API_VERSION@", provides = "EE3-API|blacklist") package com.pahimar.ee3.api.blacklist;
|
||||
|
||||
import cpw.mods.fml.common.API;
|
|
@ -2,21 +2,30 @@ package com.pahimar.ee3.api.event;
|
|||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
public class AbilityEvent extends Event
|
||||
{
|
||||
/**
|
||||
* @deprecated See {@link BlacklistEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public class AbilityEvent extends Event {
|
||||
|
||||
public final Object object;
|
||||
|
||||
public AbilityEvent(Object object)
|
||||
{
|
||||
/**
|
||||
* @deprecated See {@link BlacklistEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public AbilityEvent(Object object) {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated See {@link com.pahimar.ee3.api.event.BlacklistEvent.KnowledgeWhitelistEvent}
|
||||
*/
|
||||
public static class SetLearnableEvent extends AbilityEvent
|
||||
{
|
||||
public SetLearnableEvent(Object object)
|
||||
|
@ -25,6 +34,9 @@ public class AbilityEvent extends Event
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated See {@link com.pahimar.ee3.api.event.BlacklistEvent.KnowledgeBlacklistEvent}
|
||||
*/
|
||||
public static class SetNotLearnableEvent extends AbilityEvent
|
||||
{
|
||||
public SetNotLearnableEvent(Object object)
|
||||
|
@ -33,6 +45,9 @@ public class AbilityEvent extends Event
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated See {@link com.pahimar.ee3.api.event.BlacklistEvent.ExchangeWhitelistEvent}
|
||||
*/
|
||||
public static class SetRecoverableEvent extends AbilityEvent
|
||||
{
|
||||
public SetRecoverableEvent(Object object)
|
||||
|
@ -41,6 +56,9 @@ public class AbilityEvent extends Event
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated See {@link com.pahimar.ee3.api.event.BlacklistEvent.ExchangeBlacklistEvent}
|
||||
*/
|
||||
public static class SetNotRecoverableEvent extends AbilityEvent
|
||||
{
|
||||
public SetNotRecoverableEvent(Object object)
|
||||
|
|
45
src/main/java/com/pahimar/ee3/api/event/BlacklistEvent.java
Normal file
45
src/main/java/com/pahimar/ee3/api/event/BlacklistEvent.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
package com.pahimar.ee3.api.event;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
public class BlacklistEvent extends Event {
|
||||
|
||||
public final Object object;
|
||||
|
||||
public BlacklistEvent(Object object) {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class KnowledgeBlacklistEvent extends BlacklistEvent {
|
||||
|
||||
public KnowledgeBlacklistEvent(Object object) {
|
||||
super(object);
|
||||
}
|
||||
}
|
||||
|
||||
public static class KnowledgeWhitelistEvent extends BlacklistEvent {
|
||||
|
||||
public KnowledgeWhitelistEvent(Object object) {
|
||||
super(object);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ExchangeBlacklistEvent extends BlacklistEvent {
|
||||
|
||||
public ExchangeBlacklistEvent(Object object) {
|
||||
super(object);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ExchangeWhitelistEvent extends BlacklistEvent {
|
||||
|
||||
public ExchangeWhitelistEvent(Object object) {
|
||||
super(object);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,5 @@
|
|||
package com.pahimar.ee3.api.exchange;
|
||||
|
||||
import com.pahimar.ee3.EquivalentExchange3;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -21,7 +18,6 @@ public final class RecipeRegistryProxy {
|
|||
*/
|
||||
@Deprecated
|
||||
public static void addRecipe(Object recipeOutput, List<?> recipeInputList) {
|
||||
|
||||
com.pahimar.ee3.api.recipe.RecipeRegistryProxy.addRecipe(recipeOutput, recipeInputList);
|
||||
}
|
||||
|
||||
|
@ -31,21 +27,6 @@ public final class RecipeRegistryProxy {
|
|||
*/
|
||||
@Deprecated
|
||||
public static void dumpRecipeRegistryToLog() {
|
||||
|
||||
com.pahimar.ee3.api.recipe.RecipeRegistryProxy.dumpRecipeRegistryToLog();
|
||||
}
|
||||
|
||||
@Mod.Instance("EE3")
|
||||
private static Object ee3Mod;
|
||||
|
||||
private static class EE3Wrapper {
|
||||
private static EquivalentExchange3 ee3mod;
|
||||
}
|
||||
|
||||
private static void init() {
|
||||
|
||||
if (ee3Mod != null) {
|
||||
EE3Wrapper.ee3mod = (EquivalentExchange3) ee3Mod;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,107 +1,67 @@
|
|||
package com.pahimar.ee3.api.knowledge;
|
||||
|
||||
import com.pahimar.ee3.EquivalentExchange3;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
|
||||
public final class AbilityRegistryProxy
|
||||
{
|
||||
@Mod.Instance("EE3")
|
||||
private static Object ee3Mod;
|
||||
@Deprecated
|
||||
public final class AbilityRegistryProxy {
|
||||
|
||||
public static boolean isLearnable(Object object)
|
||||
{
|
||||
init();
|
||||
|
||||
if (ee3Mod != null)
|
||||
{
|
||||
return EE3Wrapper.ee3mod.getAbilityRegistry().isLearnable(object);
|
||||
}
|
||||
|
||||
return false;
|
||||
/**
|
||||
* @deprecated See {@link BlacklistRegistryProxy#isLearnable(Object)}
|
||||
*/
|
||||
public static boolean isLearnable(Object object) {
|
||||
return BlacklistRegistryProxy.isLearnable(object);
|
||||
}
|
||||
|
||||
public static void setAsLearnable(Object object)
|
||||
{
|
||||
init();
|
||||
|
||||
if (ee3Mod != null)
|
||||
{
|
||||
EE3Wrapper.ee3mod.getAbilityRegistry().setAsLearnable(object);
|
||||
}
|
||||
/**
|
||||
* @deprecated See {@link BlacklistRegistryProxy#setAsLearnable(Object)}
|
||||
*/
|
||||
public static void setAsLearnable(Object object) {
|
||||
BlacklistRegistryProxy.setAsLearnable(object);
|
||||
}
|
||||
|
||||
public static void setAsNotLearnable(Object object)
|
||||
{
|
||||
init();
|
||||
|
||||
if (ee3Mod != null)
|
||||
{
|
||||
EE3Wrapper.ee3mod.getAbilityRegistry().setAsNotLearnable(object);
|
||||
}
|
||||
/**
|
||||
* @deprecated See {@link BlacklistRegistryProxy#setAsNotLearnable(Object)}
|
||||
*/
|
||||
public static void setAsNotLearnable(Object object) {
|
||||
BlacklistRegistryProxy.setAsNotLearnable(object);
|
||||
}
|
||||
|
||||
public static boolean isRecoverable(Object object)
|
||||
{
|
||||
init();
|
||||
|
||||
if (ee3Mod != null)
|
||||
{
|
||||
return EE3Wrapper.ee3mod.getAbilityRegistry().isRecoverable(object);
|
||||
}
|
||||
|
||||
return false;
|
||||
/**
|
||||
* @deprecated See {@link BlacklistRegistryProxy#isExchangeable(Object)}
|
||||
*/
|
||||
public static boolean isRecoverable(Object object) {
|
||||
return BlacklistRegistryProxy.isExchangeable(object);
|
||||
}
|
||||
|
||||
public static void setAsRecoverable(Object object)
|
||||
{
|
||||
init();
|
||||
|
||||
if (ee3Mod != null)
|
||||
{
|
||||
EE3Wrapper.ee3mod.getAbilityRegistry().setAsRecoverable(object);
|
||||
}
|
||||
/**
|
||||
* @deprecated See {@link BlacklistRegistryProxy#setAsExchangeable(Object)}
|
||||
*/
|
||||
public static void setAsRecoverable(Object object) {
|
||||
BlacklistRegistryProxy.setAsExchangeable(object);
|
||||
}
|
||||
|
||||
public static void setAsNotRecoverable(Object object)
|
||||
{
|
||||
init();
|
||||
|
||||
if (ee3Mod != null)
|
||||
{
|
||||
EE3Wrapper.ee3mod.getAbilityRegistry().setAsNotRecoverable(object);
|
||||
}
|
||||
/**
|
||||
* @deprecated See {@link BlacklistRegistryProxy#setAsNotExchangeable(Object)}
|
||||
*/
|
||||
public static void setAsNotRecoverable(Object object) {
|
||||
BlacklistRegistryProxy.setAsNotExchangeable(object);
|
||||
}
|
||||
|
||||
public static void dumpAbilityRegistryToLog()
|
||||
{
|
||||
dumpAbilityRegistryToLog(Abilities.ALL);
|
||||
/**
|
||||
* @deprecated will be removed from EE3 in newer versions of Minecraft
|
||||
*/
|
||||
public static void dumpAbilityRegistryToLog() {
|
||||
// NOOP
|
||||
}
|
||||
|
||||
public static void dumpAbilityRegistryToLog(Abilities ability)
|
||||
{
|
||||
init();
|
||||
|
||||
if (ee3Mod != null)
|
||||
{
|
||||
EE3Wrapper.ee3mod.getAbilityRegistry().dumpAbilityRegistryToLog(ability);
|
||||
}
|
||||
/**
|
||||
* @deprecated will be removed from EE3 in newer versions of Minecraft
|
||||
*/
|
||||
public static void dumpAbilityRegistryToLog(Abilities ability) {
|
||||
// NOOP
|
||||
}
|
||||
|
||||
private static class EE3Wrapper
|
||||
{
|
||||
private static EquivalentExchange3 ee3mod;
|
||||
}
|
||||
|
||||
private static void init()
|
||||
{
|
||||
if (ee3Mod != null)
|
||||
{
|
||||
EE3Wrapper.ee3mod = (EquivalentExchange3) ee3Mod;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Abilities
|
||||
{
|
||||
public enum Abilities {
|
||||
NOT_LEARNABLE,
|
||||
NOT_RECOVERABLE,
|
||||
ALL
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.pahimar.ee3.api.knowledge;
|
||||
|
||||
import com.pahimar.ee3.EquivalentExchange3;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
@ -130,17 +128,4 @@ public class TransmutationKnowledgeRegistryProxy {
|
|||
public static void makeTemplateForgetEverything() {
|
||||
// NOOP
|
||||
}
|
||||
|
||||
@Mod.Instance("EE3")
|
||||
private static Object ee3Mod;
|
||||
|
||||
private static class EE3Wrapper {
|
||||
private static EquivalentExchange3 ee3mod;
|
||||
}
|
||||
|
||||
private static void init() {
|
||||
if (ee3Mod != null) {
|
||||
EE3Wrapper.ee3mod = (EquivalentExchange3) ee3Mod;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
192
src/main/java/com/pahimar/ee3/blacklist/BlacklistRegistry.java
Normal file
192
src/main/java/com/pahimar/ee3/blacklist/BlacklistRegistry.java
Normal file
|
@ -0,0 +1,192 @@
|
|||
package com.pahimar.ee3.blacklist;
|
||||
|
||||
import com.pahimar.ee3.api.exchange.EnergyValueRegistryProxy;
|
||||
import com.pahimar.ee3.exchange.WrappedStack;
|
||||
import com.pahimar.ee3.util.LoaderHelper;
|
||||
import com.pahimar.ee3.util.LogHelper;
|
||||
import com.pahimar.ee3.util.SerializationHelper;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy.Blacklist;
|
||||
import static com.pahimar.ee3.api.event.BlacklistEvent.*;
|
||||
|
||||
// TODO Logging
|
||||
public class BlacklistRegistry {
|
||||
|
||||
public static final BlacklistRegistry INSTANCE = new BlacklistRegistry();
|
||||
|
||||
private static final Marker BLACKLIST_MARKER = MarkerManager.getMarker("EE3_BLACKLIST", LogHelper.MOD_MARKER);
|
||||
private static final Marker KNOWLEDGE_BLACKLIST_MARKER = MarkerManager.getMarker("EE3_BLACKLIST_KNOWLEDGE", BLACKLIST_MARKER);
|
||||
private static final Marker KNOWLEDGE_WHITELIST_MARKER = MarkerManager.getMarker("EE3_WHITELIST_KNOWLEDGE", BLACKLIST_MARKER);
|
||||
private static final Marker EXCHANGE_BLACKLIST_MARKER = MarkerManager.getMarker("EE3_BLACKLIST_EXCHANGE", BLACKLIST_MARKER);
|
||||
private static final Marker EXCHANGE_WHITELIST_MARKER = MarkerManager.getMarker("EE3_WHITELIST_EXCHANGE", BLACKLIST_MARKER);
|
||||
|
||||
private final Set<WrappedStack> knowledgeBlacklist;
|
||||
private final Set<WrappedStack> exchangeBlacklist;
|
||||
|
||||
public static File knowledgeBlacklistFile;
|
||||
public static File exchangeBlacklistFile;
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*/
|
||||
private BlacklistRegistry() {
|
||||
|
||||
knowledgeBlacklist = new TreeSet<>();
|
||||
exchangeBlacklist = new TreeSet<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*
|
||||
* @param object
|
||||
* @return
|
||||
*/
|
||||
public boolean isLearnable(Object object) {
|
||||
|
||||
if (WrappedStack.canBeWrapped(object)) {
|
||||
|
||||
WrappedStack wrappedObject = WrappedStack.wrap(object, 1);
|
||||
|
||||
if (object instanceof ItemStack && ((ItemStack) object).isItemDamaged()) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return !knowledgeBlacklist.contains(wrappedObject) && EnergyValueRegistryProxy.hasEnergyValue(wrappedObject);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*
|
||||
* @param object
|
||||
* @return
|
||||
*/
|
||||
public boolean isExchangeable(Object object) {
|
||||
|
||||
if (WrappedStack.canBeWrapped(object)) {
|
||||
|
||||
WrappedStack wrappedStack = WrappedStack.wrap(object, 1);
|
||||
return !exchangeBlacklist.contains(wrappedStack) && EnergyValueRegistryProxy.hasEnergyValue(wrappedStack);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*
|
||||
* @param object
|
||||
* @param blacklist
|
||||
*/
|
||||
public void addToBlacklist(Object object, Blacklist blacklist) {
|
||||
|
||||
if (WrappedStack.canBeWrapped(object)) {
|
||||
|
||||
WrappedStack wrappedStack = WrappedStack.wrap(object, 1);
|
||||
|
||||
if (blacklist == Blacklist.KNOWLEDGE) {
|
||||
if (wrappedStack != null && !MinecraftForge.EVENT_BUS.post(new KnowledgeBlacklistEvent(object))) {
|
||||
LogHelper.trace(KNOWLEDGE_BLACKLIST_MARKER, "[{}] Mod with ID '{}' added object {} to the player knowledge blacklist", LoaderHelper.getLoaderState(), Loader.instance().activeModContainer().getModId(), wrappedStack);
|
||||
knowledgeBlacklist.add(WrappedStack.wrap(object, 1));
|
||||
save(blacklist);
|
||||
}
|
||||
}
|
||||
else if (blacklist == Blacklist.EXCHANGE) {
|
||||
if (wrappedStack != null && !MinecraftForge.EVENT_BUS.post(new ExchangeBlacklistEvent(object))) {
|
||||
LogHelper.trace(EXCHANGE_BLACKLIST_MARKER, "[{}] Mod with ID '{}' added object {} to the exchange blacklist", LoaderHelper.getLoaderState(), Loader.instance().activeModContainer().getModId(), wrappedStack);
|
||||
exchangeBlacklist.add(WrappedStack.wrap(object, 1));
|
||||
save(blacklist);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*
|
||||
* @param object
|
||||
* @param blacklist
|
||||
*/
|
||||
public void removeFromBlacklist(Object object, Blacklist blacklist) {
|
||||
|
||||
if (WrappedStack.canBeWrapped(object)) {
|
||||
|
||||
WrappedStack wrappedStack = WrappedStack.wrap(object, 1);
|
||||
|
||||
if (blacklist == Blacklist.KNOWLEDGE) {
|
||||
if (wrappedStack != null && !MinecraftForge.EVENT_BUS.post(new KnowledgeWhitelistEvent(object))) {
|
||||
LogHelper.trace(KNOWLEDGE_WHITELIST_MARKER, "[{}] Mod with ID '{}' removed object {} from the player knowledge blacklist", LoaderHelper.getLoaderState(), Loader.instance().activeModContainer().getModId(), wrappedStack);
|
||||
knowledgeBlacklist.remove(wrappedStack);
|
||||
}
|
||||
}
|
||||
else if (blacklist == Blacklist.EXCHANGE) {
|
||||
if (wrappedStack != null && !MinecraftForge.EVENT_BUS.post(new ExchangeWhitelistEvent(object))) {
|
||||
LogHelper.trace(EXCHANGE_WHITELIST_MARKER, "[{}] Mod with ID '{}' removed object {} from the exchange blacklist", LoaderHelper.getLoaderState(), Loader.instance().activeModContainer().getModId(), wrappedStack);
|
||||
exchangeBlacklist.remove(wrappedStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*/
|
||||
public void load() {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){
|
||||
|
||||
LogHelper.trace(BLACKLIST_MARKER, "Loading player knowledge blacklist from {}", knowledgeBlacklistFile.getAbsolutePath());
|
||||
knowledgeBlacklist.clear();
|
||||
knowledgeBlacklist.addAll(SerializationHelper.readSetFromFile(knowledgeBlacklistFile));
|
||||
|
||||
LogHelper.trace(BLACKLIST_MARKER, "Loading exchange blacklist from {}", exchangeBlacklistFile.getAbsolutePath());
|
||||
exchangeBlacklist.clear();
|
||||
exchangeBlacklist.addAll(SerializationHelper.readSetFromFile(exchangeBlacklistFile));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*
|
||||
* @param blacklist
|
||||
*/
|
||||
public void save(Blacklist blacklist) {
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
||||
|
||||
if (blacklist == Blacklist.KNOWLEDGE) {
|
||||
LogHelper.trace(BLACKLIST_MARKER, "Saving player knowledge blacklist to {}", knowledgeBlacklistFile.getAbsolutePath());
|
||||
SerializationHelper.writeJsonFile(knowledgeBlacklistFile, SerializationHelper.GSON.toJson(knowledgeBlacklist));
|
||||
}
|
||||
else if (blacklist == Blacklist.EXCHANGE) {
|
||||
LogHelper.trace(BLACKLIST_MARKER, "Saving exchange blacklist to {}", exchangeBlacklistFile.getAbsolutePath());
|
||||
SerializationHelper.writeJsonFile(exchangeBlacklistFile, SerializationHelper.GSON.toJson(exchangeBlacklist));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*/
|
||||
public void saveAll() {
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
||||
LogHelper.trace(BLACKLIST_MARKER, "Saving all blacklists to disk", exchangeBlacklistFile.getAbsolutePath());
|
||||
SerializationHelper.writeJsonFile(knowledgeBlacklistFile, SerializationHelper.GSON.toJson(knowledgeBlacklist));
|
||||
SerializationHelper.writeJsonFile(exchangeBlacklistFile, SerializationHelper.GSON.toJson(exchangeBlacklist));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -42,6 +42,7 @@ public class ItemTooltipEventHandler
|
|||
{
|
||||
WrappedStack wrappedItemStack = WrappedStack.wrap(event.itemStack);
|
||||
EnergyValue energyValue = EnergyValueRegistryProxy.getEnergyValue(wrappedItemStack);
|
||||
EnergyValue energyValue2 = EnergyValueRegistryProxy.getEnergyValueForStack(wrappedItemStack);
|
||||
|
||||
if (energyValue != null)
|
||||
{
|
||||
|
@ -49,6 +50,7 @@ public class ItemTooltipEventHandler
|
|||
{
|
||||
event.toolTip.add(String.format("Exchange Energy (Item): %s", energyValueDecimalFormat.format(energyValue.getValue()))); // TODO Localize
|
||||
event.toolTip.add(String.format("Exchange Energy (Stack of %s): %s", event.itemStack.stackSize, energyValueDecimalFormat.format(wrappedItemStack.getStackSize() * energyValue.getValue()))); // TODO Localize
|
||||
event.toolTip.add(String.format("Exchange Energy 2 (Stack of %s): %s", event.itemStack.stackSize, energyValueDecimalFormat.format(energyValue2.getValue()))); // TODO Localize
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.pahimar.ee3.command;
|
||||
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
import com.pahimar.ee3.api.knowledge.PlayerKnowledgeRegistryProxy;
|
||||
import com.pahimar.ee3.knowledge.AbilityRegistry;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
@ -50,7 +50,7 @@ public class CommandPlayerLearnCurrentItem extends CommandBase
|
|||
|
||||
if (itemStack != null)
|
||||
{
|
||||
if (AbilityRegistry.getInstance().isLearnable(itemStack))
|
||||
if (BlacklistRegistryProxy.isLearnable(itemStack))
|
||||
{
|
||||
PlayerKnowledgeRegistryProxy.teachPlayer(entityPlayer, itemStack);
|
||||
func_152373_a(commandSender, this, Messages.Commands.PLAYER_LEARN_CURRENT_ITEM_SUCCESS, new Object[]{commandSender.getCommandSenderName(), entityPlayer.getCommandSenderName(), itemStack.func_151000_E()});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.pahimar.ee3.command;
|
||||
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
import com.pahimar.ee3.api.knowledge.PlayerKnowledgeRegistryProxy;
|
||||
import com.pahimar.ee3.knowledge.AbilityRegistry;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
@ -83,7 +83,7 @@ public class CommandPlayerLearnItem extends CommandBase
|
|||
}
|
||||
}
|
||||
|
||||
if (AbilityRegistry.getInstance().isLearnable(itemStack))
|
||||
if (BlacklistRegistryProxy.isLearnable(itemStack))
|
||||
{
|
||||
PlayerKnowledgeRegistryProxy.teachPlayer(entityPlayer, itemStack);
|
||||
func_152373_a(commandSender, this, Messages.Commands.PLAYER_LEARN_ITEM_SUCCESS, new Object[]{commandSender.getCommandSenderName(), entityPlayer.getCommandSenderName(), itemStack.func_151000_E()});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.pahimar.ee3.command;
|
||||
|
||||
import com.pahimar.ee3.api.knowledge.AbilityRegistryProxy;
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import net.minecraft.command.CommandBase;
|
||||
|
@ -76,7 +76,7 @@ public class CommandSetItemLearnable extends CommandBase
|
|||
}
|
||||
}
|
||||
|
||||
AbilityRegistryProxy.setAsLearnable(itemStack);
|
||||
BlacklistRegistryProxy.removeFromBlacklist(itemStack, BlacklistRegistryProxy.Blacklist.KNOWLEDGE);
|
||||
func_152373_a(commandSender, this, Messages.Commands.SET_ITEM_LEARNABLE_SUCCESS, new Object[]{commandSender.getCommandSenderName(), itemStack.func_151000_E()});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.pahimar.ee3.command;
|
||||
|
||||
import com.pahimar.ee3.api.knowledge.AbilityRegistryProxy;
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import net.minecraft.command.CommandBase;
|
||||
|
@ -76,7 +76,7 @@ public class CommandSetItemNotLearnable extends CommandBase
|
|||
}
|
||||
}
|
||||
|
||||
AbilityRegistryProxy.setAsNotLearnable(itemStack);
|
||||
BlacklistRegistryProxy.addToBlacklist(itemStack, BlacklistRegistryProxy.Blacklist.KNOWLEDGE);
|
||||
func_152373_a(commandSender, this, Messages.Commands.SET_ITEM_NOT_LEARNABLE_SUCCESS, new Object[]{commandSender.getCommandSenderName(), itemStack.func_151000_E()});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.pahimar.ee3.command;
|
||||
|
||||
import com.pahimar.ee3.api.knowledge.AbilityRegistryProxy;
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import net.minecraft.command.CommandBase;
|
||||
|
@ -76,7 +76,7 @@ public class CommandSetItemNotRecoverable extends CommandBase
|
|||
}
|
||||
}
|
||||
|
||||
AbilityRegistryProxy.setAsNotRecoverable(itemStack);
|
||||
BlacklistRegistryProxy.addToBlacklist(itemStack, BlacklistRegistryProxy.Blacklist.EXCHANGE);
|
||||
func_152373_a(commandSender, this, Messages.Commands.SET_ITEM_NOT_RECOVERABLE_SUCCESS, new Object[]{commandSender.getCommandSenderName(), itemStack.func_151000_E()});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.pahimar.ee3.command;
|
||||
|
||||
import com.pahimar.ee3.api.knowledge.AbilityRegistryProxy;
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import net.minecraft.command.CommandBase;
|
||||
|
@ -76,7 +76,7 @@ public class CommandSetItemRecoverable extends CommandBase
|
|||
}
|
||||
}
|
||||
|
||||
AbilityRegistryProxy.setAsRecoverable(itemStack);
|
||||
BlacklistRegistryProxy.removeFromBlacklist(itemStack, BlacklistRegistryProxy.Blacklist.EXCHANGE);
|
||||
func_152373_a(commandSender, this, Messages.Commands.SET_ITEM_RECOVERABLE_SUCCESS, new Object[]{commandSender.getCommandSenderName(), itemStack.func_151000_E()});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
package com.pahimar.ee3.handler;
|
||||
|
||||
import com.pahimar.ee3.knowledge.AbilityRegistry;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
|
||||
public class AbilityRegistrySerializationHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
public void onServerTick(TickEvent.ServerTickEvent event)
|
||||
{
|
||||
if (event.phase == TickEvent.Phase.END)
|
||||
{
|
||||
if (FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getWorldTime() % 600 == 0)
|
||||
{
|
||||
AbilityRegistry.getInstance().save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.pahimar.ee3.init;
|
||||
|
||||
import com.pahimar.ee3.api.knowledge.AbilityRegistryProxy;
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
import com.pahimar.ee3.exchange.OreStack;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -12,14 +12,14 @@ public class Abilities {
|
|||
|
||||
for (String oreName : OreDictionary.getOreNames()) {
|
||||
if (oreName.startsWith("ore")) {
|
||||
OreDictionary.getOres(oreName).forEach(AbilityRegistryProxy::setAsNotLearnable);
|
||||
AbilityRegistryProxy.setAsNotLearnable(new OreStack(oreName));
|
||||
OreDictionary.getOres(oreName).forEach(BlacklistRegistryProxy::setAsNotLearnable);
|
||||
BlacklistRegistryProxy.setAsNotLearnable(new OreStack(oreName));
|
||||
}
|
||||
}
|
||||
|
||||
AbilityRegistryProxy.setAsNotLearnable(new ItemStack(Blocks.coal_ore));
|
||||
AbilityRegistryProxy.setAsNotLearnable(ModItems.shardMinium);
|
||||
AbilityRegistryProxy.setAsNotLearnable(new ItemStack(ModItems.alchemicalDust, 1, 1));
|
||||
AbilityRegistryProxy.setAsNotLearnable(new ItemStack(ModItems.alchemicalDust, 1, 2));
|
||||
BlacklistRegistryProxy.setAsNotLearnable(new ItemStack(Blocks.coal_ore));
|
||||
BlacklistRegistryProxy.setAsNotLearnable(ModItems.shardMinium);
|
||||
BlacklistRegistryProxy.setAsNotLearnable(new ItemStack(ModItems.alchemicalDust, 1, 1));
|
||||
BlacklistRegistryProxy.setAsNotLearnable(new ItemStack(ModItems.alchemicalDust, 1, 2));
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package com.pahimar.ee3.inventory;
|
||||
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
import com.pahimar.ee3.item.ItemAlchenomicon;
|
||||
import com.pahimar.ee3.knowledge.AbilityRegistry;
|
||||
import com.pahimar.ee3.tileentity.TileEntityResearchStation;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
@ -32,7 +32,7 @@ public class ContainerResearchStation extends ContainerEE
|
|||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack)
|
||||
{
|
||||
return AbilityRegistry.getInstance().isLearnable(itemStack);
|
||||
return BlacklistRegistryProxy.isLearnable(itemStack);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.pahimar.ee3.inventory;
|
||||
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
import com.pahimar.ee3.api.exchange.EnergyValueRegistryProxy;
|
||||
import com.pahimar.ee3.api.knowledge.AbilityRegistryProxy;
|
||||
import com.pahimar.ee3.api.knowledge.PlayerKnowledgeRegistryProxy;
|
||||
import com.pahimar.ee3.inventory.element.IElementButtonHandler;
|
||||
import com.pahimar.ee3.inventory.element.IElementSliderHandler;
|
||||
|
@ -372,7 +372,8 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
|||
currentSlotIndex += ascending ? -1 : 1;
|
||||
}
|
||||
|
||||
transmutationOutputSlot.onPickupFromSlot(entityPlayer, new ItemStack(itemStack.getItem(), numTransmuted));
|
||||
// transmutationOutputSlot.onPickupFromSlot(entityPlayer, new ItemStack(itemStack.getItem(), numTransmuted));
|
||||
transmutationOutputSlot.onPickupFromSlot(entityPlayer, ItemHelper.clone(itemStack, numTransmuted));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -561,7 +562,7 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
|||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack)
|
||||
{
|
||||
return EnergyValueRegistryProxy.hasEnergyValue(itemStack) && AbilityRegistryProxy.isRecoverable(itemStack);
|
||||
return EnergyValueRegistryProxy.hasEnergyValue(itemStack) && BlacklistRegistryProxy.isExchangeable(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,395 +0,0 @@
|
|||
package com.pahimar.ee3.knowledge;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.pahimar.ee3.api.event.AbilityEvent;
|
||||
import com.pahimar.ee3.api.exchange.EnergyValueRegistryProxy;
|
||||
import com.pahimar.ee3.api.knowledge.AbilityRegistryProxy;
|
||||
import com.pahimar.ee3.exchange.WrappedStack;
|
||||
import com.pahimar.ee3.reference.Files;
|
||||
import com.pahimar.ee3.util.LoaderHelper;
|
||||
import com.pahimar.ee3.util.LogHelper;
|
||||
import com.pahimar.ee3.util.SerializationHelper;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class AbilityRegistry implements JsonSerializer<AbilityRegistry>, JsonDeserializer<AbilityRegistry>
|
||||
{
|
||||
public static final Marker ABILITY_MARKER = MarkerManager.getMarker("EE3_ABILITY", LogHelper.MOD_MARKER);
|
||||
private static final Marker NOT_LEARABLE_MARKER = MarkerManager.getMarker("EE3_ABILITY_NOT_LEARNABLE", ABILITY_MARKER);
|
||||
private static final Marker LEARABLE_MARKER = MarkerManager.getMarker("EE3_ABILITY_LEARNABLE", ABILITY_MARKER);
|
||||
private static final Marker NOT_RECOVERABLE_MARKER = MarkerManager.getMarker("EE3_ABILITY_NOT_RECOVERABLE", ABILITY_MARKER);
|
||||
private static final Marker RECOVERABLE_MARKER = MarkerManager.getMarker("EE3_ABILITY_RECOVERABLE", ABILITY_MARKER);
|
||||
|
||||
private static final Gson jsonSerializer = (new GsonBuilder()).setPrettyPrinting().registerTypeAdapter(AbilityRegistry.class, new AbilityRegistry()).create();
|
||||
private static AbilityRegistry abilityRegistry = null;
|
||||
|
||||
private static File abilityDirectory;
|
||||
private boolean hasBeenModified;
|
||||
private Set<WrappedStack> notLearnableSet;
|
||||
private Set<WrappedStack> notRecoverableSet;
|
||||
|
||||
private AbilityRegistry()
|
||||
{
|
||||
hasBeenModified = false;
|
||||
notLearnableSet = new TreeSet<WrappedStack>();
|
||||
notRecoverableSet = new TreeSet<WrappedStack>();
|
||||
}
|
||||
|
||||
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 Set<WrappedStack> getNotLearnableStacks()
|
||||
{
|
||||
return this.notLearnableSet;
|
||||
}
|
||||
|
||||
public boolean isLearnable(Object object)
|
||||
{
|
||||
if (WrappedStack.canBeWrapped(object))
|
||||
{
|
||||
WrappedStack wrappedObject = WrappedStack.wrap(object);
|
||||
|
||||
if (object instanceof ItemStack && ((ItemStack) object).isItemDamaged())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return !notLearnableSet.contains(wrappedObject) && EnergyValueRegistryProxy.hasEnergyValue(wrappedObject);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setAsLearnable(Object object)
|
||||
{
|
||||
if (WrappedStack.canBeWrapped(object))
|
||||
{
|
||||
WrappedStack wrappedStack = WrappedStack.wrap(object);
|
||||
|
||||
if (wrappedStack != null && !MinecraftForge.EVENT_BUS.post(new AbilityEvent.SetLearnableEvent(object)))
|
||||
{
|
||||
if (notLearnableSet.remove(wrappedStack))
|
||||
{
|
||||
hasBeenModified = true;
|
||||
LogHelper.trace(LEARABLE_MARKER, "[{}] Mod with ID '{}' set object {} as LEARNABLE", LoaderHelper.getLoaderState(), Loader.instance().activeModContainer().getModId(), wrappedStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setAsNotLearnable(Object object)
|
||||
{
|
||||
if (WrappedStack.canBeWrapped(object))
|
||||
{
|
||||
WrappedStack wrappedStack = WrappedStack.wrap(object);
|
||||
|
||||
if (wrappedStack != null && !MinecraftForge.EVENT_BUS.post(new AbilityEvent.SetNotLearnableEvent(object)))
|
||||
{
|
||||
if (notLearnableSet.add(wrappedStack))
|
||||
{
|
||||
hasBeenModified = true;
|
||||
LogHelper.trace(NOT_LEARABLE_MARKER, "[{}] Mod with ID '{}' set object {} as NOT LEARNABLE", LoaderHelper.getLoaderState(), Loader.instance().activeModContainer().getModId(), wrappedStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Set<WrappedStack> getNotRecoverableSet()
|
||||
{
|
||||
return this.notRecoverableSet;
|
||||
}
|
||||
|
||||
public boolean isRecoverable(Object object)
|
||||
{
|
||||
if (WrappedStack.canBeWrapped(object))
|
||||
{
|
||||
WrappedStack wrappedObject = WrappedStack.wrap(object);
|
||||
return !notRecoverableSet.contains(wrappedObject) && EnergyValueRegistryProxy.hasEnergyValue(wrappedObject);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setAsRecoverable(Object object)
|
||||
{
|
||||
if (WrappedStack.canBeWrapped(object))
|
||||
{
|
||||
WrappedStack wrappedStack = WrappedStack.wrap(object);
|
||||
|
||||
if (wrappedStack != null && !MinecraftForge.EVENT_BUS.post(new AbilityEvent.SetRecoverableEvent(object)))
|
||||
{
|
||||
if (notRecoverableSet.remove(wrappedStack))
|
||||
{
|
||||
hasBeenModified = true;
|
||||
LogHelper.trace(RECOVERABLE_MARKER, "[{}] Mod with ID '{}' set object {} as RECOVERABLE", LoaderHelper.getLoaderState(), Loader.instance().activeModContainer().getModId(), wrappedStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setAsNotRecoverable(Object object)
|
||||
{
|
||||
if (WrappedStack.canBeWrapped(object))
|
||||
{
|
||||
WrappedStack wrappedStack = WrappedStack.wrap(object);
|
||||
|
||||
if (wrappedStack != null && !MinecraftForge.EVENT_BUS.post(new AbilityEvent.SetNotRecoverableEvent(object)))
|
||||
{
|
||||
if (notRecoverableSet.add(wrappedStack))
|
||||
{
|
||||
hasBeenModified = true;
|
||||
LogHelper.trace(NOT_RECOVERABLE_MARKER, "[{}] Mod with ID '{}' set object {} as NOT RECOVERABLE", LoaderHelper.getLoaderState(), Loader.instance().activeModContainer().getModId(), wrappedStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
stringBuilder.append("Not Learnables: ");
|
||||
for (WrappedStack wrappedStack : notLearnableSet)
|
||||
{
|
||||
stringBuilder.append(wrappedStack + " ");
|
||||
}
|
||||
stringBuilder.append(", Not Recoverables: ");
|
||||
for (WrappedStack wrappedStack : notRecoverableSet)
|
||||
{
|
||||
stringBuilder.append(wrappedStack + " ");
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbilityRegistry deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
if (json.isJsonObject())
|
||||
{
|
||||
JsonObject jsonObject = (JsonObject) json;
|
||||
|
||||
Set<WrappedStack> notLearnableStacks = new TreeSet<WrappedStack>();
|
||||
Set<WrappedStack> notRecoverableStacks = new TreeSet<WrappedStack>();
|
||||
|
||||
if (jsonObject.has("notLearnable") && jsonObject.get("notLearnable").isJsonArray())
|
||||
{
|
||||
JsonArray jsonArray = (JsonArray) jsonObject.get("notLearnable");
|
||||
Iterator<JsonElement> iterator = jsonArray.iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
JsonElement jsonElement = iterator.next();
|
||||
WrappedStack wrappedStack = WrappedStack.jsonSerializer.fromJson(jsonElement, WrappedStack.class);
|
||||
|
||||
if (wrappedStack != null)
|
||||
{
|
||||
notLearnableStacks.add(wrappedStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (jsonObject.has("notRecoverable") && jsonObject.get("notRecoverable").isJsonArray())
|
||||
{
|
||||
JsonArray jsonArray = (JsonArray) jsonObject.get("notRecoverable");
|
||||
Iterator<JsonElement> iterator = jsonArray.iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
JsonElement jsonElement = iterator.next();
|
||||
WrappedStack wrappedStack = WrappedStack.jsonSerializer.fromJson(jsonElement, WrappedStack.class);
|
||||
|
||||
if (wrappedStack != null)
|
||||
{
|
||||
notRecoverableStacks.add(wrappedStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AbilityRegistry abilityRegistry1 = new AbilityRegistry();
|
||||
abilityRegistry1.notLearnableSet = notLearnableStacks;
|
||||
abilityRegistry1.notRecoverableSet = notRecoverableStacks;
|
||||
return abilityRegistry1;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(AbilityRegistry abilityRegistry, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
JsonObject jsonAbilityRegistry = new JsonObject();
|
||||
|
||||
JsonArray notLearnables = new JsonArray();
|
||||
for (WrappedStack wrappedStack : abilityRegistry.getNotLearnableStacks())
|
||||
{
|
||||
notLearnables.add(WrappedStack.jsonSerializer.toJsonTree(wrappedStack));
|
||||
}
|
||||
jsonAbilityRegistry.add("notLearnable", notLearnables);
|
||||
|
||||
JsonArray notRecoverables = new JsonArray();
|
||||
for (WrappedStack wrappedStack : abilityRegistry.getNotRecoverableSet())
|
||||
{
|
||||
notRecoverables.add(WrappedStack.jsonSerializer.toJsonTree(wrappedStack));
|
||||
}
|
||||
jsonAbilityRegistry.add("notRecoverable", notRecoverables);
|
||||
|
||||
return jsonAbilityRegistry;
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
if (abilityDirectory != null)
|
||||
{
|
||||
abilityDirectory.mkdirs();
|
||||
writeToFile(new File(abilityDirectory, Files.ABILITIES_JSON_FILENAME));
|
||||
}
|
||||
}
|
||||
|
||||
private void writeToFile(File file)
|
||||
{
|
||||
JsonWriter jsonWriter;
|
||||
|
||||
if (hasBeenModified)
|
||||
{
|
||||
try
|
||||
{
|
||||
jsonWriter = new JsonWriter(new FileWriter(file));
|
||||
jsonWriter.setIndent(" ");
|
||||
jsonSerializer.toJson(this, AbilityRegistry.class, jsonWriter);
|
||||
jsonWriter.close();
|
||||
hasBeenModified = false;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadAbilityRegistryFromFile(boolean loadFileOnly)
|
||||
{
|
||||
if (abilityDirectory != null)
|
||||
{
|
||||
File abilitiesFile = new File(abilityDirectory, Files.ABILITIES_JSON_FILENAME);
|
||||
|
||||
if (abilitiesFile.exists())
|
||||
{
|
||||
readFromFile(abilitiesFile, loadFileOnly);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
abilityDirectory = new File(SerializationHelper.getInstanceDataDirectory(), "abilities");
|
||||
abilityDirectory.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
private void readFromFile(File file, boolean loadFileOnly)
|
||||
{
|
||||
JsonReader jsonReader;
|
||||
|
||||
try
|
||||
{
|
||||
jsonReader = new JsonReader(new FileReader(file));
|
||||
AbilityRegistry abilityRegistry1 = jsonSerializer.fromJson(jsonReader, AbilityRegistry.class);
|
||||
jsonReader.close();
|
||||
|
||||
if (!loadFileOnly)
|
||||
{
|
||||
for (WrappedStack wrappedStack : abilityRegistry1.getNotLearnableStacks())
|
||||
{
|
||||
if (!this.notLearnableSet.contains(wrappedStack))
|
||||
{
|
||||
this.notLearnableSet.add(wrappedStack);
|
||||
}
|
||||
}
|
||||
|
||||
for (WrappedStack wrappedStack : abilityRegistry1.getNotRecoverableSet())
|
||||
{
|
||||
if (!this.notRecoverableSet.contains(wrappedStack))
|
||||
{
|
||||
this.notRecoverableSet.add(wrappedStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.notLearnableSet = abilityRegistry1.notLearnableSet;
|
||||
this.notRecoverableSet = abilityRegistry1.notRecoverableSet;
|
||||
}
|
||||
|
||||
hasBeenModified = true;
|
||||
}
|
||||
catch (FileNotFoundException ignored)
|
||||
{
|
||||
// NOOP
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void dumpAbilityRegistryToLog()
|
||||
{
|
||||
dumpAbilityRegistryToLog(AbilityRegistryProxy.Abilities.ALL);
|
||||
}
|
||||
|
||||
public void dumpAbilityRegistryToLog(AbilityRegistryProxy.Abilities abilityType)
|
||||
{
|
||||
if (abilityType == AbilityRegistryProxy.Abilities.NOT_LEARNABLE) {
|
||||
if (this.notLearnableSet != null) {
|
||||
for (WrappedStack wrappedStack : this.notLearnableSet) {
|
||||
LogHelper.info(NOT_LEARABLE_MARKER, "Not Learnable: {}", wrappedStack);
|
||||
}
|
||||
}
|
||||
} else if (abilityType == AbilityRegistryProxy.Abilities.NOT_RECOVERABLE) {
|
||||
if (this.notRecoverableSet != null) {
|
||||
for (WrappedStack wrappedStack : this.notRecoverableSet) {
|
||||
LogHelper.info(NOT_RECOVERABLE_MARKER, "Not Recoverable: {}", wrappedStack);
|
||||
}
|
||||
}
|
||||
} else if (abilityType == AbilityRegistryProxy.Abilities.ALL) {
|
||||
if (this.notLearnableSet != null) {
|
||||
for (WrappedStack wrappedStack : this.notLearnableSet) {
|
||||
LogHelper.info(NOT_LEARABLE_MARKER, "Not Learnable: {}", wrappedStack);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.notRecoverableSet != null) {
|
||||
for (WrappedStack wrappedStack : this.notRecoverableSet) {
|
||||
LogHelper.info(NOT_RECOVERABLE_MARKER, "Not Recoverable: {}", wrappedStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package com.pahimar.ee3.knowledge;
|
||||
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.pahimar.ee3.api.knowledge.AbilityRegistryProxy;
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
import com.pahimar.ee3.handler.ConfigurationHandler;
|
||||
import com.pahimar.ee3.reference.Comparators;
|
||||
import com.pahimar.ee3.reference.Files;
|
||||
|
@ -87,7 +87,7 @@ public class PlayerKnowledgeRegistry {
|
|||
public boolean canPlayerLearn(String playerName, Object object) {
|
||||
|
||||
if (getPlayerKnowledge(playerName) != null) {
|
||||
return !getPlayerKnowledge(playerName).isKnown(object) && AbilityRegistryProxy.isLearnable(object);
|
||||
return !getPlayerKnowledge(playerName).isKnown(object) && BlacklistRegistryProxy.isLearnable(object);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -13,7 +13,6 @@ public abstract class CommonProxy implements IProxy
|
|||
PlayerEventHandler playerEventHandler = new PlayerEventHandler();
|
||||
|
||||
FMLCommonHandler.instance().bus().register(new ConfigurationHandler());
|
||||
FMLCommonHandler.instance().bus().register(new AbilityRegistrySerializationHandler());
|
||||
FMLCommonHandler.instance().bus().register(itemEventHandler);
|
||||
MinecraftForge.EVENT_BUS.register(itemEventHandler);
|
||||
MinecraftForge.EVENT_BUS.register(new WorldEventHandler());
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.pahimar.ee3.reference;
|
||||
|
||||
import com.pahimar.ee3.blacklist.BlacklistRegistry;
|
||||
import com.pahimar.ee3.exchange.EnergyValueRegistry;
|
||||
import com.pahimar.ee3.knowledge.PlayerKnowledgeRegistry;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
@ -16,8 +17,10 @@ public class Files {
|
|||
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_FILENAME = "template-player-knowledge.json";
|
||||
public static final String ABILITIES_JSON_FILENAME = "abilities.json";
|
||||
public static final String TEMPLATE_PLAYER_KNOWLEDGE_FILENAME = "template-player-knowledge.json";
|
||||
|
||||
public static final String KNOWLEDGE_BLACKLIST_FILENAME = "knowledge-blacklist.json";
|
||||
public static final String EXCHANGE_BLACKLIST_FILENAME = "exchange-blacklist.json";
|
||||
|
||||
public static File abilitiesDataDirectory;
|
||||
public static File abilitiesDataFile;
|
||||
|
@ -34,11 +37,14 @@ public class Files {
|
|||
|
||||
File templatePlayerKnowledgeDirectory = new File(globalDataDirectory, "knowledge" + File.separator + "transmutation");
|
||||
templatePlayerKnowledgeDirectory.mkdirs();
|
||||
PlayerKnowledgeRegistry.templatePlayerKnowledgeFile = new File(templatePlayerKnowledgeDirectory, TEMPLATE_JSON_FILENAME);
|
||||
PlayerKnowledgeRegistry.templatePlayerKnowledgeFile = new File(templatePlayerKnowledgeDirectory, TEMPLATE_PLAYER_KNOWLEDGE_FILENAME);
|
||||
|
||||
BlacklistRegistry.knowledgeBlacklistFile = new File(globalDataDirectory, "blacklist" + File.separator + KNOWLEDGE_BLACKLIST_FILENAME);
|
||||
BlacklistRegistry.exchangeBlacklistFile = new File(globalDataDirectory, "blacklist" + File.separator + EXCHANGE_BLACKLIST_FILENAME);
|
||||
|
||||
abilitiesDataDirectory = new File(globalDataDirectory, "abilities");
|
||||
abilitiesDataDirectory.mkdirs();
|
||||
abilitiesDataFile = new File(abilitiesDataDirectory, ABILITIES_JSON_FILENAME);
|
||||
abilitiesDataFile = new File(abilitiesDataDirectory, "abilities.json");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.pahimar.ee3.tileentity;
|
||||
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
import com.pahimar.ee3.api.knowledge.PlayerKnowledgeRegistryProxy;
|
||||
import com.pahimar.ee3.knowledge.AbilityRegistry;
|
||||
import com.pahimar.ee3.network.PacketHandler;
|
||||
import com.pahimar.ee3.network.message.MessageTileEntityResearchStation;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
|
@ -125,7 +125,7 @@ public class TileEntityResearchStation extends TileEntityEE implements IInventor
|
|||
@Override
|
||||
public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack)
|
||||
{
|
||||
return slotIndex == ITEM_SLOT_INVENTORY_INDEX && AbilityRegistry.getInstance().isLearnable(itemStack);
|
||||
return slotIndex == ITEM_SLOT_INVENTORY_INDEX && BlacklistRegistryProxy.isLearnable(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.pahimar.ee3.tileentity;
|
||||
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
import com.pahimar.ee3.api.exchange.EnergyValue;
|
||||
import com.pahimar.ee3.api.exchange.EnergyValueRegistryProxy;
|
||||
import com.pahimar.ee3.api.knowledge.AbilityRegistryProxy;
|
||||
import com.pahimar.ee3.block.BlockAshInfusedStoneSlab;
|
||||
import com.pahimar.ee3.item.ItemAlchenomicon;
|
||||
import com.pahimar.ee3.item.ItemMiniumStone;
|
||||
|
@ -62,6 +62,8 @@ public class TileEntityTransmutationTablet extends TileEntityEE implements ISide
|
|||
public void consumeInventoryForEnergyValue(ItemStack outputItemStack)
|
||||
{
|
||||
EnergyValue outputEnergyValue = EnergyValueRegistryProxy.getEnergyValueForStack(outputItemStack);
|
||||
EnergyValue ev2 = EnergyValueRegistryProxy.getEnergyValue(outputItemStack);
|
||||
|
||||
|
||||
/**
|
||||
* Algorithm:
|
||||
|
@ -313,7 +315,7 @@ public class TileEntityTransmutationTablet extends TileEntityEE implements ISide
|
|||
@Override
|
||||
public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack)
|
||||
{
|
||||
if (slotIndex < STONE_INDEX && EnergyValueRegistryProxy.hasEnergyValue(itemStack) && AbilityRegistryProxy.isRecoverable(itemStack))
|
||||
if (slotIndex < STONE_INDEX && EnergyValueRegistryProxy.hasEnergyValue(itemStack) && BlacklistRegistryProxy.isExchangeable(itemStack))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ public class SerializationHelper {
|
|||
.registerTypeAdapter(WrappedStack.class, new WrappedStackSerializer())
|
||||
.registerTypeAdapter(PlayerKnowledge.class, new PlayerKnowledgeSerializer())
|
||||
.registerTypeAdapter(ENERGY_VALUE_MAP_TYPE, new EnergyValueMapSerializer())
|
||||
.registerTypeAdapter(ENERGY_VALUE_MAP_TYPE, new EnergyValueMapSerializer())
|
||||
.create();
|
||||
|
||||
private static File instanceDataDirectory;
|
||||
|
@ -124,7 +125,7 @@ public class SerializationHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static Set<WrappedStack> readSetFromFile(File file) throws FileNotFoundException {
|
||||
public static Set<WrappedStack> readSetFromFile(File file) {
|
||||
|
||||
Set<WrappedStack> wrappedStackSet = new TreeSet<>();
|
||||
|
||||
|
@ -132,7 +133,10 @@ public class SerializationHelper {
|
|||
wrappedStackSet = GSON.fromJson(readJsonFile(file), WRAPPED_STACK_SET_TYPE);
|
||||
}
|
||||
catch (JsonParseException exception) {
|
||||
// TODO Better logging of the exception (failed parsing so no values loaded)
|
||||
LogHelper.error("Unable to parse contents from file '{}'", file.getAbsoluteFile());
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
LogHelper.warn("Unable to find file '{}'", file.getAbsoluteFile());
|
||||
}
|
||||
|
||||
return wrappedStackSet;
|
||||
|
|
Loading…
Reference in a new issue