Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
fix balky nei handlers (#102)
Browse files Browse the repository at this point in the history
* fix balky nei handlers

also cleaned up NEI plugin a bit. ore handler still looks dumb though.

* add some comment to explain the magic numbers

Former-commit-id: 1e864adcda4c39b78921280c723c540f196dd382
  • Loading branch information
Glease authored Mar 7, 2022
1 parent 95960bf commit 0e31ff7
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@
import gregtech.nei.GT_NEI_DefaultHandler;
import net.minecraft.item.ItemStack;

import java.awt.*;

public class BW_NEI_BioLabHandler extends GT_NEI_DefaultHandler {
public BW_NEI_BioLabHandler(GT_Recipe.GT_Recipe_Map aRecipeMap) {
super(aRecipeMap);
this.transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(65, 13, 36, 18), this.getOverlayIdentifier()));
if (!NEI_BW_Config.sIsAdded) {
FMLInterModComms.sendRuntimeMessage(GT_Values.GT, "NEIPlugins", "register-crafting-handler", "gregtech@" + this.getRecipeName() + "@" + this.getOverlayIdentifier());
GuiCraftingRecipe.craftinghandlers.add(this);
Expand All @@ -50,37 +47,23 @@ public TemplateRecipeHandler newInstance() {
}

public void loadCraftingRecipes(ItemStack aResult) {
if (aResult != null && aResult.getItem() instanceof LabParts && aResult.getItemDamage() < 3) {
for (GT_Recipe recipe : this.getSortedRecipes()) {
if (aResult.getTagCompound() != null && recipe != null)
for (int i = 0; i < recipe.mOutputs.length; i++) {
if (recipe.mOutputs[i] != null)
if (aResult.getTagCompound().equals(recipe.mOutputs[i].getTagCompound())) {
this.arecipes.add(new CachedDefaultRecipe(recipe));
break;
}

}
}
} else
if (aResult != null && aResult.getItem() instanceof LabParts && aResult.getItemDamage() < 3 && aResult.getTagCompound() != null) {
for (CachedDefaultRecipe recipe : getCache())
if (NEI_BW_Config.checkRecipe(aResult, recipe.mOutputs))
arecipes.add(recipe);
} else {
super.loadCraftingRecipes(aResult);
}
}

@Override
public void loadUsageRecipes(ItemStack aResult) {
if (aResult != null && aResult.getItem() instanceof LabParts && aResult.getItemDamage() < 3) {
for (GT_Recipe recipe : this.getSortedRecipes()) {
if (aResult.getTagCompound() != null && recipe != null)
for (int i = 0; i < recipe.mInputs.length; i++) {
if (recipe.mInputs[i] != null)
if (aResult.getTagCompound().equals(recipe.mInputs[i].getTagCompound())) {
this.arecipes.add(new CachedDefaultRecipe(recipe));
break;
}

}
}
} else
super.loadCraftingRecipes(aResult);
if (aResult != null && aResult.getItem() instanceof LabParts && aResult.getItemDamage() < 3 && aResult.getTagCompound() != null) {
for (CachedDefaultRecipe recipe : getCache())
if (NEI_BW_Config.checkRecipe(aResult, recipe.mInputs))
arecipes.add(recipe);
} else {
super.loadUsageRecipes(aResult);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package com.github.bartimaeusnek.bartworks.neiHandler;

import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.GuiCraftingRecipe;
import codechicken.nei.recipe.GuiUsageRecipe;
import codechicken.nei.recipe.TemplateRecipeHandler;
Expand All @@ -37,6 +38,7 @@
import net.minecraft.util.StatCollector;

import java.awt.*;
import java.util.Collections;

public class BW_NEI_BioVatHandler extends GT_NEI_DefaultHandler {

Expand Down Expand Up @@ -107,23 +109,33 @@ public void drawExtras(int aRecipeIndex) {

}

private void loadLabPartRecipes(ItemStack aResult) {
for (CachedDefaultRecipe recipe : getCache()) {
// dirty way of finding the special slot item
// see constructor of CachedDefaultRecipe on why relx==120 and rely==52 means special slot
for (PositionedStack stack : recipe.mInputs) {
if (stack.relx == 120 && stack.rely == 52) {
if (NEI_BW_Config.checkRecipe(aResult, Collections.singletonList(stack)))
arecipes.add(recipe);
}
}
}
}

@Override
public void loadUsageRecipes(ItemStack aResult) {
if (aResult != null && aResult.getItem() instanceof LabParts && aResult.getItemDamage() < 3)
for (GT_Recipe recipe : this.getSortedRecipes()) {
if (aResult.getTagCompound() != null && recipe != null)
if (recipe.mSpecialItems instanceof ItemStack && ((ItemStack) recipe.mSpecialItems).getItem() instanceof LabParts)
if (aResult.getTagCompound().equals(((ItemStack) recipe.mSpecialItems).getTagCompound())) {
this.arecipes.add(new CachedDefaultRecipe(recipe));
}
}
else
super.loadCraftingRecipes(aResult);
if (aResult != null && aResult.getItem() instanceof LabParts && aResult.getItemDamage() < 3 && aResult.getTagCompound() != null) {
loadLabPartRecipes(aResult);
} else {
super.loadUsageRecipes(aResult);
}
}

@Override
public void loadCraftingRecipes(ItemStack aResult) {
if (aResult == null || !(aResult.getItem() instanceof LabParts && aResult.getItemDamage() < 3)) {
if (aResult != null && aResult.getItem() instanceof LabParts && aResult.getItemDamage() < 3 && aResult.getTagCompound() != null) {
loadLabPartRecipes(aResult);
} else {
super.loadCraftingRecipes(aResult);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public BW_NEI_OreHandler() {
if (!NEI_BW_Config.sIsAdded) {
FMLInterModComms.sendRuntimeMessage(MainMod.MOD_ID, "NEIPlugins", "register-crafting-handler", MainMod.MOD_ID + "@" + this.getRecipeName() + "@" + this.getOverlayIdentifier());
GuiCraftingRecipe.craftinghandlers.add(this);
// GuiUsageRecipe.usagehandlers.add(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,69 @@

package com.github.bartimaeusnek.bartworks.neiHandler;

import codechicken.nei.PositionedStack;
import codechicken.nei.api.API;
import codechicken.nei.api.IConfigureNEI;
import com.github.bartimaeusnek.bartworks.MainMod;
import com.github.bartimaeusnek.bartworks.common.loaders.FluidLoader;
import com.github.bartimaeusnek.bartworks.common.loaders.ItemRegistry;
import com.github.bartimaeusnek.bartworks.system.material.WerkstoffLoader;
import com.github.bartimaeusnek.bartworks.util.BWRecipes;
import cpw.mods.fml.common.Optional;
import gregtech.api.enums.OrePrefixes;
import net.minecraft.item.ItemStack;

@Optional.Interface(iface = "codechicken.nei.api.API", modid = "NotEnoughItems")
public class NEI_BW_Config implements IConfigureNEI {

public static boolean sIsAdded = true;
static boolean sIsAdded = true;

static boolean checkRecipe(ItemStack labPart, Iterable<? extends PositionedStack> stacks) {
for (PositionedStack stack : stacks) {
for (ItemStack item : stack.items) {
if (labPart.getTagCompound().equals(item.getTagCompound())) {
return true;
}
}
}
return false;
}

@Override
public void loadConfig() {
API.hideItem(new ItemStack(ItemRegistry.TAB));
API.hideItem(new ItemStack(FluidLoader.bioFluidBlock));
API.hideItem(new ItemStack(ItemRegistry.bw_fake_glasses));
ItemStack[] prefixesToHide = {
WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustTiny, WerkstoffLoader.Bismutite).copy(),
WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustSmall, WerkstoffLoader.Bismutite).copy(),
WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.crushed, WerkstoffLoader.Bismutite).copy(),
WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.crushedPurified, WerkstoffLoader.Bismutite).copy(),
WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.crushedCentrifuged, WerkstoffLoader.Bismutite).copy(),
WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.nugget, WerkstoffLoader.Bismutite).copy(),
WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemChipped, WerkstoffLoader.Bismutite).copy(),
WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemFlawed, WerkstoffLoader.Bismutite).copy(),
WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemFlawless, WerkstoffLoader.Bismutite).copy(),
WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemExquisite, WerkstoffLoader.Bismutite).copy(),
WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustImpure, WerkstoffLoader.Bismutite).copy(),
WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustPure, WerkstoffLoader.Bismutite).copy(),
};
for (ItemStack stack : prefixesToHide) {
stack.setItemDamage(Short.MAX_VALUE);
API.hideItem(stack);
}
NEI_BW_Config.sIsAdded = false;
new BW_NEI_OreHandler();
new BW_NEI_BioVatHandler(BWRecipes.instance.getMappingsFor(BWRecipes.BACTERIALVATBYTE));
new BW_NEI_BioLabHandler(BWRecipes.instance.getMappingsFor(BWRecipes.BIOLABBYTE));
NEI_BW_Config.sIsAdded = true;
}

@Optional.Method(modid = "NotEnoughItems")
@Override
public String getName() {
return "BartWorks NEI Plugin";
}

@Optional.Method(modid = "NotEnoughItems")
@Override
public String getVersion() {
return MainMod.APIVERSION;
}
}
}

This file was deleted.

0 comments on commit 0e31ff7

Please sign in to comment.