Created
May 31, 2015 10:16
-
-
Save marchermans/3b37be8deab83baa6ec4 to your computer and use it in GitHub Desktop.
ArmoryNEIHandler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.Orion.Armory.Common.Compatibility.NEI; | |
import codechicken.nei.NEIServerUtils; | |
import codechicken.nei.PositionedStack; | |
import codechicken.nei.recipe.TemplateRecipeHandler; | |
import com.Orion.Armory.Client.GUI.GuiArmorsAnvilStandard; | |
import com.Orion.Armory.Common.Crafting.Anvil.AnvilRecipe; | |
import com.Orion.Armory.Common.Crafting.Anvil.IAnvilRecipeComponent; | |
import com.Orion.Armory.Common.Item.ItemHeatedItem; | |
import com.Orion.Armory.Common.Registry.GeneralRegistry; | |
import com.Orion.Armory.Common.TileEntity.TileEntityArmorsAnvil; | |
import com.Orion.Armory.Util.Client.Textures; | |
import com.Orion.Armory.Util.Client.TranslationKeys; | |
import com.Orion.Armory.Util.Core.ItemStackHelper; | |
import com.Orion.Armory.Util.References; | |
import net.minecraft.client.gui.inventory.GuiContainer; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.util.StatCollector; | |
import java.awt.*; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* Created by Orion | |
* Created on 29.05.2015 | |
* 17:59 | |
* <p/> | |
* Copyrighted according to Project specific license | |
*/ | |
public class ArmorsAnvilNEIHandler extends TemplateRecipeHandler { | |
public class CachedAnvilRecipe extends CachedRecipe { | |
PositionedStack iOutput; | |
ArrayList<PositionedStack> iInputs = new ArrayList<PositionedStack>(); | |
public CachedAnvilRecipe(AnvilRecipe pOriginalRecipe) { | |
ItemStack[] tCraftingInput = new ItemStack[TileEntityArmorsAnvil.MAX_CRAFTINGSLOTS]; | |
ItemStack[] tAdditionalCraftingInput = new ItemStack[TileEntityArmorsAnvil.MAX_ADDITIONALSLOTS]; | |
for (int tComponentIndex = 0; tComponentIndex < TileEntityArmorsAnvil.MAX_CRAFTINGSLOTS; tComponentIndex++) { | |
IAnvilRecipeComponent tComponent = pOriginalRecipe.getComponent(tComponentIndex); | |
if (tComponent == null) | |
continue; | |
int tXCoord = 14 + ((tComponentIndex % 5) * 18); | |
int tYCoord = 21 + ((tComponentIndex / 5) * 18); | |
ItemStack tComponentStack = tComponent.getComponentTargetStack(); | |
if (tComponentStack == null) | |
return; | |
iInputs.add(new PositionedStack(tComponentStack, tXCoord, tYCoord)); | |
tCraftingInput[tComponentIndex] = tComponent.getComponentTargetStack(); | |
} | |
if (pOriginalRecipe.iHammerUsage > 0) { | |
iInputs.add(new PositionedStack(new ItemStack(GeneralRegistry.Items.iHammer, 1, 150), 145, 22)); | |
} | |
if (pOriginalRecipe.iHammerUsage > 0) { | |
iInputs.add(new PositionedStack(new ItemStack(GeneralRegistry.Items.iTongs, 1, 150), 145, 94)); | |
} | |
for (int tComponentIndex = 0; tComponentIndex < TileEntityArmorsAnvil.MAX_ADDITIONALSLOTS; tComponentIndex++) { | |
IAnvilRecipeComponent tComponent = pOriginalRecipe.getAdditionalComponent(tComponentIndex); | |
if (tComponent == null) | |
continue; | |
int tXCoord = 185 + ((tComponentIndex % 3) * 18); | |
ItemStack tComponentStack = tComponent.getComponentTargetStack(); | |
if (tComponentStack == null) | |
return; | |
iInputs.add(new PositionedStack(tComponentStack, tXCoord, 22)); | |
tAdditionalCraftingInput[tComponentIndex] = tComponent.getComponentTargetStack(); | |
} | |
iOutput = new PositionedStack(pOriginalRecipe.getResult(tCraftingInput, tAdditionalCraftingInput), 145, 58); | |
} | |
@Override | |
public List<PositionedStack> getIngredients() { | |
return iInputs; | |
} | |
@Override | |
public PositionedStack getResult() { | |
return iOutput; | |
} | |
} | |
@Override | |
public void loadTransferRects() { | |
transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(149, 32, 16, 16), getRecipeID())); | |
} | |
@Override | |
public int recipiesPerPage() { | |
return 1; | |
} | |
public String getRecipeID() | |
{ | |
return References.General.MOD_ID + ":" + References.InternalNames.Blocks.ArmorsAnvil; | |
} | |
@Override | |
public Class<? extends GuiContainer> getGuiClass() { | |
return GuiArmorsAnvilStandard.class; | |
} | |
@Override | |
public String getGuiTexture() { | |
return Textures.Gui.Compatibility.NEI.ArmorsAnvil.GUI.getPrimaryLocation(); | |
} | |
@Override | |
public String getRecipeName() { | |
return StatCollector.translateToLocal(TranslationKeys.GUI.NEI.AnvilRecipeName); | |
} | |
@Override | |
public void loadCraftingRecipes(ItemStack result) { | |
for (AnvilRecipe tOriginalRecipe : TileEntityArmorsAnvil.getRecipes()) { | |
ItemStack[] tCraftingInput = new ItemStack[TileEntityArmorsAnvil.MAX_CRAFTINGSLOTS]; | |
ItemStack[] tAdditionalCraftingInput = new ItemStack[TileEntityArmorsAnvil.MAX_ADDITIONALSLOTS]; | |
for (int tComponentIndex = 0; tComponentIndex < TileEntityArmorsAnvil.MAX_CRAFTINGSLOTS; tComponentIndex++) { | |
IAnvilRecipeComponent tComponent = tOriginalRecipe.getComponent(tComponentIndex); | |
if (tComponent == null) | |
continue; | |
tCraftingInput[tComponentIndex] = tComponent.getComponentTargetStack(); | |
} | |
for (int tComponentIndex = 0; tComponentIndex < TileEntityArmorsAnvil.MAX_ADDITIONALSLOTS; tComponentIndex++) { | |
IAnvilRecipeComponent tComponent = tOriginalRecipe.getAdditionalComponent(tComponentIndex); | |
if (tComponent == null) | |
continue; | |
tAdditionalCraftingInput[tComponentIndex] = tComponent.getComponentTargetStack(); | |
} | |
if (tOriginalRecipe.getResult(tCraftingInput, tAdditionalCraftingInput).getItem() instanceof ItemHeatedItem) | |
{ | |
if (ItemHeatedItem.areStacksEqualExceptTemp(tOriginalRecipe.getResult(tCraftingInput, tAdditionalCraftingInput), result)) | |
{ | |
arecipes.add(new CachedAnvilRecipe(tOriginalRecipe)); | |
return; | |
} | |
} | |
else | |
{ | |
if (ItemStackHelper.equalsIgnoreStackSize(tOriginalRecipe.getResult(tCraftingInput, tAdditionalCraftingInput), result)) | |
{ | |
arecipes.add(new CachedAnvilRecipe(tOriginalRecipe)); | |
return; | |
} | |
} | |
} | |
} | |
@Override | |
public void loadCraftingRecipes(String outputId, Object... results) { | |
if (outputId.equals(getRecipeID())) { | |
for (AnvilRecipe recipe : TileEntityArmorsAnvil.getRecipes()) { | |
arecipes.add(new CachedAnvilRecipe(recipe)); | |
} | |
} else { | |
super.loadCraftingRecipes(outputId, results); | |
} | |
} | |
@Override | |
public void loadUsageRecipes(ItemStack pIngredient) | |
{ | |
for (AnvilRecipe tOriginalRecipe : TileEntityArmorsAnvil.getRecipes()) | |
{ | |
validateUsageRecipe(tOriginalRecipe, pIngredient); | |
} | |
} | |
private void validateUsageRecipe(AnvilRecipe pOriginalRecipe, ItemStack pIngredient) | |
{ | |
for (int tComponentIndex = 0; tComponentIndex < TileEntityArmorsAnvil.MAX_CRAFTINGSLOTS; tComponentIndex++) { | |
IAnvilRecipeComponent tComponent = pOriginalRecipe.getComponent(tComponentIndex); | |
if (tComponent == null) | |
continue; | |
ItemStack tComponentStack = tComponent.getComponentTargetStack(); | |
if (tComponentStack.getItem() instanceof ItemHeatedItem) | |
{ | |
if (ItemHeatedItem.areStacksEqualExceptTemp(tComponent.getComponentTargetStack(), pIngredient)) | |
{ | |
arecipes.add(new CachedAnvilRecipe(pOriginalRecipe)); | |
return; | |
} | |
} | |
else | |
{ | |
if (ItemStackHelper.equalsIgnoreStackSize(tComponent.getComponentTargetStack(), pIngredient)) | |
{ | |
arecipes.add(new CachedAnvilRecipe(pOriginalRecipe)); | |
return; | |
} | |
} | |
} | |
for (int tComponentIndex = 0; tComponentIndex < TileEntityArmorsAnvil.MAX_ADDITIONALSLOTS; tComponentIndex++) { | |
IAnvilRecipeComponent tComponent = pOriginalRecipe.getAdditionalComponent(tComponentIndex); | |
if (tComponent == null) | |
continue; | |
if (ItemStackHelper.equalsIgnoreStackSize(tComponent.getComponentTargetStack(), pIngredient)) | |
{ | |
arecipes.add(new CachedAnvilRecipe(pOriginalRecipe)); | |
return; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment