mirror of
https://github.com/GTNewHorizons/BloodMagic.git
synced 2026-11-17 10:55:10 +00:00
Fix race condition on NEIConfig#bloodOrbs initialization (#10)
This commit is contained in:
1 parent
b4db1b05c8
commit
67062474fa
4 files changed
+52
-67
No files matched your search
@@ -1,6 +1,6 @@
|
||||
package WayofTime.alchemicalWizardry.client.nei;
|
||||
|
||||
import static WayofTime.alchemicalWizardry.client.nei.NEIConfig.bloodOrbs;
|
||||
import static WayofTime.alchemicalWizardry.client.nei.NEIConfig.getBloodOrbs;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
@@ -57,7 +57,7 @@ public class NEIAlchemyRecipeHandler extends TemplateRecipeHandler {
|
||||
this.output = new PositionedStack(recipe.getResult(), 76, 25);
|
||||
this.lp = recipe.getAmountNeeded() * 100;
|
||||
this.orbs = new ArrayList<BloodOrbs>();
|
||||
for (Item orb : bloodOrbs) {
|
||||
for (Item orb : getBloodOrbs()) {
|
||||
if (((IBloodOrb) orb).getOrbLevel() >= recipe.getOrbLevel()) {
|
||||
orbs.add(new BloodOrbs(new ItemStack(orb)));
|
||||
}
|
||||
@@ -81,29 +81,6 @@ public class NEIAlchemyRecipeHandler extends TemplateRecipeHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateRecipeHandler newInstance() {
|
||||
// We need to populate available blood orbs,
|
||||
// but don't try to do it more than once
|
||||
if (bloodOrbs.isEmpty()) {
|
||||
for (ItemStack item : ItemList.items) {
|
||||
if (item != null && item.getItem() instanceof IBloodOrb) {
|
||||
bloodOrbs.add(item.getItem());
|
||||
}
|
||||
}
|
||||
if (bloodOrbs.isEmpty()) {
|
||||
// If there is NEI no cache - go to item registry
|
||||
for (Object anItemRegistry : Item.itemRegistry) {
|
||||
Item item = (Item) anItemRegistry;
|
||||
if (item != null && item instanceof IBloodOrb) {
|
||||
bloodOrbs.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.newInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOverlayIdentifier() {
|
||||
return "alchemicalwizardry.alchemy";
|
||||
|
||||
+12
-37
@@ -1,25 +1,23 @@
|
||||
package WayofTime.alchemicalWizardry.client.nei;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import WayofTime.alchemicalWizardry.api.items.ShapedBloodOrbRecipe;
|
||||
import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb;
|
||||
import codechicken.nei.ItemList;
|
||||
import codechicken.nei.NEIServerUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.recipe.ShapedRecipeHandler;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import WayofTime.alchemicalWizardry.api.items.ShapedBloodOrbRecipe;
|
||||
import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb;
|
||||
import codechicken.nei.NEIServerUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.recipe.ShapedRecipeHandler;
|
||||
|
||||
import static WayofTime.alchemicalWizardry.client.nei.NEIConfig.bloodOrbs;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static WayofTime.alchemicalWizardry.client.nei.NEIConfig.getBloodOrbs;
|
||||
|
||||
/**
|
||||
* NEI Blood Orb Shaped Recipe Handler by joshie *
|
||||
@@ -43,8 +41,8 @@ public class NEIBloodOrbShapedHandler extends ShapedRecipeHandler {
|
||||
stack.setMaxSize(1);
|
||||
ingredients.add(stack);
|
||||
} else if (o instanceof Integer) {
|
||||
ArrayList<ItemStack> orbs = new ArrayList();
|
||||
for (Item item : bloodOrbs) {
|
||||
ArrayList<ItemStack> orbs = new ArrayList<>();
|
||||
for (Item item : getBloodOrbs()) {
|
||||
if (((IBloodOrb) item).getOrbLevel() >= (Integer) o) {
|
||||
orbs.add(new ItemStack(item));
|
||||
}
|
||||
@@ -144,27 +142,4 @@ public class NEIBloodOrbShapedHandler extends ShapedRecipeHandler {
|
||||
return StatCollector.translateToLocal("bm.string.crafting.orb.shaped");
|
||||
|
||||
}
|
||||
@Override
|
||||
public TemplateRecipeHandler newInstance() {
|
||||
// We need to populate available blood orbs,
|
||||
// but don't try to do it more than once
|
||||
if (bloodOrbs.isEmpty()) {
|
||||
for (ItemStack item : ItemList.items) {
|
||||
if (item != null && item.getItem() instanceof IBloodOrb) {
|
||||
bloodOrbs.add(item.getItem());
|
||||
}
|
||||
}
|
||||
if (bloodOrbs.isEmpty()) {
|
||||
// If there is NEI no cache - go to item registry
|
||||
for (Object anItemRegistry : Item.itemRegistry) {
|
||||
Item item = (Item) anItemRegistry;
|
||||
if (item != null && item instanceof IBloodOrb) {
|
||||
bloodOrbs.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.newInstance();
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -34,8 +34,8 @@ public class NEIBloodOrbShapelessHandler extends ShapelessRecipeHandler {
|
||||
stack.setMaxSize(1);
|
||||
ingredients.add(stack);
|
||||
} else if (o instanceof Integer) {
|
||||
ArrayList<ItemStack> orbs = new ArrayList();
|
||||
for (Item item : NEIConfig.bloodOrbs) {
|
||||
ArrayList<ItemStack> orbs = new ArrayList<>();
|
||||
for (Item item : NEIConfig.getBloodOrbs()) {
|
||||
if (((IBloodOrb) item).getOrbLevel() >= (Integer) o) {
|
||||
orbs.add(new ItemStack(item));
|
||||
}
|
||||
|
||||
@@ -2,13 +2,46 @@ package WayofTime.alchemicalWizardry.client.nei;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb;
|
||||
import codechicken.nei.ItemList;
|
||||
import net.minecraft.item.Item;
|
||||
import codechicken.nei.api.API;
|
||||
import codechicken.nei.api.IConfigureNEI;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class NEIConfig implements IConfigureNEI {
|
||||
private static ArrayList<Item> bloodOrbs = null;
|
||||
|
||||
public static ArrayList<Item> getBloodOrbs() {
|
||||
if (bloodOrbs == null) {
|
||||
synchronized (NEIConfig.class) {
|
||||
if (bloodOrbs == null) {
|
||||
bloodOrbs = collectAllBloodOrbs();
|
||||
}
|
||||
}
|
||||
}
|
||||
return bloodOrbs;
|
||||
}
|
||||
|
||||
private static ArrayList<Item> collectAllBloodOrbs() {
|
||||
ArrayList<Item> bloodOrbsTemp = new ArrayList<>();
|
||||
for (ItemStack item : ItemList.items) {
|
||||
if (item != null && item.getItem() instanceof IBloodOrb) {
|
||||
bloodOrbsTemp.add(item.getItem());
|
||||
}
|
||||
}
|
||||
if (bloodOrbsTemp.isEmpty()) {
|
||||
// If there is NEI no cache - go to item registry
|
||||
for (Object anItemRegistry : Item.itemRegistry) {
|
||||
Item item = (Item) anItemRegistry;
|
||||
if (item instanceof IBloodOrb) {
|
||||
bloodOrbsTemp.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return bloodOrbsTemp;
|
||||
}
|
||||
|
||||
public class NEIConfig implements IConfigureNEI {
|
||||
public static ArrayList<Item> bloodOrbs = new ArrayList<Item>();
|
||||
|
||||
@Override
|
||||
public void loadConfig() {
|
||||
API.registerRecipeHandler(new NEIAlchemyRecipeHandler());
|
||||
|
||||
Reference in new issue
Block a user