mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-08 19:04:46 +00:00
fix new issue with sawmill
This commit is contained in:
3 files changed
+228
No files matched your search
@@ -94,6 +94,7 @@ public class NEIMekanismConfig implements IConfigureNEI
|
||||
API.setGuiOffset(GuiSolarNeutronActivator.class, SolarNeutronRecipeHandler.xOffset, SolarNeutronRecipeHandler.yOffset);
|
||||
|
||||
GuiContainerManager.addSlotClickHandler(new MekanismSlotClickHandler());
|
||||
SawingFactoryRecipeHandler.register();
|
||||
|
||||
API.registerNEIGuiHandler(new ElementBoundHandler());
|
||||
|
||||
|
||||
@@ -2,9 +2,14 @@ package mekanism.client.nei;
|
||||
|
||||
import mekanism.client.gui.GuiPrecisionSawmill;
|
||||
import mekanism.client.gui.element.GuiProgress.ProgressBar;
|
||||
import mekanism.common.Tier.FactoryTier;
|
||||
import mekanism.common.base.IFactory.RecipeType;
|
||||
import mekanism.common.recipe.RecipeHandler.Recipe;
|
||||
import mekanism.common.recipe.machines.SawmillRecipe;
|
||||
import mekanism.common.util.LangUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.RecipeUtils;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -33,6 +38,61 @@ public class PrecisionSawmillRecipeHandler extends ChanceMachineRecipeHandler
|
||||
{
|
||||
return Recipe.PRECISION_SAWMILL.get().values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCraftingRecipes(ItemStack result)
|
||||
{
|
||||
if(isSawingFactory(result))
|
||||
{
|
||||
loadCraftingRecipes(getRecipeId());
|
||||
}
|
||||
else {
|
||||
super.loadCraftingRecipes(result);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUsageRecipes(ItemStack ingredient)
|
||||
{
|
||||
if(isSawingFactory(ingredient))
|
||||
{
|
||||
loadCraftingRecipes(getRecipeId());
|
||||
}
|
||||
else {
|
||||
super.loadUsageRecipes(ingredient);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUsageRecipes(String inputId, Object... ingredients)
|
||||
{
|
||||
if(inputId.equals(getRecipeId()))
|
||||
{
|
||||
loadCraftingRecipes(getRecipeId());
|
||||
}
|
||||
else {
|
||||
super.loadUsageRecipes(inputId, ingredients);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSawingFactory(ItemStack stack)
|
||||
{
|
||||
if(stack == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for(FactoryTier tier : FactoryTier.values())
|
||||
{
|
||||
ItemStack factory = MekanismUtils.getFactory(tier, RecipeType.SAWING);
|
||||
if(factory != null && RecipeUtils.areItemsEqualForCrafting(factory, stack))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressBar getProgressType()
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
package mekanism.client.nei;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.guihook.IContainerInputHandler;
|
||||
import codechicken.nei.guihook.IContainerTooltipHandler;
|
||||
import codechicken.nei.recipe.GuiCraftingRecipe;
|
||||
import codechicken.nei.recipe.GuiUsageRecipe;
|
||||
import mekanism.client.gui.GuiFactory;
|
||||
import mekanism.common.Tier.FactoryTier;
|
||||
import mekanism.common.base.IFactory.RecipeType;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Routes NEI recipe lookups from the progress indicators in a Sawing Factory
|
||||
* to the Precision Sawmill recipe handler.
|
||||
*/
|
||||
public class SawingFactoryRecipeHandler implements IContainerInputHandler, IContainerTooltipHandler
|
||||
{
|
||||
private static final String RECIPE_ID = "mekanism.precisionsawmill";
|
||||
|
||||
public static void register()
|
||||
{
|
||||
SawingFactoryRecipeHandler handler = new SawingFactoryRecipeHandler();
|
||||
GuiContainerManager.addInputHandler(handler);
|
||||
GuiContainerManager.addTooltipHandler(handler);
|
||||
}
|
||||
|
||||
private boolean handles(GuiContainer gui, int mouseX, int mouseY)
|
||||
{
|
||||
if(!(gui instanceof GuiFactory))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
GuiFactory factoryGui = (GuiFactory)gui;
|
||||
if(factoryGui.tileEntity.recipeType != RecipeType.SAWING)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int relativeX = mouseX - factoryGui.getXPos();
|
||||
int relativeY = mouseY - factoryGui.getYPos();
|
||||
if(relativeY < 33 || relativeY >= 53)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
FactoryTier tier = factoryGui.tileEntity.tier;
|
||||
int xOffset = tier == FactoryTier.BASIC ? 59 : tier == FactoryTier.ADVANCED ? 39 : tier == FactoryTier.ELITE ? 33 : 11;
|
||||
int xDistance = tier == FactoryTier.BASIC ? 38 : tier == FactoryTier.ADVANCED ? 26 : tier == FactoryTier.ELITE ? 19 : 18;
|
||||
|
||||
for(int process = 0; process < tier.processes; process++)
|
||||
{
|
||||
int progressX = xOffset + process*xDistance;
|
||||
if(relativeX >= progressX && relativeX < progressX + 8)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean openRecipes(GuiContainer gui, int mouseX, int mouseY, boolean usage)
|
||||
{
|
||||
if(!handles(gui, mouseX, mouseY))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return usage ? GuiUsageRecipe.openRecipeGui(RECIPE_ID) : GuiCraftingRecipe.openRecipeGui(RECIPE_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyCode)
|
||||
{
|
||||
Point mouse = GuiDraw.getMousePosition();
|
||||
if(keyCode == NEIClientConfig.getKeyBinding("gui.recipe"))
|
||||
{
|
||||
return openRecipes(gui, mouse.x, mouse.y, false);
|
||||
}
|
||||
else if(keyCode == NEIClientConfig.getKeyBinding("gui.usage"))
|
||||
{
|
||||
return openRecipes(gui, mouse.x, mouse.y, true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(GuiContainer gui, int mouseX, int mouseY, int button)
|
||||
{
|
||||
if(button == 0 || button == 1)
|
||||
{
|
||||
return openRecipes(gui, mouseX, mouseY, button == 1);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleTooltip(GuiContainer gui, int mouseX, int mouseY, List<String> currentTip)
|
||||
{
|
||||
if(handles(gui, mouseX, mouseY))
|
||||
{
|
||||
currentTip.add(NEIClientUtils.translate("recipe.tooltip"));
|
||||
}
|
||||
|
||||
return currentTip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(GuiContainer gui, char keyChar, int keyCode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyTyped(GuiContainer gui, char keyChar, int keyCode)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseClicked(GuiContainer gui, int mouseX, int mouseY, int button)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseUp(GuiContainer gui, int mouseX, int mouseY, int button)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(GuiContainer gui, int mouseX, int mouseY, int scrolled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleItemDisplayName(GuiContainer gui, ItemStack stack, List<String> currentTip)
|
||||
{
|
||||
return currentTip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleItemTooltip(GuiContainer gui, ItemStack stack, int mouseX, int mouseY, List<String> currentTip)
|
||||
{
|
||||
return currentTip;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user