mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-26 23:13:27 +00:00
Update buildscript & apply automatic formatting rules
This commit is contained in:
1 parent
a7683b885d
commit
e1dc20499c
173 files changed
+4581
-5321
No files matched your search
@@ -1,19 +1,17 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import codechicken.nei.util.NBTJson;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import codechicken.nei.util.NBTJson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class BookmarkRecipeId
|
||||
{
|
||||
public class BookmarkRecipeId {
|
||||
|
||||
public int position = -1;
|
||||
|
||||
@@ -23,9 +21,7 @@ public class BookmarkRecipeId
|
||||
|
||||
public List<NBTTagCompound> ingredients = new ArrayList<>();
|
||||
|
||||
|
||||
public BookmarkRecipeId(String handlerName, List<?> stacks)
|
||||
{
|
||||
public BookmarkRecipeId(String handlerName, List<?> stacks) {
|
||||
this.handlerName = handlerName;
|
||||
|
||||
for (Object pos : stacks) {
|
||||
@@ -41,13 +37,10 @@ public class BookmarkRecipeId
|
||||
if (pos instanceof NBTTagCompound) {
|
||||
ingredients.add((NBTTagCompound) pos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public BookmarkRecipeId(JsonObject json)
|
||||
{
|
||||
public BookmarkRecipeId(JsonObject json) {
|
||||
|
||||
if (json.get("handlerName") != null) {
|
||||
handlerName = json.get("handlerName").getAsString();
|
||||
@@ -60,18 +53,12 @@ public class BookmarkRecipeId
|
||||
if (ingredients != null) {
|
||||
this.ingredients = ingredients;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public BookmarkRecipeId()
|
||||
{
|
||||
public BookmarkRecipeId() {}
|
||||
|
||||
}
|
||||
|
||||
public boolean equalsIngredients(List<PositionedStack> stacks)
|
||||
{
|
||||
public boolean equalsIngredients(List<PositionedStack> stacks) {
|
||||
|
||||
if (ingredients.size() != stacks.size()) {
|
||||
return false;
|
||||
@@ -93,8 +80,7 @@ public class BookmarkRecipeId
|
||||
return true;
|
||||
}
|
||||
|
||||
public ItemStack getItemStackWithMinimumDamage(ItemStack[] stacks)
|
||||
{
|
||||
public ItemStack getItemStackWithMinimumDamage(ItemStack[] stacks) {
|
||||
int damage = Short.MAX_VALUE;
|
||||
ItemStack result = stacks[0];
|
||||
|
||||
@@ -110,8 +96,7 @@ public class BookmarkRecipeId
|
||||
return result.copy();
|
||||
}
|
||||
|
||||
public JsonObject toJsonObject()
|
||||
{
|
||||
public JsonObject toJsonObject() {
|
||||
JsonObject json = new JsonObject();
|
||||
|
||||
if (handlerName != null) {
|
||||
@@ -122,8 +107,7 @@ public class BookmarkRecipeId
|
||||
return json;
|
||||
}
|
||||
|
||||
protected List<NBTTagCompound> convertJsonArrayToIngredients(JsonArray arr)
|
||||
{
|
||||
protected List<NBTTagCompound> convertJsonArrayToIngredients(JsonArray arr) {
|
||||
List<NBTTagCompound> ingredients = new ArrayList<>();
|
||||
|
||||
for (JsonElement elem : arr) {
|
||||
@@ -139,8 +123,7 @@ public class BookmarkRecipeId
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
protected JsonArray convertIngredientsToJsonArray(List<NBTTagCompound> ingredients)
|
||||
{
|
||||
protected JsonArray convertIngredientsToJsonArray(List<NBTTagCompound> ingredients) {
|
||||
JsonArray arr = new JsonArray();
|
||||
|
||||
for (NBTTagCompound nbTag : ingredients) {
|
||||
@@ -150,10 +133,9 @@ public class BookmarkRecipeId
|
||||
return arr;
|
||||
}
|
||||
|
||||
public boolean equals(Object anObject)
|
||||
{
|
||||
if (this == anObject) {
|
||||
return true;
|
||||
public boolean equals(Object anObject) {
|
||||
if (this == anObject) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (anObject instanceof BookmarkRecipeId) {
|
||||
@@ -176,12 +158,10 @@ public class BookmarkRecipeId
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
public BookmarkRecipeId copy()
|
||||
{
|
||||
public BookmarkRecipeId copy() {
|
||||
return new BookmarkRecipeId(handlerName, ingredients);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +1,16 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
import java.util.List;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BrewingOverlayHandler extends DefaultOverlayHandler
|
||||
{
|
||||
public class BrewingOverlayHandler extends DefaultOverlayHandler {
|
||||
@Override
|
||||
public Slot[][] mapIngredSlots(GuiContainer gui, List<PositionedStack> ingredients)
|
||||
{
|
||||
public Slot[][] mapIngredSlots(GuiContainer gui, List<PositionedStack> ingredients) {
|
||||
Slot[][] map = super.mapIngredSlots(gui, ingredients);
|
||||
Slot[] potSlots = new Slot[3];
|
||||
for(int i = 0; i < 3; i++)
|
||||
potSlots[i] = (Slot) gui.inventorySlots.inventorySlots.get(i);
|
||||
for (int i = 0; i < 3; i++) potSlots[i] = (Slot) gui.inventorySlots.inventorySlots.get(i);
|
||||
map[1] = potSlots;
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import static net.minecraft.init.Items.potionitem;
|
||||
|
||||
import codechicken.nei.ItemStackSet;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.NEIServerUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.API;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.client.gui.inventory.GuiBrewingStand;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemPotion;
|
||||
@@ -13,19 +21,8 @@ import net.minecraft.potion.Potion;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.potion.PotionHelper;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.minecraft.init.Items.potionitem;
|
||||
|
||||
public class BrewingRecipeHandler extends TemplateRecipeHandler
|
||||
{
|
||||
public static class BrewingRecipe
|
||||
{
|
||||
public class BrewingRecipeHandler extends TemplateRecipeHandler {
|
||||
public static class BrewingRecipe {
|
||||
public PositionedStack precursorPotion;
|
||||
public PositionedStack result;
|
||||
public PositionedStack ingredient;
|
||||
@@ -37,8 +34,7 @@ public class BrewingRecipeHandler extends TemplateRecipeHandler
|
||||
}
|
||||
}
|
||||
|
||||
public class CachedBrewingRecipe extends CachedRecipe
|
||||
{
|
||||
public class CachedBrewingRecipe extends CachedRecipe {
|
||||
public final BrewingRecipe recipe;
|
||||
|
||||
public CachedBrewingRecipe(BrewingRecipe recipe) {
|
||||
@@ -81,23 +77,22 @@ public class BrewingRecipeHandler extends TemplateRecipeHandler
|
||||
|
||||
@Override
|
||||
public void loadCraftingRecipes(String outputId, Object... results) {
|
||||
if (outputId.equals("brewing") && getClass() == BrewingRecipeHandler.class)//don't want subclasses getting a hold of this
|
||||
for (BrewingRecipe recipe : apotions)
|
||||
arecipes.add(new CachedBrewingRecipe(recipe));
|
||||
else
|
||||
super.loadCraftingRecipes(outputId, results);
|
||||
if (outputId.equals("brewing")
|
||||
&& getClass() == BrewingRecipeHandler.class) // don't want subclasses getting a hold of this
|
||||
for (BrewingRecipe recipe : apotions) arecipes.add(new CachedBrewingRecipe(recipe));
|
||||
else super.loadCraftingRecipes(outputId, results);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCraftingRecipes(ItemStack result) {
|
||||
if (result.getItem() != potionitem) return;
|
||||
int damage = result.getItemDamage();
|
||||
|
||||
|
||||
// Note: Not safe as written for parallelStream
|
||||
apotions.stream()
|
||||
.filter(recipe -> recipe.result.item.getItemDamage() == damage)
|
||||
.map(CachedBrewingRecipe::new)
|
||||
.collect(Collectors.toCollection(() -> arecipes));
|
||||
.filter(recipe -> recipe.result.item.getItemDamage() == damage)
|
||||
.map(CachedBrewingRecipe::new)
|
||||
.collect(Collectors.toCollection(() -> arecipes));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -106,9 +101,10 @@ public class BrewingRecipeHandler extends TemplateRecipeHandler
|
||||
|
||||
// Note: Not safe as written for parallelStream
|
||||
apotions.stream()
|
||||
.filter(recipe -> NEIServerUtils.areStacksSameType(recipe.ingredient.item, ingredient) || NEIServerUtils.areStacksSameType(recipe.precursorPotion.item, ingredient))
|
||||
.map(CachedBrewingRecipe::new)
|
||||
.collect(Collectors.toCollection(() -> arecipes));
|
||||
.filter(recipe -> NEIServerUtils.areStacksSameType(recipe.ingredient.item, ingredient)
|
||||
|| NEIServerUtils.areStacksSameType(recipe.precursorPotion.item, ingredient))
|
||||
.map(CachedBrewingRecipe::new)
|
||||
.collect(Collectors.toCollection(() -> arecipes));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,36 +126,43 @@ public class BrewingRecipeHandler extends TemplateRecipeHandler
|
||||
do {
|
||||
HashSet<Integer> newPotions = new HashSet<>();
|
||||
for (Integer basePotion : searchPotions) {
|
||||
if (ItemPotion.isSplash(basePotion))
|
||||
continue;
|
||||
if (ItemPotion.isSplash(basePotion)) continue;
|
||||
|
||||
for (ItemStack ingred : ingredients.values()) {
|
||||
int result = PotionHelper.applyIngredient(basePotion, ingred.getItem().getPotionEffect(ingred));
|
||||
int result = PotionHelper.applyIngredient(
|
||||
basePotion, ingred.getItem().getPotionEffect(ingred));
|
||||
|
||||
if (ItemPotion.isSplash(result)) {//splash potions qualify
|
||||
if (ItemPotion.isSplash(result)) { // splash potions qualify
|
||||
addPotion(ingred, basePotion, result, allPotions, newPotions);
|
||||
continue;
|
||||
}
|
||||
|
||||
List<?> baseMods = potionitem.getEffects(basePotion);
|
||||
List<?> newMods = potionitem.getEffects(result);//compare ID's
|
||||
if (basePotion > 0 && baseMods == newMods || //same modifers and not water->empty
|
||||
baseMods != null && (baseMods.equals(newMods) || newMods == null) || //modifiers different and doesn't lose modifiers
|
||||
basePotion == result ||//same potion
|
||||
levelModifierChanged(basePotion, result))//redstone/glowstone cycle
|
||||
continue;
|
||||
List<?> newMods = potionitem.getEffects(result); // compare ID's
|
||||
if (basePotion > 0 && baseMods == newMods
|
||||
|| // same modifers and not water->empty
|
||||
baseMods != null && (baseMods.equals(newMods) || newMods == null)
|
||||
|| // modifiers different and doesn't lose modifiers
|
||||
basePotion == result
|
||||
|| // same potion
|
||||
levelModifierChanged(basePotion, result)) // redstone/glowstone cycle
|
||||
continue;
|
||||
|
||||
addPotion(ingred, basePotion, result, allPotions, newPotions);
|
||||
}
|
||||
}
|
||||
|
||||
searchPotions = newPotions;
|
||||
}
|
||||
while (!searchPotions.isEmpty());
|
||||
} while (!searchPotions.isEmpty());
|
||||
|
||||
API.setItemListEntries(potionitem, allPotions.stream().map(potionID -> new ItemStack(potionitem, 1, potionID)).collect(Collectors.toList()));
|
||||
API.setItemListEntries(
|
||||
potionitem,
|
||||
allPotions.stream()
|
||||
.map(potionID -> new ItemStack(potionitem, 1, potionID))
|
||||
.collect(Collectors.toList()));
|
||||
API.addSubset("Items.Potions", new ItemStackSet().with(potionitem));
|
||||
API.addSubset("Items.Potions.Splash", item -> item.getItem() == potionitem && (item.getItemDamage() & 0x4000) != 0);
|
||||
API.addSubset(
|
||||
"Items.Potions.Splash", item -> item.getItem() == potionitem && (item.getItemDamage() & 0x4000) != 0);
|
||||
|
||||
ItemStackSet positivepots = new ItemStackSet();
|
||||
ItemStackSet negativepots = new ItemStackSet();
|
||||
@@ -170,12 +173,11 @@ public class BrewingRecipeHandler extends TemplateRecipeHandler
|
||||
int type = 0;
|
||||
if (effectlist != null && !effectlist.isEmpty())
|
||||
for (PotionEffect potioneffect : effectlist)
|
||||
if (Potion.potionTypes[potioneffect.getPotionID()].isBadEffect())
|
||||
type--;
|
||||
else
|
||||
type++;
|
||||
if (Potion.potionTypes[potioneffect.getPotionID()].isBadEffect()) type--;
|
||||
else type++;
|
||||
|
||||
(type == 0 ? neutralpots : type > 0 ? positivepots : negativepots).add(new ItemStack(potionitem, 1, potionID));
|
||||
(type == 0 ? neutralpots : type > 0 ? positivepots : negativepots)
|
||||
.add(new ItemStack(potionitem, 1, potionID));
|
||||
}
|
||||
|
||||
API.addSubset("Items.Potions.Positive", positivepots);
|
||||
@@ -190,10 +192,11 @@ public class BrewingRecipeHandler extends TemplateRecipeHandler
|
||||
return basemod != 0 && basemod != resultmod;
|
||||
}
|
||||
|
||||
private static void addPotion(ItemStack ingred, int basePotion, int result, TreeSet<Integer> allPotions, HashSet<Integer> newPotions) {
|
||||
private static void addPotion(
|
||||
ItemStack ingred, int basePotion, int result, TreeSet<Integer> allPotions, HashSet<Integer> newPotions) {
|
||||
apotions.add(new BrewingRecipe(ingred, basePotion, result));
|
||||
if (allPotions.add(result))//it's new
|
||||
newPotions.add(result);
|
||||
if (allPotions.add(result)) // it's new
|
||||
newPotions.add(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,12 +3,11 @@ package codechicken.nei.recipe;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIServerUtils;
|
||||
import com.google.common.collect.ForwardingList;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
// Do not directly extend ArrayList, see Effective Java Item 16
|
||||
public class CatalystInfoList extends ForwardingList<CatalystInfo> {
|
||||
@@ -32,7 +31,9 @@ public class CatalystInfoList extends ForwardingList<CatalystInfo> {
|
||||
@Override
|
||||
public boolean add(@Nonnull CatalystInfo catalystInfo) {
|
||||
if (contains(catalystInfo)) {
|
||||
NEIClientConfig.logger.info(String.format("catalyst %s is already registered to handler %s", catalystInfo.getStack().getDisplayName(), handlerID));
|
||||
NEIClientConfig.logger.info(String.format(
|
||||
"catalyst %s is already registered to handler %s",
|
||||
catalystInfo.getStack().getDisplayName(), handlerID));
|
||||
return false;
|
||||
}
|
||||
super.add(catalystInfo);
|
||||
@@ -49,7 +50,8 @@ public class CatalystInfoList extends ForwardingList<CatalystInfo> {
|
||||
}
|
||||
|
||||
public boolean contains(ItemStack stack) {
|
||||
return catalystInfoList.stream().anyMatch(c -> NEIServerUtils.areStacksSameTypeCraftingWithNBT(c.getStack(), stack));
|
||||
return catalystInfoList.stream()
|
||||
.anyMatch(c -> NEIServerUtils.areStacksSameTypeCraftingWithNBT(c.getStack(), stack));
|
||||
}
|
||||
|
||||
public boolean remove(ItemStack stack) {
|
||||
|
||||
@@ -9,13 +9,10 @@ import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public class CheatItemHandler extends INEIGuiAdapter
|
||||
{
|
||||
public class CheatItemHandler extends INEIGuiAdapter {
|
||||
|
||||
@Override
|
||||
public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button)
|
||||
{
|
||||
public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) {
|
||||
final Slot overSlot = gui.getSlotAtPosition(mouseX, mouseY);
|
||||
|
||||
if (overSlot != null && overSlot.isItemValid(draggedStack)) {
|
||||
@@ -28,10 +25,12 @@ public class CheatItemHandler extends INEIGuiAdapter
|
||||
contents = 0;
|
||||
}
|
||||
|
||||
final int total = Math.min(contents + add, Math.min(overSlot.getSlotStackLimit(), draggedStack.getMaxStackSize()));
|
||||
final int total = Math.min(
|
||||
contents + add, Math.min(overSlot.getSlotStackLimit(), draggedStack.getMaxStackSize()));
|
||||
|
||||
if (total > contents) {
|
||||
NEIClientUtils.setSlotContents(overSlot.slotNumber, NEIServerUtils.copyStack(draggedStack, total), true);
|
||||
NEIClientUtils.setSlotContents(
|
||||
overSlot.slotNumber, NEIServerUtils.copyStack(draggedStack, total), true);
|
||||
NEICPH.sendGiveItem(NEIServerUtils.copyStack(draggedStack, total), false, false);
|
||||
draggedStack.stackSize -= total - contents;
|
||||
}
|
||||
@@ -45,6 +44,4 @@ public class CheatItemHandler extends INEIGuiAdapter
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,10 +7,8 @@ import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ContainerRecipe extends Container
|
||||
{
|
||||
private class RecipeInventory implements IInventory
|
||||
{
|
||||
public class ContainerRecipe extends Container {
|
||||
private class RecipeInventory implements IInventory {
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
return true;
|
||||
@@ -23,8 +21,7 @@ public class ContainerRecipe extends Container
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
if (i < 0 || i > inventoryItemStacks.size())
|
||||
return null;
|
||||
if (i < 0 || i > inventoryItemStacks.size()) return null;
|
||||
return (ItemStack) inventoryItemStacks.get(i);
|
||||
}
|
||||
|
||||
@@ -35,8 +32,7 @@ public class ContainerRecipe extends Container
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack itemstack) {
|
||||
if (slot < 0 || slot >= inventoryItemStacks.size())
|
||||
return;
|
||||
if (slot < 0 || slot >= inventoryItemStacks.size()) return;
|
||||
|
||||
inventoryItemStacks.set(slot, itemstack);
|
||||
}
|
||||
@@ -52,16 +48,13 @@ public class ContainerRecipe extends Container
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
}
|
||||
public void markDirty() {}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
}
|
||||
public void openInventory() {}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
}
|
||||
public void closeInventory() {}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int var1) {
|
||||
@@ -78,47 +71,37 @@ public class ContainerRecipe extends Container
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final RecipeInventory recipeInventory = new RecipeInventory();
|
||||
|
||||
public void clearInventory()
|
||||
{
|
||||
|
||||
public void clearInventory() {
|
||||
inventoryItemStacks.clear();
|
||||
inventorySlots.clear();
|
||||
}
|
||||
|
||||
public ItemStack slotClick(int slot, int button, boolean flag, EntityPlayer entityplayer)
|
||||
{
|
||||
if(slot < 0)
|
||||
return null;
|
||||
|
||||
|
||||
public ItemStack slotClick(int slot, int button, boolean flag, EntityPlayer entityplayer) {
|
||||
if (slot < 0) return null;
|
||||
|
||||
ItemStack stack = recipeInventory.getStackInSlot(slot);
|
||||
if(stack != null)
|
||||
{
|
||||
if(button == 0)
|
||||
GuiCraftingRecipe.openRecipeGui("item", stack);
|
||||
else if(button == 1)
|
||||
GuiUsageRecipe.openRecipeGui("item", stack);
|
||||
if (stack != null) {
|
||||
if (button == 0) GuiCraftingRecipe.openRecipeGui("item", stack);
|
||||
else if (button == 1) GuiUsageRecipe.openRecipeGui("item", stack);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addSlot(PositionedStack stack, int recipex, int recipey)
|
||||
{
|
||||
|
||||
public void addSlot(PositionedStack stack, int recipex, int recipey) {
|
||||
int slot = inventorySlots.size();
|
||||
addSlotToContainer(new Slot(recipeInventory, slot, recipex+stack.relx, recipey+stack.rely)
|
||||
{
|
||||
addSlotToContainer(new Slot(recipeInventory, slot, recipex + stack.relx, recipey + stack.rely) {
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack par1ItemStack)
|
||||
{
|
||||
public boolean isItemValid(ItemStack par1ItemStack) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
recipeInventory.setInventorySlotContents(slot, stack.item);
|
||||
}
|
||||
|
||||
public Slot getSlotWithStack(PositionedStack stack, int recipex, int recipey)
|
||||
{
|
||||
public Slot getSlotWithStack(PositionedStack stack, int recipex, int recipey) {
|
||||
for (Object inventorySlot : inventorySlots) {
|
||||
Slot slot = (Slot) inventorySlot;
|
||||
if (slot.xDisplayPosition == (stack.relx + recipex) && slot.yDisplayPosition == (stack.rely + recipey))
|
||||
@@ -126,21 +109,18 @@ public class ContainerRecipe extends Container
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean canInteractWith(EntityPlayer entityplayer)
|
||||
{
|
||||
|
||||
public boolean canInteractWith(EntityPlayer entityplayer) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void putStackInSlot(int par1, ItemStack par2ItemStack)
|
||||
{
|
||||
//Server side updates do nothing!
|
||||
public void putStackInSlot(int par1, ItemStack par2ItemStack) {
|
||||
// Server side updates do nothing!
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
|
||||
{
|
||||
return null;//no shift clicking (scrolling...)
|
||||
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
|
||||
return null; // no shift clicking (scrolling...)
|
||||
}
|
||||
}
|
||||
@@ -4,22 +4,21 @@ import codechicken.lib.inventory.InventoryUtils;
|
||||
import codechicken.nei.FastTransferManager;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@SuppressWarnings("rawtypes, unchecked")
|
||||
public class DefaultOverlayHandler implements IOverlayHandler {
|
||||
public static Class gtItem;
|
||||
|
||||
|
||||
static {
|
||||
try {
|
||||
gtItem = Class.forName("gregtech.api.items.GT_MetaBase_Item");
|
||||
@@ -27,112 +26,103 @@ public class DefaultOverlayHandler implements IOverlayHandler {
|
||||
gtItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class DistributedIngred {
|
||||
public DistributedIngred(ItemStack item)
|
||||
{
|
||||
public DistributedIngred(ItemStack item) {
|
||||
stack = InventoryUtils.copyStack(item, 1);
|
||||
}
|
||||
|
||||
public ItemStack stack;
|
||||
|
||||
public ItemStack stack;
|
||||
public int invAmount;
|
||||
public int distributed;
|
||||
public int numSlots;
|
||||
public int recipeAmount;
|
||||
}
|
||||
|
||||
|
||||
public static class IngredientDistribution {
|
||||
public IngredientDistribution(DistributedIngred distrib, ItemStack permutation) {
|
||||
this.distrib = distrib;
|
||||
this.permutation = permutation;
|
||||
}
|
||||
|
||||
|
||||
public DistributedIngred distrib;
|
||||
public ItemStack permutation;
|
||||
public Slot[] slots;
|
||||
}
|
||||
|
||||
|
||||
public DefaultOverlayHandler(int x, int y) {
|
||||
offsetx = x;
|
||||
offsety = y;
|
||||
}
|
||||
|
||||
public DefaultOverlayHandler()
|
||||
{
|
||||
|
||||
public DefaultOverlayHandler() {
|
||||
this(5, 11);
|
||||
}
|
||||
|
||||
public int offsetx;
|
||||
public int offsety;
|
||||
|
||||
|
||||
@Override
|
||||
public void overlayRecipe(GuiContainer gui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
|
||||
List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
|
||||
List<DistributedIngred> ingredStacks = getPermutationIngredients(ingredients);
|
||||
|
||||
if(!clearIngredients(gui, ingredients))
|
||||
return;
|
||||
|
||||
if (!clearIngredients(gui, ingredients)) return;
|
||||
|
||||
findInventoryQuantities(gui, ingredStacks);
|
||||
|
||||
|
||||
List<IngredientDistribution> assignedIngredients = assignIngredients(ingredients, ingredStacks);
|
||||
if(assignedIngredients == null)
|
||||
return;
|
||||
|
||||
if (assignedIngredients == null) return;
|
||||
|
||||
assignIngredSlots(gui, ingredients, assignedIngredients);
|
||||
int quantity = calculateRecipeQuantity(assignedIngredients);
|
||||
|
||||
if(quantity != 0)
|
||||
moveIngredients(gui, assignedIngredients, quantity);
|
||||
|
||||
if (quantity != 0) moveIngredients(gui, assignedIngredients, quantity);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private boolean clearIngredients(GuiContainer gui, List<PositionedStack> ingreds) {
|
||||
for(PositionedStack pstack : ingreds)
|
||||
for(Slot slot : (List<Slot>)gui.inventorySlots.inventorySlots)
|
||||
if(slot.xDisplayPosition == pstack.relx+offsetx && slot.yDisplayPosition == pstack.rely+offsety) {
|
||||
if(!slot.getHasStack())
|
||||
continue;
|
||||
|
||||
for (PositionedStack pstack : ingreds)
|
||||
for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots)
|
||||
if (slot.xDisplayPosition == pstack.relx + offsetx && slot.yDisplayPosition == pstack.rely + offsety) {
|
||||
if (!slot.getHasStack()) continue;
|
||||
|
||||
FastTransferManager.clickSlot(gui, slot.slotNumber, 0, 1);
|
||||
if(slot.getHasStack())
|
||||
return false;
|
||||
if (slot.getHasStack()) return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void moveIngredients(GuiContainer gui, List<IngredientDistribution> assignedIngredients, int quantity) {
|
||||
for(IngredientDistribution distrib : assignedIngredients) {
|
||||
if(distrib.slots.length == 0) continue;
|
||||
|
||||
private void moveIngredients(GuiContainer gui, List<IngredientDistribution> assignedIngredients, int quantity) {
|
||||
for (IngredientDistribution distrib : assignedIngredients) {
|
||||
if (distrib.slots.length == 0) continue;
|
||||
|
||||
ItemStack pstack = distrib.permutation;
|
||||
int transferCap = quantity*pstack.stackSize;
|
||||
int transferCap = quantity * pstack.stackSize;
|
||||
int transferred = 0;
|
||||
|
||||
|
||||
int destSlotIndex = 0;
|
||||
Slot dest = distrib.slots[0];
|
||||
int slotTransferred = 0;
|
||||
int slotTransferCap = pstack.getMaxStackSize();
|
||||
|
||||
for(Slot slot : (List<Slot>)gui.inventorySlots.inventorySlots) {
|
||||
if(!slot.getHasStack() || !canMoveFrom(slot, gui))
|
||||
continue;
|
||||
|
||||
|
||||
for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots) {
|
||||
if (!slot.getHasStack() || !canMoveFrom(slot, gui)) continue;
|
||||
|
||||
ItemStack stack = slot.getStack();
|
||||
if(!canStack(stack, pstack))
|
||||
continue;
|
||||
|
||||
if (!canStack(stack, pstack)) continue;
|
||||
|
||||
FastTransferManager.clickSlot(gui, slot.slotNumber);
|
||||
int amount = Math.min(transferCap-transferred, stack.stackSize);
|
||||
for(int c = 0; c < amount; c++) {
|
||||
int amount = Math.min(transferCap - transferred, stack.stackSize);
|
||||
for (int c = 0; c < amount; c++) {
|
||||
FastTransferManager.clickSlot(gui, dest.slotNumber, 1);
|
||||
transferred++;
|
||||
slotTransferred++;
|
||||
if(slotTransferred >= slotTransferCap) {
|
||||
if (slotTransferred >= slotTransferCap) {
|
||||
destSlotIndex++;
|
||||
if(destSlotIndex == distrib.slots.length) {
|
||||
if (destSlotIndex == distrib.slots.length) {
|
||||
dest = null;
|
||||
break;
|
||||
}
|
||||
@@ -141,89 +131,88 @@ public class DefaultOverlayHandler implements IOverlayHandler {
|
||||
}
|
||||
}
|
||||
FastTransferManager.clickSlot(gui, slot.slotNumber);
|
||||
if(transferred >= transferCap || dest == null)
|
||||
break;
|
||||
if (transferred >= transferCap || dest == null) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int calculateRecipeQuantity(List<IngredientDistribution> assignedIngredients) {
|
||||
int quantity = Integer.MAX_VALUE;
|
||||
for(IngredientDistribution distrib : assignedIngredients) {
|
||||
for (IngredientDistribution distrib : assignedIngredients) {
|
||||
DistributedIngred istack = distrib.distrib;
|
||||
if(istack.numSlots == 0)
|
||||
return 0;
|
||||
|
||||
if (istack.numSlots == 0) return 0;
|
||||
|
||||
int allSlots = istack.invAmount;
|
||||
if(allSlots/istack.numSlots > istack.stack.getMaxStackSize())
|
||||
allSlots = istack.numSlots*istack.stack.getMaxStackSize();
|
||||
|
||||
quantity = Math.min(quantity, allSlots/istack.distributed);
|
||||
if (allSlots / istack.numSlots > istack.stack.getMaxStackSize())
|
||||
allSlots = istack.numSlots * istack.stack.getMaxStackSize();
|
||||
|
||||
quantity = Math.min(quantity, allSlots / istack.distributed);
|
||||
}
|
||||
|
||||
|
||||
return quantity;
|
||||
}
|
||||
|
||||
private Slot[][] assignIngredSlots(GuiContainer gui, List<PositionedStack> ingredients, List<IngredientDistribution> assignedIngredients) {
|
||||
Slot[][] recipeSlots = mapIngredSlots(gui, ingredients);//setup the slot map
|
||||
|
||||
private Slot[][] assignIngredSlots(
|
||||
GuiContainer gui, List<PositionedStack> ingredients, List<IngredientDistribution> assignedIngredients) {
|
||||
Slot[][] recipeSlots = mapIngredSlots(gui, ingredients); // setup the slot map
|
||||
|
||||
HashMap<Slot, Integer> distribution = new HashMap<>();
|
||||
for (Slot[] recipeSlot : recipeSlots)
|
||||
for (Slot slot : recipeSlot)
|
||||
if (!distribution.containsKey(slot))
|
||||
distribution.put(slot, -1);
|
||||
|
||||
for (Slot slot : recipeSlot) if (!distribution.containsKey(slot)) distribution.put(slot, -1);
|
||||
|
||||
HashSet<Slot> avaliableSlots = new HashSet<>(distribution.keySet());
|
||||
HashSet<Integer> remainingIngreds = new HashSet<>();
|
||||
ArrayList<LinkedList<Slot>> assignedSlots = new ArrayList<>();
|
||||
for(int i = 0; i < ingredients.size(); i++) {
|
||||
for (int i = 0; i < ingredients.size(); i++) {
|
||||
remainingIngreds.add(i);
|
||||
assignedSlots.add(new LinkedList<>());
|
||||
}
|
||||
|
||||
while(avaliableSlots.size() > 0 && remainingIngreds.size() > 0) {
|
||||
for(Iterator<Integer> iterator = remainingIngreds.iterator(); iterator.hasNext();) {
|
||||
|
||||
while (avaliableSlots.size() > 0 && remainingIngreds.size() > 0) {
|
||||
for (Iterator<Integer> iterator = remainingIngreds.iterator(); iterator.hasNext(); ) {
|
||||
int i = iterator.next();
|
||||
boolean assigned = false;
|
||||
DistributedIngred istack = assignedIngredients.get(i).distrib;
|
||||
|
||||
for(Slot slot : recipeSlots[i]) {
|
||||
if(avaliableSlots.contains(slot)) {
|
||||
|
||||
for (Slot slot : recipeSlots[i]) {
|
||||
if (avaliableSlots.contains(slot)) {
|
||||
avaliableSlots.remove(slot);
|
||||
if(slot.getHasStack())
|
||||
continue;
|
||||
|
||||
if (slot.getHasStack()) continue;
|
||||
|
||||
istack.numSlots++;
|
||||
assignedSlots.get(i).add(slot);
|
||||
assigned = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!assigned || istack.numSlots*istack.stack.getMaxStackSize() >= istack.invAmount)
|
||||
|
||||
if (!assigned || istack.numSlots * istack.stack.getMaxStackSize() >= istack.invAmount)
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < ingredients.size(); i++)
|
||||
|
||||
for (int i = 0; i < ingredients.size(); i++)
|
||||
assignedIngredients.get(i).slots = assignedSlots.get(i).toArray(new Slot[0]);
|
||||
return recipeSlots;
|
||||
}
|
||||
|
||||
private List<IngredientDistribution> assignIngredients(List<PositionedStack> ingredients, List<DistributedIngred> ingredStacks)
|
||||
{
|
||||
private List<IngredientDistribution> assignIngredients(
|
||||
List<PositionedStack> ingredients, List<DistributedIngred> ingredStacks) {
|
||||
ArrayList<IngredientDistribution> assignedIngredients = new ArrayList<>();
|
||||
for(PositionedStack posstack : ingredients)//assign what we need and have
|
||||
for (PositionedStack posstack : ingredients) // assign what we need and have
|
||||
{
|
||||
DistributedIngred biggestIngred = null;
|
||||
ItemStack permutation = null;
|
||||
int biggestSize = 0;
|
||||
for(ItemStack pstack : posstack.items) {
|
||||
for (ItemStack pstack : posstack.items) {
|
||||
for (DistributedIngred istack : ingredStacks) {
|
||||
if (!canStack(pstack, istack.stack) || istack.invAmount - istack.distributed < pstack.stackSize || istack.recipeAmount == 0 || pstack.stackSize == 0)
|
||||
continue;
|
||||
if (!canStack(pstack, istack.stack)
|
||||
|| istack.invAmount - istack.distributed < pstack.stackSize
|
||||
|| istack.recipeAmount == 0
|
||||
|| pstack.stackSize == 0) continue;
|
||||
|
||||
int relsize = (istack.invAmount - istack.invAmount / istack.recipeAmount * istack.distributed) / pstack.stackSize;
|
||||
int relsize = (istack.invAmount - istack.invAmount / istack.recipeAmount * istack.distributed)
|
||||
/ pstack.stackSize;
|
||||
if (relsize > biggestSize) {
|
||||
biggestSize = relsize;
|
||||
biggestIngred = istack;
|
||||
@@ -232,37 +221,35 @@ public class DefaultOverlayHandler implements IOverlayHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(biggestIngred == null)//not enough ingreds
|
||||
return null;
|
||||
|
||||
biggestIngred.distributed+=permutation.stackSize;
|
||||
if (biggestIngred == null) // not enough ingreds
|
||||
return null;
|
||||
|
||||
biggestIngred.distributed += permutation.stackSize;
|
||||
assignedIngredients.add(new IngredientDistribution(biggestIngred, permutation));
|
||||
}
|
||||
|
||||
|
||||
return assignedIngredients;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void findInventoryQuantities(GuiContainer gui, List<DistributedIngred> ingredStacks) {
|
||||
for(Slot slot : (List<Slot>)gui.inventorySlots.inventorySlots)/*work out how much we have to go round*/ {
|
||||
if(slot.getHasStack() && canMoveFrom(slot, gui)) {
|
||||
for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots) /*work out how much we have to go round*/ {
|
||||
if (slot.getHasStack() && canMoveFrom(slot, gui)) {
|
||||
ItemStack pstack = slot.getStack();
|
||||
DistributedIngred istack = findIngred(ingredStacks, pstack);
|
||||
if(istack != null)
|
||||
istack.invAmount+=pstack.stackSize;
|
||||
if (istack != null) istack.invAmount += pstack.stackSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<DistributedIngred> getPermutationIngredients(List<PositionedStack> ingredients) {
|
||||
ArrayList<DistributedIngred> ingredStacks = new ArrayList<>();
|
||||
for(PositionedStack posstack : ingredients)/*work out what we need*/ {
|
||||
for(ItemStack pstack : posstack.items) {
|
||||
for (PositionedStack posstack : ingredients) /*work out what we need*/ {
|
||||
for (ItemStack pstack : posstack.items) {
|
||||
DistributedIngred istack = findIngred(ingredStacks, pstack);
|
||||
if(istack == null)
|
||||
ingredStacks.add(istack = new DistributedIngred(pstack));
|
||||
istack.recipeAmount+=pstack.stackSize;
|
||||
if (istack == null) ingredStacks.add(istack = new DistributedIngred(pstack));
|
||||
istack.recipeAmount += pstack.stackSize;
|
||||
}
|
||||
}
|
||||
return ingredStacks;
|
||||
@@ -273,14 +260,13 @@ public class DefaultOverlayHandler implements IOverlayHandler {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Slot[][] mapIngredSlots(GuiContainer gui, List<PositionedStack> ingredients)
|
||||
{
|
||||
public Slot[][] mapIngredSlots(GuiContainer gui, List<PositionedStack> ingredients) {
|
||||
Slot[][] recipeSlotList = new Slot[ingredients.size()][];
|
||||
for(int i = 0; i < ingredients.size(); i++)/*identify slots*/ {
|
||||
for (int i = 0; i < ingredients.size(); i++) /*identify slots*/ {
|
||||
LinkedList<Slot> recipeSlots = new LinkedList<>();
|
||||
PositionedStack pstack = ingredients.get(i);
|
||||
for(Slot slot : (List<Slot>)gui.inventorySlots.inventorySlots) {
|
||||
if(slot.xDisplayPosition == pstack.relx+offsetx && slot.yDisplayPosition == pstack.rely+offsety) {
|
||||
for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots) {
|
||||
if (slot.xDisplayPosition == pstack.relx + offsetx && slot.yDisplayPosition == pstack.rely + offsety) {
|
||||
recipeSlots.add(slot);
|
||||
break;
|
||||
}
|
||||
@@ -291,25 +277,21 @@ public class DefaultOverlayHandler implements IOverlayHandler {
|
||||
}
|
||||
|
||||
public DistributedIngred findIngred(List<DistributedIngred> ingredStacks, ItemStack pstack) {
|
||||
for(DistributedIngred istack : ingredStacks)
|
||||
if(canStack(pstack, istack.stack))
|
||||
return istack;
|
||||
for (DistributedIngred istack : ingredStacks) if (canStack(pstack, istack.stack)) return istack;
|
||||
return null;
|
||||
}
|
||||
|
||||
protected boolean canStack(ItemStack stack1, ItemStack stack2) {
|
||||
if (stack1 == null || stack2 == null)
|
||||
return true;
|
||||
if(stack1.getItem() == stack2.getItem() && stack1.getItemDamage() == stack2.getItemDamage()) {
|
||||
if (stack1 == null || stack2 == null) return true;
|
||||
if (stack1.getItem() == stack2.getItem() && stack1.getItemDamage() == stack2.getItemDamage()) {
|
||||
if (ItemStack.areItemStackTagsEqual(stack2, stack1)) return true;
|
||||
|
||||
// GT Items don't have any NBT set for the recipe, so if either of the stacks has a NULL nbt, and the other doesn't, pretend they stack
|
||||
if (((gtItem != null && gtItem.isInstance(stack1.getItem())) || (stack1.getMaxStackSize() == 1 && stack2.getMaxStackSize() == 1))
|
||||
&& (stack1.stackTagCompound == null ^ stack2.stackTagCompound == null)
|
||||
)
|
||||
return true;
|
||||
|
||||
|
||||
// GT Items don't have any NBT set for the recipe, so if either of the stacks has a NULL nbt, and the other
|
||||
// doesn't, pretend they stack
|
||||
if (((gtItem != null && gtItem.isInstance(stack1.getItem()))
|
||||
|| (stack1.getMaxStackSize() == 1 && stack2.getMaxStackSize() == 1))
|
||||
&& (stack1.stackTagCompound == null ^ stack2.stackTagCompound == null)) return true;
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,10 @@ import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
|
||||
public class FillFluidContainerHandler extends INEIGuiAdapter
|
||||
{
|
||||
public class FillFluidContainerHandler extends INEIGuiAdapter {
|
||||
|
||||
@Override
|
||||
public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button)
|
||||
{
|
||||
public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) {
|
||||
|
||||
if (button == 2) {
|
||||
return false;
|
||||
@@ -41,25 +39,21 @@ public class FillFluidContainerHandler extends INEIGuiAdapter
|
||||
} else {
|
||||
ItemPanels.bookmarkPanel.draggedStack = container;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (button == 1 && StackInfo.getFluid(container != null? container: draggedStack) != null) {
|
||||
ItemPanels.bookmarkPanel.addOrRemoveItem((container != null? container: draggedStack).copy());
|
||||
}
|
||||
|
||||
if (button == 1 && StackInfo.getFluid(container != null ? container : draggedStack) != null) {
|
||||
ItemPanels.bookmarkPanel.addOrRemoveItem((container != null ? container : draggedStack).copy());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected ItemStack fillContainer(ItemStack draggedStack, FluidStack fluidStack)
|
||||
{
|
||||
protected ItemStack fillContainer(ItemStack draggedStack, FluidStack fluidStack) {
|
||||
fluidStack = fluidStack.copy();
|
||||
draggedStack = draggedStack.copy();
|
||||
draggedStack.stackSize = 1;
|
||||
@@ -85,10 +79,8 @@ public class FillFluidContainerHandler extends INEIGuiAdapter
|
||||
if (item.fill(draggedStack, fluidStack, true) > 0) {
|
||||
return draggedStack;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,23 +5,20 @@ import codechicken.nei.InventoryCraftingDummy;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.RecipeFireworks;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.RecipeFireworks;
|
||||
|
||||
public class FireworkRecipeHandler extends ShapelessRecipeHandler
|
||||
{
|
||||
public class CachedFireworkRecipe extends CachedShapelessRecipe
|
||||
{
|
||||
public class FireworkRecipeHandler extends ShapelessRecipeHandler {
|
||||
public class CachedFireworkRecipe extends CachedShapelessRecipe {
|
||||
final LinkedList<Object> itemList = new LinkedList<>();
|
||||
|
||||
public final Object[] baseIngredients;
|
||||
@@ -41,16 +38,14 @@ public class FireworkRecipeHandler extends ShapelessRecipeHandler
|
||||
itemList.clear();
|
||||
itemList.addAll(Arrays.asList(baseIngredients));
|
||||
int extras = (cycleticks / 40) % (10 - itemList.size());
|
||||
for (int i = 0; i < extras; i++)
|
||||
itemList.add(extraIngred);
|
||||
for (int i = 0; i < extras; i++) itemList.add(extraIngred);
|
||||
setIngredients(itemList);
|
||||
|
||||
List<PositionedStack> ingreds = getIngredients();
|
||||
for (int i = 0; i < 9; i++)
|
||||
inventoryCrafting.setInventorySlotContents(i, i < ingreds.size() ? ingreds.get(i).item : null);
|
||||
|
||||
if (!recipeFireworks.matches(inventoryCrafting, null))
|
||||
throw new RuntimeException("Invalid Recipe?");
|
||||
if (!recipeFireworks.matches(inventoryCrafting, null)) throw new RuntimeException("Invalid Recipe?");
|
||||
setResult(recipeFireworks.getCraftingResult(null));
|
||||
}
|
||||
}
|
||||
@@ -62,35 +57,34 @@ public class FireworkRecipeHandler extends ShapelessRecipeHandler
|
||||
|
||||
public FireworkRecipeHandler() {
|
||||
super();
|
||||
stackorder = new int[][]{
|
||||
{0, 0},
|
||||
{1, 0},
|
||||
{2, 0},
|
||||
{0, 1},
|
||||
{1, 1},
|
||||
{2, 1},
|
||||
{0, 2},
|
||||
{1, 2},
|
||||
{2, 2}};
|
||||
stackorder = new int[][] {
|
||||
{0, 0},
|
||||
{1, 0},
|
||||
{2, 0},
|
||||
{0, 1},
|
||||
{1, 1},
|
||||
{2, 1},
|
||||
{0, 2},
|
||||
{1, 2},
|
||||
{2, 2}
|
||||
};
|
||||
loadAllFireworks();
|
||||
}
|
||||
|
||||
private void loadAllFireworks() {
|
||||
//charges
|
||||
Item[] shapes = new Item[]{null, Items.fire_charge, Items.gold_nugget, Items.feather, Items.skull};
|
||||
Item[] effects = new Item[]{null, Items.diamond, Items.glowstone_dust};
|
||||
// charges
|
||||
Item[] shapes = new Item[] {null, Items.fire_charge, Items.gold_nugget, Items.feather, Items.skull};
|
||||
Item[] effects = new Item[] {null, Items.diamond, Items.glowstone_dust};
|
||||
for (Item shape : shapes)
|
||||
for (Item effect : effects)
|
||||
genRecipe(Items.gunpowder, shape, effect, Items.dye, Items.dye, 0);
|
||||
for (Item effect : effects) genRecipe(Items.gunpowder, shape, effect, Items.dye, Items.dye, 0);
|
||||
|
||||
//fireworks
|
||||
// fireworks
|
||||
genRecipe(Items.gunpowder, Items.paper, Items.firework_charge, 2);
|
||||
genRecipe(Items.gunpowder, Items.gunpowder, Items.paper, Items.firework_charge, 2);
|
||||
genRecipe(Items.gunpowder, Items.gunpowder, Items.gunpowder, Items.paper, Items.firework_charge, 2);
|
||||
|
||||
//setup a valid charge to use for the recolour recipe
|
||||
for (int i = 0; i < 9; i++)
|
||||
inventoryCrafting.setInventorySlotContents(i, null);
|
||||
// setup a valid charge to use for the recolour recipe
|
||||
for (int i = 0; i < 9; i++) inventoryCrafting.setInventorySlotContents(i, null);
|
||||
inventoryCrafting.setInventorySlotContents(0, new ItemStack(Items.gunpowder));
|
||||
inventoryCrafting.setInventorySlotContents(1, new ItemStack(Items.dye));
|
||||
recipeFireworks.matches(inventoryCrafting, null);
|
||||
@@ -100,20 +94,16 @@ public class FireworkRecipeHandler extends ShapelessRecipeHandler
|
||||
|
||||
private void genRecipe(Object... params) {
|
||||
int numIngreds = 0;
|
||||
for (int i = 0; i < params.length - 2; i++)
|
||||
if (params[i] != null)
|
||||
numIngreds++;
|
||||
for (int i = 0; i < params.length - 2; i++) if (params[i] != null) numIngreds++;
|
||||
|
||||
for (int i = 0; i < params.length - 1; i++)
|
||||
if (params[i] instanceof Item)
|
||||
params[i] = new ItemStack((Item) params[i], 1, Short.MAX_VALUE);
|
||||
if (params[i] instanceof Item) params[i] = new ItemStack((Item) params[i], 1, Short.MAX_VALUE);
|
||||
|
||||
Object[] ingreds = new Object[numIngreds];
|
||||
for (int i = 0, j = 0; i < params.length - 2; i++)
|
||||
if (params[i] != null)
|
||||
ingreds[j++] = params[i];
|
||||
for (int i = 0, j = 0; i < params.length - 2; i++) if (params[i] != null) ingreds[j++] = params[i];
|
||||
|
||||
mfireworks.add(new CachedFireworkRecipe(ingreds, params[params.length - 2], (Integer) params[params.length - 1]));
|
||||
mfireworks.add(
|
||||
new CachedFireworkRecipe(ingreds, params[params.length - 2], (Integer) params[params.length - 1]));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,7 +114,7 @@ public class FireworkRecipeHandler extends ShapelessRecipeHandler
|
||||
arecipes.add(recipe);
|
||||
}
|
||||
}
|
||||
//show random recolouring recipes as well
|
||||
// show random recolouring recipes as well
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -150,9 +140,7 @@ public class FireworkRecipeHandler extends ShapelessRecipeHandler
|
||||
public void onUpdate() {
|
||||
if (!NEIClientUtils.shiftKey()) {
|
||||
cycleticks++;
|
||||
if (cycleticks % 20 == 0)
|
||||
for (CachedRecipe crecipe : arecipes)
|
||||
((CachedFireworkRecipe) crecipe).cycle();
|
||||
if (cycleticks % 20 == 0) for (CachedRecipe crecipe : arecipes) ((CachedFireworkRecipe) crecipe).cycle();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,8 +155,9 @@ public class FireworkRecipeHandler extends ShapelessRecipeHandler
|
||||
Point mousepos = GuiDraw.getMousePosition();
|
||||
Point relMouse = new Point(mousepos.x - gui.guiLeft, mousepos.y - gui.guiTop);
|
||||
Point recipepos = gui.getRecipePosition(recipe);
|
||||
if (currenttip.isEmpty() && GuiContainerManager.getStackMouseOver(gui) == null &&
|
||||
new Rectangle(recipepos.x, recipepos.y, 166, 55).contains(relMouse))
|
||||
if (currenttip.isEmpty()
|
||||
&& GuiContainerManager.getStackMouseOver(gui) == null
|
||||
&& new Rectangle(recipepos.x, recipepos.y, 166, 55).contains(relMouse))
|
||||
currenttip.add(NEIClientUtils.translate(
|
||||
"recipe.firework.tooltip" + ((CachedFireworkRecipe) arecipes.get(recipe)).recipeType));
|
||||
return currenttip;
|
||||
|
||||
@@ -1,23 +1,19 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import static codechicken.nei.NEIClientUtils.translate;
|
||||
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static codechicken.nei.NEIClientUtils.translate;
|
||||
|
||||
public class FuelRecipeHandler extends FurnaceRecipeHandler
|
||||
{
|
||||
public class CachedFuelRecipe extends CachedRecipe
|
||||
{
|
||||
public class FuelRecipeHandler extends FurnaceRecipeHandler {
|
||||
public class CachedFuelRecipe extends CachedRecipe {
|
||||
public final FuelPair fuel;
|
||||
|
||||
public CachedFuelRecipe(FuelPair fuel) {
|
||||
@@ -54,29 +50,26 @@ public class FuelRecipeHandler extends FurnaceRecipeHandler
|
||||
@SuppressWarnings("unchecked")
|
||||
private void loadAllSmelting() {
|
||||
// Note: Not safe as written for parallelStream
|
||||
final Map<ItemStack, ItemStack> smeltingRecipes = (Map<ItemStack, ItemStack>) FurnaceRecipes.smelting().getSmeltingList();
|
||||
final Map<ItemStack, ItemStack> smeltingRecipes =
|
||||
(Map<ItemStack, ItemStack>) FurnaceRecipes.smelting().getSmeltingList();
|
||||
smeltingRecipes.entrySet().stream()
|
||||
.map(recipe -> new SmeltingPair(recipe.getKey(), recipe.getValue()))
|
||||
.collect(Collectors.toCollection(() -> mfurnace));
|
||||
|
||||
.map(recipe -> new SmeltingPair(recipe.getKey(), recipe.getValue()))
|
||||
.collect(Collectors.toCollection(() -> mfurnace));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCraftingRecipes(String outputId, Object... results) {
|
||||
// Note: Not safe as written for parallelStream
|
||||
if (outputId.equals("fuel") && getClass() == FuelRecipeHandler.class)
|
||||
afuels.stream()
|
||||
.map(CachedFuelRecipe::new)
|
||||
.collect(Collectors.toCollection(() -> arecipes));
|
||||
afuels.stream().map(CachedFuelRecipe::new).collect(Collectors.toCollection(() -> arecipes));
|
||||
}
|
||||
|
||||
public void loadUsageRecipes(ItemStack ingredient) {
|
||||
// Note: Not safe as written for parallelStream
|
||||
afuels.stream()
|
||||
.filter(fuel -> fuel != null && fuel.stack != null && fuel.stack.contains(ingredient))
|
||||
.map(CachedFuelRecipe::new)
|
||||
.collect(Collectors.toCollection(() -> arecipes));
|
||||
|
||||
.filter(fuel -> fuel != null && fuel.stack != null && fuel.stack.contains(ingredient))
|
||||
.map(CachedFuelRecipe::new)
|
||||
.collect(Collectors.toCollection(() -> arecipes));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,6 +89,8 @@ public class FuelRecipeHandler extends FurnaceRecipeHandler
|
||||
NumberFormat numberInstance = NumberFormat.getNumberInstance();
|
||||
numberInstance.setMaximumFractionDigits(2);
|
||||
String smeltCount = numberInstance.format(fuel.burnTime / 200f);
|
||||
Minecraft.getMinecraft().fontRenderer.drawString(translate("recipe.fuel.smeltCount", smeltCount), 73, 51, 0xFF000000);
|
||||
Minecraft.getMinecraft()
|
||||
.fontRenderer
|
||||
.drawString(translate("recipe.fuel.smeltCount", smeltCount), 73, 51, 0xFF000000);
|
||||
}
|
||||
}
|
||||
@@ -3,22 +3,19 @@ package codechicken.nei.recipe;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.NEIServerUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.gui.inventory.GuiFurnace;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.gui.inventory.GuiFurnace;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
|
||||
public class FurnaceRecipeHandler extends TemplateRecipeHandler
|
||||
{
|
||||
public class SmeltingPair extends CachedRecipe
|
||||
{
|
||||
public class FurnaceRecipeHandler extends TemplateRecipeHandler {
|
||||
public class SmeltingPair extends CachedRecipe {
|
||||
public SmeltingPair(ItemStack ingred, ItemStack result) {
|
||||
ingred.stackSize = 1;
|
||||
this.ingred = new PositionedStack(ingred, 51, 6);
|
||||
@@ -40,7 +37,7 @@ public class FurnaceRecipeHandler extends TemplateRecipeHandler
|
||||
final PositionedStack ingred;
|
||||
final PositionedStack result;
|
||||
}
|
||||
|
||||
|
||||
public static class FuelPair {
|
||||
public FuelPair(ItemStack ingred, int burnTime) {
|
||||
this.stack = new PositionedStack(ingred, 51, 42, false);
|
||||
@@ -53,7 +50,6 @@ public class FurnaceRecipeHandler extends TemplateRecipeHandler
|
||||
|
||||
public static ArrayList<FuelPair> afuels;
|
||||
|
||||
|
||||
@Override
|
||||
public void loadTransferRects() {
|
||||
transferRects.add(new RecipeTransferRect(new Rectangle(50, 23, 18, 18), "fuel"));
|
||||
@@ -72,7 +68,8 @@ public class FurnaceRecipeHandler extends TemplateRecipeHandler
|
||||
|
||||
@Override
|
||||
public TemplateRecipeHandler newInstance() {
|
||||
// Use the non parallel version since we might already be using the forkJoinPool and might have no threads available
|
||||
// Use the non parallel version since we might already be using the forkJoinPool and might have no threads
|
||||
// available
|
||||
// This will ideally have been pre-cached elsewhere and will be a NOOP
|
||||
findFuelsOnce();
|
||||
return super.newInstance();
|
||||
@@ -80,17 +77,19 @@ public class FurnaceRecipeHandler extends TemplateRecipeHandler
|
||||
|
||||
@Override
|
||||
public void loadCraftingRecipes(String outputId, Object... results) {
|
||||
if (outputId.equals("smelting") && getClass() == FurnaceRecipeHandler.class) {//don't want subclasses getting a hold of this
|
||||
Map<ItemStack, ItemStack> recipes = (Map<ItemStack, ItemStack>) FurnaceRecipes.smelting().getSmeltingList();
|
||||
if (outputId.equals("smelting")
|
||||
&& getClass() == FurnaceRecipeHandler.class) { // don't want subclasses getting a hold of this
|
||||
Map<ItemStack, ItemStack> recipes =
|
||||
(Map<ItemStack, ItemStack>) FurnaceRecipes.smelting().getSmeltingList();
|
||||
for (Entry<ItemStack, ItemStack> recipe : recipes.entrySet())
|
||||
arecipes.add(new SmeltingPair(recipe.getKey(), recipe.getValue()));
|
||||
} else
|
||||
super.loadCraftingRecipes(outputId, results);
|
||||
} else super.loadCraftingRecipes(outputId, results);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCraftingRecipes(ItemStack result) {
|
||||
Map<ItemStack, ItemStack> recipes = (Map<ItemStack, ItemStack>) FurnaceRecipes.smelting().getSmeltingList();
|
||||
Map<ItemStack, ItemStack> recipes =
|
||||
(Map<ItemStack, ItemStack>) FurnaceRecipes.smelting().getSmeltingList();
|
||||
for (Entry<ItemStack, ItemStack> recipe : recipes.entrySet())
|
||||
if (NEIServerUtils.areStacksSameType(recipe.getValue(), result))
|
||||
arecipes.add(new SmeltingPair(recipe.getKey(), recipe.getValue()));
|
||||
@@ -98,15 +97,16 @@ public class FurnaceRecipeHandler extends TemplateRecipeHandler
|
||||
|
||||
@Override
|
||||
public void loadUsageRecipes(String inputId, Object... ingredients) {
|
||||
if (inputId.equals("fuel") && getClass() == FurnaceRecipeHandler.class)//don't want subclasses getting a hold of this
|
||||
loadCraftingRecipes("smelting");
|
||||
else
|
||||
super.loadUsageRecipes(inputId, ingredients);
|
||||
if (inputId.equals("fuel")
|
||||
&& getClass() == FurnaceRecipeHandler.class) // don't want subclasses getting a hold of this
|
||||
loadCraftingRecipes("smelting");
|
||||
else super.loadUsageRecipes(inputId, ingredients);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUsageRecipes(ItemStack ingredient) {
|
||||
Map<ItemStack, ItemStack> recipes = (Map<ItemStack, ItemStack>) FurnaceRecipes.smelting().getSmeltingList();
|
||||
Map<ItemStack, ItemStack> recipes =
|
||||
(Map<ItemStack, ItemStack>) FurnaceRecipes.smelting().getSmeltingList();
|
||||
for (Entry<ItemStack, ItemStack> recipe : recipes.entrySet())
|
||||
if (NEIServerUtils.areStacksSameTypeCrafting(recipe.getKey(), ingredient)) {
|
||||
SmeltingPair arecipe = new SmeltingPair(recipe.getKey(), recipe.getValue());
|
||||
@@ -131,7 +131,6 @@ public class FurnaceRecipeHandler extends TemplateRecipeHandler
|
||||
drawProgressBar(74, 23, 176, 14, 24, 16, 48, 0);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getOverlayIdentifier() {
|
||||
return "smelting";
|
||||
|
||||
@@ -6,6 +6,10 @@ import codechicken.nei.ItemPanels;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -14,20 +18,14 @@ import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GuiCraftingRecipe extends GuiRecipe {
|
||||
public static boolean openRecipeGui(String outputId, Object... results) {
|
||||
return openRecipeGui(outputId, false, results);
|
||||
}
|
||||
|
||||
|
||||
public static boolean openRecipeGui(String outputId, Boolean overlay, Object... results) {
|
||||
Minecraft mc = NEIClientUtils.mc();
|
||||
GuiScreen prevscreen = mc.currentScreen;// instanceof GuiContainer ? (GuiContainer) mc.currentScreen : null;
|
||||
GuiScreen prevscreen = mc.currentScreen; // instanceof GuiContainer ? (GuiContainer) mc.currentScreen : null;
|
||||
|
||||
ArrayList<ICraftingHandler> handlers;
|
||||
TaskProfiler profiler = ProfilerRecipeHandler.getProfiler();
|
||||
@@ -37,14 +35,17 @@ public class GuiCraftingRecipe extends GuiRecipe {
|
||||
FuelRecipeHandler.findFuelsOnceParallel();
|
||||
|
||||
try {
|
||||
handlers = serialCraftingHandlers.stream().map(h -> h.getRecipeHandler(outputId, results))
|
||||
handlers = serialCraftingHandlers.stream()
|
||||
.map(h -> h.getRecipeHandler(outputId, results))
|
||||
.filter(h -> h.numRecipes() > 0)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
handlers.addAll(ItemList.forkJoinPool.submit(() -> craftinghandlers.parallelStream()
|
||||
.map(h -> h.getRecipeHandler(outputId, results))
|
||||
.filter(h -> h.numRecipes() > 0)
|
||||
.collect(Collectors.toCollection(ArrayList::new))).get());
|
||||
handlers.addAll(ItemList.forkJoinPool
|
||||
.submit(() -> craftinghandlers.parallelStream()
|
||||
.map(h -> h.getRecipeHandler(outputId, results))
|
||||
.filter(h -> h.numRecipes() > 0)
|
||||
.collect(Collectors.toCollection(ArrayList::new)))
|
||||
.get());
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
||||
@@ -58,8 +59,7 @@ public class GuiCraftingRecipe extends GuiRecipe {
|
||||
profiler.end();
|
||||
}
|
||||
|
||||
if (handlers.isEmpty())
|
||||
return false;
|
||||
if (handlers.isEmpty()) return false;
|
||||
|
||||
handlers.sort(NEIClientConfig.HANDLER_COMPARATOR);
|
||||
|
||||
@@ -115,13 +115,12 @@ public class GuiCraftingRecipe extends GuiRecipe {
|
||||
|
||||
public static void registerRecipeHandler(ICraftingHandler handler) {
|
||||
final String handlerId = handler.getHandlerId();
|
||||
if (craftinghandlers.stream().anyMatch(h -> h.getHandlerId().equals(handlerId)) || serialCraftingHandlers.stream().anyMatch(h -> h.getHandlerId().equals(handlerId)))
|
||||
return;
|
||||
if (craftinghandlers.stream().anyMatch(h -> h.getHandlerId().equals(handlerId))
|
||||
|| serialCraftingHandlers.stream()
|
||||
.anyMatch(h -> h.getHandlerId().equals(handlerId))) return;
|
||||
|
||||
if (NEIClientConfig.serialHandlers.contains(handlerId))
|
||||
serialCraftingHandlers.add(handler);
|
||||
else
|
||||
craftinghandlers.add(handler);
|
||||
if (NEIClientConfig.serialHandlers.contains(handlerId)) serialCraftingHandlers.add(handler);
|
||||
else craftinghandlers.add(handler);
|
||||
}
|
||||
|
||||
public ArrayList<? extends IRecipeHandler> getCurrentRecipeHandlers() {
|
||||
|
||||
@@ -18,16 +18,6 @@ import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.guihook.IContainerTooltipHandler;
|
||||
import codechicken.nei.guihook.IGuiClientSide;
|
||||
import codechicken.nei.guihook.IGuiHandleMouseWheel;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
@@ -38,13 +28,27 @@ import java.util.Optional;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOverlay, IGuiClientSide, IGuiHandleMouseWheel, IContainerTooltipHandler, INEIGuiHandler {
|
||||
public abstract class GuiRecipe extends GuiContainer
|
||||
implements IGuiContainerOverlay,
|
||||
IGuiClientSide,
|
||||
IGuiHandleMouseWheel,
|
||||
IContainerTooltipHandler,
|
||||
INEIGuiHandler {
|
||||
// Background image calculations
|
||||
private static final int BG_TOP_HEIGHT = 6;
|
||||
private static final int BG_MIDDLE_HEIGHT = 154;
|
||||
private static final int BG_BOTTOM_HEIGHT = 6;
|
||||
|
||||
|
||||
private static final int BG_TOP_Y = 0;
|
||||
private static final int BG_MIDDLE_Y = BG_TOP_Y + BG_TOP_HEIGHT;
|
||||
private static final int BG_BOTTOM_Y = BG_MIDDLE_Y + BG_MIDDLE_HEIGHT;
|
||||
@@ -55,10 +59,13 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
private static final int buttonHeight = 12;
|
||||
|
||||
// Background image
|
||||
final DrawableResource bgTop = new DrawableBuilder("nei:textures/gui/recipebg.png", 0, BG_TOP_Y, 176, BG_TOP_HEIGHT).build();
|
||||
final DrawableResource bgMiddle = new DrawableBuilder("nei:textures/gui/recipebg.png", 0, BG_MIDDLE_Y, 176, BG_MIDDLE_HEIGHT).build();
|
||||
final DrawableResource bgBottom = new DrawableBuilder("nei:textures/gui/recipebg.png", 0, BG_BOTTOM_Y, 176, BG_BOTTOM_HEIGHT).build();
|
||||
|
||||
final DrawableResource bgTop =
|
||||
new DrawableBuilder("nei:textures/gui/recipebg.png", 0, BG_TOP_Y, 176, BG_TOP_HEIGHT).build();
|
||||
final DrawableResource bgMiddle =
|
||||
new DrawableBuilder("nei:textures/gui/recipebg.png", 0, BG_MIDDLE_Y, 176, BG_MIDDLE_HEIGHT).build();
|
||||
final DrawableResource bgBottom =
|
||||
new DrawableBuilder("nei:textures/gui/recipebg.png", 0, BG_BOTTOM_Y, 176, BG_BOTTOM_HEIGHT).build();
|
||||
|
||||
public ArrayList<? extends IRecipeHandler> currenthandlers = new ArrayList<>();
|
||||
|
||||
public int page;
|
||||
@@ -72,16 +79,16 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
public GuiButton prevpage;
|
||||
private GuiButton nexttype;
|
||||
private GuiButton prevtype;
|
||||
|
||||
|
||||
private int OVERLAY_BUTTON_ID_START = 4;
|
||||
private GuiButton[] overlayButtons;
|
||||
|
||||
|
||||
private final Rectangle area = new Rectangle();
|
||||
private final GuiRecipeTabs recipeTabs;
|
||||
private final GuiRecipeCatalyst guiRecipeCatalyst;
|
||||
private IRecipeHandler handler;
|
||||
private HandlerInfo handlerInfo;
|
||||
|
||||
|
||||
private int yShift = 0;
|
||||
|
||||
protected GuiRecipe(GuiScreen prevgui) {
|
||||
@@ -92,14 +99,12 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
|
||||
this.prevGui = prevgui;
|
||||
this.firstGuiGeneral = prevgui;
|
||||
if(prevgui instanceof GuiContainer)
|
||||
this.firstGui = (GuiContainer)prevgui;
|
||||
if (prevgui instanceof GuiContainer) this.firstGui = (GuiContainer) prevgui;
|
||||
|
||||
if (prevgui instanceof IGuiContainerOverlay) {
|
||||
this.firstGui = ((IGuiContainerOverlay) prevgui).getFirstScreen();
|
||||
this.firstGuiGeneral = ((IGuiContainerOverlay) prevgui).getFirstScreenGeneral();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,10 +122,9 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
private HeightHack() {
|
||||
trueHeight = height;
|
||||
|
||||
boolean applyHeightHack =
|
||||
NEIClientConfig.heightHackHandlerRegex.stream()
|
||||
.map(pattern -> pattern.matcher(handler.getHandlerId()))
|
||||
.anyMatch(Matcher::matches);
|
||||
boolean applyHeightHack = NEIClientConfig.heightHackHandlerRegex.stream()
|
||||
.map(pattern -> pattern.matcher(handler.getHandlerId()))
|
||||
.anyMatch(Matcher::matches);
|
||||
if (applyHeightHack) {
|
||||
// The old mods use the calculation ((height - 166) / 2) to compute the y-value of
|
||||
// the top edge of the NEI window.
|
||||
@@ -142,7 +146,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
height = trueHeight;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void initGui() {
|
||||
@@ -151,30 +155,28 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
super.initGui();
|
||||
guiTop = (height - ySize) / 2 + 10;
|
||||
currenthandlers = getCurrentRecipeHandlers(); // Probably don't comment me out
|
||||
|
||||
if(handler == null)
|
||||
setRecipePage(recipetype);
|
||||
else
|
||||
initOverlayButtons();
|
||||
|
||||
|
||||
if (handler == null) setRecipePage(recipetype);
|
||||
else initOverlayButtons();
|
||||
|
||||
checkYShift();
|
||||
|
||||
|
||||
final int rightButtonX = guiLeft + xSize - borderPadding - buttonWidth;
|
||||
final int leftButtonX = guiLeft + borderPadding;
|
||||
|
||||
nexttype = new GuiNEIButton(0, leftButtonX, guiTop + 3, buttonWidth, buttonHeight, "<");
|
||||
prevtype = new GuiNEIButton(1, rightButtonX, guiTop + 3, buttonWidth, buttonHeight, ">");
|
||||
|
||||
|
||||
nextpage = new GuiNEIButton(2, leftButtonX, guiTop + 17, buttonWidth, buttonHeight, "<");
|
||||
prevpage = new GuiNEIButton(3, rightButtonX, guiTop + 17, buttonWidth, buttonHeight, ">");
|
||||
|
||||
|
||||
buttonList.addAll(Arrays.asList(nexttype, prevtype, nextpage, prevpage));
|
||||
|
||||
if (currenthandlers.size() == 1) {
|
||||
nexttype.visible = false;
|
||||
prevtype.visible = false;
|
||||
}
|
||||
|
||||
|
||||
recipeTabs.initLayout();
|
||||
refreshPage();
|
||||
}
|
||||
@@ -184,23 +186,22 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
if (overlayButtons != null) {
|
||||
buttonList.removeIf(Arrays.asList(overlayButtons)::contains);
|
||||
}
|
||||
|
||||
|
||||
final int recipesPerPage = getRecipesPerPage();
|
||||
overlayButtons = new GuiButton[recipesPerPage];
|
||||
for (int i = 0 ; i < recipesPerPage ; i++) {
|
||||
for (int i = 0; i < recipesPerPage; i++) {
|
||||
overlayButtons[i] = new GuiNEIButton(
|
||||
OVERLAY_BUTTON_ID_START + i,
|
||||
(width / 2) + 65,
|
||||
guiTop + 16 + (handlerInfo.getHeight() * (i+1)) - 2,
|
||||
buttonWidth,
|
||||
buttonHeight,
|
||||
"?");
|
||||
OVERLAY_BUTTON_ID_START + i,
|
||||
(width / 2) + 65,
|
||||
guiTop + 16 + (handlerInfo.getHeight() * (i + 1)) - 2,
|
||||
buttonWidth,
|
||||
buttonHeight,
|
||||
"?");
|
||||
}
|
||||
Collections.addAll(buttonList, overlayButtons);
|
||||
itemPresenceCacheRecipe = -1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void checkYShift() {
|
||||
yShift = handlerInfo == null ? 0 : handlerInfo.getYShift();
|
||||
}
|
||||
@@ -216,14 +217,13 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
|
||||
handler = currenthandlers.get(recipetype);
|
||||
handlerInfo = GuiRecipeTab.getHandlerInfo(handler);
|
||||
page = Math.min(Math.max(0, position), handler.numRecipes() - 1) / getRecipesPerPage();
|
||||
page = Math.min(Math.max(0, position), handler.numRecipes() - 1) / getRecipesPerPage();
|
||||
recipeTabs.calcPageNumber();
|
||||
checkYShift();
|
||||
initOverlayButtons();
|
||||
}
|
||||
|
||||
public void openTargetRecipe(BookmarkRecipeId recipeId)
|
||||
{
|
||||
public void openTargetRecipe(BookmarkRecipeId recipeId) {
|
||||
|
||||
if (recipeId == null) {
|
||||
return;
|
||||
@@ -238,7 +238,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
for (int j = 0; j < currenthandlers.size(); j++) {
|
||||
IRecipeHandler localHandler = currenthandlers.get(j);
|
||||
HandlerInfo localHandlerInfo = GuiRecipeTab.getHandlerInfo(localHandler);
|
||||
|
||||
|
||||
if (localHandlerInfo.getHandlerName().equals(recipeId.handlerName)) {
|
||||
recipeId.recipetype = j;
|
||||
|
||||
@@ -249,24 +249,19 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
recipeId.position = i;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
setRecipePage(recipeId.recipetype, recipeId.position);
|
||||
setRecipePage(recipeId.recipetype, recipeId.position);
|
||||
}
|
||||
|
||||
public List<PositionedStack> getFocusedRecipeIngredients()
|
||||
{
|
||||
public List<PositionedStack> getFocusedRecipeIngredients() {
|
||||
final int recipesPerPage = getRecipesPerPage();
|
||||
|
||||
for (int idx = page * recipesPerPage; idx < handler.numRecipes() && idx < (page + 1) * recipesPerPage; idx++) {
|
||||
@@ -278,8 +273,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
return null;
|
||||
}
|
||||
|
||||
protected boolean recipeInFocus(int idx)
|
||||
{
|
||||
protected boolean recipeInFocus(int idx) {
|
||||
final PositionedStack result = handler.getResultStack(idx);
|
||||
if (result != null && isMouseOver(result, idx)) {
|
||||
return true;
|
||||
@@ -295,8 +289,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getHandlerName()
|
||||
{
|
||||
public String getHandlerName() {
|
||||
return handlerInfo.getHandlerName();
|
||||
}
|
||||
|
||||
@@ -314,45 +307,32 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int i) {
|
||||
if (i == Keyboard.KEY_ESCAPE) //esc
|
||||
if (i == Keyboard.KEY_ESCAPE) // esc
|
||||
{
|
||||
mc.displayGuiScreen(firstGuiGeneral);
|
||||
return;
|
||||
}
|
||||
if (GuiContainerManager.getManager(this).lastKeyTyped(i, c))
|
||||
return;
|
||||
if (GuiContainerManager.getManager(this).lastKeyTyped(i, c)) return;
|
||||
|
||||
try (HeightHack heightHack = new HeightHack()) {
|
||||
for (int recipe : getRecipeIndices())
|
||||
if (handler.keyTyped(this, c, i, recipe))
|
||||
return;
|
||||
for (int recipe : getRecipeIndices()) if (handler.keyTyped(this, c, i, recipe)) return;
|
||||
}
|
||||
|
||||
if (i == mc.gameSettings.keyBindInventory.getKeyCode())
|
||||
mc.displayGuiScreen(firstGuiGeneral);
|
||||
else if (i == NEIClientConfig.getKeyBinding("gui.back"))
|
||||
mc.displayGuiScreen(prevGui);
|
||||
else if (i == NEIClientConfig.getKeyBinding("gui.prev_machine"))
|
||||
prevType();
|
||||
else if (i == NEIClientConfig.getKeyBinding("gui.next_machine"))
|
||||
nextType();
|
||||
else if (i == NEIClientConfig.getKeyBinding("gui.prev_recipe"))
|
||||
prevPage();
|
||||
else if (i == NEIClientConfig.getKeyBinding("gui.next_recipe"))
|
||||
nextPage();
|
||||
|
||||
if (i == mc.gameSettings.keyBindInventory.getKeyCode()) mc.displayGuiScreen(firstGuiGeneral);
|
||||
else if (i == NEIClientConfig.getKeyBinding("gui.back")) mc.displayGuiScreen(prevGui);
|
||||
else if (i == NEIClientConfig.getKeyBinding("gui.prev_machine")) prevType();
|
||||
else if (i == NEIClientConfig.getKeyBinding("gui.next_machine")) nextType();
|
||||
else if (i == NEIClientConfig.getKeyBinding("gui.prev_recipe")) prevPage();
|
||||
else if (i == NEIClientConfig.getKeyBinding("gui.next_recipe")) nextPage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int button) {
|
||||
try (HeightHack heightHack = new HeightHack()) {
|
||||
for (int recipe : getRecipeIndices())
|
||||
if (handler.mouseClicked(this, button, recipe))
|
||||
return;
|
||||
for (int recipe : getRecipeIndices()) if (handler.mouseClicked(this, button, recipe)) return;
|
||||
}
|
||||
|
||||
if (recipeTabs.mouseClicked(x, y, button))
|
||||
return;
|
||||
if (recipeTabs.mouseClicked(x, y, button)) return;
|
||||
|
||||
super.mouseClicked(x, y, button);
|
||||
}
|
||||
@@ -364,13 +344,11 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
// the value of the height field will be different from in other mouseover methods, which
|
||||
// could be confusing...
|
||||
|
||||
for (int recipe : getRecipeIndices())
|
||||
if (handler.mouseScrolled(this, i, recipe))
|
||||
return;
|
||||
for (int recipe : getRecipeIndices()) if (handler.mouseScrolled(this, i, recipe)) return;
|
||||
|
||||
if (new Rectangle(guiLeft, guiTop, xSize, ySize).contains(GuiDraw.getMousePosition())) {
|
||||
if (i > 0) prevPage();
|
||||
else nextPage();
|
||||
else nextPage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,7 +369,9 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
nextPage();
|
||||
return;
|
||||
}
|
||||
if (overlayButtons != null && guibutton.id >= OVERLAY_BUTTON_ID_START && guibutton.id < OVERLAY_BUTTON_ID_START + overlayButtons.length) {
|
||||
if (overlayButtons != null
|
||||
&& guibutton.id >= OVERLAY_BUTTON_ID_START
|
||||
&& guibutton.id < OVERLAY_BUTTON_ID_START + overlayButtons.length) {
|
||||
overlayRecipe(page * getRecipesPerPage() + guibutton.id - OVERLAY_BUTTON_ID_START);
|
||||
}
|
||||
}
|
||||
@@ -406,19 +386,18 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
@Override
|
||||
public List<String> handleTooltip(GuiContainer gui, int mousex, int mousey, List<String> currenttip) {
|
||||
try (HeightHack heightHack = new HeightHack()) {
|
||||
for (int i : getRecipeIndices())
|
||||
currenttip = handler.handleTooltip(this, currenttip, i);
|
||||
for (int i : getRecipeIndices()) currenttip = handler.handleTooltip(this, currenttip, i);
|
||||
}
|
||||
recipeTabs.handleTooltip(mousex, mousey, currenttip);
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleItemTooltip(GuiContainer gui, ItemStack stack, int mousex, int mousey, List<String> currenttip) {
|
||||
public List<String> handleItemTooltip(
|
||||
GuiContainer gui, ItemStack stack, int mousex, int mousey, List<String> currenttip) {
|
||||
// Height hacking is probably not needed as it doesn't look like any mods check mouse
|
||||
// position for this method.
|
||||
for (int i : getRecipeIndices())
|
||||
currenttip = handler.handleItemTooltip(this, stack, currenttip, i);
|
||||
for (int i : getRecipeIndices()) currenttip = handler.handleItemTooltip(this, stack, currenttip, i);
|
||||
|
||||
return currenttip;
|
||||
}
|
||||
@@ -462,7 +441,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
LayoutManager.overlayRenderer = renderer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void refreshPage() {
|
||||
RecipeCatalysts.updatePosition(ySize - BG_TOP_HEIGHT - (GuiRecipeCatalyst.fullBorder * 2));
|
||||
refreshSlots();
|
||||
@@ -474,17 +453,17 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
area.width = handlerInfo.getWidth();
|
||||
area.height = handlerInfo.getHeight() * numRecipes;
|
||||
area.x = guiLeft - 2;
|
||||
area.y = guiTop - 4 + yShift;
|
||||
area.y = guiTop - 4 + yShift;
|
||||
checkYShift();
|
||||
|
||||
nextpage.enabled = prevpage.enabled = multiplepages;
|
||||
|
||||
if(firstGui == null) {
|
||||
|
||||
if (firstGui == null) {
|
||||
for (GuiButton overlay : overlayButtons) {
|
||||
overlay.visible = false;
|
||||
}
|
||||
} else {
|
||||
for(int i = 0 ; i < overlayButtons.length ; i ++) {
|
||||
for (int i = 0; i < overlayButtons.length; i++) {
|
||||
if (i >= numRecipes) {
|
||||
overlayButtons[i].visible = false;
|
||||
} else {
|
||||
@@ -504,16 +483,13 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
Point p = getRecipePosition(i);
|
||||
|
||||
List<PositionedStack> stacks = handler.getIngredientStacks(i);
|
||||
for (PositionedStack stack : stacks)
|
||||
slotcontainer.addSlot(stack, p.x, p.y);
|
||||
for (PositionedStack stack : stacks) slotcontainer.addSlot(stack, p.x, p.y);
|
||||
|
||||
stacks = handler.getOtherStacks(i);
|
||||
for (PositionedStack stack : stacks)
|
||||
slotcontainer.addSlot(stack, p.x, p.y);
|
||||
for (PositionedStack stack : stacks) slotcontainer.addSlot(stack, p.x, p.y);
|
||||
|
||||
PositionedStack result = handler.getResultStack(i);
|
||||
if (result != null)
|
||||
slotcontainer.addSlot(result, p.x, p.y);
|
||||
if (result != null) slotcontainer.addSlot(result, p.x, p.y);
|
||||
|
||||
List<PositionedStack> catalysts = RecipeCatalysts.getRecipeCatalysts(handler);
|
||||
for (PositionedStack catalyst : catalysts) {
|
||||
@@ -534,12 +510,19 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
itemPresenceCacheRecipe = recipe;
|
||||
itemPresenceCacheSlots.clear();
|
||||
List<PositionedStack> ingredients = handler.getIngredientStacks(recipe);
|
||||
ArrayList<ItemStack> invStacks = ((List<Slot>) firstGui.inventorySlots.inventorySlots).stream()
|
||||
.filter(s -> s != null && s.getStack() != null && s.getStack().stackSize > 0 && s.isItemValid(s.getStack()) && s.canTakeStack(mc.thePlayer))
|
||||
.map(s -> s.getStack().copy())
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
ArrayList<ItemStack> invStacks = ((List<Slot>) firstGui.inventorySlots.inventorySlots)
|
||||
.stream()
|
||||
.filter(s -> s != null
|
||||
&& s.getStack() != null
|
||||
&& s.getStack().stackSize > 0
|
||||
&& s.isItemValid(s.getStack())
|
||||
&& s.canTakeStack(mc.thePlayer))
|
||||
.map(s -> s.getStack().copy())
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
for (PositionedStack stack : ingredients) {
|
||||
Optional<ItemStack> used = invStacks.stream().filter(is -> is.stackSize > 0 && stack.contains(is)).findFirst();
|
||||
Optional<ItemStack> used = invStacks.stream()
|
||||
.filter(is -> is.stackSize > 0 && stack.contains(is))
|
||||
.findFirst();
|
||||
itemPresenceCacheSlots.add(used.isPresent());
|
||||
if (used.isPresent()) {
|
||||
ItemStack is = used.get();
|
||||
@@ -563,10 +546,13 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
try (HeightHack heightHack = new HeightHack()) {
|
||||
for (int i = page * recipesPerPage; i < handler.numRecipes() && i < (page + 1) * recipesPerPage; i++) {
|
||||
handler.drawForeground(i);
|
||||
if (drawItemPresence && isMouseOverOverlayButton(i - page * recipesPerPage)
|
||||
if (drawItemPresence
|
||||
&& isMouseOverOverlayButton(i - page * recipesPerPage)
|
||||
&& firstGui.inventorySlots != null) {
|
||||
List<PositionedStack> ingredients = handler.getIngredientStacks(i);
|
||||
if (itemPresenceCacheRecipe != i || itemPresenceCacheSlots == null || itemPresenceCacheSlots.size() != ingredients.size()) {
|
||||
if (itemPresenceCacheRecipe != i
|
||||
|| itemPresenceCacheSlots == null
|
||||
|| itemPresenceCacheSlots.size() != ingredients.size()) {
|
||||
updateItemPresenceCache(i);
|
||||
}
|
||||
for (int j = 0; j < ingredients.size(); j++) {
|
||||
@@ -585,22 +571,24 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) {
|
||||
final int recipesPerPage = getRecipesPerPage();
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
final int j = (width - xSize) / 2;
|
||||
final int j = (width - xSize) / 2;
|
||||
final int k = guiTop;
|
||||
|
||||
|
||||
drawBackgroundTiled(j, k);
|
||||
|
||||
drawRect(guiLeft + borderPadding + buttonWidth - 1,
|
||||
nexttype.yPosition,
|
||||
guiLeft + xSize - borderPadding - buttonWidth,
|
||||
nexttype.yPosition + buttonHeight,
|
||||
0x30000000);
|
||||
drawRect(guiLeft + borderPadding + buttonWidth - 1,
|
||||
nextpage.yPosition,
|
||||
guiLeft + xSize - borderPadding - buttonWidth,
|
||||
nextpage.yPosition + buttonHeight,
|
||||
0x30000000);
|
||||
|
||||
drawRect(
|
||||
guiLeft + borderPadding + buttonWidth - 1,
|
||||
nexttype.yPosition,
|
||||
guiLeft + xSize - borderPadding - buttonWidth,
|
||||
nexttype.yPosition + buttonHeight,
|
||||
0x30000000);
|
||||
drawRect(
|
||||
guiLeft + borderPadding + buttonWidth - 1,
|
||||
nextpage.yPosition,
|
||||
guiLeft + xSize - borderPadding - buttonWidth,
|
||||
nextpage.yPosition + buttonHeight,
|
||||
0x30000000);
|
||||
|
||||
if (NEIClientConfig.areJEIStyleTabsVisible()) {
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240f, 240f);
|
||||
@@ -633,7 +621,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
final int yTileCount = tiledHeight / BG_MIDDLE_HEIGHT;
|
||||
final int yRemainder = tiledHeight - (yTileCount * BG_MIDDLE_HEIGHT);
|
||||
final int yStart = k + BG_TOP_HEIGHT + tiledHeight;
|
||||
|
||||
|
||||
for (int yTile = 0; yTile <= yTileCount; yTile++) {
|
||||
final int tileHeight = (yTile == yTileCount) ? yRemainder : BG_MIDDLE_HEIGHT;
|
||||
final int y = yStart - ((yTile + 1) * BG_MIDDLE_HEIGHT);
|
||||
@@ -658,7 +646,8 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
}
|
||||
|
||||
public boolean isMouseOver(PositionedStack stack, int recipe) {
|
||||
Slot stackSlot = slotcontainer.getSlotWithStack(stack, getRecipePosition(recipe).x, getRecipePosition(recipe).y);
|
||||
Slot stackSlot =
|
||||
slotcontainer.getSlotWithStack(stack, getRecipePosition(recipe).x, getRecipePosition(recipe).y);
|
||||
Point mousepos = GuiDraw.getMousePosition();
|
||||
Slot mouseoverSlot = getSlotAtPosition(mousepos.x, mousepos.y);
|
||||
|
||||
@@ -666,11 +655,14 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
}
|
||||
|
||||
private boolean isMouseOverOverlayButton(int buttonId) {
|
||||
if(buttonId >= 0 && buttonId < overlayButtons.length) {
|
||||
if (buttonId >= 0 && buttonId < overlayButtons.length) {
|
||||
GuiButton button = overlayButtons[buttonId];
|
||||
Point mousePos = GuiDraw.getMousePosition();
|
||||
return button.visible && mousePos.x >= button.xPosition && mousePos.y >= button.yPosition
|
||||
&& mousePos.x < button.xPosition + button.width && mousePos.y < button.yPosition + button.height;
|
||||
return button.visible
|
||||
&& mousePos.x >= button.xPosition
|
||||
&& mousePos.y >= button.yPosition
|
||||
&& mousePos.x < button.xPosition + button.width
|
||||
&& mousePos.y < button.yPosition + button.height;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -679,12 +671,15 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
private int getRecipesPerPage() {
|
||||
return getRecipesPerPage(handlerInfo);
|
||||
}
|
||||
|
||||
|
||||
private int getRecipesPerPage(HandlerInfo handlerInfo) {
|
||||
if(handlerInfo != null)
|
||||
return Math.max(Math.min(((ySize - (buttonHeight*3)) / handlerInfo.getHeight()), handlerInfo.getMaxRecipesPerPage()), 1);
|
||||
else
|
||||
return (handler.recipiesPerPage());
|
||||
if (handlerInfo != null)
|
||||
return Math.max(
|
||||
Math.min(
|
||||
((ySize - (buttonHeight * 3)) / handlerInfo.getHeight()),
|
||||
handlerInfo.getMaxRecipesPerPage()),
|
||||
1);
|
||||
else return (handler.recipiesPerPage());
|
||||
}
|
||||
|
||||
public Point getRecipePosition(int recipe) {
|
||||
@@ -694,8 +689,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
public abstract ArrayList<? extends IRecipeHandler> getCurrentRecipeHandlers();
|
||||
|
||||
@Override
|
||||
public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility)
|
||||
{
|
||||
public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility) {
|
||||
return currentVisibility;
|
||||
}
|
||||
|
||||
@@ -704,7 +698,6 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<TaggedInventoryArea> getInventoryAreas(GuiContainer gui) {
|
||||
return null;
|
||||
@@ -720,5 +713,4 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
// Because some of the handlers *cough avaritia* are oversized
|
||||
return area.intersects(x, y, w, h);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,8 @@ public class GuiRecipeCatalyst extends INEIGuiAdapter {
|
||||
|
||||
public void draw() {
|
||||
if (guiRecipe == null) return;
|
||||
int catalystsSize = RecipeCatalysts.getRecipeCatalysts(guiRecipe.getHandler()).size();
|
||||
int catalystsSize =
|
||||
RecipeCatalysts.getRecipeCatalysts(guiRecipe.getHandler()).size();
|
||||
if (catalystsSize == 0) return;
|
||||
|
||||
int availableHeight = RecipeCatalysts.getHeight();
|
||||
@@ -49,7 +50,8 @@ public class GuiRecipeCatalyst extends INEIGuiAdapter {
|
||||
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
|
||||
if (!(gui instanceof GuiRecipe)) return false;
|
||||
guiRecipe = (GuiRecipe) gui;
|
||||
int catalystsSize = RecipeCatalysts.getRecipeCatalysts(guiRecipe.getHandler()).size();
|
||||
int catalystsSize =
|
||||
RecipeCatalysts.getRecipeCatalysts(guiRecipe.getHandler()).size();
|
||||
if (catalystsSize == 0) return false;
|
||||
|
||||
int availableHeight = RecipeCatalysts.getHeight();
|
||||
@@ -66,19 +68,48 @@ public class GuiRecipeCatalyst extends INEIGuiAdapter {
|
||||
return targetRect.intersects(catalystRect);
|
||||
}
|
||||
|
||||
private void drawBordered(String location, int xPos, int yPos, int width, int height, int texWidth, int texHeight, int sliceLeft, int sliceRight, int sliceTop, int sliceBottom) {
|
||||
private void drawBordered(
|
||||
String location,
|
||||
int xPos,
|
||||
int yPos,
|
||||
int width,
|
||||
int height,
|
||||
int texWidth,
|
||||
int texHeight,
|
||||
int sliceLeft,
|
||||
int sliceRight,
|
||||
int sliceTop,
|
||||
int sliceBottom) {
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(location));
|
||||
|
||||
GuiElementDuex cornerTopLeft = new GuiElementDuex(0, 0, sliceLeft, sliceTop, texWidth, texHeight);
|
||||
GuiElementDuex cornerTopRight = new GuiElementDuex(texWidth - sliceRight, 0, sliceRight, sliceTop, texWidth, texHeight);
|
||||
GuiElementDuex cornerBottomLeft = new GuiElementDuex(0, texHeight - sliceBottom, sliceLeft, sliceBottom, texWidth, texHeight);
|
||||
GuiElementDuex cornerBottomRight = new GuiElementDuex(texWidth - sliceRight, texHeight - sliceBottom, sliceRight, sliceBottom, texWidth, texHeight);
|
||||
GuiElementDuex cornerTopRight =
|
||||
new GuiElementDuex(texWidth - sliceRight, 0, sliceRight, sliceTop, texWidth, texHeight);
|
||||
GuiElementDuex cornerBottomLeft =
|
||||
new GuiElementDuex(0, texHeight - sliceBottom, sliceLeft, sliceBottom, texWidth, texHeight);
|
||||
GuiElementDuex cornerBottomRight = new GuiElementDuex(
|
||||
texWidth - sliceRight, texHeight - sliceBottom, sliceRight, sliceBottom, texWidth, texHeight);
|
||||
|
||||
GuiElementScalable borderTop = new GuiElementScalable(sliceLeft, 0, texWidth - sliceLeft - sliceRight, sliceTop, texWidth, texHeight);
|
||||
GuiElementScalable borderBottom = new GuiElementScalable(sliceLeft, texHeight - sliceBottom, texWidth - sliceLeft - sliceRight, sliceBottom, texWidth, texHeight);
|
||||
GuiElementScalable borderLeft = new GuiElementScalable(0, sliceTop, sliceLeft, texHeight - sliceTop - sliceBottom, texWidth, texHeight);
|
||||
GuiElementScalable borderRight = new GuiElementScalable(texWidth - sliceRight, sliceTop, sliceRight, texHeight - sliceTop - sliceBottom, texWidth, texHeight);
|
||||
GuiElementScalable center = new GuiElementScalable(sliceLeft, sliceTop, texWidth - sliceLeft - sliceRight, texHeight - sliceTop - sliceBottom, texWidth, texHeight);
|
||||
GuiElementScalable borderTop =
|
||||
new GuiElementScalable(sliceLeft, 0, texWidth - sliceLeft - sliceRight, sliceTop, texWidth, texHeight);
|
||||
GuiElementScalable borderBottom = new GuiElementScalable(
|
||||
sliceLeft,
|
||||
texHeight - sliceBottom,
|
||||
texWidth - sliceLeft - sliceRight,
|
||||
sliceBottom,
|
||||
texWidth,
|
||||
texHeight);
|
||||
GuiElementScalable borderLeft =
|
||||
new GuiElementScalable(0, sliceTop, sliceLeft, texHeight - sliceTop - sliceBottom, texWidth, texHeight);
|
||||
GuiElementScalable borderRight = new GuiElementScalable(
|
||||
texWidth - sliceRight, sliceTop, sliceRight, texHeight - sliceTop - sliceBottom, texWidth, texHeight);
|
||||
GuiElementScalable center = new GuiElementScalable(
|
||||
sliceLeft,
|
||||
sliceTop,
|
||||
texWidth - sliceLeft - sliceRight,
|
||||
texHeight - sliceTop - sliceBottom,
|
||||
texWidth,
|
||||
texHeight);
|
||||
|
||||
int midW = width - borderLeft.w - borderRight.w;
|
||||
int midH = height - borderTop.h - borderBottom.h;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.Widget;
|
||||
@@ -8,17 +7,6 @@ import codechicken.nei.drawable.DrawableResource;
|
||||
import codechicken.nei.event.NEIRegisterHandlerInfosEvent;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import org.apache.commons.csv.CSVFormat;
|
||||
import org.apache.commons.csv.CSVParser;
|
||||
import org.apache.commons.csv.CSVRecord;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -30,6 +18,16 @@ import java.nio.channels.Channels;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.*;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import org.apache.commons.csv.CSVFormat;
|
||||
import org.apache.commons.csv.CSVParser;
|
||||
import org.apache.commons.csv.CSVRecord;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
public abstract class GuiRecipeTab extends Widget {
|
||||
public static HandlerInfo DEFAULT_HANDLER_INFO = getDefaultHandlerInfo();
|
||||
@@ -43,16 +41,18 @@ public abstract class GuiRecipeTab extends Widget {
|
||||
private final String handlerID;
|
||||
|
||||
private boolean selected;
|
||||
|
||||
|
||||
public abstract int getWidth();
|
||||
|
||||
public abstract int getHeight();
|
||||
|
||||
|
||||
public abstract DrawableResource getSelectedTabImage();
|
||||
|
||||
public abstract DrawableResource getUnselectedTabImage();
|
||||
|
||||
protected abstract int getForegroundIconX();
|
||||
protected abstract int getForegroundIconY();
|
||||
|
||||
protected abstract int getForegroundIconY();
|
||||
|
||||
public GuiRecipeTab(GuiRecipe guiRecipe, IRecipeHandler handler, int x, int y) {
|
||||
super();
|
||||
@@ -65,7 +65,7 @@ public abstract class GuiRecipeTab extends Widget {
|
||||
this.guiRecipe = guiRecipe;
|
||||
this.selected = false;
|
||||
|
||||
if(handler instanceof TemplateRecipeHandler) {
|
||||
if (handler instanceof TemplateRecipeHandler) {
|
||||
handlerID = handler.getOverlayIdentifier();
|
||||
} else {
|
||||
handlerID = null;
|
||||
@@ -82,10 +82,10 @@ public abstract class GuiRecipeTab extends Widget {
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
final DrawableResource image;
|
||||
if (selected) image = getSelectedTabImage();
|
||||
else image = getUnselectedTabImage();
|
||||
if (selected) image = getSelectedTabImage();
|
||||
else image = getUnselectedTabImage();
|
||||
|
||||
final int iconX = x + (w - image.getWidth()) / 2;
|
||||
final int iconX = x + (w - image.getWidth()) / 2;
|
||||
final int iconY = y + (h - image.getHeight()) / 2;
|
||||
image.draw(iconX, iconY);
|
||||
}
|
||||
@@ -97,9 +97,8 @@ public abstract class GuiRecipeTab extends Widget {
|
||||
final FontRenderer fontRenderer = GuiDraw.fontRenderer;
|
||||
final HandlerInfo handlerInfo = getHandlerInfo(handlerName, handlerID);
|
||||
final DrawableResource icon = handlerInfo != null ? handlerInfo.getImage() : null;
|
||||
final ItemStack itemStack = handlerInfo != null ? handlerInfo.getItemStack() : null;
|
||||
|
||||
|
||||
final ItemStack itemStack = handlerInfo != null ? handlerInfo.getItemStack() : null;
|
||||
|
||||
if (icon != null) {
|
||||
icon.draw(iconX + 1, iconY + 1);
|
||||
} else if (itemStack != null) {
|
||||
@@ -108,8 +107,7 @@ public abstract class GuiRecipeTab extends Widget {
|
||||
GuiContainerManager.drawItems.zLevel += 100;
|
||||
GuiContainerManager.drawItem(iconX, iconY, itemStack);
|
||||
GuiContainerManager.drawItems.zLevel -= 100;
|
||||
if (!isEnabled)
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
if (!isEnabled) GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
} else {
|
||||
// Text fallback
|
||||
String text = handler.getRecipeName();
|
||||
@@ -120,45 +118,44 @@ public abstract class GuiRecipeTab extends Widget {
|
||||
} else {
|
||||
text = "??";
|
||||
}
|
||||
|
||||
|
||||
int textCenterX = x + (int) (getWidth() / 2f);
|
||||
int textCenterY = y + (int) (getHeight() / 2f) - 3;
|
||||
int color = selected ? 0xffffa0 : 0xe0e0e0;
|
||||
fontRenderer.drawStringWithShadow(text, textCenterX - (int) (fontRenderer.getStringWidth(text) / 2f), textCenterY, color);
|
||||
fontRenderer.drawStringWithShadow(
|
||||
text, textCenterX - (int) (fontRenderer.getStringWidth(text) / 2f), textCenterY, color);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addTooltips(List<String> tooltip) {
|
||||
tooltip.add(handler.getRecipeTabName().trim());
|
||||
|
||||
|
||||
String handlerMod = getHandlerMod(handlerName, handlerID);
|
||||
tooltip.add(EnumChatFormatting.BLUE + handlerMod);
|
||||
|
||||
boolean shiftHeld = Keyboard.getEventKeyState() && (Keyboard.getEventKey() == Keyboard.KEY_LSHIFT || Keyboard.getEventKey() == Keyboard.KEY_RSHIFT);
|
||||
boolean shiftHeld = Keyboard.getEventKeyState()
|
||||
&& (Keyboard.getEventKey() == Keyboard.KEY_LSHIFT || Keyboard.getEventKey() == Keyboard.KEY_RSHIFT);
|
||||
if (handlerMod.equals("Unknown") || shiftHeld) {
|
||||
tooltip.add("");
|
||||
tooltip.add("HandlerName: " + handlerName);
|
||||
tooltip.add("HandlerID: " + handlerID);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public boolean onButtonPress(boolean rightclick) {
|
||||
int newIdx = guiRecipe.currenthandlers.indexOf(handler);
|
||||
if (newIdx == -1)
|
||||
return false;
|
||||
if (newIdx == -1) return false;
|
||||
|
||||
guiRecipe.setRecipePage(newIdx);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void setSelected(IRecipeHandler current) {
|
||||
selected = handler == current;
|
||||
}
|
||||
|
||||
public static HandlerInfo getHandlerInfo(IRecipeHandler handler)
|
||||
{
|
||||
public static HandlerInfo getHandlerInfo(IRecipeHandler handler) {
|
||||
final String handlerID;
|
||||
|
||||
if (handler instanceof TemplateRecipeHandler) {
|
||||
@@ -168,29 +165,26 @@ public abstract class GuiRecipeTab extends Widget {
|
||||
}
|
||||
|
||||
HandlerInfo info = getHandlerInfo(handler.getHandlerId(), handlerID);
|
||||
|
||||
if (info == null)
|
||||
return GuiRecipeTab.DEFAULT_HANDLER_INFO;
|
||||
|
||||
|
||||
if (info == null) return GuiRecipeTab.DEFAULT_HANDLER_INFO;
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
public static HandlerInfo getHandlerInfo(String name, String name2) {
|
||||
HandlerInfo res = handlerMap.get(name);
|
||||
if (res == null) res = handlerMap.get(name2);
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public static String getHandlerMod(String name, String name2) {
|
||||
HandlerInfo info = getHandlerInfo(name, name2);
|
||||
if (info == null)
|
||||
return "Unknown";
|
||||
HandlerInfo info = getHandlerInfo(name, name2);
|
||||
if (info == null) return "Unknown";
|
||||
|
||||
return info.getModName();
|
||||
}
|
||||
|
||||
|
||||
public static void loadHandlerInfo() {
|
||||
final boolean fromJar = NEIClientConfig.loadHandlersFromJar();
|
||||
NEIClientConfig.logger.info("Loading handler info from " + (fromJar ? "JAR" : "Config"));
|
||||
@@ -206,7 +200,7 @@ public abstract class GuiRecipeTab extends Widget {
|
||||
}
|
||||
} else {
|
||||
File handlerFile = NEIClientConfig.handlerFile;
|
||||
if(!handlerFile.exists()) {
|
||||
if (!handlerFile.exists()) {
|
||||
NEIClientConfig.logger.info("Config file doesn't exist, creating");
|
||||
try {
|
||||
assert handlerUrl != null;
|
||||
@@ -238,37 +232,36 @@ public abstract class GuiRecipeTab extends Widget {
|
||||
|
||||
if (requiresMod && !Loader.isModLoaded(modId)) continue;
|
||||
if (excludedModId != null && Loader.isModLoaded(excludedModId)) continue;
|
||||
|
||||
|
||||
|
||||
HandlerInfo info = new HandlerInfo(handler, modName, modId, requiresMod, excludedModId);
|
||||
final String imageResource = record.get("imageResource");
|
||||
if(imageResource != null && !imageResource.equals("")) {
|
||||
info.setImage(imageResource,
|
||||
Integer.parseInt(record.get("imageX")),
|
||||
Integer.parseInt(record.get("imageY")),
|
||||
Integer.parseInt(record.get("imageWidth")),
|
||||
Integer.parseInt(record.get("imageHeight"))
|
||||
);
|
||||
if (imageResource != null && !imageResource.equals("")) {
|
||||
info.setImage(
|
||||
imageResource,
|
||||
Integer.parseInt(record.get("imageX")),
|
||||
Integer.parseInt(record.get("imageY")),
|
||||
Integer.parseInt(record.get("imageWidth")),
|
||||
Integer.parseInt(record.get("imageHeight")));
|
||||
}
|
||||
if(!info.hasImageOrItem()) {
|
||||
if (!info.hasImageOrItem()) {
|
||||
final String itemName = record.get("itemName");
|
||||
if (itemName != null && !itemName.equals("")) {
|
||||
info.setItem(itemName, record.get("nbtInfo"));
|
||||
}
|
||||
}
|
||||
final String yShift = record.get("yShift");
|
||||
if (yShift != null && !yShift.equals(""))
|
||||
info.setYShift(Integer.parseInt(yShift));
|
||||
|
||||
if (yShift != null && !yShift.equals("")) info.setYShift(Integer.parseInt(yShift));
|
||||
|
||||
try {
|
||||
final int imageHeight = intOrDefault(record.get("handlerHeight"), HandlerInfo.DEFAULT_HEIGHT);
|
||||
final int imageWidth = intOrDefault(record.get("handlerWidth"), HandlerInfo.DEFAULT_WIDTH);
|
||||
final int maxRecipesPerPage = intOrDefault(record.get("maxRecipesPerPage"), HandlerInfo.DEFAULT_MAX_PER_PAGE);
|
||||
final int maxRecipesPerPage =
|
||||
intOrDefault(record.get("maxRecipesPerPage"), HandlerInfo.DEFAULT_MAX_PER_PAGE);
|
||||
info.setHandlerDimensions(imageHeight, imageWidth, maxRecipesPerPage);
|
||||
} catch (NumberFormatException ignored) {
|
||||
NEIClientConfig.logger.info("Error setting handler dimensions for " + handler);
|
||||
}
|
||||
|
||||
|
||||
handlerMap.put(handler, info);
|
||||
NEIClientConfig.logger.info("Loaded " + handler);
|
||||
}
|
||||
@@ -283,10 +276,11 @@ public abstract class GuiRecipeTab extends Widget {
|
||||
NEIClientConfig.logger.info("Sending {}", NEIRegisterHandlerInfosEvent.class.getSimpleName());
|
||||
MinecraftForge.EVENT_BUS.post(new NEIRegisterHandlerInfosEvent());
|
||||
}
|
||||
|
||||
|
||||
private static HandlerInfo getDefaultHandlerInfo() {
|
||||
final HandlerInfo info = new HandlerInfo("Unknown", "Unknown", "Unknown", false, "");
|
||||
info.setHandlerDimensions(HandlerInfo.DEFAULT_HEIGHT, HandlerInfo.DEFAULT_WIDTH, HandlerInfo.DEFAULT_MAX_PER_PAGE);
|
||||
info.setHandlerDimensions(
|
||||
HandlerInfo.DEFAULT_HEIGHT, HandlerInfo.DEFAULT_WIDTH, HandlerInfo.DEFAULT_MAX_PER_PAGE);
|
||||
return info;
|
||||
}
|
||||
|
||||
@@ -298,6 +292,4 @@ public abstract class GuiRecipeTab extends Widget {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
|
||||
import codechicken.nei.drawable.DrawableBuilder;
|
||||
import codechicken.nei.drawable.DrawableResource;
|
||||
|
||||
public class GuiRecipeTabCreative extends GuiRecipeTab {
|
||||
public static final int TAB_WIDTH = 28;
|
||||
public static final int TAB_HEIGHT = 31;
|
||||
private static final DrawableResource selectedTabImage = new DrawableBuilder("minecraft:textures/gui/container/creative_inventory/tabs.png", 28, 32, 28, 32).build();
|
||||
private static final DrawableResource unselectedTabImage = new DrawableBuilder("minecraft:textures/gui/container/creative_inventory/tabs.png", 28, 0, 28, 30).build();
|
||||
private static final DrawableResource selectedTabImage =
|
||||
new DrawableBuilder("minecraft:textures/gui/container/creative_inventory/tabs.png", 28, 32, 28, 32).build();
|
||||
private static final DrawableResource unselectedTabImage =
|
||||
new DrawableBuilder("minecraft:textures/gui/container/creative_inventory/tabs.png", 28, 0, 28, 30).build();
|
||||
|
||||
public GuiRecipeTabCreative(GuiRecipe guiRecipe, IRecipeHandler handler, int x, int y) {
|
||||
super(guiRecipe, handler, x, y);
|
||||
@@ -33,7 +34,7 @@ public class GuiRecipeTabCreative extends GuiRecipeTab {
|
||||
protected int getForegroundIconY() {
|
||||
return y + h - 22;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public DrawableResource getSelectedTabImage() {
|
||||
return selectedTabImage;
|
||||
@@ -43,5 +44,4 @@ public class GuiRecipeTabCreative extends GuiRecipeTab {
|
||||
public DrawableResource getUnselectedTabImage() {
|
||||
return unselectedTabImage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
|
||||
import codechicken.nei.drawable.DrawableBuilder;
|
||||
import codechicken.nei.drawable.DrawableResource;
|
||||
|
||||
public class GuiRecipeTabJEI extends GuiRecipeTab {
|
||||
public static final int TAB_WIDTH = 24;
|
||||
public static final int TAB_HEIGHT = 24;
|
||||
private static final DrawableResource selectedTabImage = new DrawableBuilder("nei:textures/nei_tabbed_sprites.png", 0, 16, 24, 24).build();
|
||||
private static final DrawableResource unselectedTabImage = new DrawableBuilder("nei:textures/nei_tabbed_sprites.png", 24, 16, 24, 24).build();
|
||||
private static final DrawableResource selectedTabImage =
|
||||
new DrawableBuilder("nei:textures/nei_tabbed_sprites.png", 0, 16, 24, 24).build();
|
||||
private static final DrawableResource unselectedTabImage =
|
||||
new DrawableBuilder("nei:textures/nei_tabbed_sprites.png", 24, 16, 24, 24).build();
|
||||
|
||||
public GuiRecipeTabJEI(GuiRecipe guiRecipe, IRecipeHandler handler, int x, int y) {
|
||||
super(guiRecipe, handler, x, y);
|
||||
@@ -31,7 +32,7 @@ public class GuiRecipeTabJEI extends GuiRecipeTab {
|
||||
|
||||
@Override
|
||||
protected int getForegroundIconY() {
|
||||
return y + 4;
|
||||
return y + 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,5 +44,4 @@ public class GuiRecipeTabJEI extends GuiRecipeTab {
|
||||
public DrawableResource getUnselectedTabImage() {
|
||||
return unselectedTabImage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package codechicken.nei.recipe;
|
||||
import codechicken.nei.Button;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -15,7 +14,7 @@ public class GuiRecipeTabs {
|
||||
|
||||
private final Rectangle area = new Rectangle();
|
||||
private boolean creative_tab_style;
|
||||
|
||||
|
||||
private int pageCount = 1;
|
||||
private int pageNumber = 0;
|
||||
private int categoriesPerPage = 1;
|
||||
@@ -26,18 +25,17 @@ public class GuiRecipeTabs {
|
||||
public GuiRecipeTabs(GuiRecipe guiRecipe) {
|
||||
this.guiRecipe = guiRecipe;
|
||||
}
|
||||
|
||||
|
||||
public void initLayout() {
|
||||
creative_tab_style = NEIClientConfig.useCreativeTabStyle();
|
||||
if(creative_tab_style) {
|
||||
creative_tab_style = NEIClientConfig.useCreativeTabStyle();
|
||||
if (creative_tab_style) {
|
||||
tabWidth = GuiRecipeTabCreative.TAB_WIDTH;
|
||||
tabHeight = GuiRecipeTabCreative.TAB_HEIGHT;
|
||||
} else {
|
||||
tabWidth = GuiRecipeTabJEI.TAB_WIDTH;
|
||||
tabHeight = GuiRecipeTabJEI.TAB_HEIGHT;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int totalWidth = 0;
|
||||
categoriesPerPage = 0;
|
||||
numHandlers = guiRecipe.currenthandlers.size();
|
||||
@@ -62,28 +60,27 @@ public class GuiRecipeTabs {
|
||||
navigationArea.height = 20;
|
||||
navigationArea.translate(0, -(2 + navigationArea.height));
|
||||
}
|
||||
|
||||
|
||||
public void calcPageNumber() {
|
||||
pageNumber = guiRecipe.recipetype / Math.max(categoriesPerPage, 1);
|
||||
}
|
||||
|
||||
|
||||
public void refreshPage() {
|
||||
tabs.clear();
|
||||
buttons.clear();
|
||||
|
||||
|
||||
final int startIndex = pageNumber * categoriesPerPage;
|
||||
for (int i = 0 ; i < categoriesPerPage ; i++) {
|
||||
for (int i = 0; i < categoriesPerPage; i++) {
|
||||
final int index = i + startIndex;
|
||||
if (index >= numHandlers) break;
|
||||
IRecipeHandler handler = guiRecipe.currenthandlers.get(index);
|
||||
int tabX = area.x + (i * tabWidth);
|
||||
|
||||
if(NEIClientConfig.useCreativeTabStyle())
|
||||
|
||||
if (NEIClientConfig.useCreativeTabStyle())
|
||||
tabs.add(new GuiRecipeTabCreative(guiRecipe, handler, tabX, area.y));
|
||||
else
|
||||
tabs.add(new GuiRecipeTabJEI(guiRecipe, handler, tabX, area.y));
|
||||
else tabs.add(new GuiRecipeTabJEI(guiRecipe, handler, tabX, area.y));
|
||||
}
|
||||
|
||||
|
||||
// Maybe add buttons
|
||||
if (numHandlers > categoriesPerPage) {
|
||||
Button prevTab = new Button("prevTab") {
|
||||
@@ -92,9 +89,9 @@ public class GuiRecipeTabs {
|
||||
if (!rightClick) {
|
||||
NEIClientUtils.playClickSound();
|
||||
return previousPage();
|
||||
} else
|
||||
return false;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRenderLabel() {
|
||||
return "<";
|
||||
@@ -105,15 +102,16 @@ public class GuiRecipeTabs {
|
||||
prevTab.x = area.x - prevTab.w + 1;
|
||||
prevTab.y = area.y + 2;
|
||||
buttons.add(prevTab);
|
||||
|
||||
|
||||
Button nextTab = new Button("nextTab") {
|
||||
@Override
|
||||
public boolean onButtonPress(boolean rightclick) {
|
||||
if (!rightclick) {
|
||||
NEIClientUtils.playClickSound();
|
||||
return nextPage();
|
||||
} else return false;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRenderLabel() {
|
||||
return ">";
|
||||
@@ -126,11 +124,11 @@ public class GuiRecipeTabs {
|
||||
buttons.add(nextTab);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean nextPage() {
|
||||
if (hasNext()) pageNumber++;
|
||||
if (hasNext()) pageNumber++;
|
||||
else pageNumber = 0;
|
||||
|
||||
|
||||
refreshPage();
|
||||
return true;
|
||||
}
|
||||
@@ -142,7 +140,7 @@ public class GuiRecipeTabs {
|
||||
public boolean previousPage() {
|
||||
if (hasPrevious()) pageNumber--;
|
||||
else pageNumber = pageCount - 1;
|
||||
|
||||
|
||||
refreshPage();
|
||||
return true;
|
||||
}
|
||||
@@ -151,7 +149,6 @@ public class GuiRecipeTabs {
|
||||
return pageNumber > 0;
|
||||
}
|
||||
|
||||
|
||||
public void draw(int mouseX, int mouseY) {
|
||||
IRecipeHandler current = guiRecipe.currenthandlers.get(guiRecipe.recipetype);
|
||||
for (GuiRecipeTab tab : tabs) {
|
||||
@@ -172,11 +169,12 @@ public class GuiRecipeTabs {
|
||||
}
|
||||
}
|
||||
for (Button button : buttons) {
|
||||
if (button.contains(mousex, mousey)){
|
||||
if (button.contains(mousex, mousey)) {
|
||||
button.addTooltips(tooltips);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean mouseClicked(int x, int y, int mouseButton) {
|
||||
if (!NEIClientConfig.areJEIStyleTabsVisible()) return false;
|
||||
|
||||
@@ -192,5 +190,4 @@ public class GuiRecipeTabs {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,9 @@ import codechicken.core.TaskProfiler;
|
||||
import codechicken.nei.ItemList;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -11,12 +14,7 @@ import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GuiUsageRecipe extends GuiRecipe
|
||||
{
|
||||
public class GuiUsageRecipe extends GuiRecipe {
|
||||
public static boolean openRecipeGui(String inputId, Object... ingredients) {
|
||||
Minecraft mc = NEIClientUtils.mc();
|
||||
GuiContainer prevscreen = mc.currentScreen instanceof GuiContainer ? (GuiContainer) mc.currentScreen : null;
|
||||
@@ -29,14 +27,17 @@ public class GuiUsageRecipe extends GuiRecipe
|
||||
|
||||
profiler.start("recipe.concurrent.usage");
|
||||
try {
|
||||
handlers = serialUsageHandlers.stream().map(h -> getUsageOrCatalystHandler(h, inputId, ingredients))
|
||||
.filter(h -> h.numRecipes() > 0)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
handlers = serialUsageHandlers.stream()
|
||||
.map(h -> getUsageOrCatalystHandler(h, inputId, ingredients))
|
||||
.filter(h -> h.numRecipes() > 0)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
handlers.addAll(ItemList.forkJoinPool.submit(() -> usagehandlers.parallelStream()
|
||||
.map(h -> getUsageOrCatalystHandler(h, inputId, ingredients))
|
||||
.filter(h -> h.numRecipes() > 0)
|
||||
.collect(Collectors.toCollection(ArrayList::new))).get());
|
||||
handlers.addAll(ItemList.forkJoinPool
|
||||
.submit(() -> usagehandlers.parallelStream()
|
||||
.map(h -> getUsageOrCatalystHandler(h, inputId, ingredients))
|
||||
.filter(h -> h.numRecipes() > 0)
|
||||
.collect(Collectors.toCollection(ArrayList::new)))
|
||||
.get());
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
||||
@@ -50,8 +51,7 @@ public class GuiUsageRecipe extends GuiRecipe
|
||||
profiler.end();
|
||||
}
|
||||
|
||||
if (handlers.isEmpty())
|
||||
return false;
|
||||
if (handlers.isEmpty()) return false;
|
||||
|
||||
handlers.sort(NEIClientConfig.HANDLER_COMPARATOR);
|
||||
|
||||
@@ -61,7 +61,7 @@ public class GuiUsageRecipe extends GuiRecipe
|
||||
recipeId = (((GuiRecipe) prevscreen).recipeId).copy();
|
||||
}
|
||||
|
||||
GuiUsageRecipe gui = new GuiUsageRecipe(prevscreen, handlers, recipeId);
|
||||
GuiUsageRecipe gui = new GuiUsageRecipe(prevscreen, handlers, recipeId);
|
||||
|
||||
mc.displayGuiScreen(gui);
|
||||
|
||||
@@ -72,8 +72,7 @@ public class GuiUsageRecipe extends GuiRecipe
|
||||
return true;
|
||||
}
|
||||
|
||||
private GuiUsageRecipe(GuiContainer prevgui, ArrayList<IUsageHandler> handlers, BookmarkRecipeId recipeId)
|
||||
{
|
||||
private GuiUsageRecipe(GuiContainer prevgui, ArrayList<IUsageHandler> handlers, BookmarkRecipeId recipeId) {
|
||||
this(prevgui, handlers);
|
||||
this.recipeId = recipeId;
|
||||
}
|
||||
@@ -85,20 +84,19 @@ public class GuiUsageRecipe extends GuiRecipe
|
||||
|
||||
public static void registerUsageHandler(IUsageHandler handler) {
|
||||
final String handlerId = handler.getHandlerId();
|
||||
if(usagehandlers.stream().anyMatch(h -> h.getHandlerId().equals(handlerId)) || serialUsageHandlers.stream().anyMatch(h -> h.getHandlerId().equals(handlerId)))
|
||||
return;
|
||||
if (usagehandlers.stream().anyMatch(h -> h.getHandlerId().equals(handlerId))
|
||||
|| serialUsageHandlers.stream().anyMatch(h -> h.getHandlerId().equals(handlerId))) return;
|
||||
|
||||
if(NEIClientConfig.serialHandlers.contains(handlerId))
|
||||
serialUsageHandlers.add(handler);
|
||||
else
|
||||
usagehandlers.add(handler);
|
||||
if (NEIClientConfig.serialHandlers.contains(handlerId)) serialUsageHandlers.add(handler);
|
||||
else usagehandlers.add(handler);
|
||||
}
|
||||
|
||||
public ArrayList<? extends IRecipeHandler> getCurrentRecipeHandlers() {
|
||||
return currenthandlers;
|
||||
}
|
||||
|
||||
private static IUsageHandler getUsageOrCatalystHandler(IUsageHandler handler, String inputId, Object... ingredients) {
|
||||
private static IUsageHandler getUsageOrCatalystHandler(
|
||||
IUsageHandler handler, String inputId, Object... ingredients) {
|
||||
boolean skipCatalyst = NEIClientUtils.controlKey();
|
||||
if (NEIClientConfig.areJEIStyleRecipeCatalystsVisible() && !skipCatalyst) {
|
||||
return handler.getUsageAndCatalystHandler(inputId, ingredients);
|
||||
|
||||
@@ -4,28 +4,21 @@ import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIServerUtils;
|
||||
import codechicken.nei.drawable.DrawableBuilder;
|
||||
import codechicken.nei.drawable.DrawableResource;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
public class HandlerInfo {
|
||||
public static int DEFAULT_HEIGHT = 65;
|
||||
public static int DEFAULT_WIDTH = 166;
|
||||
public static int DEFAULT_MAX_PER_PAGE = 1;
|
||||
|
||||
|
||||
private String handlerName;
|
||||
|
||||
|
||||
private String modName;
|
||||
private String modId;
|
||||
private boolean requiresMod;
|
||||
private String excludedModId;
|
||||
|
||||
|
||||
private String itemId;
|
||||
private String nbtString;
|
||||
|
||||
@@ -33,10 +26,10 @@ public class HandlerInfo {
|
||||
private int height = DEFAULT_HEIGHT;
|
||||
private int width = DEFAULT_WIDTH;
|
||||
private int maxRecipesPerPage = DEFAULT_MAX_PER_PAGE;
|
||||
|
||||
|
||||
private ItemStack itemStack = null;
|
||||
private DrawableResource image = null;
|
||||
|
||||
|
||||
public HandlerInfo(String handlerName, String modName, String modId, boolean requiresMod, String excludedModId) {
|
||||
this.handlerName = handlerName;
|
||||
this.modName = modName;
|
||||
@@ -44,7 +37,7 @@ public class HandlerInfo {
|
||||
this.requiresMod = requiresMod;
|
||||
this.excludedModId = excludedModId;
|
||||
}
|
||||
|
||||
|
||||
public void setHandlerDimensions(int height, int width, int maxRecipesPerPage) {
|
||||
this.height = height;
|
||||
this.width = width;
|
||||
@@ -52,35 +45,32 @@ public class HandlerInfo {
|
||||
}
|
||||
|
||||
public boolean setItem(String itemId, String nbtString) {
|
||||
if(hasImageOrItem())
|
||||
return false;
|
||||
if (hasImageOrItem()) return false;
|
||||
|
||||
itemStack = NEIServerUtils.getModdedItem(itemId, nbtString);
|
||||
if (itemStack == null)
|
||||
NEIClientConfig.logger.info("Couldn't find " + modName + " - " + itemId);
|
||||
if (itemStack == null) NEIClientConfig.logger.info("Couldn't find " + modName + " - " + itemId);
|
||||
else {
|
||||
this.itemId = itemId;
|
||||
this.nbtString = nbtString;
|
||||
}
|
||||
return (itemStack != null);
|
||||
}
|
||||
|
||||
|
||||
public boolean setImage(String resourceLocation, int imageX, int imageY, int imageWidth, int imageHeight) {
|
||||
if(hasImageOrItem())
|
||||
return false;
|
||||
|
||||
this.image = new DrawableBuilder(resourceLocation, imageX, imageY, imageWidth, imageHeight).build();
|
||||
if (hasImageOrItem()) return false;
|
||||
|
||||
this.image = new DrawableBuilder(resourceLocation, imageX, imageY, imageWidth, imageHeight).build();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public DrawableResource getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
|
||||
public String getModName() {
|
||||
return modName;
|
||||
}
|
||||
@@ -100,7 +90,7 @@ public class HandlerInfo {
|
||||
public int getMaxRecipesPerPage() {
|
||||
return Math.max(maxRecipesPerPage, 1);
|
||||
}
|
||||
|
||||
|
||||
public int getYShift() {
|
||||
return yShift;
|
||||
}
|
||||
@@ -112,7 +102,7 @@ public class HandlerInfo {
|
||||
public boolean hasImageOrItem() {
|
||||
if (image != null) return true;
|
||||
if (itemStack != null) return true;
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -138,7 +128,8 @@ public class HandlerInfo {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setDisplayImage(ResourceLocation location, int imageX, int imageY, int imageWidth, int imageHeight) {
|
||||
public Builder setDisplayImage(
|
||||
ResourceLocation location, int imageX, int imageY, int imageWidth, int imageHeight) {
|
||||
info.itemStack = null;
|
||||
info.setImage(location.toString(), imageX, imageY, imageWidth, imageHeight);
|
||||
return this;
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Implement this to show custom recipes in the usage viewer.
|
||||
* See the default vanilla ones for more info.
|
||||
*
|
||||
*/
|
||||
public interface ICraftingHandler extends IRecipeHandler
|
||||
{
|
||||
public interface ICraftingHandler extends IRecipeHandler {
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param outputId A String identifier representing the type of output produced. Eg. {"item", "fuel"}
|
||||
* @param results Objects representing the results that matching recipes must produce.
|
||||
* @return An instance of {@link ICraftingHandler} configured with a list of recipes that produce matching output.
|
||||
|
||||
@@ -3,18 +3,16 @@ package codechicken.nei.recipe;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.api.IRecipeOverlayRenderer;
|
||||
import java.util.List;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Do not implement this. Implement one of it's subinterfaces, either {@link ICraftingHandler} or {@link IUsageHandler}
|
||||
*/
|
||||
public interface IRecipeHandler
|
||||
{
|
||||
public interface IRecipeHandler {
|
||||
/**
|
||||
* For legacy compatibility reasons, this method's default implementation returns the class name.
|
||||
*
|
||||
@@ -25,8 +23,8 @@ public interface IRecipeHandler
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The name of this inventory.
|
||||
*
|
||||
* @return The name of this inventory.
|
||||
* To be displayed at the top of the viewing container.
|
||||
*/
|
||||
String getRecipeName();
|
||||
@@ -42,7 +40,7 @@ public interface IRecipeHandler
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return The number of recipes that this handler contains.
|
||||
*/
|
||||
int numRecipes();
|
||||
@@ -57,19 +55,19 @@ public interface IRecipeHandler
|
||||
*/
|
||||
void drawForeground(int recipe);
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param recipe The recipe index to get items for.
|
||||
* @return A list of the ingredient {@link PositionedStack}s in this recipe relative to the top left corner of your recipe drawing space.
|
||||
*/
|
||||
List<PositionedStack> getIngredientStacks(int recipe);
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param recipetype The recipe index to get items for.
|
||||
* @return A list of the other {@link PositionedStack}s in this recipe relative to the top left corner of your recipe drawing space. For example fuel in furnaces.
|
||||
*/
|
||||
List<PositionedStack> getOtherStacks(int recipetype);
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param recipe The recipe index to get the result for.
|
||||
* @return The recipe result {@link PositionedStack} relative to the top left corner of your recipe drawing space.
|
||||
*/
|
||||
@@ -79,7 +77,7 @@ public interface IRecipeHandler
|
||||
*/
|
||||
void onUpdate();
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param recipe The recipe index to check for.
|
||||
* @param gui The GUI to overlay.
|
||||
* @param container The container of the GUI.
|
||||
@@ -87,13 +85,13 @@ public interface IRecipeHandler
|
||||
*/
|
||||
boolean hasOverlay(GuiContainer gui, Container container, int recipe);
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param recipe The recipe index to get the overlay renderer for.
|
||||
* @return An instance of {@link IRecipeOverlayRenderer} to be used for rendering the overlay of this specific recipe.
|
||||
*/
|
||||
IRecipeOverlayRenderer getOverlayRenderer(GuiContainer gui, int recipe);
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param recipe The recipe index to get the overlay renderer for.
|
||||
* @return An instance of {@link IOverlayHandler} to be used for rendering the overlay of this specific recipe.
|
||||
*/
|
||||
@@ -108,12 +106,12 @@ public interface IRecipeHandler
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return The number of recipes that can fit on a page in the viewer (1 or 2)
|
||||
*/
|
||||
int recipiesPerPage();
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param gui An instance of the currentscreen
|
||||
* @param currenttip The current tooltip, will contain item name and info
|
||||
* @param recipe The recipe index being handled
|
||||
@@ -121,7 +119,7 @@ public interface IRecipeHandler
|
||||
*/
|
||||
List<String> handleTooltip(GuiRecipe gui, List<String> currenttip, int recipe);
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param gui An instance of the currentscreen
|
||||
* @param stack The itemstack currently under the mouse
|
||||
* @param currenttip The current tooltip, will contain item name and info
|
||||
@@ -129,9 +127,9 @@ public interface IRecipeHandler
|
||||
* @return The modified tooltip. DO NOT return null
|
||||
*/
|
||||
List<String> handleItemTooltip(GuiRecipe gui, ItemStack stack, List<String> currenttip, int recipe);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param gui An instance of the currentscreen
|
||||
* @param keyChar The character representing the keyPress
|
||||
* @param keyCode The KeyCode as defined in {@link Keyboard}
|
||||
@@ -140,7 +138,7 @@ public interface IRecipeHandler
|
||||
boolean keyTyped(GuiRecipe gui, char keyChar, int keyCode, int recipe);
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param gui An instance of the currentscreen
|
||||
* @param button The button index being pressed, {0 = Left Click, 1 = Right Click, 2 = Middle Click}
|
||||
* @return true to terminate further processing of this event.
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Implement this to show custom recipes in the usage viewer.
|
||||
* See the default vanilla ones for more info.
|
||||
*
|
||||
*/
|
||||
public interface IUsageHandler extends IRecipeHandler
|
||||
{
|
||||
public interface IUsageHandler extends IRecipeHandler {
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param inputId A String identifier representing the type of ingredients used. Eg. {"item", "fuel"}
|
||||
* @param ingredients Objects representing the ingredients that matching recipes must contain.
|
||||
* @return An instance of {@link IUsageHandler} configured with a list of recipes that contain matching input
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import static codechicken.lib.gui.GuiDraw.drawString;
|
||||
import static codechicken.lib.gui.GuiDraw.getStringWidth;
|
||||
|
||||
import codechicken.core.TaskProfiler;
|
||||
import codechicken.core.TaskProfiler.ProfilerResult;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
@@ -7,164 +10,132 @@ import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.api.IRecipeOverlayRenderer;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import static codechicken.lib.gui.GuiDraw.drawString;
|
||||
import static codechicken.lib.gui.GuiDraw.getStringWidth;
|
||||
|
||||
public class ProfilerRecipeHandler implements ICraftingHandler, IUsageHandler
|
||||
{
|
||||
public class ProfilerRecipeHandler implements ICraftingHandler, IUsageHandler {
|
||||
private static final TaskProfiler profiler = new TaskProfiler();
|
||||
|
||||
public static TaskProfiler getProfiler()
|
||||
{
|
||||
public static TaskProfiler getProfiler() {
|
||||
profiler.clear();
|
||||
return profiler;
|
||||
}
|
||||
|
||||
|
||||
private final boolean crafting;
|
||||
|
||||
public ProfilerRecipeHandler(boolean crafting)
|
||||
{
|
||||
|
||||
public ProfilerRecipeHandler(boolean crafting) {
|
||||
this.crafting = crafting;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getRecipeName()
|
||||
{
|
||||
return NEIClientUtils.translate("recipe.profiler."+(crafting ? "crafting" : "usage"));
|
||||
public String getRecipeName() {
|
||||
return NEIClientUtils.translate("recipe.profiler." + (crafting ? "crafting" : "usage"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numRecipes()
|
||||
{
|
||||
if(!NEIClientConfig.getBooleanSetting("inventory.profileRecipes"))
|
||||
return 0;
|
||||
|
||||
return (int) Math.ceil(((crafting ?
|
||||
GuiCraftingRecipe.craftinghandlers.size() :
|
||||
GuiUsageRecipe.usagehandlers.size())-1)/6D);
|
||||
public int numRecipes() {
|
||||
if (!NEIClientConfig.getBooleanSetting("inventory.profileRecipes")) return 0;
|
||||
|
||||
return (int) Math.ceil(
|
||||
((crafting ? GuiCraftingRecipe.craftinghandlers.size() : GuiUsageRecipe.usagehandlers.size()) - 1)
|
||||
/ 6D);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(int recipe)
|
||||
{
|
||||
}
|
||||
public void drawBackground(int recipe) {}
|
||||
|
||||
@Override
|
||||
public void drawForeground(int recipe)
|
||||
{
|
||||
public void drawForeground(int recipe) {
|
||||
List<ProfilerResult> results = profiler.getResults();
|
||||
for(Iterator<ProfilerResult> it = results.iterator(); it.hasNext();)
|
||||
if(it.next().name.equals(getRecipeName()))
|
||||
it.remove();
|
||||
|
||||
for (Iterator<ProfilerResult> it = results.iterator(); it.hasNext(); )
|
||||
if (it.next().name.equals(getRecipeName())) it.remove();
|
||||
|
||||
results.sort((o1, o2) -> o1.time < o2.time ? 1 : -1);
|
||||
|
||||
for(int i = recipe*6; i < results.size() && i < (recipe+1)*6; i++)
|
||||
{
|
||||
|
||||
for (int i = recipe * 6; i < results.size() && i < (recipe + 1) * 6; i++) {
|
||||
ProfilerResult r = results.get(i);
|
||||
int y = (i%6)*20+6;
|
||||
int y = (i % 6) * 20 + 6;
|
||||
drawString(r.name, 8, y, 0xFF808080, false);
|
||||
|
||||
DecimalFormat format = new DecimalFormat("0.00");
|
||||
String s = format.format(r.fraction*100)+"%";
|
||||
if(r.time < 1000000L)
|
||||
s+= " ("+(r.time/1000)+"us)";
|
||||
else
|
||||
s+= " ("+(r.time/1000000)+"ms)";
|
||||
|
||||
drawString(s, 156-getStringWidth(s), y+10, 0xFF404040, false);
|
||||
String s = format.format(r.fraction * 100) + "%";
|
||||
if (r.time < 1000000L) s += " (" + (r.time / 1000) + "us)";
|
||||
else s += " (" + (r.time / 1000000) + "ms)";
|
||||
|
||||
drawString(s, 156 - getStringWidth(s), y + 10, 0xFF404040, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<PositionedStack> getIngredientStacks(int recipe)
|
||||
{
|
||||
public ArrayList<PositionedStack> getIngredientStacks(int recipe) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<PositionedStack> getOtherStacks(int recipetype)
|
||||
{
|
||||
public ArrayList<PositionedStack> getOtherStacks(int recipetype) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PositionedStack getResultStack(int recipe)
|
||||
{
|
||||
public PositionedStack getResultStack(int recipe) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate()
|
||||
{
|
||||
}
|
||||
public void onUpdate() {}
|
||||
|
||||
@Override
|
||||
public boolean hasOverlay(GuiContainer gui, Container container, int recipe)
|
||||
{
|
||||
public boolean hasOverlay(GuiContainer gui, Container container, int recipe) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeOverlayRenderer getOverlayRenderer(GuiContainer gui, int recipe)
|
||||
{
|
||||
public IRecipeOverlayRenderer getOverlayRenderer(GuiContainer gui, int recipe) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IOverlayHandler getOverlayHandler(GuiContainer gui, int recipe)
|
||||
{
|
||||
public IOverlayHandler getOverlayHandler(GuiContainer gui, int recipe) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int recipiesPerPage()
|
||||
{
|
||||
public int recipiesPerPage() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleTooltip(GuiRecipe gui, List<String> currenttip, int recipe)
|
||||
{
|
||||
public List<String> handleTooltip(GuiRecipe gui, List<String> currenttip, int recipe) {
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleItemTooltip(GuiRecipe gui, ItemStack stack, List<String> currenttip, int recipe)
|
||||
{
|
||||
public List<String> handleItemTooltip(GuiRecipe gui, ItemStack stack, List<String> currenttip, int recipe) {
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(GuiRecipe gui, char keyChar, int keyCode, int recipe)
|
||||
{
|
||||
public boolean keyTyped(GuiRecipe gui, char keyChar, int keyCode, int recipe) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(GuiRecipe gui, int button, int recipe)
|
||||
{
|
||||
public boolean mouseClicked(GuiRecipe gui, int button, int recipe) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IUsageHandler getUsageHandler(String inputId, Object... ingredients)
|
||||
{
|
||||
public IUsageHandler getUsageHandler(String inputId, Object... ingredients) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICraftingHandler getRecipeHandler(String outputId, Object... results)
|
||||
{
|
||||
public ICraftingHandler getRecipeHandler(String outputId, Object... results) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,6 @@ import codechicken.nei.NEIServerUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import com.google.common.base.Objects;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.apache.commons.csv.CSVFormat;
|
||||
import org.apache.commons.csv.CSVParser;
|
||||
import org.apache.commons.csv.CSVRecord;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -25,6 +20,10 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.apache.commons.csv.CSVFormat;
|
||||
import org.apache.commons.csv.CSVParser;
|
||||
import org.apache.commons.csv.CSVRecord;
|
||||
|
||||
public class RecipeCatalysts {
|
||||
private static final Map<String, CatalystInfoList> catalystsAdderFromAPI = new HashMap<>();
|
||||
@@ -90,7 +89,8 @@ public class RecipeCatalysts {
|
||||
ItemStack catalyst = catalysts.get(index).getStack();
|
||||
int column = index / rowCount;
|
||||
int row = index % rowCount;
|
||||
newStacks.add(new PositionedStack(catalyst, -column * GuiRecipeCatalyst.ingredientSize, row * GuiRecipeCatalyst.ingredientSize));
|
||||
newStacks.add(new PositionedStack(
|
||||
catalyst, -column * GuiRecipeCatalyst.ingredientSize, row * GuiRecipeCatalyst.ingredientSize));
|
||||
}
|
||||
newMap.put(entry.getKey(), newStacks);
|
||||
}
|
||||
@@ -131,7 +131,7 @@ public class RecipeCatalysts {
|
||||
}
|
||||
} else {
|
||||
File catalystFile = NEIClientConfig.catalystFile;
|
||||
if(!catalystFile.exists()) {
|
||||
if (!catalystFile.exists()) {
|
||||
NEIClientConfig.logger.info("Config file doesn't exist, creating");
|
||||
try {
|
||||
assert handlerUrl != null;
|
||||
@@ -247,9 +247,7 @@ public class RecipeCatalysts {
|
||||
if (forceClassNameList.stream().anyMatch(s -> s.equals(handler.getHandlerId()))) {
|
||||
return handler.getHandlerId();
|
||||
}
|
||||
return Objects.firstNonNull(
|
||||
handler.getOverlayIdentifier(),
|
||||
handler.getHandlerId());
|
||||
return Objects.firstNonNull(handler.getOverlayIdentifier(), handler.getHandlerId());
|
||||
}
|
||||
|
||||
public static void addOrPut(Map<String, CatalystInfoList> map, String handlerID, CatalystInfo catalyst) {
|
||||
@@ -270,8 +268,7 @@ public class RecipeCatalysts {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void addRecipeCatalyst(List<ItemStack> stacks, Class<? extends IRecipeHandler> handler) {
|
||||
}
|
||||
public static void addRecipeCatalyst(List<ItemStack> stacks, Class<? extends IRecipeHandler> handler) {}
|
||||
|
||||
@Deprecated
|
||||
public static List<PositionedStack> getRecipeCatalysts(Class<? extends IRecipeHandler> handler) {
|
||||
|
||||
@@ -5,95 +5,80 @@ import codechicken.nei.api.API;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.api.IStackPositioner;
|
||||
import com.google.common.base.Objects;
|
||||
import java.util.HashMap;
|
||||
import net.minecraft.client.gui.inventory.GuiBrewingStand;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.gui.inventory.GuiCrafting;
|
||||
import net.minecraft.client.gui.inventory.GuiFurnace;
|
||||
import net.minecraft.client.gui.inventory.GuiInventory;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class RecipeInfo
|
||||
{
|
||||
private static class OverlayKey
|
||||
{
|
||||
public class RecipeInfo {
|
||||
private static class OverlayKey {
|
||||
final String ident;
|
||||
final Class<? extends GuiContainer> guiClass;
|
||||
|
||||
public OverlayKey(Class<? extends GuiContainer> classz, String ident)
|
||||
{
|
||||
|
||||
public OverlayKey(Class<? extends GuiContainer> classz, String ident) {
|
||||
this.guiClass = classz;
|
||||
this.ident = ident;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if(!(obj instanceof OverlayKey))
|
||||
return false;
|
||||
OverlayKey key = (OverlayKey)obj;
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof OverlayKey)) return false;
|
||||
OverlayKey key = (OverlayKey) obj;
|
||||
return Objects.equal(ident, key.ident) && guiClass == key.guiClass;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(ident, guiClass);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static final HashMap<OverlayKey, IOverlayHandler> overlayMap = new HashMap<>();
|
||||
static final HashMap<OverlayKey, IStackPositioner> positionerMap = new HashMap<>();
|
||||
static final HashMap<Class<? extends GuiContainer>, int[]> offsets = new HashMap<>();
|
||||
|
||||
public static void registerOverlayHandler(Class<? extends GuiContainer> classz, IOverlayHandler handler, String ident)
|
||||
{
|
||||
|
||||
public static void registerOverlayHandler(
|
||||
Class<? extends GuiContainer> classz, IOverlayHandler handler, String ident) {
|
||||
overlayMap.put(new OverlayKey(classz, ident), handler);
|
||||
}
|
||||
|
||||
public static void registerGuiOverlay(Class<? extends GuiContainer> classz, String ident, IStackPositioner positioner)
|
||||
{
|
||||
|
||||
public static void registerGuiOverlay(
|
||||
Class<? extends GuiContainer> classz, String ident, IStackPositioner positioner) {
|
||||
positionerMap.put(new OverlayKey(classz, ident), positioner);
|
||||
if(positioner instanceof OffsetPositioner && !offsets.containsKey(classz))
|
||||
{
|
||||
OffsetPositioner p = (OffsetPositioner)positioner;
|
||||
if (positioner instanceof OffsetPositioner && !offsets.containsKey(classz)) {
|
||||
OffsetPositioner p = (OffsetPositioner) positioner;
|
||||
setGuiOffset(classz, p.offsetx, p.offsety);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setGuiOffset(Class<? extends GuiContainer> classz, int x, int y)
|
||||
{
|
||||
offsets.put(classz, new int[]{x, y});
|
||||
public static void setGuiOffset(Class<? extends GuiContainer> classz, int x, int y) {
|
||||
offsets.put(classz, new int[] {x, y});
|
||||
}
|
||||
|
||||
public static boolean hasDefaultOverlay(GuiContainer gui, String ident)
|
||||
{
|
||||
public static boolean hasDefaultOverlay(GuiContainer gui, String ident) {
|
||||
return positionerMap.containsKey(new OverlayKey(gui.getClass(), ident));
|
||||
}
|
||||
|
||||
public static boolean hasOverlayHandler(GuiContainer gui, String ident)
|
||||
{
|
||||
public static boolean hasOverlayHandler(GuiContainer gui, String ident) {
|
||||
return overlayMap.containsKey(new OverlayKey(gui.getClass(), ident));
|
||||
}
|
||||
|
||||
public static IOverlayHandler getOverlayHandler(GuiContainer gui, String ident)
|
||||
{
|
||||
public static IOverlayHandler getOverlayHandler(GuiContainer gui, String ident) {
|
||||
return overlayMap.get(new OverlayKey(gui.getClass(), ident));
|
||||
}
|
||||
|
||||
public static IStackPositioner getStackPositioner(GuiContainer gui, String ident)
|
||||
{
|
||||
public static IStackPositioner getStackPositioner(GuiContainer gui, String ident) {
|
||||
return positionerMap.get(new OverlayKey(gui.getClass(), ident));
|
||||
}
|
||||
|
||||
public static int[] getGuiOffset(GuiContainer gui)
|
||||
{
|
||||
|
||||
public static int[] getGuiOffset(GuiContainer gui) {
|
||||
int[] offset = offsets.get(gui.getClass());
|
||||
return offset == null ? new int[]{5, 11} : offset;
|
||||
return offset == null ? new int[] {5, 11} : offset;
|
||||
}
|
||||
|
||||
public static void load()
|
||||
{
|
||||
public static void load() {
|
||||
API.registerRecipeHandler(new ShapedRecipeHandler());
|
||||
API.registerUsageHandler(new ShapedRecipeHandler());
|
||||
API.registerRecipeHandler(new ShapelessRecipeHandler());
|
||||
@@ -116,9 +101,8 @@ public class RecipeInfo
|
||||
API.registerGuiOverlayHandler(GuiCrafting.class, new DefaultOverlayHandler(), "crafting");
|
||||
API.registerGuiOverlayHandler(GuiInventory.class, new DefaultOverlayHandler(63, 20), "crafting2x2");
|
||||
API.registerGuiOverlayHandler(GuiBrewingStand.class, new BrewingOverlayHandler(), "brewing");
|
||||
|
||||
|
||||
API.registerRecipeHandler(new ProfilerRecipeHandler(true));
|
||||
API.registerUsageHandler(new ProfilerRecipeHandler(false));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,11 +7,10 @@ import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.guihook.IContainerInputHandler;
|
||||
import java.util.List;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RecipeItemInputHandler implements IContainerInputHandler {
|
||||
@Override
|
||||
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyCode) {
|
||||
@@ -44,8 +43,9 @@ public class RecipeItemInputHandler implements IContainerInputHandler {
|
||||
}
|
||||
if (!NEIClientConfig.saveCurrentRecipeInBookmarksEnabled()) return false;
|
||||
final BookmarkRecipeId mouseOverRecipeId = ItemPanels.bookmarkPanel.getBookmarkMouseOverRecipeId();
|
||||
if (mouseOverRecipeId == null || mouseOverRecipeId.ingredients == null || mouseOverRecipeId.ingredients.isEmpty())
|
||||
return false;
|
||||
if (mouseOverRecipeId == null
|
||||
|| mouseOverRecipeId.ingredients == null
|
||||
|| mouseOverRecipeId.ingredients.isEmpty()) return false;
|
||||
return GuiCraftingRecipe.openRecipeGui("item", true, stackover.copy());
|
||||
}
|
||||
|
||||
@@ -60,8 +60,10 @@ public class RecipeItemInputHandler implements IContainerInputHandler {
|
||||
|
||||
if (!(gui instanceof GuiRecipe)) return false;
|
||||
|
||||
//disabled open recipe gui if hold shift (player have move recipe)
|
||||
if (button == 0 && ItemPanels.bookmarkPanel.getStackMouseOver(mousex, mousey) != null && NEIClientUtils.shiftKey()) {
|
||||
// disabled open recipe gui if hold shift (player have move recipe)
|
||||
if (button == 0
|
||||
&& ItemPanels.bookmarkPanel.getStackMouseOver(mousex, mousey) != null
|
||||
&& NEIClientUtils.shiftKey()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -73,16 +75,13 @@ public class RecipeItemInputHandler implements IContainerInputHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyTyped(GuiContainer gui, char keyChar, int keyID) {
|
||||
}
|
||||
public void onKeyTyped(GuiContainer gui, char keyChar, int keyID) {}
|
||||
|
||||
@Override
|
||||
public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
|
||||
}
|
||||
public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button) {}
|
||||
|
||||
@Override
|
||||
public void onMouseUp(GuiContainer gui, int mousex, int mousey, int button) {
|
||||
}
|
||||
public void onMouseUp(GuiContainer gui, int mousex, int mousey, int button) {}
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(GuiContainer gui, char keyChar, int keyID) {
|
||||
@@ -95,10 +94,8 @@ public class RecipeItemInputHandler implements IContainerInputHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {
|
||||
}
|
||||
public void onMouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {}
|
||||
|
||||
@Override
|
||||
public void onMouseDragged(GuiContainer gui, int mousex, int mousey, int button, long heldTime) {
|
||||
}
|
||||
public void onMouseDragged(GuiContainer gui, int mousex, int mousey, int button, long heldTime) {}
|
||||
}
|
||||
@@ -1,23 +1,21 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import codechicken.nei.api.INEIGuiAdapter;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
import static codechicken.nei.LayoutManager.searchField;
|
||||
|
||||
public class SearchInputDropHandler extends INEIGuiAdapter
|
||||
{
|
||||
import codechicken.nei.api.INEIGuiAdapter;
|
||||
import java.util.regex.Pattern;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public class SearchInputDropHandler extends INEIGuiAdapter {
|
||||
|
||||
protected static final Pattern SPECIAL_REGEX_CHARS = Pattern.compile("[{}()\\[\\].+*?^$\\\\|]");
|
||||
|
||||
@Override
|
||||
public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button)
|
||||
{
|
||||
|
||||
public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) {
|
||||
|
||||
if (searchField.contains(mouseX, mouseY)) {
|
||||
final FluidStack fluidStack = StackInfo.getFluid(draggedStack);
|
||||
|
||||
@@ -33,9 +31,9 @@ public class SearchInputDropHandler extends INEIGuiAdapter
|
||||
return false;
|
||||
}
|
||||
|
||||
protected String formattingText(String displayName)
|
||||
{
|
||||
return SPECIAL_REGEX_CHARS.matcher(EnumChatFormatting.getTextWithoutFormattingCodes(displayName)).replaceAll("\\\\$0");
|
||||
protected String formattingText(String displayName) {
|
||||
return SPECIAL_REGEX_CHARS
|
||||
.matcher(EnumChatFormatting.getTextWithoutFormattingCodes(displayName))
|
||||
.replaceAll("\\\\$0");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,9 @@ import codechicken.nei.api.DefaultOverlayRenderer;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.api.IRecipeOverlayRenderer;
|
||||
import codechicken.nei.api.IStackPositioner;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.gui.inventory.GuiCrafting;
|
||||
import net.minecraft.inventory.Container;
|
||||
@@ -18,14 +21,8 @@ import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ShapedRecipeHandler extends TemplateRecipeHandler
|
||||
{
|
||||
public class CachedShapedRecipe extends CachedRecipe
|
||||
{
|
||||
public class ShapedRecipeHandler extends TemplateRecipeHandler {
|
||||
public class CachedShapedRecipe extends CachedRecipe {
|
||||
public ArrayList<PositionedStack> ingredients;
|
||||
public PositionedStack result;
|
||||
|
||||
@@ -47,8 +44,7 @@ public class ShapedRecipeHandler extends TemplateRecipeHandler
|
||||
public void setIngredients(int width, int height, Object[] items) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
if (items[y * width + x] == null)
|
||||
continue;
|
||||
if (items[y * width + x] == null) continue;
|
||||
|
||||
PositionedStack stack = new PositionedStack(items[y * width + x], 25 + x * 18, 6 + y * 18, false);
|
||||
stack.setMaxSize(1);
|
||||
@@ -67,8 +63,7 @@ public class ShapedRecipeHandler extends TemplateRecipeHandler
|
||||
}
|
||||
|
||||
public void computeVisuals() {
|
||||
for (PositionedStack p : ingredients)
|
||||
p.generatePermutations();
|
||||
for (PositionedStack p : ingredients) p.generatePermutations();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,13 +87,10 @@ public class ShapedRecipeHandler extends TemplateRecipeHandler
|
||||
if (outputId.equals("crafting") && getClass() == ShapedRecipeHandler.class) {
|
||||
for (IRecipe irecipe : (List<IRecipe>) CraftingManager.getInstance().getRecipeList()) {
|
||||
CachedShapedRecipe recipe = null;
|
||||
if (irecipe instanceof ShapedRecipes)
|
||||
recipe = new CachedShapedRecipe((ShapedRecipes) irecipe);
|
||||
else if (irecipe instanceof ShapedOreRecipe)
|
||||
recipe = forgeShapedRecipe((ShapedOreRecipe) irecipe);
|
||||
if (irecipe instanceof ShapedRecipes) recipe = new CachedShapedRecipe((ShapedRecipes) irecipe);
|
||||
else if (irecipe instanceof ShapedOreRecipe) recipe = forgeShapedRecipe((ShapedOreRecipe) irecipe);
|
||||
|
||||
if (recipe == null)
|
||||
continue;
|
||||
if (recipe == null) continue;
|
||||
|
||||
recipe.computeVisuals();
|
||||
arecipes.add(recipe);
|
||||
@@ -113,13 +105,10 @@ public class ShapedRecipeHandler extends TemplateRecipeHandler
|
||||
for (IRecipe irecipe : (List<IRecipe>) CraftingManager.getInstance().getRecipeList()) {
|
||||
if (NEIServerUtils.areStacksSameTypeCrafting(irecipe.getRecipeOutput(), result)) {
|
||||
CachedShapedRecipe recipe = null;
|
||||
if (irecipe instanceof ShapedRecipes)
|
||||
recipe = new CachedShapedRecipe((ShapedRecipes) irecipe);
|
||||
else if (irecipe instanceof ShapedOreRecipe)
|
||||
recipe = forgeShapedRecipe((ShapedOreRecipe) irecipe);
|
||||
if (irecipe instanceof ShapedRecipes) recipe = new CachedShapedRecipe((ShapedRecipes) irecipe);
|
||||
else if (irecipe instanceof ShapedOreRecipe) recipe = forgeShapedRecipe((ShapedOreRecipe) irecipe);
|
||||
|
||||
if (recipe == null)
|
||||
continue;
|
||||
if (recipe == null) continue;
|
||||
|
||||
recipe.computeVisuals();
|
||||
arecipes.add(recipe);
|
||||
@@ -131,13 +120,10 @@ public class ShapedRecipeHandler extends TemplateRecipeHandler
|
||||
public void loadUsageRecipes(ItemStack ingredient) {
|
||||
for (IRecipe irecipe : (List<IRecipe>) CraftingManager.getInstance().getRecipeList()) {
|
||||
CachedShapedRecipe recipe = null;
|
||||
if (irecipe instanceof ShapedRecipes)
|
||||
recipe = new CachedShapedRecipe((ShapedRecipes) irecipe);
|
||||
else if (irecipe instanceof ShapedOreRecipe)
|
||||
recipe = forgeShapedRecipe((ShapedOreRecipe) irecipe);
|
||||
if (irecipe instanceof ShapedRecipes) recipe = new CachedShapedRecipe((ShapedRecipes) irecipe);
|
||||
else if (irecipe instanceof ShapedOreRecipe) recipe = forgeShapedRecipe((ShapedOreRecipe) irecipe);
|
||||
|
||||
if (recipe == null || !recipe.contains(recipe.ingredients, ingredient.getItem()))
|
||||
continue;
|
||||
if (recipe == null || !recipe.contains(recipe.ingredients, ingredient.getItem())) continue;
|
||||
|
||||
recipe.computeVisuals();
|
||||
if (recipe.contains(recipe.ingredients, ingredient)) {
|
||||
@@ -154,8 +140,8 @@ public class ShapedRecipeHandler extends TemplateRecipeHandler
|
||||
|
||||
Object[] items = recipe.getInput();
|
||||
for (Object item : items)
|
||||
if (item instanceof List && ((List<?>) item).isEmpty()) //ore handler, no ores
|
||||
return null;
|
||||
if (item instanceof List && ((List<?>) item).isEmpty()) // ore handler, no ores
|
||||
return null;
|
||||
|
||||
return new CachedShapedRecipe(width, height, items, recipe.getRecipeOutput());
|
||||
} catch (Exception e) {
|
||||
@@ -175,35 +161,30 @@ public class ShapedRecipeHandler extends TemplateRecipeHandler
|
||||
}
|
||||
|
||||
public boolean hasOverlay(GuiContainer gui, Container container, int recipe) {
|
||||
return super.hasOverlay(gui, container, recipe) ||
|
||||
isRecipe2x2(recipe) && RecipeInfo.hasDefaultOverlay(gui, "crafting2x2");
|
||||
return super.hasOverlay(gui, container, recipe)
|
||||
|| isRecipe2x2(recipe) && RecipeInfo.hasDefaultOverlay(gui, "crafting2x2");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeOverlayRenderer getOverlayRenderer(GuiContainer gui, int recipe) {
|
||||
IRecipeOverlayRenderer renderer = super.getOverlayRenderer(gui, recipe);
|
||||
if (renderer != null)
|
||||
return renderer;
|
||||
if (renderer != null) return renderer;
|
||||
|
||||
IStackPositioner positioner = RecipeInfo.getStackPositioner(gui, "crafting2x2");
|
||||
if (positioner == null)
|
||||
return null;
|
||||
if (positioner == null) return null;
|
||||
return new DefaultOverlayRenderer(getIngredientStacks(recipe), positioner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IOverlayHandler getOverlayHandler(GuiContainer gui, int recipe) {
|
||||
IOverlayHandler handler = super.getOverlayHandler(gui, recipe);
|
||||
if (handler != null)
|
||||
return handler;
|
||||
if (handler != null) return handler;
|
||||
|
||||
return RecipeInfo.getOverlayHandler(gui, "crafting2x2");
|
||||
}
|
||||
|
||||
public boolean isRecipe2x2(int recipe) {
|
||||
for (PositionedStack stack : getIngredientStacks(recipe))
|
||||
if (stack.relx > 43 || stack.rely > 24)
|
||||
return false;
|
||||
for (PositionedStack stack : getIngredientStacks(recipe)) if (stack.relx > 43 || stack.rely > 24) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,31 +4,29 @@ import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.NEIServerUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
public class ShapelessRecipeHandler extends ShapedRecipeHandler {
|
||||
public int[][] stackorder = new int[][] {
|
||||
{0, 0},
|
||||
{1, 0},
|
||||
{0, 1},
|
||||
{1, 1},
|
||||
{0, 2},
|
||||
{1, 2},
|
||||
{2, 0},
|
||||
{2, 1},
|
||||
{2, 2}
|
||||
};
|
||||
|
||||
public class ShapelessRecipeHandler extends ShapedRecipeHandler
|
||||
{
|
||||
public int[][] stackorder = new int[][]{
|
||||
{0, 0},
|
||||
{1, 0},
|
||||
{0, 1},
|
||||
{1, 1},
|
||||
{0, 2},
|
||||
{1, 2},
|
||||
{2, 0},
|
||||
{2, 1},
|
||||
{2, 2}};
|
||||
|
||||
public class CachedShapelessRecipe extends CachedRecipe
|
||||
{
|
||||
public class CachedShapelessRecipe extends CachedRecipe {
|
||||
public CachedShapelessRecipe() {
|
||||
ingredients = new ArrayList<>();
|
||||
}
|
||||
@@ -51,11 +49,13 @@ public class ShapelessRecipeHandler extends ShapedRecipeHandler
|
||||
ingredients.clear();
|
||||
int itemsSize = items.size();
|
||||
if (itemsSize > stackorder.length) {
|
||||
NEIClientConfig.logger.error("RECIPE BUG: Too many items (" + itemsSize + ") for " + this.result.toString());
|
||||
NEIClientConfig.logger.error(
|
||||
"RECIPE BUG: Too many items (" + itemsSize + ") for " + this.result.toString());
|
||||
itemsSize = stackorder.length;
|
||||
}
|
||||
for (int ingred = 0; ingred < itemsSize; ingred++) {
|
||||
PositionedStack stack = new PositionedStack(items.get(ingred), 25 + stackorder[ingred][0] * 18, 6 + stackorder[ingred][1] * 18);
|
||||
PositionedStack stack = new PositionedStack(
|
||||
items.get(ingred), 25 + stackorder[ingred][0] * 18, 6 + stackorder[ingred][1] * 18);
|
||||
stack.setMaxSize(1);
|
||||
ingredients.add(stack);
|
||||
}
|
||||
@@ -89,13 +89,11 @@ public class ShapelessRecipeHandler extends ShapedRecipeHandler
|
||||
List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
|
||||
for (IRecipe irecipe : allrecipes) {
|
||||
CachedShapelessRecipe recipe = null;
|
||||
if (irecipe instanceof ShapelessRecipes)
|
||||
recipe = shapelessRecipe((ShapelessRecipes) irecipe);
|
||||
if (irecipe instanceof ShapelessRecipes) recipe = shapelessRecipe((ShapelessRecipes) irecipe);
|
||||
else if (irecipe instanceof ShapelessOreRecipe)
|
||||
recipe = forgeShapelessRecipe((ShapelessOreRecipe) irecipe);
|
||||
|
||||
if (recipe == null)
|
||||
continue;
|
||||
if (recipe == null) continue;
|
||||
|
||||
arecipes.add(recipe);
|
||||
}
|
||||
@@ -110,13 +108,11 @@ public class ShapelessRecipeHandler extends ShapedRecipeHandler
|
||||
for (IRecipe irecipe : allrecipes) {
|
||||
if (NEIServerUtils.areStacksSameTypeCrafting(irecipe.getRecipeOutput(), result)) {
|
||||
CachedShapelessRecipe recipe = null;
|
||||
if (irecipe instanceof ShapelessRecipes)
|
||||
recipe = shapelessRecipe((ShapelessRecipes) irecipe);
|
||||
if (irecipe instanceof ShapelessRecipes) recipe = shapelessRecipe((ShapelessRecipes) irecipe);
|
||||
else if (irecipe instanceof ShapelessOreRecipe)
|
||||
recipe = forgeShapelessRecipe((ShapelessOreRecipe) irecipe);
|
||||
|
||||
if (recipe == null)
|
||||
continue;
|
||||
if (recipe == null) continue;
|
||||
|
||||
arecipes.add(recipe);
|
||||
}
|
||||
@@ -128,13 +124,10 @@ public class ShapelessRecipeHandler extends ShapedRecipeHandler
|
||||
List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
|
||||
for (IRecipe irecipe : allrecipes) {
|
||||
CachedShapelessRecipe recipe = null;
|
||||
if (irecipe instanceof ShapelessRecipes)
|
||||
recipe = shapelessRecipe((ShapelessRecipes) irecipe);
|
||||
else if (irecipe instanceof ShapelessOreRecipe)
|
||||
recipe = forgeShapelessRecipe((ShapelessOreRecipe) irecipe);
|
||||
if (irecipe instanceof ShapelessRecipes) recipe = shapelessRecipe((ShapelessRecipes) irecipe);
|
||||
else if (irecipe instanceof ShapelessOreRecipe) recipe = forgeShapelessRecipe((ShapelessOreRecipe) irecipe);
|
||||
|
||||
if (recipe == null)
|
||||
continue;
|
||||
if (recipe == null) continue;
|
||||
|
||||
if (recipe.contains(recipe.ingredients, ingredient)) {
|
||||
recipe.setIngredientPermutation(recipe.ingredients, ingredient);
|
||||
@@ -144,12 +137,12 @@ public class ShapelessRecipeHandler extends ShapedRecipeHandler
|
||||
}
|
||||
|
||||
private CachedShapelessRecipe shapelessRecipe(ShapelessRecipes recipe) {
|
||||
if(recipe.recipeItems == null) //because some mod subclasses actually do this
|
||||
return null;
|
||||
if (recipe.recipeItems == null) // because some mod subclasses actually do this
|
||||
return null;
|
||||
|
||||
try {
|
||||
return new CachedShapelessRecipe(recipe.recipeItems, recipe.getRecipeOutput());
|
||||
} catch (ClassCastException e) { //because some mod subclasses put whatever they want in recipeItems
|
||||
} catch (ClassCastException e) { // because some mod subclasses put whatever they want in recipeItems
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -158,8 +151,8 @@ public class ShapelessRecipeHandler extends ShapedRecipeHandler
|
||||
ArrayList<Object> items = recipe.getInput();
|
||||
|
||||
for (Object item : items)
|
||||
if (item instanceof List && ((List<?>) item).isEmpty())//ore handler, no ores
|
||||
return null;
|
||||
if (item instanceof List && ((List<?>) item).isEmpty()) // ore handler, no ores
|
||||
return null;
|
||||
|
||||
try {
|
||||
return new CachedShapelessRecipe(items, recipe.getRecipeOutput());
|
||||
|
||||
@@ -4,13 +4,6 @@ import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.api.IStackStringifyHandler;
|
||||
import codechicken.nei.recipe.stackinfo.DefaultStackStringifyHandler;
|
||||
import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
@@ -21,27 +14,29 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.WeakHashMap;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
public class StackInfo
|
||||
{
|
||||
|
||||
public class StackInfo {
|
||||
|
||||
public static final ArrayList<IStackStringifyHandler> stackStringifyHandlers = new ArrayList<>();
|
||||
private static final HashMap<String, HashMap<String, String[]>> guidfilters = new HashMap<>();
|
||||
private static final WeakHashMap<ItemStack, String> guidcache = new WeakHashMap<>();
|
||||
|
||||
|
||||
static {
|
||||
stackStringifyHandlers.add(new DefaultStackStringifyHandler());
|
||||
stackStringifyHandlers.add(new GTFluidStackStringifyHandler());
|
||||
}
|
||||
|
||||
public static NBTTagCompound itemStackToNBT(ItemStack stack)
|
||||
{
|
||||
public static NBTTagCompound itemStackToNBT(ItemStack stack) {
|
||||
return itemStackToNBT(stack, true);
|
||||
}
|
||||
|
||||
public static NBTTagCompound itemStackToNBT(ItemStack stack, boolean saveStackSize)
|
||||
{
|
||||
public static NBTTagCompound itemStackToNBT(ItemStack stack, boolean saveStackSize) {
|
||||
NBTTagCompound nbTag = null;
|
||||
|
||||
for (int i = stackStringifyHandlers.size() - 1; i >= 0 && nbTag == null; i--) {
|
||||
@@ -51,8 +46,7 @@ public class StackInfo
|
||||
return nbTag;
|
||||
}
|
||||
|
||||
public static ItemStack loadFromNBT(NBTTagCompound nbtTag)
|
||||
{
|
||||
public static ItemStack loadFromNBT(NBTTagCompound nbtTag) {
|
||||
ItemStack stack = null;
|
||||
|
||||
for (int i = stackStringifyHandlers.size() - 1; i >= 0 && nbtTag != null && stack == null; i--) {
|
||||
@@ -62,8 +56,7 @@ public class StackInfo
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static boolean equalItemAndNBT(ItemStack stackA, ItemStack stackB, boolean useNBT)
|
||||
{
|
||||
public static boolean equalItemAndNBT(ItemStack stackA, ItemStack stackB, boolean useNBT) {
|
||||
if (!stackA.isItemEqual(stackB)) {
|
||||
return false;
|
||||
}
|
||||
@@ -72,14 +65,14 @@ public class StackInfo
|
||||
NBTTagCompound tagCompoundA = itemStackToNBT(stackA, false);
|
||||
NBTTagCompound tagCompoundB = itemStackToNBT(stackB, false);
|
||||
|
||||
return tagCompoundA == null && tagCompoundB == null || tagCompoundA != null && tagCompoundB != null && tagCompoundA.equals(tagCompoundB);
|
||||
return tagCompoundA == null && tagCompoundB == null
|
||||
|| tagCompoundA != null && tagCompoundB != null && tagCompoundA.equals(tagCompoundB);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static FluidStack getFluid(ItemStack stack)
|
||||
{
|
||||
public static FluidStack getFluid(ItemStack stack) {
|
||||
FluidStack fluid = null;
|
||||
|
||||
for (int i = stackStringifyHandlers.size() - 1; i >= 0 && fluid == null; i--) {
|
||||
@@ -89,8 +82,7 @@ public class StackInfo
|
||||
return fluid;
|
||||
}
|
||||
|
||||
public static String getItemStackGUID(ItemStack stack)
|
||||
{
|
||||
public static String getItemStackGUID(ItemStack stack) {
|
||||
if (!guidcache.containsKey(stack)) {
|
||||
|
||||
final NBTTagCompound nbTag = itemStackToNBT(stack, false);
|
||||
@@ -133,15 +125,13 @@ public class StackInfo
|
||||
} catch (Throwable e) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (local instanceof NBTBase) {
|
||||
keys.add(((NBTBase)local).toString());
|
||||
keys.add(((NBTBase) local).toString());
|
||||
} else if (local != null) {
|
||||
keys.add(String.valueOf(local));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
synchronized (guidcache) {
|
||||
@@ -152,14 +142,12 @@ public class StackInfo
|
||||
guidcache.put(stack, nbTag.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return guidcache.get(stack);
|
||||
}
|
||||
|
||||
public static void loadGuidFilters()
|
||||
{
|
||||
public static void loadGuidFilters() {
|
||||
|
||||
guidfilters.clear();
|
||||
|
||||
@@ -177,8 +165,9 @@ public class StackInfo
|
||||
}
|
||||
|
||||
} else {
|
||||
final URL filterUrl = Thread.currentThread().getContextClassLoader().getResource("assets/nei/guidfilters.cfg");
|
||||
|
||||
final URL filterUrl =
|
||||
Thread.currentThread().getContextClassLoader().getResource("assets/nei/guidfilters.cfg");
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(filterUrl.openStream()))) {
|
||||
itemStrings = IOUtils.readLines(reader);
|
||||
} catch (IOException e) {
|
||||
@@ -188,20 +177,17 @@ public class StackInfo
|
||||
NEIClientConfig.logger.info("Error parsing guid filters");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (String guidStr: itemStrings) {
|
||||
for (String guidStr : itemStrings) {
|
||||
final String[] parts = guidStr.split(",");
|
||||
final HashMap<String, String[]> rules = new HashMap<>();
|
||||
|
||||
for (int j = 1; j < parts.length; j++) {
|
||||
rules.put(parts[j], parts[j].split("\\."));
|
||||
}
|
||||
|
||||
|
||||
guidfilters.put(parts[0], rules);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import static codechicken.lib.gui.GuiDraw.changeTexture;
|
||||
import static codechicken.lib.gui.GuiDraw.drawTexturedModalRect;
|
||||
import static codechicken.lib.gui.GuiDraw.getMousePosition;
|
||||
|
||||
import codechicken.nei.ItemList;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
@@ -13,15 +17,6 @@ import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.guihook.IContainerInputHandler;
|
||||
import codechicken.nei.guihook.IContainerTooltipHandler;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
@@ -36,10 +31,14 @@ import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static codechicken.lib.gui.GuiDraw.changeTexture;
|
||||
import static codechicken.lib.gui.GuiDraw.drawTexturedModalRect;
|
||||
import static codechicken.lib.gui.GuiDraw.getMousePosition;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
* A Template Recipe Handler!
|
||||
@@ -48,33 +47,31 @@ import static codechicken.lib.gui.GuiDraw.getMousePosition;
|
||||
* you can now extend this class to make your custom recipe handlers much easier to create.
|
||||
* Just look at the 5 handlers included by default to work out how to do stuff if you are still stuck.
|
||||
*/
|
||||
public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageHandler
|
||||
{
|
||||
public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageHandler {
|
||||
protected static ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
public static void findFuelsOnce() {
|
||||
// Ensure we only find fuels once, even if threaded
|
||||
lock.lock();
|
||||
try {
|
||||
if (FurnaceRecipeHandler.afuels == null || FurnaceRecipeHandler.afuels.isEmpty())
|
||||
findFuels(false);
|
||||
if (FurnaceRecipeHandler.afuels == null || FurnaceRecipeHandler.afuels.isEmpty()) findFuels(false);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void findFuelsOnceParallel() {
|
||||
// Ensure we only find fuels once, even if threaded
|
||||
lock.lock();
|
||||
try {
|
||||
if (FurnaceRecipeHandler.afuels == null || FurnaceRecipeHandler.afuels.isEmpty())
|
||||
findFuels(true);
|
||||
if (FurnaceRecipeHandler.afuels == null || FurnaceRecipeHandler.afuels.isEmpty()) findFuels(true);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Set<Item> efuels;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
private static void findFuels(boolean parallel) {
|
||||
efuels = new HashSet<>();
|
||||
@@ -84,22 +81,30 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
efuels.add(Item.getItemFromBlock(Blocks.wall_sign));
|
||||
efuels.add(Item.getItemFromBlock(Blocks.wooden_door));
|
||||
efuels.add(Item.getItemFromBlock(Blocks.trapped_chest));
|
||||
|
||||
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
if (parallel) {
|
||||
try {
|
||||
FurnaceRecipeHandler.afuels = ItemList.forkJoinPool.submit(() -> ItemList.items.parallelStream().map(TemplateRecipeHandler::identifyFuel).filter(Objects::nonNull).collect(Collectors.toCollection(ArrayList::new))).get();
|
||||
FurnaceRecipeHandler.afuels = ItemList.forkJoinPool
|
||||
.submit(() -> ItemList.items.parallelStream()
|
||||
.map(TemplateRecipeHandler::identifyFuel)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toCollection(ArrayList::new)))
|
||||
.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
FurnaceRecipeHandler.afuels = new ArrayList<>();
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
FurnaceRecipeHandler.afuels = ItemList.items.stream().map(TemplateRecipeHandler::identifyFuel).filter(Objects::nonNull).collect(Collectors.toCollection(ArrayList::new));
|
||||
FurnaceRecipeHandler.afuels = ItemList.items.stream()
|
||||
.map(TemplateRecipeHandler::identifyFuel)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
}
|
||||
|
||||
NEIClientConfig.logger.info("FindFuels took " + stopwatch.stop() );
|
||||
NEIClientConfig.logger.info("FindFuels took " + stopwatch.stop());
|
||||
}
|
||||
|
||||
|
||||
private static FurnaceRecipeHandler.FuelPair identifyFuel(final ItemStack itemStack) {
|
||||
if (efuels.contains(itemStack.getItem())) return null;
|
||||
final int burnTime = TileEntityFurnace.getItemBurnTime(itemStack);
|
||||
@@ -111,8 +116,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
* This Recipe Handler runs on this internal class
|
||||
* Fill the recipe array with subclasses of this to make transforming the different types of recipes out there into a nice format for NEI a much easier job.
|
||||
*/
|
||||
public abstract class CachedRecipe
|
||||
{
|
||||
public abstract class CachedRecipe {
|
||||
final long offset = System.currentTimeMillis();
|
||||
|
||||
/**
|
||||
@@ -129,8 +133,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
public List<PositionedStack> getIngredients() {
|
||||
ArrayList<PositionedStack> stacks = new ArrayList<>();
|
||||
PositionedStack stack = getIngredient();
|
||||
if (stack != null)
|
||||
stacks.add(stack);
|
||||
if (stack != null) stacks.add(stack);
|
||||
return stacks;
|
||||
}
|
||||
|
||||
@@ -151,8 +154,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
ArrayList<PositionedStack> stacks = new ArrayList<>();
|
||||
try {
|
||||
PositionedStack stack = getOtherStack();
|
||||
if (stack != null)
|
||||
stacks.add(stack);
|
||||
if (stack != null) stacks.add(stack);
|
||||
} catch (ArithmeticException e) {
|
||||
NEIClientConfig.logger.error("Error in getOtherStacks: " + e);
|
||||
}
|
||||
@@ -197,9 +199,10 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
stack.item = stack.items[i];
|
||||
stack.item.setItemDamage(ingredient.getItemDamage());
|
||||
if (ingredient.hasTagCompound()) {
|
||||
stack.item.setTagCompound((NBTTagCompound) ingredient.getTagCompound().copy());
|
||||
stack.item.setTagCompound(
|
||||
(NBTTagCompound) ingredient.getTagCompound().copy());
|
||||
}
|
||||
stack.items = new ItemStack[]{stack.item};
|
||||
stack.items = new ItemStack[] {stack.item};
|
||||
stack.setPermutationToRender(0);
|
||||
break;
|
||||
}
|
||||
@@ -212,9 +215,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
* @return true if any of the permutations of any of the ingredients contain this stack
|
||||
*/
|
||||
public boolean contains(Collection<PositionedStack> ingredients, ItemStack ingredient) {
|
||||
for (PositionedStack stack : ingredients)
|
||||
if (stack.contains(ingredient))
|
||||
return true;
|
||||
for (PositionedStack stack : ingredients) if (stack.contains(ingredient)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -223,9 +224,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
* NBT-friendly version of {@link #contains(Collection, ItemStack)}
|
||||
*/
|
||||
public boolean containsWithNBT(Collection<PositionedStack> ingredients, ItemStack ingredient) {
|
||||
for (PositionedStack stack : ingredients)
|
||||
if (stack.containsWithNBT(ingredient))
|
||||
return true;
|
||||
for (PositionedStack stack : ingredients) if (stack.containsWithNBT(ingredient)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -235,9 +234,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
* @return true if any of the permutations of any of the ingredients contain this stack
|
||||
*/
|
||||
public boolean contains(Collection<PositionedStack> ingredients, Item ingred) {
|
||||
for (PositionedStack stack : ingredients)
|
||||
if (stack.contains(ingred))
|
||||
return true;
|
||||
for (PositionedStack stack : ingredients) if (stack.contains(ingred)) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -246,8 +243,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
* The Rectangle is an region of the gui relative to the corner of the recipe that will activate the recipe with the corresponding outputId apon being clicked.
|
||||
* Apply this over fuel icons or arrows that the user may click to see all recipes pertaining to that action.
|
||||
*/
|
||||
public static class RecipeTransferRect
|
||||
{
|
||||
public static class RecipeTransferRect {
|
||||
public RecipeTransferRect(Rectangle rectangle, String outputId, Object... results) {
|
||||
rect = rectangle;
|
||||
this.outputId = outputId;
|
||||
@@ -255,8 +251,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof RecipeTransferRect))
|
||||
return false;
|
||||
if (!(obj instanceof RecipeTransferRect)) return false;
|
||||
|
||||
return rect.equals(((RecipeTransferRect) obj).rect);
|
||||
}
|
||||
@@ -270,13 +265,12 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
Object[] results;
|
||||
}
|
||||
|
||||
public static class RecipeTransferRectHandler implements IContainerInputHandler, IContainerTooltipHandler
|
||||
{
|
||||
public static class RecipeTransferRectHandler implements IContainerInputHandler, IContainerTooltipHandler {
|
||||
private static HashMap<Class<? extends GuiContainer>, HashSet<RecipeTransferRect>> guiMap = new HashMap<>();
|
||||
|
||||
public static void registerRectsToGuis(List<Class<? extends GuiContainer>> classes, List<RecipeTransferRect> rects) {
|
||||
if (classes == null)
|
||||
return;
|
||||
public static void registerRectsToGuis(
|
||||
List<Class<? extends GuiContainer>> classes, List<RecipeTransferRect> rects) {
|
||||
if (classes == null) return;
|
||||
|
||||
for (Class<? extends GuiContainer> clazz : classes) {
|
||||
HashSet<RecipeTransferRect> set = guiMap.computeIfAbsent(clazz, k -> new HashSet<>());
|
||||
@@ -290,26 +284,20 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
|
||||
@Override
|
||||
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyCode) {
|
||||
if (!canHandle(gui))
|
||||
return false;
|
||||
if (!canHandle(gui)) return false;
|
||||
|
||||
if (keyCode == NEIClientConfig.getKeyBinding("gui.recipe"))
|
||||
return transferRect(gui, false);
|
||||
else if (keyCode == NEIClientConfig.getKeyBinding("gui.usage"))
|
||||
return transferRect(gui, true);
|
||||
if (keyCode == NEIClientConfig.getKeyBinding("gui.recipe")) return transferRect(gui, false);
|
||||
else if (keyCode == NEIClientConfig.getKeyBinding("gui.usage")) return transferRect(gui, true);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
|
||||
if (!canHandle(gui))
|
||||
return false;
|
||||
if (!canHandle(gui)) return false;
|
||||
|
||||
if (button == 0)
|
||||
return transferRect(gui, false);
|
||||
else if (button == 1)
|
||||
return transferRect(gui, true);
|
||||
if (button == 0) return transferRect(gui, false);
|
||||
else if (button == 1) return transferRect(gui, true);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -320,16 +308,13 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyTyped(GuiContainer gui, char keyChar, int keyID) {
|
||||
}
|
||||
public void onKeyTyped(GuiContainer gui, char keyChar, int keyID) {}
|
||||
|
||||
@Override
|
||||
public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
|
||||
}
|
||||
public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button) {}
|
||||
|
||||
@Override
|
||||
public void onMouseUp(GuiContainer gui, int mousex, int mousey, int button) {
|
||||
}
|
||||
public void onMouseUp(GuiContainer gui, int mousex, int mousey, int button) {}
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(GuiContainer gui, char keyChar, int keyID) {
|
||||
@@ -342,17 +327,16 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {
|
||||
}
|
||||
public void onMouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {}
|
||||
|
||||
@Override
|
||||
public List<String> handleTooltip(GuiContainer gui, int mousex, int mousey, List<String> currenttip) {
|
||||
if (!canHandle(gui))
|
||||
return currenttip;
|
||||
if (!canHandle(gui)) return currenttip;
|
||||
|
||||
if (GuiContainerManager.shouldShowTooltip(gui) && currenttip.size() == 0) {
|
||||
int[] offset = RecipeInfo.getGuiOffset(gui);
|
||||
currenttip = TemplateRecipeHandler.transferRectTooltip(gui, guiMap.get(gui.getClass()), offset[0], offset[1], currenttip);
|
||||
currenttip = TemplateRecipeHandler.transferRectTooltip(
|
||||
gui, guiMap.get(gui.getClass()), offset[0], offset[1], currenttip);
|
||||
}
|
||||
return currenttip;
|
||||
}
|
||||
@@ -363,13 +347,13 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleItemTooltip(GuiContainer gui, ItemStack itemstack, int mousex, int mousey, List<String> currenttip) {
|
||||
public List<String> handleItemTooltip(
|
||||
GuiContainer gui, ItemStack itemstack, int mousex, int mousey, List<String> currenttip) {
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseDragged(GuiContainer gui, int mousex, int mousey, int button, long heldTime) {
|
||||
}
|
||||
public void onMouseDragged(GuiContainer gui, int mousex, int mousey, int button, long heldTime) {}
|
||||
}
|
||||
|
||||
static {
|
||||
@@ -400,9 +384,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
* Add all RecipeTransferRects to the transferRects list during this call.
|
||||
* Afterward they may be added to the input handler for the corresponding guis from getRecipeTransferRectGuis
|
||||
*/
|
||||
public void loadTransferRects() {
|
||||
|
||||
}
|
||||
public void loadTransferRects() {}
|
||||
|
||||
/**
|
||||
* In this function you need to fill up the empty recipe array with recipes.
|
||||
@@ -412,8 +394,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
* @param results Objects representing the results that matching recipes must produce.
|
||||
*/
|
||||
public void loadCraftingRecipes(String outputId, Object... results) {
|
||||
if (outputId.equals("item"))
|
||||
loadCraftingRecipes((ItemStack) results[0]);
|
||||
if (outputId.equals("item")) loadCraftingRecipes((ItemStack) results[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -431,8 +412,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
* @param ingredients Objects representing the ingredients that matching recipes must contain.
|
||||
*/
|
||||
public void loadUsageRecipes(String inputId, Object... ingredients) {
|
||||
if (inputId.equals("item"))
|
||||
loadUsageRecipes((ItemStack) ingredients[0]);
|
||||
if (inputId.equals("item")) loadUsageRecipes((ItemStack) ingredients[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -504,16 +484,16 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
int var = (int) (completion * (direction % 2 == 0 ? w : h));
|
||||
|
||||
switch (direction) {
|
||||
case 0://right
|
||||
case 0: // right
|
||||
drawTexturedModalRect(x, y, tx, ty, var, h);
|
||||
break;
|
||||
case 1://down
|
||||
case 1: // down
|
||||
drawTexturedModalRect(x, y, tx, ty, w, var);
|
||||
break;
|
||||
case 2://left
|
||||
case 2: // left
|
||||
drawTexturedModalRect(x + w - var, y, tx + w - var, ty, var, h);
|
||||
break;
|
||||
case 3://up
|
||||
case 3: // up
|
||||
drawTexturedModalRect(x, y + h - var, tx, ty + h - var, w, var);
|
||||
break;
|
||||
}
|
||||
@@ -541,9 +521,10 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
|
||||
public TemplateRecipeHandler newInstance() {
|
||||
try {
|
||||
// Use the non parallel version since we might already be using the forkJoinPool and might have no threads available
|
||||
// Use the non parallel version since we might already be using the forkJoinPool and might have no threads
|
||||
// available
|
||||
// This will ideally have been pre-cached elsewhere and will be a NOOP
|
||||
findFuelsOnce();
|
||||
findFuelsOnce();
|
||||
return getClass().newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -578,7 +559,9 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
NEIClientConfig.logger.info("failed to load catalyst handler, implement `loadTransferRects` for your handler " + handler.getClass().getName());
|
||||
NEIClientConfig.logger.info(
|
||||
"failed to load catalyst handler, implement `loadTransferRects` for your handler "
|
||||
+ handler.getClass().getName());
|
||||
}
|
||||
}
|
||||
return this.getUsageHandler(inputId, ingredients);
|
||||
@@ -622,18 +605,17 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
}
|
||||
|
||||
public void onUpdate() {
|
||||
if (!NEIClientUtils.shiftKey())
|
||||
cycleticks++;
|
||||
if (!NEIClientUtils.shiftKey()) cycleticks++;
|
||||
}
|
||||
|
||||
public boolean hasOverlay(GuiContainer gui, Container container, int recipe) {
|
||||
return RecipeInfo.hasDefaultOverlay(gui, getOverlayIdentifier()) || RecipeInfo.hasOverlayHandler(gui, getOverlayIdentifier());
|
||||
return RecipeInfo.hasDefaultOverlay(gui, getOverlayIdentifier())
|
||||
|| RecipeInfo.hasOverlayHandler(gui, getOverlayIdentifier());
|
||||
}
|
||||
|
||||
public IRecipeOverlayRenderer getOverlayRenderer(GuiContainer gui, int recipe) {
|
||||
IStackPositioner positioner = RecipeInfo.getStackPositioner(gui, getOverlayIdentifier());
|
||||
if (positioner == null)
|
||||
return null;
|
||||
if (positioner == null) return null;
|
||||
return new DefaultOverlayRenderer(getIngredientStacks(recipe), positioner);
|
||||
}
|
||||
|
||||
@@ -663,20 +645,16 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(GuiRecipe gui, char keyChar, int keyCode, int recipe) {
|
||||
if (keyCode == NEIClientConfig.getKeyBinding("gui.recipe"))
|
||||
return transferRect(gui, recipe, false);
|
||||
else if (keyCode == NEIClientConfig.getKeyBinding("gui.usage"))
|
||||
return transferRect(gui, recipe, true);
|
||||
if (keyCode == NEIClientConfig.getKeyBinding("gui.recipe")) return transferRect(gui, recipe, false);
|
||||
else if (keyCode == NEIClientConfig.getKeyBinding("gui.usage")) return transferRect(gui, recipe, true);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(GuiRecipe gui, int button, int recipe) {
|
||||
if (button == 0)
|
||||
return transferRect(gui, recipe, false);
|
||||
else if (button == 1)
|
||||
return transferRect(gui, recipe, true);
|
||||
if (button == 0) return transferRect(gui, recipe, false);
|
||||
else if (button == 1) return transferRect(gui, recipe, true);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -691,21 +669,26 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
return transferRect(gui, transferRects, offset.x, offset.y, usage);
|
||||
}
|
||||
|
||||
private static boolean transferRect(GuiContainer gui, Collection<RecipeTransferRect> transferRects, int offsetx, int offsety, boolean usage) {
|
||||
private static boolean transferRect(
|
||||
GuiContainer gui, Collection<RecipeTransferRect> transferRects, int offsetx, int offsety, boolean usage) {
|
||||
Point pos = getMousePosition();
|
||||
Point relMouse = new Point(pos.x - gui.guiLeft - offsetx, pos.y - gui.guiTop - offsety);
|
||||
for (RecipeTransferRect rect : transferRects) {
|
||||
if (rect.rect.contains(relMouse) &&
|
||||
(usage ?
|
||||
GuiUsageRecipe.openRecipeGui(rect.outputId, rect.results) :
|
||||
GuiCraftingRecipe.openRecipeGui(rect.outputId, rect.results)))
|
||||
return true;
|
||||
if (rect.rect.contains(relMouse)
|
||||
&& (usage
|
||||
? GuiUsageRecipe.openRecipeGui(rect.outputId, rect.results)
|
||||
: GuiCraftingRecipe.openRecipeGui(rect.outputId, rect.results))) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static List<String> transferRectTooltip(GuiContainer gui, Collection<RecipeTransferRect> transferRects, int offsetx, int offsety, List<String> currenttip) {
|
||||
private static List<String> transferRectTooltip(
|
||||
GuiContainer gui,
|
||||
Collection<RecipeTransferRect> transferRects,
|
||||
int offsetx,
|
||||
int offsety,
|
||||
List<String> currenttip) {
|
||||
Point pos = getMousePosition();
|
||||
Point relMouse = new Point(pos.x - gui.guiLeft - offsetx, pos.y - gui.guiTop - offsety);
|
||||
for (RecipeTransferRect rect : transferRects) {
|
||||
|
||||
@@ -9,11 +9,9 @@ import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
|
||||
public class DefaultStackStringifyHandler implements IStackStringifyHandler
|
||||
{
|
||||
public class DefaultStackStringifyHandler implements IStackStringifyHandler {
|
||||
|
||||
public NBTTagCompound convertItemStackToNBT(ItemStack stack, boolean saveStackSize)
|
||||
{
|
||||
public NBTTagCompound convertItemStackToNBT(ItemStack stack, boolean saveStackSize) {
|
||||
final String strId = Item.itemRegistry.getNameForObject(stack.getItem());
|
||||
|
||||
if (strId == null) {
|
||||
@@ -22,9 +20,9 @@ public class DefaultStackStringifyHandler implements IStackStringifyHandler
|
||||
|
||||
final NBTTagCompound nbTag = new NBTTagCompound();
|
||||
nbTag.setString("strId", strId);
|
||||
nbTag.setInteger("Count", Math.max(saveStackSize? stack.stackSize: 1, 1));
|
||||
nbTag.setShort("Damage", (short)stack.getItemDamage());
|
||||
|
||||
nbTag.setInteger("Count", Math.max(saveStackSize ? stack.stackSize : 1, 1));
|
||||
nbTag.setShort("Damage", (short) stack.getItemDamage());
|
||||
|
||||
if (stack.hasTagCompound()) {
|
||||
nbTag.setTag("tag", stack.getTagCompound());
|
||||
}
|
||||
@@ -32,12 +30,11 @@ public class DefaultStackStringifyHandler implements IStackStringifyHandler
|
||||
return nbTag;
|
||||
}
|
||||
|
||||
public ItemStack convertNBTToItemStack(NBTTagCompound nbtTag)
|
||||
{
|
||||
public ItemStack convertNBTToItemStack(NBTTagCompound nbtTag) {
|
||||
final String strId = nbtTag.getString("strId");
|
||||
|
||||
nbtTag = (NBTTagCompound)nbtTag.copy();
|
||||
nbtTag.setInteger("id", GameData.getItemRegistry().getId(strId)); //getObject
|
||||
nbtTag = (NBTTagCompound) nbtTag.copy();
|
||||
nbtTag.setInteger("id", GameData.getItemRegistry().getId(strId)); // getObject
|
||||
|
||||
final ItemStack stack = ItemStack.loadItemStackFromNBT(nbtTag);
|
||||
|
||||
@@ -48,8 +45,7 @@ public class DefaultStackStringifyHandler implements IStackStringifyHandler
|
||||
return stack;
|
||||
}
|
||||
|
||||
public FluidStack getFluid(ItemStack stack)
|
||||
{
|
||||
public FluidStack getFluid(ItemStack stack) {
|
||||
FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(stack);
|
||||
|
||||
if (fluidStack == null && stack.getItem() instanceof IFluidContainerItem) {
|
||||
@@ -58,5 +54,4 @@ public class DefaultStackStringifyHandler implements IStackStringifyHandler
|
||||
|
||||
return fluidStack;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +1,19 @@
|
||||
package codechicken.nei.recipe.stackinfo;
|
||||
|
||||
import codechicken.nei.api.IStackStringifyHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class GTFluidStackStringifyHandler implements IStackStringifyHandler
|
||||
{
|
||||
public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
|
||||
|
||||
public static Class GTDisplayFluid = null;
|
||||
public static Method getFluidDisplayStack = null;
|
||||
public static Method getFluidFromDisplayStack = null;
|
||||
|
||||
|
||||
static {
|
||||
try {
|
||||
final Class gtUtility = Class.forName("gregtech.api.util.GT_Utility");
|
||||
@@ -24,11 +22,12 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler
|
||||
getFluidFromDisplayStack = gtUtility.getMethod("getFluidFromDisplayStack", ItemStack.class);
|
||||
getFluidDisplayStack = gtUtility.getMethod("getFluidDisplayStack", FluidStack.class, boolean.class);
|
||||
|
||||
} catch (Exception ignored) { /*Do nothing*/ }
|
||||
} catch (Exception ignored) {
|
||||
/*Do nothing*/
|
||||
}
|
||||
}
|
||||
|
||||
public NBTTagCompound convertItemStackToNBT(ItemStack stack, boolean saveStackSize)
|
||||
{
|
||||
public NBTTagCompound convertItemStackToNBT(ItemStack stack, boolean saveStackSize) {
|
||||
|
||||
if (GTDisplayFluid != null && GTDisplayFluid.isInstance(stack.getItem())) {
|
||||
final FluidStack fluidStack = getFluid(stack);
|
||||
@@ -36,17 +35,15 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler
|
||||
if (fluidStack != null) {
|
||||
final NBTTagCompound nbTag = new NBTTagCompound();
|
||||
nbTag.setString("gtFluidName", fluidStack.getFluid().getName());
|
||||
nbTag.setInteger("Count", saveStackSize? fluidStack.amount: 1);
|
||||
nbTag.setInteger("Count", saveStackSize ? fluidStack.amount : 1);
|
||||
return nbTag;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack convertNBTToItemStack(NBTTagCompound nbtTag)
|
||||
{
|
||||
public ItemStack convertNBTToItemStack(NBTTagCompound nbtTag) {
|
||||
|
||||
if (getFluidDisplayStack != null && nbtTag.hasKey("gtFluidName")) {
|
||||
final String fluidName = nbtTag.getString("gtFluidName");
|
||||
@@ -60,28 +57,27 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler
|
||||
return (ItemStack) obj;
|
||||
}
|
||||
|
||||
} catch (Exception e) {}
|
||||
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public FluidStack getFluid(ItemStack stack)
|
||||
{
|
||||
public FluidStack getFluid(ItemStack stack) {
|
||||
|
||||
if (getFluidFromDisplayStack != null && GTDisplayFluid != null && GTDisplayFluid.isInstance(stack.getItem())) {
|
||||
try {
|
||||
final Object obj = getFluidFromDisplayStack.invoke(null, stack);
|
||||
|
||||
|
||||
if (obj != null) {
|
||||
return (FluidStack) obj;
|
||||
}
|
||||
|
||||
} catch (Exception e) {}
|
||||
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user