Added more TRACE level logging to PlayerKnowledgeRegistry

Improved logic in BlacklistRegistry.isLearnable and BlacklistRegistry.isExchangeable to check it the itemstack is a member of an ore dictionary entry which is blacklisted. If it is, it's not learnable/exchange

(cherry picked from commit 7ac01e09a6b37561c6bd2fc34fe1768f682cf0cd)
This commit is contained in:
Pahimar 2016-06-01 15:07:40 -04:00 committed by bombcar
parent b3c2f63e2d
commit e056caee88
2 changed files with 45 additions and 3 deletions

View File

@ -1,9 +1,11 @@
package com.pahimar.ee3.blacklist;
import com.pahimar.ee3.api.exchange.EnergyValueRegistryProxy;
import com.pahimar.ee3.exchange.OreStack;
import com.pahimar.ee3.exchange.WrappedStack;
import com.pahimar.ee3.util.LoaderHelper;
import com.pahimar.ee3.util.LogHelper;
import com.pahimar.ee3.util.OreDictionaryHelper;
import com.pahimar.ee3.util.SerializationHelper;
import cpw.mods.fml.common.Loader;
import net.minecraft.item.ItemStack;
@ -12,6 +14,7 @@ import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;
@ -81,7 +84,20 @@ public class BlacklistRegistry {
return false;
}
else {
return !knowledgeBlacklist.contains(wrappedObject) && EnergyValueRegistryProxy.hasEnergyValue(wrappedObject);
if (EnergyValueRegistryProxy.hasEnergyValue(wrappedObject)) {
if (knowledgeBlacklist.contains(wrappedObject)) {
return false;
}
else if (object instanceof ItemStack){
Collection<String> oreNames = OreDictionaryHelper.getOreNames((ItemStack) object);
for (String oreName : oreNames) {
boolean isNotLearnable = !isLearnable(new OreStack(oreName));
if (isNotLearnable) {
return false;
}
}
}
}
}
}
@ -98,8 +114,22 @@ public class BlacklistRegistry {
if (WrappedStack.canBeWrapped(object)) {
WrappedStack wrappedStack = WrappedStack.wrap(object, 1);
return !exchangeBlacklist.contains(wrappedStack) && EnergyValueRegistryProxy.hasEnergyValue(wrappedStack);
WrappedStack wrappedObject = WrappedStack.wrap(object, 1);
if (EnergyValueRegistryProxy.hasEnergyValue(wrappedObject)) {
if (exchangeBlacklist.contains(wrappedObject)) {
return false;
}
else if (object instanceof ItemStack){
Collection<String> oreNames = OreDictionaryHelper.getOreNames((ItemStack) object);
for (String oreName : oreNames) {
boolean isNotLearnable = !isLearnable(new OreStack(oreName));
if (isNotLearnable) {
return false;
}
}
}
}
}
return false;

View File

@ -11,6 +11,8 @@ import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import java.io.File;
import java.io.FileNotFoundException;
@ -28,6 +30,11 @@ public class PlayerKnowledgeRegistry {
public static File templatePlayerKnowledgeFile;
public static final Marker PLAYER_KNOWLEDGE_MARKER = MarkerManager.getMarker("EE3_PLAYER_KNOWLEDGE", LogHelper.MOD_MARKER);
public static final Marker PLAYER_LEARN_KNOWLEDGE = MarkerManager.getMarker("EE3_PLAYER_TEACH_KNOWLEDGE", PLAYER_KNOWLEDGE_MARKER);
public static final Marker PLAYER_FORGET_KNOWLEDGE_MARKER = MarkerManager.getMarker("EE3_PLAYER_FORGET_KNOWLEDGE", PLAYER_KNOWLEDGE_MARKER);
public static final Marker PLAYER_FORGET_ALL_KNOWLEDGE_MARKER = MarkerManager.getMarker("EE3_PLAYER_FORGET_ALL_KNOWLEDGE", PLAYER_FORGET_KNOWLEDGE_MARKER);
private PlayerKnowledgeRegistry() {
playerKnowledgeMap = new TreeMap<>(Comparators.STRING_COMPARATOR);
@ -116,6 +123,7 @@ public class PlayerKnowledgeRegistry {
if (getPlayerKnowledge(playerName) != null) {
getPlayerKnowledge(playerName).learn(object);
LogHelper.trace(PLAYER_LEARN_KNOWLEDGE, "Player {} learned {}", playerName, object);
save(playerName);
}
}
@ -148,6 +156,7 @@ public class PlayerKnowledgeRegistry {
if (playerKnowledge != null) {
for (Object object : objects){
getPlayerKnowledge(playerName).learn(object);
LogHelper.trace(PLAYER_LEARN_KNOWLEDGE, "Player {} learned {}", playerName, object);
}
save(playerName);
}
@ -177,6 +186,7 @@ public class PlayerKnowledgeRegistry {
if (getPlayerKnowledge(playerName) != null) {
getPlayerKnowledge(playerName).forget(object);
LogHelper.trace(PLAYER_FORGET_KNOWLEDGE_MARKER, "Player {} forgot {}", playerName, object);
save(playerName);
}
}
@ -209,6 +219,7 @@ public class PlayerKnowledgeRegistry {
if (playerKnowledge != null) {
for (Object object : objects) {
getPlayerKnowledge(playerName).forget(object);
LogHelper.trace(PLAYER_FORGET_KNOWLEDGE_MARKER, "Player {} forgot {}", playerName, object);
}
save(playerName);
}
@ -237,6 +248,7 @@ public class PlayerKnowledgeRegistry {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
if (playerName != null && !playerName.isEmpty()) {
playerKnowledgeMap.put(playerName, new PlayerKnowledge());
LogHelper.trace(PLAYER_FORGET_ALL_KNOWLEDGE_MARKER, "Player {} forget everything", playerName);
save(playerName);
}
}