Fixed issue with NEI and font size.
Added Crafting Terminal Integration for NEI. Added Inscriber Recipe Plugin for NEI.
This commit is contained in:
parent
c904033567
commit
4a2c7c2710
|
@ -44,10 +44,12 @@ import appeng.container.slot.SlotOutput;
|
|||
import appeng.container.slot.SlotRestrictedInput;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketInventoryAction;
|
||||
import appeng.core.sync.packets.PacketSwapSlots;
|
||||
import appeng.helpers.InventoryAction;
|
||||
import appeng.integration.abstraction.INEI;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||
|
||||
|
@ -560,6 +562,22 @@ public abstract class AEBaseGui extends GuiContainer
|
|||
return builder.toString();
|
||||
}
|
||||
|
||||
boolean useNEI = false;
|
||||
|
||||
private RenderItem setItemRender(RenderItem aeri2)
|
||||
{
|
||||
if ( AppEng.instance.isIntegrationEnabled( "NEI" ) )
|
||||
{
|
||||
return ((INEI) AppEng.instance.getIntegration( "NEI" )).setItemRender( aeri2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderItem ri = itemRender;
|
||||
itemRender = aeri2;
|
||||
return ri;
|
||||
}
|
||||
}
|
||||
|
||||
private void safeDrawSlot(Slot s)
|
||||
{
|
||||
try
|
||||
|
@ -597,8 +615,7 @@ public abstract class AEBaseGui extends GuiContainer
|
|||
{
|
||||
if ( s instanceof SlotME )
|
||||
{
|
||||
RenderItem pIR = itemRender;
|
||||
itemRender = aeri;
|
||||
RenderItem pIR = setItemRender( aeri );
|
||||
try
|
||||
{
|
||||
this.zLevel = 100.0F;
|
||||
|
@ -627,7 +644,7 @@ public abstract class AEBaseGui extends GuiContainer
|
|||
if ( Platform.isDrawing( Tessellator.instance ) )
|
||||
Tessellator.instance.draw();
|
||||
}
|
||||
itemRender = pIR;
|
||||
setItemRender( pIR );
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -65,6 +65,11 @@ public abstract class AEBaseContainer extends Container
|
|||
|
||||
int ticksSinceCheck = 900;
|
||||
|
||||
public BaseActionSource getSource()
|
||||
{
|
||||
return mySrc;
|
||||
}
|
||||
|
||||
public void verifyPermissions(SecurityPermissions security, boolean requirePower)
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
|
|
|
@ -22,7 +22,7 @@ public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAE
|
|||
SlotCraftingMatrix craftingSlots[] = new SlotCraftingMatrix[9];
|
||||
SlotCraftingTerm outputSlot;
|
||||
|
||||
PartCraftingTerminal ct;
|
||||
public PartCraftingTerminal ct;
|
||||
|
||||
/**
|
||||
* Callback for when the crafting matrix is changed.
|
||||
|
|
|
@ -62,6 +62,11 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
|
|||
public IConfigManagerHost gui;
|
||||
private IGridNode networkNode;
|
||||
|
||||
public IGridNode getNetworkNode()
|
||||
{
|
||||
return networkNode;
|
||||
}
|
||||
|
||||
protected ContainerMEMonitorable(InventoryPlayer ip, ITerminalHost montiorable, boolean bindInventory) {
|
||||
super( ip, montiorable instanceof TileEntity ? (TileEntity) montiorable : null, montiorable instanceof IPart ? (IPart) montiorable : null );
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public enum GuiText
|
|||
|
||||
METunnel, ItemTunnel, RedstoneTunnel, MJTunnel, EUTunnel, FluidTunnel, StoredSize,
|
||||
|
||||
StoredPower, MaxPower, RequiredPower, Efficiency;
|
||||
StoredPower, MaxPower, RequiredPower, Efficiency, InWorldCrafting, inWorldFluix, inWorldPurification, inWorldSingularity;
|
||||
|
||||
String root;
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import appeng.core.sync.packets.PacketMEInventoryUpdate;
|
|||
import appeng.core.sync.packets.PacketMatterCannon;
|
||||
import appeng.core.sync.packets.PacketMockExplosion;
|
||||
import appeng.core.sync.packets.PacketMultiPart;
|
||||
import appeng.core.sync.packets.PacketNEIRecipe;
|
||||
import appeng.core.sync.packets.PacketNewStorageDimension;
|
||||
import appeng.core.sync.packets.PacketPartPlacement;
|
||||
import appeng.core.sync.packets.PacketProgressBar;
|
||||
|
@ -64,7 +65,9 @@ public class AppEngPacketHandlerBase
|
|||
|
||||
PACKET_SWITCH_GUIS(PacketSwitchGuis.class),
|
||||
|
||||
PACKET_SWAP_SLOTS(PacketSwapSlots.class);
|
||||
PACKET_SWAP_SLOTS(PacketSwapSlots.class),
|
||||
|
||||
PACKET_RECIPE_NEI(PacketNEIRecipe.class);
|
||||
|
||||
final public Class pc;
|
||||
final public Constructor con;
|
||||
|
|
149
core/sync/packets/PacketNEIRecipe.java
Normal file
149
core/sync/packets/PacketNEIRecipe.java
Normal file
|
@ -0,0 +1,149 @@
|
|||
package appeng.core.sync.packets;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.security.ISecurityGrid;
|
||||
import appeng.api.networking.storage.IStorageGrid;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.container.ContainerNull;
|
||||
import appeng.container.implementations.ContainerCraftingTerm;
|
||||
import appeng.core.sync.AppEngPacket;
|
||||
import appeng.core.sync.network.INetworkInfo;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class PacketNEIRecipe extends AppEngPacket
|
||||
{
|
||||
|
||||
ItemStack[] recipe;
|
||||
|
||||
// automatic.
|
||||
public PacketNEIRecipe(ByteBuf stream) throws IOException {
|
||||
ByteArrayInputStream bytes = new ByteArrayInputStream( stream.array() );
|
||||
bytes.skip( stream.readerIndex() );
|
||||
NBTTagCompound comp = CompressedStreamTools.readCompressed( bytes );
|
||||
if ( comp != null )
|
||||
{
|
||||
recipe = new ItemStack[9];
|
||||
for (int x = 0; x < recipe.length; x++)
|
||||
{
|
||||
recipe[x] = ItemStack.loadItemStackFromNBT( comp.getCompoundTag( "#" + x ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
|
||||
{
|
||||
EntityPlayerMP pmp = (EntityPlayerMP) player;
|
||||
Container con = pmp.openContainer;
|
||||
|
||||
if ( con != null && con instanceof ContainerCraftingTerm )
|
||||
{
|
||||
ContainerCraftingTerm cct = (ContainerCraftingTerm) con;
|
||||
IGridNode node = cct.getNetworkNode();
|
||||
if ( node != null )
|
||||
{
|
||||
IGrid grid = node.getGrid();
|
||||
if ( grid == null )
|
||||
return;
|
||||
|
||||
IStorageGrid inv = grid.getCache( IStorageGrid.class );
|
||||
IEnergyGrid energy = grid.getCache( IEnergyGrid.class );
|
||||
ISecurityGrid security = grid.getCache( ISecurityGrid.class );
|
||||
IInventory craftMatrix = cct.ct.getInventoryByName( "crafting" );
|
||||
|
||||
if ( inv != null && recipe != null && security != null )
|
||||
{
|
||||
InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||
for (int x = 0; x < 9; x++)
|
||||
ic.setInventorySlotContents( x, recipe[x] );
|
||||
|
||||
IRecipe r = Platform.findMatchingRecipe( ic, pmp.worldObj );
|
||||
|
||||
if ( r != null && security.hasPermission( player, SecurityPermissions.EXTRACT ) )
|
||||
{
|
||||
ItemStack is = r.getCraftingResult( ic );
|
||||
|
||||
if ( is != null )
|
||||
{
|
||||
IMEMonitor<IAEItemStack> stor = inv.getItemInventory();
|
||||
IItemList all = stor.getStorageList();
|
||||
|
||||
for (int x = 0; x < craftMatrix.getSizeInventory(); x++)
|
||||
{
|
||||
ItemStack PatternItem = ic.getStackInSlot( x );
|
||||
|
||||
ItemStack currentItem = craftMatrix.getStackInSlot( x );
|
||||
if ( currentItem != null )
|
||||
{
|
||||
ic.setInventorySlotContents( x, currentItem );
|
||||
ItemStack newis = r.matches( ic, pmp.worldObj ) ? r.getCraftingResult( ic ) : null;
|
||||
ic.setInventorySlotContents( x, PatternItem );
|
||||
|
||||
if ( newis == null || !Platform.isSameItemPrecise( newis, is ) )
|
||||
{
|
||||
IAEItemStack in = AEItemStack.create( currentItem );
|
||||
if ( in != null )
|
||||
{
|
||||
IAEItemStack out = Platform.poweredInsert( energy, stor, in, cct.getSource() );
|
||||
if ( out != null )
|
||||
craftMatrix.setInventorySlotContents( x, out.getItemStack() );
|
||||
else
|
||||
craftMatrix.setInventorySlotContents( x, null );
|
||||
|
||||
currentItem = craftMatrix.getStackInSlot( x );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( PatternItem != null && currentItem == null )
|
||||
{
|
||||
craftMatrix.setInventorySlotContents( x,
|
||||
Platform.extractItemsByRecipe( energy, cct.getSource(), stor, player.worldObj, r, is, ic, PatternItem, x, all ) );
|
||||
}
|
||||
}
|
||||
con.onCraftMatrixChanged( craftMatrix );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// api
|
||||
public PacketNEIRecipe(NBTTagCompound recipe) throws IOException {
|
||||
ByteBuf data = Unpooled.buffer();
|
||||
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream datao = new DataOutputStream( bytes );
|
||||
|
||||
data.writeInt( getPacketID() );
|
||||
|
||||
CompressedStreamTools.writeCompressed( recipe, datao );
|
||||
data.writeBytes( bytes.toByteArray() );
|
||||
|
||||
configureWrite( data );
|
||||
}
|
||||
}
|
13
integration/abstraction/INEI.java
Normal file
13
integration/abstraction/INEI.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package appeng.integration.abstraction;
|
||||
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.inventory.Slot;
|
||||
|
||||
public interface INEI
|
||||
{
|
||||
|
||||
void drawSlot(Slot s);
|
||||
|
||||
RenderItem setItemRender(RenderItem aeri2);
|
||||
|
||||
}
|
|
@ -1,45 +1,64 @@
|
|||
package appeng.integration.modules;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.client.gui.implementations.GuiCraftingTerm;
|
||||
import appeng.integration.IIntegrationModule;
|
||||
import appeng.integration.abstraction.INEI;
|
||||
import appeng.integration.modules.helpers.NEIAEShapedRecipeHandler;
|
||||
import appeng.integration.modules.helpers.NEIAEShapelessRecipeHandler;
|
||||
import appeng.integration.modules.helpers.NEICraftingHandler;
|
||||
import appeng.integration.modules.helpers.NEIInscriberRecipeHandler;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
|
||||
public class NEI implements IIntegrationModule
|
||||
public class NEI implements IIntegrationModule, INEI
|
||||
{
|
||||
|
||||
public static NEI instance;
|
||||
|
||||
Class API;
|
||||
|
||||
// recipe handler...
|
||||
Method registerRecipeHandler;
|
||||
Method registerUsageHandler;
|
||||
|
||||
public NEI() throws ClassNotFoundException {
|
||||
API = Class.forName( "codechicken.nei.api.API" );
|
||||
}
|
||||
|
||||
public void registerRecipeHandler(Object o) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
|
||||
{
|
||||
registerRecipeHandler.invoke( API, o );
|
||||
registerUsageHandler.invoke( API, o );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Init() throws Throwable
|
||||
{
|
||||
Method registerRecipeHandler = API.getDeclaredMethod( "registerRecipeHandler", new Class[] { codechicken.nei.recipe.ICraftingHandler.class } );
|
||||
Method registerUsageHandler = API.getDeclaredMethod( "registerUsageHandler", new Class[] { codechicken.nei.recipe.IUsageHandler.class } );
|
||||
registerRecipeHandler = API.getDeclaredMethod( "registerRecipeHandler", new Class[] { codechicken.nei.recipe.ICraftingHandler.class } );
|
||||
registerUsageHandler = API.getDeclaredMethod( "registerUsageHandler", new Class[] { codechicken.nei.recipe.IUsageHandler.class } );
|
||||
|
||||
registerRecipeHandler.invoke( API, new NEIAEShapedRecipeHandler() );
|
||||
registerUsageHandler.invoke( API, new NEIAEShapedRecipeHandler() );
|
||||
registerRecipeHandler( new NEIAEShapedRecipeHandler() );
|
||||
registerRecipeHandler( new NEIAEShapelessRecipeHandler() );
|
||||
registerRecipeHandler( new NEIInscriberRecipeHandler() );
|
||||
|
||||
registerRecipeHandler.invoke( API, new NEIAEShapelessRecipeHandler() );
|
||||
registerUsageHandler.invoke( API, new NEIAEShapelessRecipeHandler() );
|
||||
// crafting terminal...
|
||||
Method registerGuiOverlay = API.getDeclaredMethod( "registerGuiOverlay", new Class[] { Class.class, String.class, int.class, int.class } );
|
||||
Class IOverlayHandler = Class.forName( "codechicken.nei.api.IOverlayHandler" );
|
||||
Class DefaultOverlayHandler = NEICraftingHandler.class;
|
||||
|
||||
/*
|
||||
* Method registerGuiOverlay = API.getDeclaredMethod( "registerGuiOverlay", new Class[] { Class.class,
|
||||
* String.class, int.class, int.class } ); Class IOverlayHandler = Class.forName(
|
||||
* "codechicken.nei.api.IOverlayHandler" ); Class DefaultOverlayHandler =
|
||||
* NEICraftingTerminalOverlayHandler.class; Method registerGuiOverlayHandler = API.getDeclaredMethod(
|
||||
* "registerGuiOverlayHandler", new Class[] { Class.class, IOverlayHandler, String.class } );
|
||||
* registerGuiOverlay.invoke( API, GuiCraftingTerminal.class, "crafting", 6, 75 ); Constructor
|
||||
* DefaultOverlayHandlerConstructor = DefaultOverlayHandler .getConstructor( new Class[] { int.class, int.class
|
||||
* } ); registerGuiOverlayHandler.invoke( API, GuiCraftingTerminal.class,
|
||||
* DefaultOverlayHandlerConstructor.newInstance( 6, 75 ), "crafting" );
|
||||
*/
|
||||
Method registerGuiOverlayHandler = API.getDeclaredMethod( "registerGuiOverlayHandler", new Class[] { Class.class, IOverlayHandler, String.class } );
|
||||
registerGuiOverlay.invoke( API, GuiCraftingTerm.class, "crafting", 6, 75 );
|
||||
|
||||
Constructor DefaultOverlayHandlerConstructor = DefaultOverlayHandler.getConstructor( new Class[] { int.class, int.class } );
|
||||
registerGuiOverlayHandler.invoke( API, GuiCraftingTerm.class, DefaultOverlayHandlerConstructor.newInstance( 6, 75 ), "crafting" );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -48,4 +67,32 @@ public class NEI implements IIntegrationModule
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSlot(Slot s)
|
||||
{
|
||||
if ( s == null )
|
||||
return;
|
||||
|
||||
ItemStack stack = s.getStack();
|
||||
|
||||
if ( stack == null )
|
||||
return;
|
||||
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
FontRenderer fontRenderer = mc.fontRenderer;
|
||||
int x = s.xDisplayPosition;
|
||||
int y = s.yDisplayPosition;
|
||||
|
||||
GuiContainerManager.drawItems.renderItemAndEffectIntoGUI( fontRenderer, mc.getTextureManager(), stack, x, y );
|
||||
GuiContainerManager.drawItems.renderItemOverlayIntoGUI( fontRenderer, mc.getTextureManager(), stack, x, y, "" + stack.stackSize );
|
||||
}
|
||||
|
||||
@Override
|
||||
public RenderItem setItemRender(RenderItem aeri2)
|
||||
{
|
||||
RenderItem ri = GuiContainerManager.drawItems;
|
||||
GuiContainerManager.drawItems = aeri2;
|
||||
return ri;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class NEIAEShapedRecipeHandler extends TemplateRecipeHandler
|
|||
}
|
||||
|
||||
@Override
|
||||
public void loadCraftingRecipes(String outputId, Object[] results)
|
||||
public void loadCraftingRecipes(String outputId, Object... results)
|
||||
{
|
||||
if ( (outputId.equals( "crafting" )) && (getClass() == NEIAEShapedRecipeHandler.class) )
|
||||
{
|
||||
|
|
|
@ -41,7 +41,7 @@ public class NEIAEShapelessRecipeHandler extends TemplateRecipeHandler
|
|||
}
|
||||
|
||||
@Override
|
||||
public void loadCraftingRecipes(String outputId, Object[] results)
|
||||
public void loadCraftingRecipes(String outputId, Object... results)
|
||||
{
|
||||
if ( (outputId.equals( "crafting" )) && (getClass() == NEIAEShapelessRecipeHandler.class) )
|
||||
{
|
||||
|
|
86
integration/modules/helpers/NEICraftingHandler.java
Normal file
86
integration/modules/helpers/NEICraftingHandler.java
Normal file
|
@ -0,0 +1,86 @@
|
|||
package appeng.integration.modules.helpers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import appeng.client.gui.implementations.GuiCraftingTerm;
|
||||
import appeng.container.slot.SlotCraftingMatrix;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketNEIRecipe;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
|
||||
public class NEICraftingHandler implements IOverlayHandler
|
||||
{
|
||||
|
||||
public NEICraftingHandler(int x, int y) {
|
||||
offsetx = x;
|
||||
offsety = y;
|
||||
}
|
||||
|
||||
int offsetx;
|
||||
int offsety;
|
||||
|
||||
// @override
|
||||
public void overlayRecipe(GuiContainer gui, IRecipeHandler recipe, int recipeIndex, boolean shift)
|
||||
{
|
||||
try
|
||||
{
|
||||
List ingredients = recipe.getIngredientStacks( recipeIndex );
|
||||
overlayRecipe( gui, ingredients, shift );
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
}
|
||||
catch (Error err)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// @override
|
||||
public void overlayRecipe(GuiContainer gui, List<PositionedStack> ingredients, boolean shift)
|
||||
{
|
||||
try
|
||||
{
|
||||
NBTTagCompound recipe = new NBTTagCompound();
|
||||
|
||||
if ( gui instanceof GuiCraftingTerm )
|
||||
{
|
||||
for (int i = 0; i < ingredients.size(); i++)// identify slots
|
||||
{
|
||||
PositionedStack pstack = ingredients.get( i );
|
||||
int col = (pstack.relx - 25) / 18;
|
||||
int row = (pstack.rely - 6) / 18;
|
||||
if ( pstack.item != null )
|
||||
{
|
||||
for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots)
|
||||
{
|
||||
if ( slot instanceof SlotCraftingMatrix )
|
||||
{
|
||||
SlotCraftingMatrix ctSlot = (SlotCraftingMatrix) slot;
|
||||
if ( ctSlot.getSlotIndex() == col + row * 3 )
|
||||
{
|
||||
NBTTagCompound inbt = new NBTTagCompound();
|
||||
pstack.item.writeToNBT( inbt );
|
||||
recipe.setTag( "#" + ((SlotCraftingMatrix) slot).getSlotIndex(), inbt );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NetworkHandler.instance.sendToServer( new PacketNEIRecipe( recipe ) );
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
}
|
||||
catch (Error err)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
176
integration/modules/helpers/NEIInscriberRecipeHandler.java
Normal file
176
integration/modules/helpers/NEIInscriberRecipeHandler.java
Normal file
|
@ -0,0 +1,176 @@
|
|||
package appeng.integration.modules.helpers;
|
||||
|
||||
import static codechicken.lib.gui.GuiDraw.changeTexture;
|
||||
import static codechicken.lib.gui.GuiDraw.drawTexturedModalRect;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import appeng.client.gui.implementations.GuiInscriber;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.recipes.handlers.Inscribe;
|
||||
import appeng.recipes.handlers.Inscribe.InscriberRecipe;
|
||||
import codechicken.nei.NEIServerUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.api.IRecipeOverlayRenderer;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||
|
||||
public class NEIInscriberRecipeHandler extends TemplateRecipeHandler
|
||||
{
|
||||
|
||||
public void drawBackground(int recipe)
|
||||
{
|
||||
GL11.glColor4f( 1, 1, 1, 1 );
|
||||
changeTexture( getGuiTexture() );
|
||||
drawTexturedModalRect( 0, 0, 5, 11, 166, 75 );
|
||||
}
|
||||
|
||||
public void loadTransferRects()
|
||||
{
|
||||
this.transferRects.add( new TemplateRecipeHandler.RecipeTransferRect( new Rectangle( 84, 23, 24, 18 ), "inscriber", new Object[0] ) );
|
||||
}
|
||||
|
||||
public Class<? extends GuiContainer> getGuiClass()
|
||||
{
|
||||
return GuiInscriber.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeName()
|
||||
{
|
||||
return GuiText.Inscriber.getLocal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCraftingRecipes(String outputId, Object... results)
|
||||
{
|
||||
if ( (outputId.equals( "inscriber" )) && (getClass() == NEIInscriberRecipeHandler.class) )
|
||||
{
|
||||
for (InscriberRecipe irecipe : Inscribe.recipes)
|
||||
{
|
||||
CachedInscriberRecipe recipe = new CachedInscriberRecipe( irecipe );
|
||||
if ( recipe != null )
|
||||
{
|
||||
recipe.computeVisuals();
|
||||
this.arecipes.add( recipe );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
super.loadCraftingRecipes( outputId, results );
|
||||
}
|
||||
}
|
||||
|
||||
public void loadCraftingRecipes(ItemStack result)
|
||||
{
|
||||
for (InscriberRecipe irecipe : Inscribe.recipes)
|
||||
{
|
||||
if ( NEIServerUtils.areStacksSameTypeCrafting( irecipe.output, result ) )
|
||||
{
|
||||
CachedInscriberRecipe recipe = new CachedInscriberRecipe( irecipe );
|
||||
recipe.computeVisuals();
|
||||
this.arecipes.add( recipe );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadUsageRecipes(ItemStack ingredient)
|
||||
{
|
||||
for (InscriberRecipe irecipe : Inscribe.recipes)
|
||||
{
|
||||
CachedInscriberRecipe recipe = new CachedInscriberRecipe( irecipe );
|
||||
|
||||
if ( (recipe != null) && (recipe.contains( recipe.ingredients, ingredient.getItem() )) )
|
||||
{
|
||||
recipe.computeVisuals();
|
||||
if ( recipe.contains( recipe.ingredients, ingredient ) )
|
||||
{
|
||||
recipe.setIngredientPermutation( recipe.ingredients, ingredient );
|
||||
this.arecipes.add( recipe );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getGuiTexture()
|
||||
{
|
||||
ResourceLocation loc = new ResourceLocation( "appliedenergistics2", "textures/guis/inscriber.png" );
|
||||
String f = loc.toString();
|
||||
return f;
|
||||
}
|
||||
|
||||
public String getOverlayIdentifier()
|
||||
{
|
||||
return "inscriber";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOverlay(GuiContainer gui, Container container, int recipe)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeOverlayRenderer getOverlayRenderer(GuiContainer gui, int recipe)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IOverlayHandler getOverlayHandler(GuiContainer gui, int recipe)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public class CachedInscriberRecipe extends TemplateRecipeHandler.CachedRecipe
|
||||
{
|
||||
|
||||
public ArrayList<PositionedStack> ingredients;
|
||||
public PositionedStack result;
|
||||
|
||||
public CachedInscriberRecipe(InscriberRecipe irecipe) {
|
||||
result = new PositionedStack( irecipe.output, 108, 29 );
|
||||
ingredients = new ArrayList<PositionedStack>();
|
||||
|
||||
if ( irecipe.plateA != null )
|
||||
ingredients.add( new PositionedStack( irecipe.plateA, 40, 5 ) );
|
||||
|
||||
if ( irecipe.imprintable != null )
|
||||
ingredients.add( new PositionedStack( irecipe.imprintable, 40 + 18, 28 ) );
|
||||
|
||||
if ( irecipe.plateB != null )
|
||||
ingredients.add( new PositionedStack( irecipe.plateB, 40, 51 ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PositionedStack> getIngredients()
|
||||
{
|
||||
return getCycledIngredients( cycleticks / 20, this.ingredients );
|
||||
}
|
||||
|
||||
@Override
|
||||
public PositionedStack getResult()
|
||||
{
|
||||
return this.result;
|
||||
}
|
||||
|
||||
public void computeVisuals()
|
||||
{
|
||||
for (PositionedStack p : this.ingredients)
|
||||
{
|
||||
p.generatePermutations();
|
||||
}
|
||||
this.result.generatePermutations();
|
||||
}
|
||||
}
|
||||
}
|
162
integration/modules/helpers/NEIWorldCraftingHandler.java
Normal file
162
integration/modules/helpers/NEIWorldCraftingHandler.java
Normal file
|
@ -0,0 +1,162 @@
|
|||
package appeng.integration.modules.helpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.util.AEItemDefinition;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.localization.GuiText;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.api.IRecipeOverlayRenderer;
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
import codechicken.nei.recipe.ICraftingHandler;
|
||||
import codechicken.nei.recipe.IUsageHandler;
|
||||
|
||||
public class NEIWorldCraftingHandler implements ICraftingHandler, IUsageHandler
|
||||
{
|
||||
|
||||
HashMap<AEItemDefinition, String> details = new HashMap<AEItemDefinition, String>();
|
||||
List<AEItemDefinition> offsets = new LinkedList();
|
||||
|
||||
private void addRecipe(AEItemDefinition def, String msg)
|
||||
{
|
||||
offsets.add( def );
|
||||
details.put( def, msg );
|
||||
}
|
||||
|
||||
public NEIWorldCraftingHandler() {
|
||||
|
||||
if ( AEConfig.instance.isFeatureEnabled( AEFeature.inWorldFluix ) )
|
||||
addRecipe( AEApi.instance().materials().materialFluixCrystal, GuiText.inWorldFluix.getLocal() );
|
||||
|
||||
if ( AEConfig.instance.isFeatureEnabled( AEFeature.inWorldSingularity ) )
|
||||
addRecipe( AEApi.instance().materials().materialQESingularity, GuiText.inWorldSingularity.getLocal() );
|
||||
|
||||
if ( AEConfig.instance.isFeatureEnabled( AEFeature.inWorldPurification ) )
|
||||
{
|
||||
addRecipe( AEApi.instance().materials().materialPureifiedCertusQuartzCrystal, GuiText.inWorldPurification.getLocal() );
|
||||
addRecipe( AEApi.instance().materials().materialPureifiedNetherQuartzCrystal, GuiText.inWorldPurification.getLocal() );
|
||||
addRecipe( AEApi.instance().materials().materialPureifiedFluixCrystal, GuiText.inWorldPurification.getLocal() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeName()
|
||||
{
|
||||
return GuiText.InWorldCrafting.getLocal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numRecipes()
|
||||
{
|
||||
return offsets.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(int recipe)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawForeground(int recipe)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PositionedStack> getIngredientStacks(int recipe)
|
||||
{
|
||||
return new ArrayList<PositionedStack>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PositionedStack> getOtherStacks(int recipetype)
|
||||
{
|
||||
return new ArrayList<PositionedStack>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PositionedStack getResultStack(int recipe)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOverlay(GuiContainer gui, Container container, int recipe)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeOverlayRenderer getOverlayRenderer(GuiContainer gui, int recipe)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IOverlayHandler getOverlayHandler(GuiContainer gui, int recipe)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int recipiesPerPage()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleTooltip(GuiRecipe gui, List<String> currenttip, int recipe)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleItemTooltip(GuiRecipe gui, ItemStack stack, List<String> currenttip, int recipe)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(GuiRecipe gui, char keyChar, int keyCode, int recipe)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(GuiRecipe gui, int button, int recipe)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IUsageHandler getUsageHandler(String inputId, Object... ingredients)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICraftingHandler getRecipeHandler(String outputId, Object... results)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -68,6 +68,7 @@ import appeng.api.networking.security.MachineSource;
|
|||
import appeng.api.networking.security.PlayerSource;
|
||||
import appeng.api.networking.storage.IStorageGrid;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
|
@ -1544,4 +1545,54 @@ public class Platform
|
|||
}
|
||||
}
|
||||
|
||||
public static ItemStack extractItemsByRecipe(IEnergySource energySrc, BaseActionSource mySrc, IMEMonitor<IAEItemStack> src, World w, IRecipe r,
|
||||
ItemStack output, InventoryCrafting ci, ItemStack providedTemplate, int slot, IItemList<IAEItemStack> aitems)
|
||||
{
|
||||
if ( energySrc.extractAEPower( 1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0.9 )
|
||||
{
|
||||
if ( providedTemplate == null )
|
||||
return null;
|
||||
|
||||
AEItemStack ae_req = AEItemStack.create( providedTemplate );
|
||||
ae_req.setStackSize( 1 );
|
||||
|
||||
IAEItemStack ae_ext = src.extractItems( ae_req, Actionable.MODULATE, mySrc );
|
||||
if ( ae_ext != null )
|
||||
{
|
||||
ItemStack extracted = ae_ext.getItemStack();
|
||||
if ( extracted != null )
|
||||
{
|
||||
energySrc.extractAEPower( 1, Actionable.MODULATE, PowerMultiplier.CONFIG );
|
||||
return extracted;
|
||||
}
|
||||
}
|
||||
|
||||
if ( aitems != null && (ae_req.isOre() || providedTemplate.hasTagCompound() || providedTemplate.isItemStackDamageable()) )
|
||||
{
|
||||
for (IAEItemStack x : aitems)
|
||||
{
|
||||
ItemStack sh = x.getItemStack();
|
||||
if ( (Platform.isSameItemType( providedTemplate, sh ) || ae_req.sameOre( x )) && !Platform.isSameItem( sh, output ) )
|
||||
{ // Platform.isSameItemType( sh, providedTemplate )
|
||||
ItemStack cp = Platform.cloneItemStack( sh );
|
||||
cp.stackSize = 1;
|
||||
ci.setInventorySlotContents( slot, cp );
|
||||
if ( r.matches( ci, w ) && Platform.isSameItem( r.getCraftingResult( ci ), output ) )
|
||||
{
|
||||
IAEItemStack ex = src.extractItems( AEItemStack.create( cp ), Actionable.MODULATE, mySrc );
|
||||
if ( ex != null )
|
||||
{
|
||||
energySrc.extractAEPower( 1, Actionable.MODULATE, PowerMultiplier.CONFIG );
|
||||
return ex.getItemStack();
|
||||
}
|
||||
}
|
||||
ci.setInventorySlotContents( slot, providedTemplate );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue