Merge pull request #2491 from mikkerlo/master

Add NEI overlay functionality so recipe on anvil can be selected via NEI.
This commit is contained in:
HbmMods 2025-10-23 12:03:42 +02:00 committed by GitHub
commit d6f957f975
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 185 additions and 101 deletions

View File

@ -0,0 +1,37 @@
package com.hbm.handler.nei;
import com.hbm.inventory.gui.GUIAnvil;
import com.hbm.inventory.recipes.anvil.AnvilRecipes.AnvilConstructionRecipe;
import codechicken.nei.api.IOverlayHandler;
import codechicken.nei.recipe.IRecipeHandler;
import net.minecraft.client.gui.inventory.GuiContainer;
/**
* Links NEI overlay interactions with the {@link GUIAnvil} so selecting a recipe focuses the anvil view.
*/
public class AnvilOverlayHandler implements IOverlayHandler {
/**
* {@inheritDoc}
*
* <p>When the NEI overlay is opened for the Nuclear Tech anvil, the GUI is instructed to focus the selected recipe.</p>
* <p>It will not craft the recepie. Only select it.</p>
*
* @param firstGui the GUI currently displaying the overlay
* @param recipe the NEI recipe handler backing the overlay
* @param recipeIndex index of the recipe within the handler
* @param maxTransfer whether NEI is performing a maximal transfer (ignored)
*/
@Override
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean maxTransfer) {
if(!(firstGui instanceof GUIAnvil) || !(recipe instanceof AnvilRecipeHandler)) {
return;
}
AnvilConstructionRecipe construction = ((AnvilRecipeHandler) recipe).getConstructionRecipe(recipeIndex);
if(construction != null) {
((GUIAnvil) firstGui).focusRecipe(construction);
}
}
}

View File

@ -50,20 +50,25 @@ public class AnvilRecipeHandler extends TemplateRecipeHandler implements ICompat
return "ntmAnvil"; return "ntmAnvil";
} }
@Override
public String getOverlayIdentifier() {
return "ntmAnvil";
}
public LinkedList<RecipeTransferRect> transferRectsRec = new LinkedList<RecipeTransferRect>(); public LinkedList<RecipeTransferRect> transferRectsRec = new LinkedList<RecipeTransferRect>();
public LinkedList<RecipeTransferRect> transferRectsGui = new LinkedList<RecipeTransferRect>(); public LinkedList<RecipeTransferRect> transferRectsGui = new LinkedList<RecipeTransferRect>();
public LinkedList<Class<? extends GuiContainer>> guiRec = new LinkedList<Class<? extends GuiContainer>>(); public LinkedList<Class<? extends GuiContainer>> guiRec = new LinkedList<Class<? extends GuiContainer>>();
public LinkedList<Class<? extends GuiContainer>> guiGui = new LinkedList<Class<? extends GuiContainer>>(); public LinkedList<Class<? extends GuiContainer>> guiGui = new LinkedList<Class<? extends GuiContainer>>();
public class RecipeSet extends TemplateRecipeHandler.CachedRecipe { public class RecipeSet extends TemplateRecipeHandler.CachedRecipe {
List<PositionedStack> input = new ArrayList(); List<PositionedStack> input = new ArrayList();
List<PositionedStack> output = new ArrayList(); List<PositionedStack> output = new ArrayList();
PositionedStack anvil; PositionedStack anvil;
int tier; int tier;
final AnvilConstructionRecipe recipe;
OverlayType shape; OverlayType shape;
public RecipeSet(List<Object> in, List<Object> out, int tier) { public RecipeSet(List<Object> in, List<Object> out, int tier, AnvilConstructionRecipe recipe) {
//not the prettiest of solutions but certainly the most pleasant to work with //not the prettiest of solutions but certainly the most pleasant to work with
int inLine = 1; int inLine = 1;
@ -74,7 +79,7 @@ public class AnvilRecipeHandler extends TemplateRecipeHandler implements ICompat
int outOY = 0; int outOY = 0;
int anvX = 0; int anvX = 0;
int anvY = 31; int anvY = 31;
if(in.size() == 1 && out.size() == 1) { if(in.size() == 1 && out.size() == 1) {
shape = OverlayType.SMITHING; shape = OverlayType.SMITHING;
inOX = 48; inOX = 48;
@ -108,18 +113,19 @@ public class AnvilRecipeHandler extends TemplateRecipeHandler implements ICompat
outOY = 6; outOY = 6;
anvX = 75; anvX = 75;
} }
for(int i = 0; i < in.size(); i++) { for(int i = 0; i < in.size(); i++) {
this.input.add(new PositionedStack(in.get(i), inOX + 18 * (i % inLine), inOY + 18 * (i / inLine))); this.input.add(new PositionedStack(in.get(i), inOX + 18 * (i % inLine), inOY + 18 * (i / inLine)));
} }
for(int i = 0; i < out.size(); i++) { for(int i = 0; i < out.size(); i++) {
this.output.add(new PositionedStack(out.get(i), outOX + 18 * (i % outLine), outOY + 18 * (i / outLine))); this.output.add(new PositionedStack(out.get(i), outOX + 18 * (i % outLine), outOY + 18 * (i / outLine)));
} }
this.anvil = new PositionedStack(NTMAnvil.getAnvilsFromTier(tier), anvX, anvY); this.anvil = new PositionedStack(NTMAnvil.getAnvilsFromTier(tier), anvX, anvY);
this.tier = tier; this.tier = tier;
this.recipe = recipe;
} }
@Override @Override
@ -148,10 +154,10 @@ public class AnvilRecipeHandler extends TemplateRecipeHandler implements ICompat
@Override @Override
public void loadCraftingRecipes(String outputId, Object... results) { public void loadCraftingRecipes(String outputId, Object... results) {
if(outputId.equals("ntmAnvil")) { if(outputId.equals("ntmAnvil")) {
List<AnvilConstructionRecipe> recipes = AnvilRecipes.getConstruction(); List<AnvilConstructionRecipe> recipes = AnvilRecipes.getConstruction();
for(AnvilConstructionRecipe recipe : recipes) { for(AnvilConstructionRecipe recipe : recipes) {
this.addRecipeToList(recipe); this.addRecipeToList(recipe);
} }
@ -164,9 +170,9 @@ public class AnvilRecipeHandler extends TemplateRecipeHandler implements ICompat
public void loadCraftingRecipes(ItemStack result) { public void loadCraftingRecipes(ItemStack result) {
List<AnvilConstructionRecipe> recipes = AnvilRecipes.getConstruction(); List<AnvilConstructionRecipe> recipes = AnvilRecipes.getConstruction();
for(AnvilConstructionRecipe recipe : recipes) { for(AnvilConstructionRecipe recipe : recipes) {
for(AnvilOutput out : recipe.output) { for(AnvilOutput out : recipe.output) {
if(NEIServerUtils.areStacksSameTypeCrafting(out.stack, result)) { if(NEIServerUtils.areStacksSameTypeCrafting(out.stack, result)) {
this.addRecipeToList(recipe); this.addRecipeToList(recipe);
@ -178,7 +184,7 @@ public class AnvilRecipeHandler extends TemplateRecipeHandler implements ICompat
@Override @Override
public void loadUsageRecipes(String inputId, Object... ingredients) { public void loadUsageRecipes(String inputId, Object... ingredients) {
if(inputId.equals("ntmAnvil")) { if(inputId.equals("ntmAnvil")) {
loadCraftingRecipes("ntmAnvil", new Object[0]); loadCraftingRecipes("ntmAnvil", new Object[0]);
} else { } else {
@ -190,12 +196,12 @@ public class AnvilRecipeHandler extends TemplateRecipeHandler implements ICompat
public void loadUsageRecipes(ItemStack ingredient) { public void loadUsageRecipes(ItemStack ingredient) {
List<AnvilConstructionRecipe> recipes = AnvilRecipes.getConstruction(); List<AnvilConstructionRecipe> recipes = AnvilRecipes.getConstruction();
for(AnvilConstructionRecipe recipe : recipes) { for(AnvilConstructionRecipe recipe : recipes) {
outer: outer:
for(AStack in : recipe.input) { for(AStack in : recipe.input) {
List<ItemStack> stacks = in.extractForNEI(); List<ItemStack> stacks = in.extractForNEI();
for(ItemStack stack : stacks) { for(ItemStack stack : stacks) {
if(NEIServerUtils.areStacksSameTypeCrafting(stack, ingredient)) { if(NEIServerUtils.areStacksSameTypeCrafting(stack, ingredient)) {
@ -206,38 +212,38 @@ public class AnvilRecipeHandler extends TemplateRecipeHandler implements ICompat
} }
} }
} }
private void addRecipeToList(AnvilConstructionRecipe recipe) { private void addRecipeToList(AnvilConstructionRecipe recipe) {
List<Object> ins = new ArrayList(); List<Object> ins = new ArrayList();
for(AStack input : recipe.input) { for(AStack input : recipe.input) {
ins.add(input.extractForNEI()); ins.add(input.extractForNEI());
} }
List<Object> outs = new ArrayList(); List<Object> outs = new ArrayList();
for(AnvilOutput output : recipe.output) { for(AnvilOutput output : recipe.output) {
ItemStack stack = output.stack.copy(); ItemStack stack = output.stack.copy();
if(output.chance != 1) { if(output.chance != 1) {
ItemStackUtil.addTooltipToStack(stack, EnumChatFormatting.RED + "" + (((int)(output.chance * 1000)) / 10D) + "%"); ItemStackUtil.addTooltipToStack(stack, EnumChatFormatting.RED + "" + (((int)(output.chance * 1000)) / 10D) + "%");
} }
outs.add(stack); outs.add(stack);
} }
this.arecipes.add(new RecipeSet(ins, outs, recipe.tierLower)); this.arecipes.add(new RecipeSet(ins, outs, recipe.tierLower, recipe));
} }
@Override @Override
public void loadTransferRects() { public void loadTransferRects() {
//hey asshole, stop nulling my fucking lists //hey asshole, stop nulling my fucking lists
transferRectsGui = new LinkedList<RecipeTransferRect>(); transferRectsGui = new LinkedList<RecipeTransferRect>();
guiGui = new LinkedList<Class<? extends GuiContainer>>(); guiGui = new LinkedList<Class<? extends GuiContainer>>();
transferRectsGui.add(new RecipeTransferRect(new Rectangle(11, 42, 36, 18), "ntmAnvil")); transferRectsGui.add(new RecipeTransferRect(new Rectangle(11, 42, 36, 18), "ntmAnvil"));
transferRectsGui.add(new RecipeTransferRect(new Rectangle(65, 42, 36, 18), "ntmAnvil")); transferRectsGui.add(new RecipeTransferRect(new Rectangle(65, 42, 36, 18), "ntmAnvil"));
guiGui.add(GUIAnvil.class); guiGui.add(GUIAnvil.class);
RecipeTransferRectHandler.registerRectsToGuis(guiGui, transferRectsGui); RecipeTransferRectHandler.registerRectsToGuis(guiGui, transferRectsGui);
} }
@ -247,12 +253,26 @@ public class AnvilRecipeHandler extends TemplateRecipeHandler implements ICompat
return RefStrings.MODID + ":textures/gui/nei/gui_nei_anvil.png"; return RefStrings.MODID + ":textures/gui/nei/gui_nei_anvil.png";
} }
/**
* Resolves the underlying anvil recipe for the NEI recipe index.
*
* @param index recipe index supplied by NEI
* @return the construction recipe or {@code null} if the index is out of bounds
*/
public AnvilConstructionRecipe getConstructionRecipe(int index) {
if(index < 0 || index >= this.arecipes.size()) {
return null;
}
return ((RecipeSet) this.arecipes.get(index)).recipe;
}
@Override @Override
public void drawBackground(int recipe) { public void drawBackground(int recipe) {
super.drawBackground(recipe); super.drawBackground(recipe);
RecipeSet set = (RecipeSet) this.arecipes.get(recipe); RecipeSet set = (RecipeSet) this.arecipes.get(recipe);
switch(set.shape) { switch(set.shape) {
case NONE: case NONE:
drawTexturedModalRect(2, 5, 5, 87, 72, 54); //in drawTexturedModalRect(2, 5, 5, 87, 72, 54); //in

View File

@ -37,7 +37,7 @@ import net.minecraftforge.oredict.OreDictionary;
public class GUIAnvil extends GuiContainer { public class GUIAnvil extends GuiContainer {
public static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/processing/gui_anvil.png"); public static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/processing/gui_anvil.png");
private int tier; private int tier;
private List<AnvilConstructionRecipe> originList = new ArrayList(); private List<AnvilConstructionRecipe> originList = new ArrayList();
private List<AnvilConstructionRecipe> recipes = new ArrayList(); private List<AnvilConstructionRecipe> recipes = new ArrayList();
@ -59,13 +59,13 @@ public class GUIAnvil extends GuiContainer {
if(recipe.isTierValid(this.tier)) if(recipe.isTierValid(this.tier))
this.originList.add(recipe); this.originList.add(recipe);
} }
regenerateRecipes(); regenerateRecipes();
guiLeft = (this.width - this.xSize) / 2; guiLeft = (this.width - this.xSize) / 2;
guiTop = (this.height - this.ySize) / 2; guiTop = (this.height - this.ySize) / 2;
} }
@Override @Override
public void initGui() { public void initGui() {
@ -78,28 +78,52 @@ public class GUIAnvil extends GuiContainer {
this.search.setEnableBackgroundDrawing(false); this.search.setEnableBackgroundDrawing(false);
this.search.setMaxStringLength(25); this.search.setMaxStringLength(25);
} }
/**
* Requests the GUI to focus on the supplied recipe. Used by the NEI overlay handler when a recipe is selected externally.
*
* @param target the recipe instance to focus, may be {@code null}
*/
public void focusRecipe(AnvilConstructionRecipe target) {
if(target == null) {
return;
}
if (!this.originList.contains(target)) {
return;
}
search.setText("");
regenerateRecipes();
int pos = this.recipes.indexOf(target);
if(pos < 0) {
return;
}
this.selection = pos;
this.index = MathHelper.clamp_int(pos / 2, 0, this.size);
}
private void regenerateRecipes() { private void regenerateRecipes() {
this.recipes.clear(); this.recipes.clear();
this.recipes.addAll(this.originList); this.recipes.addAll(this.originList);
resetPaging(); resetPaging();
} }
private void search(String search) { private void search(String search) {
search = search.toLowerCase(Locale.US); search = search.toLowerCase(Locale.US);
this.recipes.clear(); this.recipes.clear();
if(search.isEmpty()) { if(search.isEmpty()) {
this.recipes.addAll(this.originList); this.recipes.addAll(this.originList);
} else { } else {
for(AnvilConstructionRecipe recipe : this.originList) { for(AnvilConstructionRecipe recipe : this.originList) {
List<String> list = recipeToSearchList(recipe); List<String> list = recipeToSearchList(recipe);
for(String s : list) { for(String s : list) {
if(s.contains(search)) { if(s.contains(search)) {
this.recipes.add(recipe); this.recipes.add(recipe);
@ -108,24 +132,24 @@ public class GUIAnvil extends GuiContainer {
} }
} }
} }
resetPaging(); resetPaging();
} }
private void resetPaging() { private void resetPaging() {
this.index = 0; this.index = 0;
this.selection = -1; this.selection = -1;
this.size = Math.max(0, (int)Math.ceil((this.recipes.size() - 10) / 2D)); this.size = Math.max(0, (int)Math.ceil((this.recipes.size() - 10) / 2D));
} }
@Override @Override
public void drawScreen(int x, int y, float interp) { public void drawScreen(int x, int y, float interp) {
super.drawScreen(x, y, interp); super.drawScreen(x, y, interp);
for(Object obj : this.inventorySlots.inventorySlots) { for(Object obj : this.inventorySlots.inventorySlots) {
Slot slot = (Slot) obj; Slot slot = (Slot) obj;
// if the mouse is over a slot, cancel // if the mouse is over a slot, cancel
if(this.func_146978_c(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, x, y) && slot.getHasStack()) { if(this.func_146978_c(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, x, y) && slot.getHasStack()) {
return; return;
@ -135,13 +159,13 @@ public class GUIAnvil extends GuiContainer {
if(guiLeft <= x && guiLeft + xSize > x && guiTop < y && guiTop + ySize >= y && getSlotAtPosition(x, y) == null) { if(guiLeft <= x && guiLeft + xSize > x && guiTop < y && guiTop + ySize >= y && getSlotAtPosition(x, y) == null) {
if(!Mouse.isButtonDown(0) && !Mouse.isButtonDown(1) && Mouse.next()) { if(!Mouse.isButtonDown(0) && !Mouse.isButtonDown(1) && Mouse.next()) {
int scroll = Mouse.getEventDWheel(); int scroll = Mouse.getEventDWheel();
if(scroll > 0 && this.index > 0) this.index--; if(scroll > 0 && this.index > 0) this.index--;
if(scroll < 0 && this.index < this.size) this.index++; if(scroll < 0 && this.index < this.size) this.index++;
} }
} }
} }
private Slot getSlotAtPosition(int x, int y) { private Slot getSlotAtPosition(int x, int y) {
for(int k = 0; k < this.inventorySlots.inventorySlots.size(); ++k) { for(int k = 0; k < this.inventorySlots.inventorySlots.size(); ++k) {
Slot slot = (Slot) this.inventorySlots.inventorySlots.get(k); Slot slot = (Slot) this.inventorySlots.inventorySlots.get(k);
@ -153,91 +177,91 @@ public class GUIAnvil extends GuiContainer {
return null; return null;
} }
private boolean isMouseOverSlot(Slot slot, int x, int y) { private boolean isMouseOverSlot(Slot slot, int x, int y) {
return this.func_146978_c(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, x, y); return this.func_146978_c(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, x, y);
} }
@Override @Override
protected void mouseClicked(int x, int y, int k) { protected void mouseClicked(int x, int y, int k) {
super.mouseClicked(x, y, k); super.mouseClicked(x, y, k);
this.search.mouseClicked(x, y, k); this.search.mouseClicked(x, y, k);
if(guiLeft + 7 <= x && guiLeft + 7 + 9 > x && guiTop + 71 < y && guiTop + 71 + 36 >= y) { if(guiLeft + 7 <= x && guiLeft + 7 + 9 > x && guiTop + 71 < y && guiTop + 71 + 36 >= y) {
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
if(this.index > 0) if(this.index > 0)
this.index--; this.index--;
return; return;
} }
if(guiLeft + 106 <= x && guiLeft + 106 + 9 > x && guiTop + 71 < y && guiTop + 71 + 36 >= y) { if(guiLeft + 106 <= x && guiLeft + 106 + 9 > x && guiTop + 71 < y && guiTop + 71 + 36 >= y) {
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
if(this.index < this.size) if(this.index < this.size)
this.index++; this.index++;
return; return;
} }
if(guiLeft + 52 <= x && guiLeft + 52 + 18 > x && guiTop + 53 < y && guiTop + 53 + 18 >= y) { if(guiLeft + 52 <= x && guiLeft + 52 + 18 > x && guiTop + 53 < y && guiTop + 53 + 18 >= y) {
if(this.selection == -1) if(this.selection == -1)
return; return;
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
PacketDispatcher.wrapper.sendToServer(new AnvilCraftPacket(this.recipes.get(this.selection), Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) ? 1 : 0)); PacketDispatcher.wrapper.sendToServer(new AnvilCraftPacket(this.recipes.get(this.selection), Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) ? 1 : 0));
return; return;
} }
/*if(guiLeft + 97 <= x && guiLeft + 97 + 18 > x && guiTop + 107 < y && guiTop + 107 + 18 >= y) { /*if(guiLeft + 97 <= x && guiLeft + 97 + 18 > x && guiTop + 107 < y && guiTop + 107 + 18 >= y) {
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
search(this.search.getText()); search(this.search.getText());
return; return;
}*/ }*/
for(int i = index * 2; i < index * 2 + 10; i++) { for(int i = index * 2; i < index * 2 + 10; i++) {
if(i >= this.recipes.size()) if(i >= this.recipes.size())
break; break;
int ind = i - index * 2; int ind = i - index * 2;
int ix = 16 + 18 * (ind / 2); int ix = 16 + 18 * (ind / 2);
int iy = 71 + 18 * (ind % 2); int iy = 71 + 18 * (ind % 2);
if(guiLeft + ix <= x && guiLeft + ix + 18 > x && guiTop + iy < y && guiTop + iy + 18 >= y) { if(guiLeft + ix <= x && guiLeft + ix + 18 > x && guiTop + iy < y && guiTop + iy + 18 >= y) {
if(this.selection != i) if(this.selection != i)
this.selection = i; this.selection = i;
else else
this.selection = -1; this.selection = -1;
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
return; return;
} }
} }
} }
@Override @Override
protected void drawGuiContainerForegroundLayer(int mX, int mY) { protected void drawGuiContainerForegroundLayer(int mX, int mY) {
String name = I18n.format("container.anvil", tier); String name = I18n.format("container.anvil", tier);
this.fontRendererObj.drawString(name, 61 - this.fontRendererObj.getStringWidth(name) / 2, 8, 4210752); this.fontRendererObj.drawString(name, 61 - this.fontRendererObj.getStringWidth(name) / 2, 8, 4210752);
this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752); this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
if(this.selection >= 0) { if(this.selection >= 0) {
AnvilConstructionRecipe recipe = recipes.get(this.selection); AnvilConstructionRecipe recipe = recipes.get(this.selection);
List<String> list = recipeToList(recipe, playerInventory); List<String> list = recipeToList(recipe, playerInventory);
int longest = 0; int longest = 0;
for(String s : list) { for(String s : list) {
int length = this.fontRendererObj.getStringWidth(s); int length = this.fontRendererObj.getStringWidth(s);
if(length > longest) if(length > longest)
longest = length; longest = length;
} }
double scale = 0.5D; double scale = 0.5D;
GL11.glScaled(scale, scale, scale); GL11.glScaled(scale, scale, scale);
int offset = 0; int offset = 0;
@ -245,15 +269,15 @@ public class GUIAnvil extends GuiContainer {
this.fontRendererObj.drawString(s, 260, 50 + offset, 0xffffff); this.fontRendererObj.drawString(s, 260, 50 + offset, 0xffffff);
offset += 9; offset += 9;
} }
this.lastSize = (int)(longest * scale); this.lastSize = (int)(longest * scale);
GL11.glScaled(1D/scale, 1D/scale, 1D/scale); GL11.glScaled(1D/scale, 1D/scale, 1D/scale);
} else { } else {
this.lastSize = 0; this.lastSize = 0;
} }
} }
/** /**
* Generates the neat structured list for showing ingredients * Generates the neat structured list for showing ingredients
* @param recipe * @param recipe
@ -323,7 +347,7 @@ public class GUIAnvil extends GuiContainer {
return list; return list;
} }
/** /**
* Generates a simple, unstructured list of inputs (and all ore dict variants) and outputs for searching * Generates a simple, unstructured list of inputs (and all ore dict variants) and outputs for searching
* @param recipe * @param recipe
@ -332,16 +356,16 @@ public class GUIAnvil extends GuiContainer {
public List<String> recipeToSearchList(AnvilConstructionRecipe recipe) { public List<String> recipeToSearchList(AnvilConstructionRecipe recipe) {
List<String> list = new ArrayList(); List<String> list = new ArrayList();
for(AStack stack : recipe.input) { for(AStack stack : recipe.input) {
if(stack instanceof ComparableStack) { if(stack instanceof ComparableStack) {
ItemStack input = ((ComparableStack) stack).toStack(); ItemStack input = ((ComparableStack) stack).toStack();
try { list.add(input.getDisplayName().toLowerCase(Locale.US)); } catch(Exception ex) { list.add("I AM ERROR"); } try { list.add(input.getDisplayName().toLowerCase(Locale.US)); } catch(Exception ex) { list.add("I AM ERROR"); }
} else if(stack instanceof OreDictStack) { } else if(stack instanceof OreDictStack) {
OreDictStack input = (OreDictStack) stack; OreDictStack input = (OreDictStack) stack;
ArrayList<ItemStack> ores = OreDictionary.getOres(input.name); ArrayList<ItemStack> ores = OreDictionary.getOres(input.name);
if(ores.size() > 0) { if(ores.size() > 0) {
for(ItemStack ore : ores) { for(ItemStack ore : ores) {
try { list.add(ore.getDisplayName().toLowerCase(Locale.US)); } catch(Exception ex) { list.add("I AM ERROR"); } try { list.add(ore.getDisplayName().toLowerCase(Locale.US)); } catch(Exception ex) { list.add("I AM ERROR"); }
@ -349,44 +373,44 @@ public class GUIAnvil extends GuiContainer {
} }
} }
} }
for(AnvilOutput stack : recipe.output) { for(AnvilOutput stack : recipe.output) {
list.add(stack.stack.getDisplayName().toLowerCase(Locale.US)); list.add(stack.stack.getDisplayName().toLowerCase(Locale.US));
} }
return list; return list;
} }
int lastSize = 1; int lastSize = 1;
@Override @Override
protected void drawGuiContainerBackgroundLayer(float inter, int mX, int mY) { protected void drawGuiContainerBackgroundLayer(float inter, int mX, int mY) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(texture); this.mc.getTextureManager().bindTexture(texture);
this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, this.xSize, this.ySize); this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, this.xSize, this.ySize);
int slide = MathHelper.clamp_int(this.lastSize - 42, 0, 1000); int slide = MathHelper.clamp_int(this.lastSize - 42, 0, 1000);
int mul = 1; int mul = 1;
while(true) { while(true) {
if(slide >= 51 * mul) { if(slide >= 51 * mul) {
this.drawTexturedModalRect(guiLeft + 125 + 51 * mul, guiTop + 17, 125, 17, 54, 108); this.drawTexturedModalRect(guiLeft + 125 + 51 * mul, guiTop + 17, 125, 17, 54, 108);
mul++; mul++;
} else { } else {
break; break;
} }
} }
this.drawTexturedModalRect(guiLeft + 125 + slide, guiTop + 17, 125, 17, 54, 108); this.drawTexturedModalRect(guiLeft + 125 + slide, guiTop + 17, 125, 17, 54, 108);
if(this.search.isFocused()) { if(this.search.isFocused()) {
drawTexturedModalRect(guiLeft + 8, guiTop + 108, 168, 222, 88, 16); drawTexturedModalRect(guiLeft + 8, guiTop + 108, 168, 222, 88, 16);
} }
if(guiLeft + 7 <= mX && guiLeft + 7 + 9 > mX && guiTop + 71 < mY && guiTop + 71 + 36 >= mY) { if(guiLeft + 7 <= mX && guiLeft + 7 + 9 > mX && guiTop + 71 < mY && guiTop + 71 + 36 >= mY) {
drawTexturedModalRect(guiLeft + 7, guiTop + 71, 176, 186, 9, 36); drawTexturedModalRect(guiLeft + 7, guiTop + 71, 176, 186, 9, 36);
} }
@ -399,25 +423,25 @@ public class GUIAnvil extends GuiContainer {
/*if(guiLeft + 97 <= mX && guiLeft + 97 + 18 > mX && guiTop + 107 < mY && guiTop + 107 + 18 >= mY) { /*if(guiLeft + 97 <= mX && guiLeft + 97 + 18 > mX && guiTop + 107 < mY && guiTop + 107 + 18 >= mY) {
drawTexturedModalRect(guiLeft + 97, guiTop + 107, 176, 168, 18, 18); drawTexturedModalRect(guiLeft + 97, guiTop + 107, 176, 168, 18, 18);
}*/ }*/
for(int i = index * 2; i < index * 2 + 10; i++) { for(int i = index * 2; i < index * 2 + 10; i++) {
if(i >= recipes.size()) if(i >= recipes.size())
break; break;
int ind = i - index * 2; int ind = i - index * 2;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
RenderHelper.enableGUIStandardItemLighting(); RenderHelper.enableGUIStandardItemLighting();
GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glEnable(GL12.GL_RESCALE_NORMAL);
AnvilConstructionRecipe recipe = recipes.get(i); AnvilConstructionRecipe recipe = recipes.get(i);
ItemStack display = recipe.getDisplay(); ItemStack display = recipe.getDisplay();
FontRenderer font = null; FontRenderer font = null;
if (display != null) font = display.getItem().getFontRenderer(display); if (display != null) font = display.getItem().getFontRenderer(display);
if (font == null) font = fontRendererObj; if (font == null) font = fontRendererObj;
itemRender.zLevel = 100.0F; itemRender.zLevel = 100.0F;
itemRender.renderItemAndEffectIntoGUI(font, this.mc.getTextureManager(), recipe.getDisplay(), guiLeft + 17 + 18 * (ind / 2), guiTop + 72 + 18 * (ind % 2)); itemRender.renderItemAndEffectIntoGUI(font, this.mc.getTextureManager(), recipe.getDisplay(), guiLeft + 17 + 18 * (ind / 2), guiTop + 72 + 18 * (ind % 2));
itemRender.zLevel = 0.0F; itemRender.zLevel = 0.0F;
@ -427,17 +451,17 @@ public class GUIAnvil extends GuiContainer {
this.mc.getTextureManager().bindTexture(texture); this.mc.getTextureManager().bindTexture(texture);
this.zLevel = 300.0F; this.zLevel = 300.0F;
this.drawTexturedModalRect(guiLeft + 16 + 18 * (ind / 2), guiTop + 71 + 18 * (ind % 2), 18 + 18 * recipe.getOverlay().ordinal(), 222, 18, 18); this.drawTexturedModalRect(guiLeft + 16 + 18 * (ind / 2), guiTop + 71 + 18 * (ind % 2), 18 + 18 * recipe.getOverlay().ordinal(), 222, 18, 18);
if(selection == i) if(selection == i)
this.drawTexturedModalRect(guiLeft + 16 + 18 * (ind / 2), guiTop + 71 + 18 * (ind % 2), 0, 222, 18, 18); this.drawTexturedModalRect(guiLeft + 16 + 18 * (ind / 2), guiTop + 71 + 18 * (ind % 2), 0, 222, 18, 18);
} }
this.search.drawTextBox(); this.search.drawTextBox();
} }
@Override @Override
protected void keyTyped(char c, int key) { protected void keyTyped(char c, int key) {
if(this.search.textboxKeyTyped(c, key)) { if(this.search.textboxKeyTyped(c, key)) {
search(this.search.getText()); search(this.search.getText());
} else { } else {

View File

@ -9,8 +9,10 @@ import com.hbm.blocks.ModBlocks;
import com.hbm.blocks.generic.BlockPlushie.TileEntityPlushie; import com.hbm.blocks.generic.BlockPlushie.TileEntityPlushie;
import com.hbm.config.ClientConfig; import com.hbm.config.ClientConfig;
import com.hbm.config.CustomMachineConfigJSON; import com.hbm.config.CustomMachineConfigJSON;
import com.hbm.handler.nei.AnvilOverlayHandler;
import com.hbm.handler.nei.CustomMachineHandler; import com.hbm.handler.nei.CustomMachineHandler;
import com.hbm.items.ItemEnums.EnumIngotMetal; import com.hbm.items.ItemEnums.EnumIngotMetal;
import com.hbm.inventory.gui.GUIAnvil;
import com.hbm.items.ItemEnums.EnumSecretType; import com.hbm.items.ItemEnums.EnumSecretType;
import com.hbm.items.ModItems; import com.hbm.items.ModItems;
import com.hbm.items.machine.ItemBattery; import com.hbm.items.machine.ItemBattery;
@ -33,6 +35,7 @@ public class NEIConfig implements IConfigureNEI {
for (TemplateRecipeHandler handler: NEIRegistry.listAllHandlers()) { for (TemplateRecipeHandler handler: NEIRegistry.listAllHandlers()) {
registerHandler(handler); registerHandler(handler);
} }
API.registerGuiOverlayHandler(GUIAnvil.class, new AnvilOverlayHandler(), "ntmAnvil");
for(CustomMachineConfigJSON.MachineConfiguration conf : CustomMachineConfigJSON.niceList) { for(CustomMachineConfigJSON.MachineConfiguration conf : CustomMachineConfigJSON.niceList) {
registerHandlerBypass(new CustomMachineHandler(conf)); registerHandlerBypass(new CustomMachineHandler(conf));
@ -43,7 +46,7 @@ public class NEIConfig implements IConfigureNEI {
for(int i = 0; i < EnumAmmoSecret.values().length; i++) API.hideItem(new ItemStack(ModItems.ammo_secret, 1, i)); for(int i = 0; i < EnumAmmoSecret.values().length; i++) API.hideItem(new ItemStack(ModItems.ammo_secret, 1, i));
for(int i = 0; i < EnumSecretType.values().length; i++) API.hideItem(new ItemStack(ModItems.item_secret, 1, i)); for(int i = 0; i < EnumSecretType.values().length; i++) API.hideItem(new ItemStack(ModItems.item_secret, 1, i));
} }
for(int i = 0; i < EnumIngotMetal.values().length; i++) API.hideItem(new ItemStack(ModItems.ingot_metal, 1, i)); for(int i = 0; i < EnumIngotMetal.values().length; i++) API.hideItem(new ItemStack(ModItems.ingot_metal, 1, i));
//Some things are even beyond my control...or are they? //Some things are even beyond my control...or are they?