Added some more NPE protection to the ID based ItemStack comparator
Added back in the small and medium sized Alchemical Chest aludel recipes Added a recipe to make a chalk block from 4 pieces of chalk Created an EE test suite to test EE specific energy values Re-registered several EE items Removed a duplicate Gson type adapter registration Changed the ItemStackSerializer to return JsonNull in the event that there is no registered name for the item (the item would never deserialize as it wouldn't have a name to lookup) Changed the EnergyValueMapSerializer to allow serializing of null energy values (as JsonNull). Used for energy value testing.
This commit is contained in:
parent
9112666443
commit
f41b0279a6
|
@ -14,7 +14,9 @@ import com.pahimar.ee3.recipe.RecipeRegistry;
|
|||
import com.pahimar.ee3.reference.Files;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Reference;
|
||||
import com.pahimar.ee3.test.EETestSuite;
|
||||
import com.pahimar.ee3.test.EnergyValueTestSuite;
|
||||
import com.pahimar.ee3.test.VanillaTestSuite;
|
||||
import com.pahimar.ee3.util.FluidHelper;
|
||||
import com.pahimar.ee3.util.LogHelper;
|
||||
import com.pahimar.ee3.util.SerializationHelper;
|
||||
|
@ -108,8 +110,13 @@ public class EquivalentExchange3
|
|||
@EventHandler
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
|
||||
// Initialize the blacklist registry
|
||||
BlacklistRegistry.INSTANCE.load();
|
||||
Abilities.init();
|
||||
|
||||
// Initialize our test files
|
||||
new VanillaTestSuite().build().save();
|
||||
new EETestSuite().build().save();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.pahimar.ee3.command;
|
||||
|
||||
import com.pahimar.ee3.reference.Files;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import com.pahimar.ee3.reference.Reference;
|
||||
import com.pahimar.ee3.reference.Tests;
|
||||
import com.pahimar.ee3.test.EnergyValueTestSuite;
|
||||
import com.pahimar.ee3.util.LogHelper;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
@ -39,8 +39,8 @@ public class CommandRunTest extends CommandEE {
|
|||
|
||||
boolean testFound = false;
|
||||
|
||||
if (Tests.globalTestDirectory != null) {
|
||||
for (File testCaseFile : Tests.globalTestDirectory.listFiles()) {
|
||||
if (Files.globalTestDirectory != null) {
|
||||
for (File testCaseFile : Files.globalTestDirectory.listFiles()) {
|
||||
if (testCaseFile.isFile() && testCaseFile.getName().equalsIgnoreCase(args[1])) {
|
||||
testFound = true;
|
||||
EnergyValueTestSuite energyValueTestSuite = new EnergyValueTestSuite(testCaseFile);
|
||||
|
@ -76,8 +76,8 @@ public class CommandRunTest extends CommandEE {
|
|||
|
||||
ArrayList<String> fileNames = new ArrayList<>();
|
||||
|
||||
if (Tests.globalTestDirectory != null) {
|
||||
for (File testCaseFile : Tests.globalTestDirectory.listFiles()) {
|
||||
if (Files.globalTestDirectory != null) {
|
||||
for (File testCaseFile : Files.globalTestDirectory.listFiles()) {
|
||||
if (testCaseFile.isFile() && testCaseFile.getAbsolutePath().endsWith(".json")) {
|
||||
fileNames.add(testCaseFile.getName());
|
||||
}
|
||||
|
|
|
@ -291,43 +291,40 @@ public class WrappedStack implements Comparable<WrappedStack> {
|
|||
* @return a string representation of the object.
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if (wrappedStack instanceof ItemStack)
|
||||
{
|
||||
public String toString() {
|
||||
|
||||
if (wrappedStack instanceof ItemStack) {
|
||||
ItemStack itemStack = (ItemStack) wrappedStack;
|
||||
String unlocalizedName;
|
||||
try
|
||||
{
|
||||
// unlocalizedName = itemStack.getUnlocalizedName();
|
||||
String unlocalizedName = null;
|
||||
try {
|
||||
if (itemStack.getItem() != null) {
|
||||
unlocalizedName = Item.itemRegistry.getNameForObject(itemStack.getItem());
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e)
|
||||
{
|
||||
|
||||
if (unlocalizedName == null) {
|
||||
unlocalizedName = itemStack.getUnlocalizedName();
|
||||
}
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e) {
|
||||
unlocalizedName = "no-name";
|
||||
}
|
||||
|
||||
if (itemStack.hasTagCompound())
|
||||
{
|
||||
if (itemStack.hasTagCompound()) {
|
||||
return String.format("%sxitemStack[%s@%s:%s]", stackSize, unlocalizedName, itemStack.getItemDamage(), itemStack.getTagCompound());
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
return String.format("%sxitemStack[%s@%s]", stackSize, unlocalizedName, itemStack.getItemDamage());
|
||||
}
|
||||
}
|
||||
else if (wrappedStack instanceof OreStack)
|
||||
{
|
||||
else if (wrappedStack instanceof OreStack) {
|
||||
OreStack oreStack = (OreStack) wrappedStack;
|
||||
return String.format("%sxoreStack[%s]", stackSize, oreStack.oreName);
|
||||
}
|
||||
else if (wrappedStack instanceof FluidStack)
|
||||
{
|
||||
else if (wrappedStack instanceof FluidStack) {
|
||||
FluidStack fluidStack = (FluidStack) wrappedStack;
|
||||
return String.format("%sxfluidStack[%s]", stackSize, fluidStack.getFluid().getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
return "null-wrappedstack";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,25 +48,25 @@ public class ModItems
|
|||
GameRegistry.registerItem(stonePhilosophers, Names.Items.PHILOSOPHERS_STONE);
|
||||
GameRegistry.registerItem(chalk, Names.Items.CHALK);
|
||||
GameRegistry.registerItem(alchemicalUpgrade, Names.Items.ALCHEMICAL_UPGRADE);
|
||||
// GameRegistry.registerItem(diviningRod, Names.Items.DIVINING_ROD);
|
||||
GameRegistry.registerItem(diviningRod, Names.Items.DIVINING_ROD);
|
||||
GameRegistry.registerItem(alchenomicon, Names.Items.ALCHENOMICON, Names.Items.ALCHEMICAL_TOME);
|
||||
// GameRegistry.registerItem(matter, Names.Items.MATTER);
|
||||
// GameRegistry.registerItem(gem, Names.Items.GEM);
|
||||
// GameRegistry.registerItem(lootBall, Names.Items.LOOT_BALL);
|
||||
// GameRegistry.registerItem(knowledgeScroll, Names.Items.KNOWLEDGE_SCROLL);
|
||||
// GameRegistry.registerItem(potionLethe, Names.Items.POTION_LETHE);
|
||||
GameRegistry.registerItem(matter, Names.Items.MATTER);
|
||||
GameRegistry.registerItem(gem, Names.Items.GEM);
|
||||
GameRegistry.registerItem(lootBall, Names.Items.LOOT_BALL);
|
||||
GameRegistry.registerItem(knowledgeScroll, Names.Items.KNOWLEDGE_SCROLL);
|
||||
GameRegistry.registerItem(potionLethe, Names.Items.POTION_LETHE);
|
||||
|
||||
// GameRegistry.registerItem(shovelDarkMatter, Names.Tools.DARK_MATTER_SHOVEL);
|
||||
// GameRegistry.registerItem(pickAxeDarkMatter, Names.Tools.DARK_MATTER_PICKAXE);
|
||||
// GameRegistry.registerItem(hammerDarkMatter, Names.Tools.DARK_MATTER_HAMMER);
|
||||
// GameRegistry.registerItem(axeDarkMatter, Names.Tools.DARK_MATTER_AXE);
|
||||
// GameRegistry.registerItem(hoeDarkMatter, Names.Tools.DARK_MATTER_HOE);
|
||||
// GameRegistry.registerItem(fishingRodDarkMatter, Names.Tools.DARK_MATTER_FISHING_ROD);
|
||||
// GameRegistry.registerItem(shearsDarkMatter, Names.Tools.DARK_MATTER_SHEARS);
|
||||
GameRegistry.registerItem(shovelDarkMatter, Names.Tools.DARK_MATTER_SHOVEL);
|
||||
GameRegistry.registerItem(pickAxeDarkMatter, Names.Tools.DARK_MATTER_PICKAXE);
|
||||
GameRegistry.registerItem(hammerDarkMatter, Names.Tools.DARK_MATTER_HAMMER);
|
||||
GameRegistry.registerItem(axeDarkMatter, Names.Tools.DARK_MATTER_AXE);
|
||||
GameRegistry.registerItem(hoeDarkMatter, Names.Tools.DARK_MATTER_HOE);
|
||||
GameRegistry.registerItem(fishingRodDarkMatter, Names.Tools.DARK_MATTER_FISHING_ROD);
|
||||
GameRegistry.registerItem(shearsDarkMatter, Names.Tools.DARK_MATTER_SHEARS);
|
||||
|
||||
// GameRegistry.registerItem(bowDarkMatter, Names.Weapons.DARK_MATTER_BOW);
|
||||
// GameRegistry.registerItem(arrowDarkMatter, Names.Weapons.DARK_MATTER_ARROW);
|
||||
// GameRegistry.registerItem(swordDarkMatter, Names.Weapons.DARK_MATTER_SWORD);
|
||||
GameRegistry.registerItem(bowDarkMatter, Names.Weapons.DARK_MATTER_BOW);
|
||||
GameRegistry.registerItem(arrowDarkMatter, Names.Weapons.DARK_MATTER_ARROW);
|
||||
GameRegistry.registerItem(swordDarkMatter, Names.Weapons.DARK_MATTER_SWORD);
|
||||
|
||||
// Helm
|
||||
// Chest
|
||||
|
|
|
@ -30,6 +30,7 @@ public class Recipes
|
|||
GameRegistry.addShapedRecipe(new ItemStack(ModBlocks.ashInfusedStone, 1), "s", "s", 's', new ItemStack(ModBlocks.ashInfusedStoneSlab));
|
||||
|
||||
GameRegistry.addShapelessRecipe(new ItemStack(ModItems.chalk), new ItemStack(Items.dye, 1, 15), new ItemStack(Items.clay_ball));
|
||||
GameRegistry.addShapedRecipe(new ItemStack(ModBlocks.chalkBlock), "cc", "cc", 'c', ModItems.chalk);
|
||||
|
||||
GameRegistry.addShapedRecipe(new ItemStack(ModBlocks.glassBell), "ggg", "g g", "g g", 'g', Blocks.glass);
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModBlocks.calcinator), "i i", "sis", "s s", 'i', "ingotIron", 's', Blocks.stone));
|
||||
|
@ -77,6 +78,10 @@ public class Recipes
|
|||
AludelRecipeManager.getInstance().addRecipe(new ItemStack(ModItems.alchemicalFuel, 1, 2), new ItemStack(ModItems.alchemicalFuel, 1, 1), new ItemStack(ModItems.alchemicalDust, 14, 3));
|
||||
|
||||
// Alchemical Chest
|
||||
AludelRecipeManager.getInstance().addRecipe(new ItemStack(ModBlocks.alchemicalChest, 1, 0), new ItemStack(Blocks.chest, 1, OreDictionary.WILDCARD_VALUE), new ItemStack(ModItems.alchemicalDust, 8, 1));
|
||||
AludelRecipeManager.getInstance().addRecipe(new ItemStack(ModBlocks.alchemicalChest, 1, 0), new ItemStack(Blocks.trapped_chest, 1, OreDictionary.WILDCARD_VALUE), new ItemStack(ModItems.alchemicalDust, 8, 1));
|
||||
AludelRecipeManager.getInstance().addRecipe(new ItemStack(ModBlocks.alchemicalChest, 1, 1), new ItemStack(Blocks.chest, 1, OreDictionary.WILDCARD_VALUE), new ItemStack(ModItems.alchemicalDust, 8, 2));
|
||||
AludelRecipeManager.getInstance().addRecipe(new ItemStack(ModBlocks.alchemicalChest, 1, 1), new ItemStack(ModBlocks.alchemicalChest, 1, 0), new ItemStack(ModItems.alchemicalDust, 8, 2));
|
||||
AludelRecipeManager.getInstance().addRecipe(new ItemStack(ModBlocks.alchemicalChest, 1, 2), new ItemStack(Blocks.chest, 1, OreDictionary.WILDCARD_VALUE), new ItemStack(ModItems.alchemicalDust, 8, 3));
|
||||
AludelRecipeManager.getInstance().addRecipe(new ItemStack(ModBlocks.alchemicalChest, 1, 2), new ItemStack(ModBlocks.alchemicalChest, 1, 0), new ItemStack(ModItems.alchemicalDust, 8, 3));
|
||||
AludelRecipeManager.getInstance().addRecipe(new ItemStack(ModBlocks.alchemicalChest, 1, 2), new ItemStack(ModBlocks.alchemicalChest, 1, 1), new ItemStack(ModItems.alchemicalDust, 8, 3));
|
||||
|
|
|
@ -53,6 +53,7 @@ public class Comparators {
|
|||
public int compare(ItemStack itemStack1, ItemStack itemStack2) {
|
||||
|
||||
if (itemStack1 != null && itemStack2 != null) {
|
||||
if (itemStack1.getItem() != null && itemStack2.getItem() != null) {
|
||||
// Sort on id
|
||||
if (Item.getIdFromItem(itemStack1.getItem()) - Item.getIdFromItem(itemStack2.getItem()) == 0) {
|
||||
// Sort on item
|
||||
|
@ -64,31 +65,34 @@ public class Comparators {
|
|||
// Then sort on stack size
|
||||
if (ItemStack.areItemStackTagsEqual(itemStack1, itemStack2)) {
|
||||
return (itemStack1.stackSize - itemStack2.stackSize);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return (itemStack1.getTagCompound().hashCode() - itemStack2.getTagCompound().hashCode());
|
||||
}
|
||||
} else if (!(itemStack1.hasTagCompound()) && itemStack2.hasTagCompound()) {
|
||||
return -1;
|
||||
} else if (itemStack1.hasTagCompound() && !(itemStack2.hasTagCompound())) {
|
||||
return 1;
|
||||
} else {
|
||||
return (itemStack1.stackSize - itemStack2.stackSize);
|
||||
}
|
||||
else if (!(itemStack1.hasTagCompound()) && itemStack2.hasTagCompound()) {
|
||||
} else {
|
||||
return (itemStack1.getItemDamage() - itemStack2.getItemDamage());
|
||||
}
|
||||
} else {
|
||||
return itemStack1.getItem().getUnlocalizedName(itemStack1).compareToIgnoreCase(itemStack2.getItem().getUnlocalizedName(itemStack2));
|
||||
}
|
||||
} else {
|
||||
return Item.getIdFromItem(itemStack1.getItem()) - Item.getIdFromItem(itemStack2.getItem());
|
||||
}
|
||||
}
|
||||
else if (itemStack1.getItem() != null) {
|
||||
return -1;
|
||||
}
|
||||
else if (itemStack1.hasTagCompound() && !(itemStack2.hasTagCompound())) {
|
||||
else if (itemStack2.getItem() != null) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return (itemStack1.stackSize - itemStack2.stackSize);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return (itemStack1.getItemDamage() - itemStack2.getItemDamage());
|
||||
}
|
||||
}
|
||||
else {
|
||||
return itemStack1.getItem().getUnlocalizedName(itemStack1).compareToIgnoreCase(itemStack2.getItem().getUnlocalizedName(itemStack2));
|
||||
}
|
||||
}
|
||||
else {
|
||||
return Item.getIdFromItem(itemStack1.getItem()) - Item.getIdFromItem(itemStack2.getItem());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (itemStack1 != null) {
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.io.File;
|
|||
public class Files {
|
||||
|
||||
public static File globalDataDirectory;
|
||||
public static File globalTestDirectory;
|
||||
public static File playerDataDirectory;
|
||||
|
||||
private static final String ENERGY_VALUES_JSON_FILENAME = "energy-values.json";
|
||||
|
@ -25,9 +26,8 @@ public class Files {
|
|||
public static void init(FMLPreInitializationEvent event) {
|
||||
|
||||
globalDataDirectory = new File(event.getModConfigurationDirectory().getParentFile(), "data" + File.separator + Reference.LOWERCASE_MOD_ID);
|
||||
Tests.globalTestDirectory = new File(globalDataDirectory, "tests");
|
||||
Tests.globalTestDirectory.mkdirs();
|
||||
Tests.VANILLA_TEST_SUITE.save();
|
||||
globalTestDirectory = new File(globalDataDirectory, "tests");
|
||||
globalTestDirectory.mkdirs();
|
||||
|
||||
EnergyValueRegistry.energyValuesDirectory = new File(globalDataDirectory, "energy-values");
|
||||
EnergyValueRegistry.energyValuesDirectory.mkdirs();
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
package com.pahimar.ee3.reference;
|
||||
|
||||
import com.pahimar.ee3.test.VanillaTestSuite;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Tests {
|
||||
|
||||
public static File globalTestDirectory;
|
||||
|
||||
public static final VanillaTestSuite VANILLA_TEST_SUITE = new VanillaTestSuite();
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package com.pahimar.ee3.test;
|
||||
|
||||
import com.pahimar.ee3.init.ModBlocks;
|
||||
import com.pahimar.ee3.init.ModItems;
|
||||
import com.pahimar.ee3.reference.Files;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class EETestSuite extends EnergyValueTestSuite {
|
||||
|
||||
public EETestSuite() {
|
||||
super();
|
||||
}
|
||||
|
||||
public EETestSuite build() {
|
||||
|
||||
add(ModBlocks.calcinator, 772);
|
||||
add(ModBlocks.aludel, 1794);
|
||||
add(ModBlocks.glassBell, 7);
|
||||
add(ModBlocks.researchStation, 520);
|
||||
add(ModBlocks.augmentationTable, 284);
|
||||
add(new ItemStack(ModBlocks.alchemicalChest, 1, 0), 576);
|
||||
add(new ItemStack(ModBlocks.alchemicalChest, 1, 1), 16448);
|
||||
add(new ItemStack(ModBlocks.alchemicalChest, 1, 2), 65600);
|
||||
add(ModBlocks.chalkBlock, 320);
|
||||
add(new ItemStack(ModBlocks.alchemicalFuelBlock, 1, 0), 18720);
|
||||
add(new ItemStack(ModBlocks.alchemicalFuelBlock, 1, 1), 147744);
|
||||
add(new ItemStack(ModBlocks.alchemicalFuelBlock, 1, 2), 1179936);
|
||||
add(ModBlocks.ashInfusedStone, 2);
|
||||
add(ModBlocks.ashInfusedStoneSlab, 1);
|
||||
add(new ItemStack(ModItems.alchemicalBag, 1, 0), 560);
|
||||
add(new ItemStack(ModItems.alchemicalBag, 1, 1), 16432);
|
||||
add(new ItemStack(ModItems.alchemicalBag, 1, 2), 65584);
|
||||
add(new ItemStack(ModItems.alchemicalDust, 1, 0), 1);
|
||||
add(new ItemStack(ModItems.alchemicalDust, 1, 1), 64);
|
||||
add(new ItemStack(ModItems.alchemicalDust, 1, 2), 2048);
|
||||
add(new ItemStack(ModItems.alchemicalDust, 1, 3), 8192);
|
||||
add(new ItemStack(ModItems.alchemicalFuel, 1, 0), 2080);
|
||||
add(new ItemStack(ModItems.alchemicalFuel, 1, 1), 16416);
|
||||
add(new ItemStack(ModItems.alchemicalFuel, 1, 2), 131104);
|
||||
add(ModItems.stoneInert, 3076);
|
||||
add(ModItems.shardMinium, 8192);
|
||||
add(ModItems.stoneMinium, 68612);
|
||||
add(ModItems.stonePhilosophers, null);
|
||||
add(ModItems.chalk, 80);
|
||||
add(new ItemStack(ModItems.alchemicalUpgrade, 1, 0), null);
|
||||
add(new ItemStack(ModItems.alchemicalUpgrade, 1, 1), null);
|
||||
add(new ItemStack(ModItems.alchemicalUpgrade, 1, 2), null);
|
||||
add(ModItems.diviningRod, 16);
|
||||
add(ModItems.alchenomicon, 8352);
|
||||
add(new ItemStack(ModItems.matter, 1, 0), null);
|
||||
add(new ItemStack(ModItems.matter, 1, 1), null);
|
||||
add(new ItemStack(ModItems.matter, 1, 2), null);
|
||||
add(new ItemStack(ModItems.matter, 1, 3), null);
|
||||
add(new ItemStack(ModItems.matter, 1, 4), null);
|
||||
add(new ItemStack(ModItems.matter, 1, 5), null);
|
||||
add(new ItemStack(ModItems.matter, 1, 6), null);
|
||||
add(new ItemStack(ModItems.matter, 1, 7), null);
|
||||
add(new ItemStack(ModItems.matter, 1, 8), null);
|
||||
add(new ItemStack(ModItems.gem, 1, 0), null);
|
||||
add(new ItemStack(ModItems.gem, 1, 1), null);
|
||||
add(new ItemStack(ModItems.gem, 1, 2), null);
|
||||
add(new ItemStack(ModItems.gem, 1, 3), null);
|
||||
add(new ItemStack(ModItems.gem, 1, 4), null);
|
||||
add(new ItemStack(ModItems.gem, 1, 5), null);
|
||||
add(new ItemStack(ModItems.gem, 1, 6), null);
|
||||
add(ModItems.lootBall, null);
|
||||
add(ModItems.knowledgeScroll, null);
|
||||
add(ModItems.potionLethe, null);
|
||||
add(ModItems.shovelDarkMatter, null);
|
||||
add(ModItems.pickAxeDarkMatter, null);
|
||||
add(ModItems.hammerDarkMatter, null);
|
||||
add(ModItems.axeDarkMatter, null);
|
||||
add(ModItems.hoeDarkMatter, null);
|
||||
add(ModItems.fishingRodDarkMatter, null);
|
||||
add(ModItems.shearsDarkMatter, null);
|
||||
add(ModItems.bowDarkMatter, null);
|
||||
add(ModItems.swordDarkMatter, null);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
this.save(new File(Files.globalTestDirectory, "ee3-v1710-test-suite.json"));
|
||||
}
|
||||
}
|
|
@ -10,7 +10,10 @@ import org.apache.logging.log4j.MarkerManager;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class EnergyValueTestSuite {
|
||||
|
||||
|
@ -21,15 +24,9 @@ public class EnergyValueTestSuite {
|
|||
private static final Marker FAILURE_NO_VALUE_MARKER = MarkerManager.getMarker("EE3_TEST_FAILURE_NO_VALUE", FAILURE_MARKER);
|
||||
|
||||
private Map<WrappedStack, EnergyValue> testSuiteValueMap;
|
||||
private transient Set<WrappedStack> stacksWithCorrectValue;
|
||||
private transient Set<WrappedStack> failureStacksWithWrongValue;
|
||||
private transient Set<WrappedStack> failureStacksWithNoValue;
|
||||
|
||||
public EnergyValueTestSuite() {
|
||||
testSuiteValueMap = new TreeMap<>();
|
||||
stacksWithCorrectValue = new TreeSet<>();
|
||||
failureStacksWithWrongValue = new TreeSet<>();
|
||||
failureStacksWithNoValue = new TreeSet<>();
|
||||
}
|
||||
|
||||
public EnergyValueTestSuite(File file) {
|
||||
|
@ -70,10 +67,6 @@ public class EnergyValueTestSuite {
|
|||
|
||||
public void run(boolean strict) {
|
||||
|
||||
stacksWithCorrectValue.clear();
|
||||
failureStacksWithWrongValue.clear();
|
||||
failureStacksWithNoValue.clear();
|
||||
|
||||
List<String> successMessages = new ArrayList<>();
|
||||
List<String> failureMessagesWrongValue = new ArrayList<>();
|
||||
List<String> failureMessagesNoValue = new ArrayList<>();
|
||||
|
@ -86,24 +79,20 @@ public class EnergyValueTestSuite {
|
|||
if (actualValue == null && expectedValue == null) {
|
||||
// Success - anticipated that no value was found and no value was found
|
||||
successMessages.add(String.format("SUCCESS: Object '%s' had the expected energy value [Expected (%s), Found (%s)]", wrappedStack, expectedValue, actualValue));
|
||||
stacksWithCorrectValue.add(wrappedStack);
|
||||
}
|
||||
else if (actualValue == null) {
|
||||
// Failure - anticipated that a value would be found but no value was found
|
||||
failureMessagesNoValue.add(String.format("FAILURE: Object '%s' did not have the expected energy value [Expected (%s), Found (%s)]", wrappedStack, expectedValue, actualValue));
|
||||
failureStacksWithNoValue.add(wrappedStack);
|
||||
}
|
||||
else if (actualValue != null && expectedValue != null) {
|
||||
|
||||
if (actualValue.equals(expectedValue)) {
|
||||
// Success - anticipated that a specific value would be found and the anticipated value was found
|
||||
successMessages.add(String.format("SUCCESS: Object '%s' had the expected energy value [Expected (%s), Found (%s)]", wrappedStack, expectedValue, actualValue));
|
||||
stacksWithCorrectValue.add(wrappedStack);
|
||||
}
|
||||
else {
|
||||
// Failure - anticipated that a specific value would be found and while a value was found it was not the anticipated one
|
||||
failureMessagesWrongValue.add(String.format("FAILURE: Object '%s' did not have the expected energy value [Expected (%s), Found (%s)]", wrappedStack, expectedValue, actualValue));
|
||||
failureStacksWithWrongValue.add(wrappedStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,10 +120,6 @@ public class EnergyValueTestSuite {
|
|||
testSuiteValueMap = new TreeMap<>();
|
||||
}
|
||||
|
||||
stacksWithCorrectValue = new TreeSet<>();
|
||||
failureStacksWithWrongValue = new TreeSet<>();
|
||||
failureStacksWithNoValue = new TreeSet<>();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.pahimar.ee3.test;
|
||||
|
||||
import com.pahimar.ee3.reference.Tests;
|
||||
import com.pahimar.ee3.reference.Files;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -11,10 +11,10 @@ import java.io.File;
|
|||
public class VanillaTestSuite extends EnergyValueTestSuite {
|
||||
|
||||
public VanillaTestSuite() {
|
||||
buildTestSuite();
|
||||
super();
|
||||
}
|
||||
|
||||
private void buildTestSuite() {
|
||||
public VanillaTestSuite build() {
|
||||
|
||||
addBuildingBlocksTabTestCases();
|
||||
addDecorationBlocksTabTestCases();
|
||||
|
@ -26,6 +26,8 @@ public class VanillaTestSuite extends EnergyValueTestSuite {
|
|||
addCombatTabTestCases();
|
||||
addBrewingTabTestCases();
|
||||
addMaterialsTabTestCases();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private void addBuildingBlocksTabTestCases() {
|
||||
|
@ -599,6 +601,6 @@ public class VanillaTestSuite extends EnergyValueTestSuite {
|
|||
}
|
||||
|
||||
public void save() {
|
||||
this.save(new File(Tests.globalTestDirectory, "minecraft-v1710-vanilla-test-suite.json"));
|
||||
this.save(new File(Files.globalTestDirectory, "minecraft-v1710-vanilla-test-suite.json"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ 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;
|
||||
|
|
|
@ -41,6 +41,7 @@ public class EnergyValueMapSerializer implements JsonSerializer<Map<WrappedStack
|
|||
|
||||
if (jsonValueMapping.get(ENERGY_VALUE).isJsonPrimitive()) {
|
||||
|
||||
if (jsonValueMapping.getAsJsonPrimitive(ENERGY_VALUE).isNumber()) {
|
||||
try {
|
||||
energyValue = new EnergyValue(jsonValueMapping.getAsJsonPrimitive(ENERGY_VALUE).getAsNumber());
|
||||
}
|
||||
|
@ -48,6 +49,7 @@ public class EnergyValueMapSerializer implements JsonSerializer<Map<WrappedStack
|
|||
// TODO Logging
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (jsonValueMapping.has(TYPE_ITEM_STACK)) {
|
||||
|
||||
|
@ -97,12 +99,23 @@ public class EnergyValueMapSerializer implements JsonSerializer<Map<WrappedStack
|
|||
|
||||
if (src != null) {
|
||||
src.keySet().stream()
|
||||
.filter(wrappedStack -> wrappedStack != null && wrappedStack.getWrappedObject() != null & src.get(wrappedStack) != null)
|
||||
.filter(wrappedStack -> wrappedStack != null && wrappedStack.getWrappedObject() != null)
|
||||
.forEach(wrappedStack -> {
|
||||
JsonObject jsonMapping = new JsonObject();
|
||||
JsonElement jsonElement = context.serialize(wrappedStack.getWrappedObject());
|
||||
|
||||
if (jsonElement.isJsonObject()) {
|
||||
jsonMapping.add(wrappedStack.getWrappedObject().getClass().getSimpleName().toLowerCase(), context.serialize(wrappedStack.getWrappedObject()));
|
||||
|
||||
if (src.get(wrappedStack) != null) {
|
||||
jsonMapping.addProperty(ENERGY_VALUE, src.get(wrappedStack).getValue());
|
||||
}
|
||||
else {
|
||||
jsonMapping.add(ENERGY_VALUE, JsonNull.INSTANCE);
|
||||
}
|
||||
|
||||
jsonArray.add(jsonMapping);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -73,10 +73,15 @@ public class ItemStackSerializer implements JsonSerializer<ItemStack>, JsonDeser
|
|||
@Override
|
||||
public JsonElement serialize(ItemStack src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
|
||||
if (src != null) {
|
||||
if (src != null && src.getItem() != null) {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
|
||||
if (Item.itemRegistry.getNameForObject(src.getItem()) != null) {
|
||||
jsonObject.addProperty(NAME, Item.itemRegistry.getNameForObject(src.getItem()));
|
||||
}
|
||||
else {
|
||||
return JsonNull.INSTANCE;
|
||||
}
|
||||
|
||||
if (src.getItemDamage() != 0) {
|
||||
jsonObject.addProperty(META_VALUE, src.getItemDamage());
|
||||
|
@ -89,6 +94,6 @@ public class ItemStackSerializer implements JsonSerializer<ItemStack>, JsonDeser
|
|||
return jsonObject;
|
||||
}
|
||||
|
||||
return null;
|
||||
return JsonNull.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue