2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2014-04-04 07:17:20 +02:00
|
|
|
package appeng.integration.modules;
|
2014-02-15 07:40:02 +01:00
|
|
|
|
2014-11-28 04:36:46 +01:00
|
|
|
|
2014-05-01 06:01:22 +02:00
|
|
|
import java.lang.reflect.Constructor;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
2014-02-15 07:40:02 +01:00
|
|
|
import java.lang.reflect.Method;
|
2014-07-15 05:30:32 +02:00
|
|
|
import java.util.List;
|
2014-02-15 07:40:02 +01:00
|
|
|
|
2014-05-01 06:01:22 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.FontRenderer;
|
2014-07-15 05:30:32 +02:00
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
2014-05-01 06:01:22 +02:00
|
|
|
import net.minecraft.client.renderer.entity.RenderItem;
|
|
|
|
import net.minecraft.inventory.Slot;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-11-28 04:36:46 +01:00
|
|
|
|
|
|
|
import codechicken.nei.api.IStackPositioner;
|
|
|
|
import codechicken.nei.guihook.GuiContainerManager;
|
|
|
|
import codechicken.nei.guihook.IContainerTooltipHandler;
|
|
|
|
|
2014-07-15 05:30:32 +02:00
|
|
|
import appeng.client.gui.AEBaseMEGui;
|
2014-05-01 06:01:22 +02:00
|
|
|
import appeng.client.gui.implementations.GuiCraftingTerm;
|
2014-07-06 08:52:29 +02:00
|
|
|
import appeng.client.gui.implementations.GuiPatternTerm;
|
2014-08-14 03:26:41 +02:00
|
|
|
import appeng.core.AEConfig;
|
|
|
|
import appeng.core.features.AEFeature;
|
2015-05-08 22:53:50 +02:00
|
|
|
import appeng.helpers.Reflected;
|
2015-09-25 23:28:57 +02:00
|
|
|
import appeng.integration.IIntegrationModule;
|
2015-08-06 16:01:56 +02:00
|
|
|
import appeng.integration.IntegrationHelper;
|
2014-05-01 06:01:22 +02:00
|
|
|
import appeng.integration.abstraction.INEI;
|
2014-05-11 18:27:32 +02:00
|
|
|
import appeng.integration.modules.NEIHelpers.NEIAEShapedRecipeHandler;
|
|
|
|
import appeng.integration.modules.NEIHelpers.NEIAEShapelessRecipeHandler;
|
|
|
|
import appeng.integration.modules.NEIHelpers.NEICraftingHandler;
|
2014-08-14 03:26:41 +02:00
|
|
|
import appeng.integration.modules.NEIHelpers.NEIFacadeRecipeHandler;
|
2014-05-11 18:27:32 +02:00
|
|
|
import appeng.integration.modules.NEIHelpers.NEIGrinderRecipeHandler;
|
|
|
|
import appeng.integration.modules.NEIHelpers.NEIInscriberRecipeHandler;
|
|
|
|
import appeng.integration.modules.NEIHelpers.NEIWorldCraftingHandler;
|
2014-07-10 05:18:50 +02:00
|
|
|
import appeng.integration.modules.NEIHelpers.TerminalCraftingSlotFinder;
|
2014-02-15 07:40:02 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-09-25 23:28:57 +02:00
|
|
|
public class NEI implements INEI, IContainerTooltipHandler, IIntegrationModule
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2015-05-08 22:53:50 +02:00
|
|
|
@Reflected
|
2014-02-15 07:40:02 +01:00
|
|
|
public static NEI instance;
|
|
|
|
|
2015-05-08 22:53:50 +02:00
|
|
|
private final Class<?> apiClass;
|
2014-04-06 10:20:30 +02:00
|
|
|
|
2014-05-01 06:01:22 +02:00
|
|
|
// recipe handler...
|
2015-08-06 16:01:56 +02:00
|
|
|
private Method registerRecipeHandler;
|
|
|
|
private Method registerUsageHandler;
|
2014-05-01 06:01:22 +02:00
|
|
|
|
2015-05-08 22:53:50 +02:00
|
|
|
@Reflected
|
2015-04-03 08:54:31 +02:00
|
|
|
public NEI() throws ClassNotFoundException
|
|
|
|
{
|
2015-08-06 16:01:56 +02:00
|
|
|
IntegrationHelper.testClassExistence( this, codechicken.nei.api.API.class );
|
|
|
|
IntegrationHelper.testClassExistence( this, codechicken.nei.api.IStackPositioner.class );
|
|
|
|
IntegrationHelper.testClassExistence( this, codechicken.nei.guihook.GuiContainerManager.class );
|
|
|
|
IntegrationHelper.testClassExistence( this, codechicken.nei.guihook.IContainerTooltipHandler.class );
|
|
|
|
IntegrationHelper.testClassExistence( this, codechicken.nei.recipe.ICraftingHandler.class );
|
|
|
|
IntegrationHelper.testClassExistence( this, codechicken.nei.recipe.IUsageHandler.class );
|
|
|
|
|
2015-05-08 22:53:50 +02:00
|
|
|
this.apiClass = Class.forName( "codechicken.nei.api.API" );
|
2014-04-06 10:20:30 +02:00
|
|
|
}
|
|
|
|
|
2014-02-15 07:40:02 +01:00
|
|
|
@Override
|
2014-12-19 19:01:51 +01:00
|
|
|
public void init() throws Throwable
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
2015-05-08 22:53:50 +02:00
|
|
|
this.registerRecipeHandler = this.apiClass.getDeclaredMethod( "registerRecipeHandler", codechicken.nei.recipe.ICraftingHandler.class );
|
|
|
|
this.registerUsageHandler = this.apiClass.getDeclaredMethod( "registerUsageHandler", codechicken.nei.recipe.IUsageHandler.class );
|
2014-05-01 06:01:22 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.registerRecipeHandler( new NEIAEShapedRecipeHandler() );
|
|
|
|
this.registerRecipeHandler( new NEIAEShapelessRecipeHandler() );
|
|
|
|
this.registerRecipeHandler( new NEIInscriberRecipeHandler() );
|
|
|
|
this.registerRecipeHandler( new NEIWorldCraftingHandler() );
|
|
|
|
this.registerRecipeHandler( new NEIGrinderRecipeHandler() );
|
2014-05-01 06:01:22 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( AEConfig.instance.isFeatureEnabled( AEFeature.Facades ) && AEConfig.instance.isFeatureEnabled( AEFeature.enableFacadeCrafting ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.registerRecipeHandler( new NEIFacadeRecipeHandler() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-14 03:26:41 +02:00
|
|
|
|
2014-07-15 05:30:32 +02:00
|
|
|
// large stack tooltips
|
|
|
|
GuiContainerManager.addTooltipHandler( this );
|
|
|
|
|
2014-05-01 06:01:22 +02:00
|
|
|
// crafting terminal...
|
2015-09-25 23:10:56 +02:00
|
|
|
final Method registerGuiOverlay = this.apiClass.getDeclaredMethod( "registerGuiOverlay", Class.class, String.class, IStackPositioner.class );
|
|
|
|
final Class overlayHandler = Class.forName( "codechicken.nei.api.IOverlayHandler" );
|
2014-05-01 06:01:22 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final Method registrar = this.apiClass.getDeclaredMethod( "registerGuiOverlayHandler", Class.class, overlayHandler, String.class );
|
2015-05-08 22:53:50 +02:00
|
|
|
registerGuiOverlay.invoke( this.apiClass, GuiCraftingTerm.class, "crafting", new TerminalCraftingSlotFinder() );
|
|
|
|
registerGuiOverlay.invoke( this.apiClass, GuiPatternTerm.class, "crafting", new TerminalCraftingSlotFinder() );
|
2014-05-01 06:01:22 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final Class<NEICraftingHandler> defaultHandler = NEICraftingHandler.class;
|
|
|
|
final Constructor defaultConstructor = defaultHandler.getConstructor( int.class, int.class );
|
2015-05-08 23:34:24 +02:00
|
|
|
registrar.invoke( this.apiClass, GuiCraftingTerm.class, defaultConstructor.newInstance( 6, 75 ), "crafting" );
|
|
|
|
registrar.invoke( this.apiClass, GuiPatternTerm.class, defaultConstructor.newInstance( 6, 75 ), "crafting" );
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
public void registerRecipeHandler( final Object o ) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-05-08 22:53:50 +02:00
|
|
|
this.registerRecipeHandler.invoke( this.apiClass, o );
|
|
|
|
this.registerUsageHandler.invoke( this.apiClass, o );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
2014-02-15 07:40:02 +01:00
|
|
|
@Override
|
2014-12-19 19:01:51 +01:00
|
|
|
public void postInit()
|
2014-02-15 07:40:02 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-01 06:01:22 +02:00
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void drawSlot( final Slot s )
|
2014-05-01 06:01:22 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( s == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-05-01 06:01:22 +02:00
|
|
|
return;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-05-01 06:01:22 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final ItemStack stack = s.getStack();
|
2014-05-01 06:01:22 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( stack == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-05-01 06:01:22 +02:00
|
|
|
return;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-05-01 06:01:22 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final Minecraft mc = Minecraft.getMinecraft();
|
|
|
|
final FontRenderer fontRenderer = mc.fontRenderer;
|
|
|
|
final int x = s.xDisplayPosition;
|
|
|
|
final int y = s.yDisplayPosition;
|
2014-05-01 06:01:22 +02:00
|
|
|
|
|
|
|
GuiContainerManager.drawItems.renderItemAndEffectIntoGUI( fontRenderer, mc.getTextureManager(), stack, x, y );
|
2014-11-28 04:36:46 +01:00
|
|
|
GuiContainerManager.drawItems.renderItemOverlayIntoGUI( fontRenderer, mc.getTextureManager(), stack, x, y, String.valueOf( stack.stackSize ) );
|
2014-05-01 06:01:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public RenderItem setItemRender( final RenderItem renderItem )
|
2014-05-01 06:01:22 +02:00
|
|
|
{
|
2014-05-19 04:36:08 +02:00
|
|
|
try
|
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final RenderItem ri = GuiContainerManager.drawItems;
|
2014-09-28 11:47:17 +02:00
|
|
|
GuiContainerManager.drawItems = renderItem;
|
2014-05-19 04:36:08 +02:00
|
|
|
return ri;
|
|
|
|
}
|
2015-09-25 23:10:56 +02:00
|
|
|
catch( final Throwable t )
|
2014-05-19 04:36:08 +02:00
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalStateException( "Invalid version of NEI, please update", t );
|
2014-05-19 04:36:08 +02:00
|
|
|
}
|
2014-05-01 06:01:22 +02:00
|
|
|
}
|
|
|
|
|
2014-07-15 05:30:32 +02:00
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public List<String> handleTooltip( final GuiContainer arg0, final int arg1, final int arg2, final List<String> current )
|
2014-07-15 05:30:32 +02:00
|
|
|
{
|
|
|
|
return current;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public List<String> handleItemDisplayName( final GuiContainer arg0, final ItemStack arg1, final List<String> current )
|
2014-07-15 05:30:32 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return current;
|
2014-07-15 05:30:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public List<String> handleItemTooltip( final GuiContainer guiScreen, final ItemStack stack, final int mouseX, final int mouseY, final List<String> currentToolTip )
|
2014-07-15 05:30:32 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( guiScreen instanceof AEBaseMEGui )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return ( (AEBaseMEGui) guiScreen ).handleItemTooltip( stack, mouseX, mouseY, currentToolTip );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-15 05:30:32 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
return currentToolTip;
|
|
|
|
}
|
2014-02-15 07:40:02 +01:00
|
|
|
}
|