diff --git a/client/gui/AEBaseGui.java b/client/gui/AEBaseGui.java index 951ff8cc4..62b9a59ba 100644 --- a/client/gui/AEBaseGui.java +++ b/client/gui/AEBaseGui.java @@ -45,10 +45,12 @@ import appeng.container.slot.SlotPatternTerm; 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; @@ -580,6 +582,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 @@ -617,8 +635,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; @@ -647,7 +664,7 @@ public abstract class AEBaseGui extends GuiContainer if ( Platform.isDrawing( Tessellator.instance ) ) Tessellator.instance.draw(); } - itemRender = pIR; + setItemRender( pIR ); return; } else diff --git a/client/gui/implementations/GuiMEMonitorable.java b/client/gui/implementations/GuiMEMonitorable.java index a3214b74e..9530c1e21 100644 --- a/client/gui/implementations/GuiMEMonitorable.java +++ b/client/gui/implementations/GuiMEMonitorable.java @@ -151,6 +151,9 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi if ( hasNEI ) rows--; + if ( rows < 3 ) + rows = 3; + meSlots.clear(); for (int y = 0; y < rows; y++) { diff --git a/container/AEBaseContainer.java b/container/AEBaseContainer.java index ac00d5188..37eb8ca89 100644 --- a/container/AEBaseContainer.java +++ b/container/AEBaseContainer.java @@ -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() ) diff --git a/container/implementations/ContainerCraftingTerm.java b/container/implementations/ContainerCraftingTerm.java index 3009da045..9e4ca8b80 100644 --- a/container/implementations/ContainerCraftingTerm.java +++ b/container/implementations/ContainerCraftingTerm.java @@ -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. diff --git a/container/implementations/ContainerMEMonitorable.java b/container/implementations/ContainerMEMonitorable.java index 679597c6b..f1be06bb1 100644 --- a/container/implementations/ContainerMEMonitorable.java +++ b/container/implementations/ContainerMEMonitorable.java @@ -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 ); diff --git a/core/AEConfig.java b/core/AEConfig.java index 62baae283..8b56b001d 100644 --- a/core/AEConfig.java +++ b/core/AEConfig.java @@ -25,7 +25,7 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo public static AEConfig instance; - public static float TunnelPowerLoss = 0.05f; + public static double TunnelPowerLoss = 0.05; public String latestVersion = VERSION; public long latestTimeStamp = 0; @@ -270,8 +270,8 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo if ( alreadyUsed ) { - if ( min < 1000 ) - min = 1000; + if ( min < 16383 ) + min = 16383; return min; } diff --git a/core/Registration.java b/core/Registration.java index 66e6fa3a7..f5ea161a2 100644 --- a/core/Registration.java +++ b/core/Registration.java @@ -132,6 +132,7 @@ import appeng.recipes.RecipeHandler; import appeng.recipes.game.FacadeRecipe; import appeng.recipes.game.ShapedRecipe; import appeng.recipes.game.ShapelessRecipe; +import appeng.recipes.handlers.Crusher; import appeng.recipes.handlers.Grind; import appeng.recipes.handlers.GrindFZ; import appeng.recipes.handlers.Inscribe; @@ -181,6 +182,7 @@ public class Registration recipeRegistery.addNewSubItemResolver( new AEItemResolver() ); recipeRegistery.addNewCraftHandler( "grind", Grind.class ); + recipeRegistery.addNewCraftHandler( "crusher", Crusher.class ); recipeRegistery.addNewCraftHandler( "grindfz", GrindFZ.class ); recipeRegistery.addNewCraftHandler( "pulverizer", Pulverizer.class ); recipeRegistery.addNewCraftHandler( "macerator", Macerator.class ); @@ -468,6 +470,7 @@ public class Registration ph.registerNewLayer( "appeng.api.parts.layers.LayerIPowerEmitter", "buildcraft.api.power.IPowerEmitter" ); ph.registerNewLayer( "appeng.api.parts.layers.LayerIPowerReceptor", "buildcraft.api.power.IPowerReceptor" ); ph.registerNewLayer( "appeng.api.parts.layers.LayerIFluidHandler", "net.minecraftforge.fluids.IFluidHandler" ); + ph.registerNewLayer( "appeng.api.parts.layers.LayerIEnergyHandler", "cofh.api.energy.IEnergyHandler" ); ph.registerNewLayer( "appeng.api.parts.layers.LayerITileStorageMonitorable", "appeng.api.implementations.tiles.ITileStorageMonitorable" ); FMLCommonHandler.instance().bus().register( TickHandler.instance ); @@ -604,7 +607,7 @@ public class Registration mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityHopper.class ); /** - * Whitelist AE + * Whitelist AE2 */ mr.whiteListTileEntity( AEBaseTile.class ); diff --git a/core/features/AEFeature.java b/core/features/AEFeature.java index 348fe086b..6857ff7bc 100644 --- a/core/features/AEFeature.java +++ b/core/features/AEFeature.java @@ -41,8 +41,8 @@ public enum AEFeature DenseEnergyCells("HigherCapacity"), DenseCables("HigherCapacity"), - P2PTunnelME("P2PTunnels"), P2PTunnelItems("P2PTunnels"), P2PTunnelRedstone("P2PTunnels"), P2PTunnelEU("P2PTunnels"), P2PTunnelMJ("P2PTunnels"), P2PTunnelLiquids( - "P2PTunnels"), + P2PTunnelRF("P2PTunnels"), P2PTunnelME("P2PTunnels"), P2PTunnelItems("P2PTunnels"), P2PTunnelRedstone("P2PTunnels"), P2PTunnelEU("P2PTunnels"), P2PTunnelMJ( + "P2PTunnels"), P2PTunnelLiquids("P2PTunnels"), MassCannonBlockDamage("BlockFeatures"), TinyTNTBlockDamage("BlockFeatures"), Facades("Facades"), diff --git a/core/features/registries/GrinderRecipeManager.java b/core/features/registries/GrinderRecipeManager.java index b73ae2924..c108c1165 100644 --- a/core/features/registries/GrinderRecipeManager.java +++ b/core/features/registries/GrinderRecipeManager.java @@ -11,8 +11,8 @@ import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import appeng.api.features.IGrinderEntry; import appeng.api.features.IGrinderRegistry; -import appeng.core.AELog; import appeng.core.AEConfig; +import appeng.core.AELog; import appeng.core.features.registries.entries.AppEngGrinderRecipe; import appeng.recipes.ores.IOreListener; import appeng.recipes.ores.OreDictionaryHandler; @@ -60,6 +60,15 @@ public class GrinderRecipeManager implements IGrinderRegistry, IOreListener return RecipeList; } + private void injectRecipe(AppEngGrinderRecipe appEngGrinderRecipe) + { + for (IGrinderEntry gr : RecipeList) + if ( Platform.isSameItemPrecise( gr.getInput(), appEngGrinderRecipe.getInput() ) ) + return; + + RecipeList.add( appEngGrinderRecipe ); + } + @Override public void addRecipe(ItemStack in, ItemStack out, int cost) { @@ -70,7 +79,7 @@ public class GrinderRecipeManager implements IGrinderRegistry, IOreListener } log( "Allow Grinding of " + Platform.getItemDisplayName( in ) + " to " + Platform.getItemDisplayName( out ) + " for " + cost ); - RecipeList.add( new AppEngGrinderRecipe( copy( in ), copy( out ), cost ) ); + injectRecipe( new AppEngGrinderRecipe( copy( in ), copy( out ), cost ) ); } @Override @@ -84,7 +93,7 @@ public class GrinderRecipeManager implements IGrinderRegistry, IOreListener log( "Allow Grinding of " + Platform.getItemDisplayName( in ) + " to " + Platform.getItemDisplayName( out ) + " with optional " + Platform.getItemDisplayName( optional ) + " for " + cost ); - RecipeList.add( new AppEngGrinderRecipe( copy( in ), copy( out ), copy( optional ), chance, cost ) ); + injectRecipe( new AppEngGrinderRecipe( copy( in ), copy( out ), copy( optional ), chance, cost ) ); } @Override diff --git a/core/features/registries/P2PTunnelRegistry.java b/core/features/registries/P2PTunnelRegistry.java index 9bd13afcc..6000e4fab 100644 --- a/core/features/registries/P2PTunnelRegistry.java +++ b/core/features/registries/P2PTunnelRegistry.java @@ -6,6 +6,7 @@ import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.oredict.OreDictionary; import appeng.api.AEApi; import appeng.api.config.TunnelType; import appeng.api.definitions.Parts; @@ -70,7 +71,7 @@ public class P2PTunnelRegistry implements IP2PTunnelRegistry @Override public void addNewAttunement(ItemStack trigger, TunnelType type) { - if ( type == null ) + if ( type == null || trigger == null ) return; Tunnels.put( trigger, type ); @@ -79,13 +80,19 @@ public class P2PTunnelRegistry implements IP2PTunnelRegistry @Override public TunnelType getTunnelTypeByItem(ItemStack trigger) { - if ( FluidContainerRegistry.isContainer( trigger ) ) - return TunnelType.FLUID; - - for (ItemStack is : Tunnels.keySet()) + if ( trigger != null ) { - if ( Platform.isSameItem( is, trigger ) ) - return Tunnels.get( is ); + if ( FluidContainerRegistry.isContainer( trigger ) ) + return TunnelType.FLUID; + + for (ItemStack is : Tunnels.keySet()) + { + if ( is.getItem() == trigger.getItem() && is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) + return Tunnels.get( is ); + + if ( Platform.isSameItem( is, trigger ) ) + return Tunnels.get( is ); + } } return null; diff --git a/core/localization/GuiText.java b/core/localization/GuiText.java index ce4b2af12..6aa65b7a3 100644 --- a/core/localization/GuiText.java +++ b/core/localization/GuiText.java @@ -25,10 +25,10 @@ public enum GuiText CraftingTerminal, FormationPlane, Inscriber, QuartzCuttingKnife, METunnel, ItemTunnel, RedstoneTunnel, MJTunnel, EUTunnel, FluidTunnel, StoredSize, - - StoredPower, MaxPower, RequiredPower, Efficiency, CopyMode, CopyModeDesc, PatternTerminal, - - CraftingPattern, ProcessingPattern, Crafts, Creates, And, With, MolecularAssembler; + + CopyMode, CopyModeDesc, PatternTerminal, CraftingPattern, ProcessingPattern, Crafts, Creates, And, With, MolecularAssembler, + + StoredPower, MaxPower, RequiredPower, Efficiency, InWorldCrafting, inWorldFluix, inWorldPurification, inWorldSingularity, OfSecondOutput, NoSecondOutput, RFTunnel; String root; diff --git a/core/sync/AppEngPacketHandlerBase.java b/core/sync/AppEngPacketHandlerBase.java index 3e48d391c..984acf13a 100644 --- a/core/sync/AppEngPacketHandlerBase.java +++ b/core/sync/AppEngPacketHandlerBase.java @@ -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.PacketPatternSlot; @@ -67,7 +68,9 @@ public class AppEngPacketHandlerBase PACKET_SWAP_SLOTS(PacketSwapSlots.class), - PACKET_PATTERN_SLOT(PacketPatternSlot.class); + PACKET_PATTERN_SLOT(PacketPatternSlot.class), + + PACKET_RECIPE_NEI(PacketNEIRecipe.class); final public Class pc; final public Constructor con; diff --git a/core/sync/packets/PacketNEIRecipe.java b/core/sync/packets/PacketNEIRecipe.java new file mode 100644 index 000000000..f5a93e238 --- /dev/null +++ b/core/sync/packets/PacketNEIRecipe.java @@ -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 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 ); + } +} diff --git a/fmp/CableBusPart.java b/fmp/CableBusPart.java index 63d25db27..f4011821b 100644 --- a/fmp/CableBusPart.java +++ b/fmp/CableBusPart.java @@ -73,6 +73,7 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds new Cuboid6( 10.0 / 16.0, 6.0 / 16.0, 6.0 / 16.0, 1.0, 10.0 / 16.0, 10.0 / 16.0 ),// EAST(1, 0, 0), }; + public static ThreadLocal disableFacadeOcclusion = new ThreadLocal(); public CableBusContainer cb = new CableBusContainer( this ); @Override @@ -149,7 +150,7 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds { AxisAlignedBB b = null; - for (AxisAlignedBB bx : cb.getSelectedBoundingBoxsFromPool( false, null, true )) + for (AxisAlignedBB bx : cb.getSelectedBoundingBoxsFromPool( false, true, null, true )) { if ( b == null ) b = bx; @@ -299,7 +300,10 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds bp.getBoxes( bch ); for (AxisAlignedBB bb : boxes) { - if ( !tile().canAddPart( new NormallyOccludedPart( new Cuboid6( bb ) ) ) ) + disableFacadeOcclusion.set( true ); + boolean canAdd = tile().canAddPart( new NormallyOccludedPart( new Cuboid6( bb ) ) ); + disableFacadeOcclusion.remove(); + if ( !canAdd ) { return false; } @@ -389,7 +393,7 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds public Iterable getCollisionBoxes() { LinkedList l = new LinkedList(); - for (AxisAlignedBB b : cb.getSelectedBoundingBoxsFromPool( false, null, false )) + for (AxisAlignedBB b : cb.getSelectedBoundingBoxsFromPool( false, true, null, false )) { l.add( new Cuboid6( b.minX, b.minY, b.minZ, b.maxX, b.maxY, b.maxZ ) ); } @@ -412,7 +416,7 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds public Iterable getOcclusionBoxes() { LinkedList l = new LinkedList(); - for (AxisAlignedBB b : cb.getSelectedBoundingBoxsFromPool( true, null, true )) + for (AxisAlignedBB b : cb.getSelectedBoundingBoxsFromPool( true, disableFacadeOcclusion.get() == null, null, true )) { l.add( new Cuboid6( b.minX, b.minY, b.minZ, b.maxX, b.maxY, b.maxZ ) ); } @@ -442,7 +446,12 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds { if ( side == null || side == ForgeDirection.UNKNOWN || tile() == null ) return false; - return !tile().canAddPart( new NormallyOccludedPart( sideTests[side.ordinal()] ) ); + + disableFacadeOcclusion.set( true ); + boolean blocked = !tile().canAddPart( new NormallyOccludedPart( sideTests[side.ordinal()] ) ); + disableFacadeOcclusion.remove(); + + return blocked; } @Override diff --git a/helpers/MeteoritePlacer.java b/helpers/MeteoritePlacer.java index a406b107f..fe27436e5 100644 --- a/helpers/MeteoritePlacer.java +++ b/helpers/MeteoritePlacer.java @@ -1,6 +1,8 @@ package appeng.helpers; import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; import net.minecraft.block.Block; import net.minecraft.entity.Entity; @@ -12,6 +14,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.oredict.OreDictionary; import appeng.api.AEApi; import appeng.util.InventoryAdaptor; import appeng.util.Platform; @@ -350,10 +353,25 @@ public class MeteoritePlacer ap.addItems( AEApi.instance().blocks().blockSkyStone.stack( (int) (Math.random() * 12) + 1 ) ); break; case 1: - ap.addItems( AEApi.instance().materials().materialIronNugget.stack( (int) (Math.random() * 12) + 1 ) ); - break; - case 2: - ap.addItems( new ItemStack( net.minecraft.init.Items.gold_nugget, (int) (Math.random() * 12) + 1 ) ); + List possibles = new LinkedList(); + possibles.addAll( OreDictionary.getOres( "nuggetIron" ) ); + possibles.addAll( OreDictionary.getOres( "nuggetCopper" ) ); + possibles.addAll( OreDictionary.getOres( "nuggetTin" ) ); + possibles.addAll( OreDictionary.getOres( "nuggetSilver" ) ); + possibles.addAll( OreDictionary.getOres( "nuggetLead" ) ); + possibles.addAll( OreDictionary.getOres( "nuggetPlatinum" ) ); + possibles.addAll( OreDictionary.getOres( "nuggetNickel" ) ); + possibles.addAll( OreDictionary.getOres( "nuggetAluminium" ) ); + possibles.addAll( OreDictionary.getOres( "nuggetElectrum" ) ); + possibles.add( new ItemStack( net.minecraft.init.Items.gold_nugget ) ); + + ItemStack nugget = Platform.pickRandom( possibles ); + if ( nugget != null ) + { + nugget = nugget.copy(); + nugget.stackSize = (int) (Math.random() * 12) + 1; + ap.addItems( nugget ); + } break; } } diff --git a/integration/abstraction/INEI.java b/integration/abstraction/INEI.java new file mode 100644 index 000000000..1c69dcebb --- /dev/null +++ b/integration/abstraction/INEI.java @@ -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); + +} diff --git a/integration/abstraction/IRC.java b/integration/abstraction/IRC.java new file mode 100644 index 000000000..7b48d9a1d --- /dev/null +++ b/integration/abstraction/IRC.java @@ -0,0 +1,10 @@ +package appeng.integration.abstraction; + +import net.minecraft.item.ItemStack; + +public interface IRC +{ + + void rockCrusher(ItemStack input, ItemStack output); + +} diff --git a/integration/modules/NEI.java b/integration/modules/NEI.java index 665458446..1d4413631 100644 --- a/integration/modules/NEI.java +++ b/integration/modules/NEI.java @@ -1,45 +1,68 @@ 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.NEIGrinderRecipeHandler; +import appeng.integration.modules.helpers.NEIInscriberRecipeHandler; +import appeng.integration.modules.helpers.NEIWorldCraftingHandler; +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( new NEIWorldCraftingHandler() ); + registerRecipeHandler( new NEIGrinderRecipeHandler() ); - 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 +71,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; + } + } diff --git a/integration/modules/RC.java b/integration/modules/RC.java new file mode 100644 index 000000000..eba9526fd --- /dev/null +++ b/integration/modules/RC.java @@ -0,0 +1,39 @@ +package appeng.integration.modules; + +import mods.railcraft.api.crafting.IRockCrusherRecipe; +import mods.railcraft.api.crafting.RailcraftCraftingManager; +import net.minecraft.item.ItemStack; +import appeng.integration.BaseModule; +import appeng.integration.IIntegrationModule; +import appeng.integration.abstraction.IRC; + +public class RC extends BaseModule implements IIntegrationModule, IRC +{ + + public static RC instance; + + @Override + public void rockCrusher(ItemStack input, ItemStack output) + { + IRockCrusherRecipe re = RailcraftCraftingManager.rockCrusher.createNewRecipe( input, true, true ); + re.addOutput( output, 1.0f ); + } + + public RC() { + TestClass( RailcraftCraftingManager.class ); + TestClass( IRockCrusherRecipe.class ); + } + + @Override + public void Init() + { + // TODO Auto-generated method stub + + } + + @Override + public void PostInit() + { + + } +} diff --git a/integration/modules/RF.java b/integration/modules/RF.java index 375d6e972..61114cfc9 100644 --- a/integration/modules/RF.java +++ b/integration/modules/RF.java @@ -1,7 +1,13 @@ package appeng.integration.modules; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; +import appeng.api.AEApi; +import appeng.api.config.TunnelType; +import appeng.api.features.IP2PTunnelRegistry; import appeng.integration.BaseModule; import appeng.integration.IIntegrationModule; +import cpw.mods.fml.common.registry.GameRegistry; public class RF extends BaseModule implements IIntegrationModule { @@ -15,7 +21,17 @@ public class RF extends BaseModule implements IIntegrationModule @Override public void Init() { + IP2PTunnelRegistry reg = AEApi.instance().registries().p2pTunnel(); + ItemStack energyConduit = GameRegistry.findItemStack( "EnderIO", "itemPowerConduit", 1 ); + if ( energyConduit != null ) + { + energyConduit.setItemDamage( OreDictionary.WILDCARD_VALUE ); + reg.addNewAttunement( energyConduit, TunnelType.RF_POWER ); + } + + reg.addNewAttunement( GameRegistry.findItemStack( "EnderIO", "blockCapacitorBank", 1 ), TunnelType.RF_POWER ); + reg.addNewAttunement( GameRegistry.findItemStack( "EnderIO", "blockPowerMonitor", 1 ), TunnelType.RF_POWER ); } @Override diff --git a/integration/modules/dead/GT.java b/integration/modules/dead/GT.java index feff1f78d..f977b6855 100644 --- a/integration/modules/dead/GT.java +++ b/integration/modules/dead/GT.java @@ -1,6 +1,6 @@ -package appeng.integration.modules.dead; +package appeng.integration.modules; -import gregtechmod.api.interfaces.IDigitalChest; +import gregtech.api.interfaces.tileentity.IDigitalChest; import net.minecraft.inventory.IInventory; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; @@ -8,8 +8,8 @@ import appeng.api.AEApi; import appeng.api.storage.IMEInventory; import appeng.integration.IIntegrationModule; import appeng.integration.abstraction.IGT; -import appeng.integration.modules.helpers.dead.GregTechHandler; -import appeng.integration.modules.helpers.dead.GregTechQuantumChest; +import appeng.integration.modules.helpers.GregTechHandler; +import appeng.integration.modules.helpers.GregTechQuantumChest; import appeng.util.InventoryAdaptor; public class GT implements IGT, IIntegrationModule diff --git a/integration/modules/dead/RC.java b/integration/modules/dead/RC.java deleted file mode 100644 index 92623c2ff..000000000 --- a/integration/modules/dead/RC.java +++ /dev/null @@ -1,51 +0,0 @@ -package appeng.integration.modules.dead; - -import mods.railcraft.api.crafting.IRockCrusherRecipe; -import mods.railcraft.api.crafting.RailcraftCraftingManager; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import appeng.api.AEApi; -import appeng.integration.IIntegrationModule; - -public class RC implements IIntegrationModule -{ - - public static RC instance; - - public void rockCrusher(ItemStack input, ItemStack output) - { - IRockCrusherRecipe re = RailcraftCraftingManager.rockCrusher.createNewRecipe( input, true, true ); - re.addOutput( output, 1.0f ); - } - - public void rockCrusher(ItemStack input, ItemStack output, ItemStack secondary, float chance) - { - IRockCrusherRecipe re = RailcraftCraftingManager.rockCrusher.createNewRecipe( input, true, true ); - re.addOutput( output, 1.0f ); - if ( secondary != null ) re.addOutput( secondary, chance ); - } - - @Override - public void Init() - { - // TODO Auto-generated method stub - - } - - @Override - public void PostInit() - { - // certus quartz - rockCrusher( AEApi.instance().materials().materialCertusQuartzCrystal.stack( 1 ), - AEApi.instance().materials().materialCertusQuartzDust.stack( 1 ) ); - - rockCrusher( AEApi.instance().materials().materialCertusQuartzCrystalCharged.stack( 1 ), - AEApi.instance().materials().materialCertusQuartzDust.stack( 1 ) ); - - // fluix - rockCrusher( AEApi.instance().materials().materialFluixCrystal.stack( 1 ), AEApi.instance().materials().materialFluixDust.stack( 1 ) ); - - // nether quartz - rockCrusher( new ItemStack( Item.netherQuartz ), AEApi.instance().materials().materialNetherQuartzDust.stack( 1 ) ); - } -} diff --git a/integration/modules/helpers/NEIAEShapedRecipeHandler.java b/integration/modules/helpers/NEIAEShapedRecipeHandler.java index 8665e9b9e..ab3621074 100644 --- a/integration/modules/helpers/NEIAEShapedRecipeHandler.java +++ b/integration/modules/helpers/NEIAEShapedRecipeHandler.java @@ -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) ) { diff --git a/integration/modules/helpers/NEIAEShapelessRecipeHandler.java b/integration/modules/helpers/NEIAEShapelessRecipeHandler.java index db189bac2..b8f81830d 100644 --- a/integration/modules/helpers/NEIAEShapelessRecipeHandler.java +++ b/integration/modules/helpers/NEIAEShapelessRecipeHandler.java @@ -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) ) { diff --git a/integration/modules/helpers/NEICraftingHandler.java b/integration/modules/helpers/NEICraftingHandler.java new file mode 100644 index 000000000..58a712335 --- /dev/null +++ b/integration/modules/helpers/NEICraftingHandler.java @@ -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 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) 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) + { + } + } +} diff --git a/integration/modules/helpers/NEIGrinderRecipeHandler.java b/integration/modules/helpers/NEIGrinderRecipeHandler.java new file mode 100644 index 000000000..79235d2b2 --- /dev/null +++ b/integration/modules/helpers/NEIGrinderRecipeHandler.java @@ -0,0 +1,208 @@ +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.Minecraft; +import net.minecraft.client.gui.FontRenderer; +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.api.AEApi; +import appeng.api.features.IGrinderEntry; +import appeng.client.gui.implementations.GuiInscriber; +import appeng.core.localization.GuiText; +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 NEIGrinderRecipeHandler extends TemplateRecipeHandler +{ + + public void drawBackground(int recipe) + { + GL11.glColor4f( 1, 1, 1, 1 ); + changeTexture( getGuiTexture() ); + drawTexturedModalRect( 40, 10, 75, 16 + 10, 90, 66 ); + } + + @Override + public void drawForeground(int recipe) + { + super.drawForeground( recipe ); + if ( this.arecipes.size() > recipe ) + { + CachedRecipe cr = this.arecipes.get( recipe ); + if ( cr instanceof CachedGrindStoneRecipe ) + { + CachedGrindStoneRecipe cgsr = (CachedGrindStoneRecipe) cr; + if ( cgsr.hasOptional ) + { + FontRenderer fr = Minecraft.getMinecraft().fontRenderer; + int width = fr.getStringWidth( cgsr.Chance ); + fr.drawString( cgsr.Chance, (168 - width) / 2, 5, 0 ); + } + else + { + FontRenderer fr = Minecraft.getMinecraft().fontRenderer; + int width = fr.getStringWidth( GuiText.NoSecondOutput.getLocal() ); + fr.drawString( GuiText.NoSecondOutput.getLocal(), (168 - width) / 2, 5, 0 ); + } + } + } + } + + public void loadTransferRects() + { + this.transferRects.add( new TemplateRecipeHandler.RecipeTransferRect( new Rectangle( 84, 23, 24, 18 ), "inscriber", new Object[0] ) ); + } + + public Class getGuiClass() + { + return GuiInscriber.class; + } + + @Override + public String getRecipeName() + { + return GuiText.GrindStone.getLocal(); + } + + @Override + public void loadCraftingRecipes(String outputId, Object... results) + { + if ( (outputId.equals( "grindstone" )) && (getClass() == NEIGrinderRecipeHandler.class) ) + { + for (IGrinderEntry irecipe : AEApi.instance().registries().grinder().getRecipes()) + { + CachedGrindStoneRecipe recipe = new CachedGrindStoneRecipe( irecipe ); + if ( recipe != null ) + { + recipe.computeVisuals(); + this.arecipes.add( recipe ); + } + } + } + else + { + super.loadCraftingRecipes( outputId, results ); + } + } + + public void loadCraftingRecipes(ItemStack result) + { + for (IGrinderEntry irecipe : AEApi.instance().registries().grinder().getRecipes()) + { + if ( NEIServerUtils.areStacksSameTypeCrafting( irecipe.getOutput(), result ) ) + { + CachedGrindStoneRecipe recipe = new CachedGrindStoneRecipe( irecipe ); + recipe.computeVisuals(); + this.arecipes.add( recipe ); + } + } + } + + public void loadUsageRecipes(ItemStack ingredient) + { + for (IGrinderEntry irecipe : AEApi.instance().registries().grinder().getRecipes()) + { + CachedGrindStoneRecipe recipe = new CachedGrindStoneRecipe( 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/grinder.png" ); + String f = loc.toString(); + return f; + } + + public String getOverlayIdentifier() + { + return "grindstone"; + } + + @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 CachedGrindStoneRecipe extends TemplateRecipeHandler.CachedRecipe + { + + public ArrayList ingredients; + public PositionedStack result; + + boolean hasOptional = false; + public String Chance; + + public CachedGrindStoneRecipe(IGrinderEntry irecipe) { + result = new PositionedStack( irecipe.getOutput(), -30 + 107, 47 ); + ingredients = new ArrayList(); + + if ( irecipe.getOptionalOutput() != null ) + { + hasOptional = true; + Chance = ((int) (irecipe.getOptionalChance() * 100)) + GuiText.OfSecondOutput.getLocal(); + ingredients.add( new PositionedStack( irecipe.getOptionalOutput(), -30 + 107 + 18, 47 ) ); + } + + if ( irecipe.getInput() != null ) + ingredients.add( new PositionedStack( irecipe.getInput(), 45, 24 ) ); + } + + @Override + public List 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(); + } + } +} \ No newline at end of file diff --git a/integration/modules/helpers/NEIInscriberRecipeHandler.java b/integration/modules/helpers/NEIInscriberRecipeHandler.java new file mode 100644 index 000000000..497320670 --- /dev/null +++ b/integration/modules/helpers/NEIInscriberRecipeHandler.java @@ -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 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 ingredients; + public PositionedStack result; + + public CachedInscriberRecipe(InscriberRecipe irecipe) { + result = new PositionedStack( irecipe.output, 108, 29 ); + ingredients = new ArrayList(); + + 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 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(); + } + } +} \ No newline at end of file diff --git a/integration/modules/helpers/NEIWorldCraftingHandler.java b/integration/modules/helpers/NEIWorldCraftingHandler.java new file mode 100644 index 000000000..ed9f71293 --- /dev/null +++ b/integration/modules/helpers/NEIWorldCraftingHandler.java @@ -0,0 +1,197 @@ +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.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; + +import org.lwjgl.opengl.GL11; + +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.NEIServerUtils; +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 details = new HashMap(); + List offsets = new LinkedList(); + List outputs = new LinkedList(); + + ItemStack target; + + private void addRecipe(AEItemDefinition def, String msg) + { + if ( NEIServerUtils.areStacksSameTypeCrafting( def.stack( 1 ), target ) ) + { + offsets.add( def ); + outputs.add( new PositionedStack( def.stack( 1 ), 75, 4 ) ); + details.put( def, msg ); + } + } + + private void addRecipes() + { + 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(); + } + + public void drawBackground(int recipe) + { + GL11.glColor4f( 1, 1, 1, 1 );// nothing. + } + + @Override + public void drawForeground(int recipe) + { + if ( this.outputs.size() > recipe ) + { + // PositionedStack cr = this.outputs.get( recipe ); + String details = this.details.get( this.offsets.get( recipe ) ); + + FontRenderer fr = Minecraft.getMinecraft().fontRenderer; + fr.drawSplitString( details, 10, 25, 150, 0 ); + } + } + + @Override + public List getIngredientStacks(int recipe) + { + return new ArrayList(); + } + + @Override + public List getOtherStacks(int recipetype) + { + return new ArrayList(); + } + + @Override + public PositionedStack getResultStack(int recipe) + { + return outputs.get( recipe ); + } + + @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 handleTooltip(GuiRecipe gui, List currenttip, int recipe) + { + return currenttip; + } + + @Override + public List handleItemTooltip(GuiRecipe gui, ItemStack stack, List currenttip, int recipe) + { + return currenttip; + } + + @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; + } + + public NEIWorldCraftingHandler newInstance() + { + try + { + return getClass().newInstance(); + } + catch (Exception e) + { + throw new RuntimeException( e ); + } + } + + @Override + public IUsageHandler getUsageHandler(String inputId, Object... ingredients) + { + return this; + } + + @Override + public ICraftingHandler getRecipeHandler(String outputId, Object... results) + { + NEIWorldCraftingHandler g = newInstance(); + if ( results.length > 0 && results[0] instanceof ItemStack ) + { + g.target = (ItemStack) results[0]; + g.addRecipes(); + return g; + } + return this; + } + +} \ No newline at end of file diff --git a/integration/modules/helpers/NullRFHandler.java b/integration/modules/helpers/NullRFHandler.java new file mode 100644 index 000000000..d0249d655 --- /dev/null +++ b/integration/modules/helpers/NullRFHandler.java @@ -0,0 +1,38 @@ +package appeng.integration.modules.helpers; +import net.minecraftforge.common.util.ForgeDirection; +import cofh.api.energy.IEnergyHandler; + +public class NullRFHandler implements IEnergyHandler +{ + + @Override + public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) + { + return 0; + } + + @Override + public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) + { + return 0; + } + + @Override + public boolean canInterface(ForgeDirection from) + { + return true; + } + + @Override + public int getEnergyStored(ForgeDirection from) + { + return 0; + } + + @Override + public int getMaxEnergyStored(ForgeDirection from) + { + return 0; + } + +} diff --git a/integration/modules/helpers/dead/GregTechHandler.java b/integration/modules/helpers/dead/GregTechHandler.java index baf990cac..d9e7dea48 100644 --- a/integration/modules/helpers/dead/GregTechHandler.java +++ b/integration/modules/helpers/dead/GregTechHandler.java @@ -1,7 +1,8 @@ -package appeng.integration.modules.helpers.dead; +package appeng.integration.modules.helpers; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.networking.security.BaseActionSource; import appeng.api.storage.IExternalStorageHandler; import appeng.api.storage.IMEInventory; import appeng.api.storage.StorageChannel; @@ -17,9 +18,9 @@ public class GregTechHandler implements IExternalStorageHandler } @Override - public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel chan) + public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel channel, BaseActionSource src) { - if ( chan == StorageChannel.ITEMS ) + if ( channel == StorageChannel.ITEMS ) return GT.instance.getQuantumChest( te ); return null; } diff --git a/integration/modules/helpers/dead/GregTechQuantumChest.java b/integration/modules/helpers/dead/GregTechQuantumChest.java index f321417a7..14635e72b 100644 --- a/integration/modules/helpers/dead/GregTechQuantumChest.java +++ b/integration/modules/helpers/dead/GregTechQuantumChest.java @@ -1,6 +1,6 @@ -package appeng.integration.modules.helpers.dead; +package appeng.integration.modules.helpers; -import gregtechmod.api.interfaces.IDigitalChest; +import gregtech.api.interfaces.tileentity.IDigitalChest; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import appeng.api.config.Actionable; @@ -24,7 +24,7 @@ public class GregTechQuantumChest extends MEIInventoryWrapper private ItemStack getType() { ItemStack[] array = qc.getStoredItemData(); - if ( array.length > 0 && array[0].itemID > 0 ) + if ( array.length > 0 && array[0].getItem() != null ) return array[0]; return null; } diff --git a/items/materials/ItemMaterial.java b/items/materials/ItemMaterial.java index f669bab3e..d032d0acf 100644 --- a/items/materials/ItemMaterial.java +++ b/items/materials/ItemMaterial.java @@ -25,6 +25,7 @@ import appeng.api.config.Upgrades; import appeng.api.implementations.items.IItemGroup; import appeng.api.implementations.items.IStorageComponent; import appeng.api.implementations.items.IUpgradeModule; +import appeng.client.texture.MissingIcon; import appeng.core.AEConfig; import appeng.core.features.AEFeature; import appeng.core.features.AEFeatureHandler; @@ -156,13 +157,17 @@ public class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgr public MaterialType getTypeByStack(ItemStack is) { - return dmgToMaterial.get( is.getItemDamage() ); + if ( dmgToMaterial.containsKey( is.getItemDamage() ) ) + return dmgToMaterial.get( is.getItemDamage() ); + return null; } @Override public IIcon getIconFromDamage(int dmg) { - return dmgToMaterial.get( dmg ).IIcon; + if ( dmgToMaterial.containsKey( dmg ) ) + return dmgToMaterial.get( dmg ).IIcon; + return new MissingIcon( this ); } private String nameOf(ItemStack is) diff --git a/items/parts/ItemPart.java b/items/parts/ItemPart.java index 85e261694..9299c542d 100644 --- a/items/parts/ItemPart.java +++ b/items/parts/ItemPart.java @@ -80,7 +80,7 @@ public class ItemPart extends AEBaseItem implements IPartItem, IItemGroup if ( enabled ) { - int newPartNum = AEConfig.instance.get( "parts", name, AEConfig.instance.getFreePart( varID ) ).getInt(); + int newPartNum = AEConfig.instance.get( "parts", name, AEConfig.instance.getFreePart( mat.ordinal() * 32 + varID ) ).getInt(); ItemStackSrc output = new ItemStackSrc( this, newPartNum ); PartTypeIst pti = new PartTypeIst(); diff --git a/items/parts/PartType.java b/items/parts/PartType.java index 1e3f56ab8..c48a2344e 100644 --- a/items/parts/PartType.java +++ b/items/parts/PartType.java @@ -25,6 +25,7 @@ import appeng.parts.p2p.PartP2PBCPower; import appeng.parts.p2p.PartP2PIC2Power; import appeng.parts.p2p.PartP2PItems; import appeng.parts.p2p.PartP2PLiquids; +import appeng.parts.p2p.PartP2PRFPower; import appeng.parts.p2p.PartP2PRedstone; import appeng.parts.p2p.PartP2PTunnelME; import appeng.parts.reporting.PartConversionMonitor; @@ -92,7 +93,9 @@ public enum PartType ConversionMonitor(AEFeature.PartConversionMonitor, PartConversionMonitor.class), - Interface(AEFeature.Core, PartInterface.class); + Interface(AEFeature.Core, PartInterface.class), + + P2PTunnelRF(AEFeature.P2PTunnelRF, PartP2PRFPower.class, GuiText.RFTunnel); private final EnumSet features; private final Class myPart; diff --git a/items/tools/ToolNetworkTool.java b/items/tools/ToolNetworkTool.java index 802e171fe..e88ea42a0 100644 --- a/items/tools/ToolNetworkTool.java +++ b/items/tools/ToolNetworkTool.java @@ -8,12 +8,16 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import appeng.api.implementations.guiobjects.IGuiItem; import appeng.api.implementations.guiobjects.IGuiItemObject; import appeng.api.implementations.items.IAEWrench; import appeng.api.networking.IGridHost; +import appeng.api.parts.IPartHost; +import appeng.api.parts.SelectedPart; +import appeng.api.util.INetworkToolAgent; import appeng.client.ClientHelper; import appeng.container.AEBaseContainer; import appeng.core.AELog; @@ -72,6 +76,22 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench, @Override public boolean onItemUseFirst(ItemStack is, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { + MovingObjectPosition mop = new MovingObjectPosition( x, y, z, side, Vec3.createVectorHelper( hitX, hitY, hitZ ) ); + TileEntity te = world.getTileEntity( x, y, z ); + if ( te instanceof IPartHost ) + { + SelectedPart part = ((IPartHost) te).selectPart( mop.hitVec ); + if ( part.part != null ) + { + if ( part.part instanceof INetworkToolAgent && !((INetworkToolAgent) part.part).showNetworkInfo( mop ) ) + return false; + } + } + else if ( te instanceof INetworkToolAgent && !((INetworkToolAgent) te).showNetworkInfo( mop ) ) + { + return false; + } + if ( Platform.isClient() ) { try @@ -110,10 +130,12 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench, return true; TileEntity te = w.getTileEntity( x, y, z ); + if ( te instanceof IGridHost ) Platform.openGUI( p, te, ForgeDirection.getOrientation( side ), GuiBridge.GUI_NETWORK_STATUS ); else Platform.openGUI( p, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_NETWORK_TOOL ); + return true; } else diff --git a/me/storage/NetworkInventoryHandler.java b/me/storage/NetworkInventoryHandler.java index fc20055fd..cd4374464 100644 --- a/me/storage/NetworkInventoryHandler.java +++ b/me/storage/NetworkInventoryHandler.java @@ -59,20 +59,31 @@ public class NetworkInventoryHandler> implements IMEInvent static int currentPass = 0; int myPass = 0; - final static public LinkedList depth = new LinkedList(); + static final ThreadLocal depth = new ThreadLocal(); + + private LinkedList getDepth() + { + LinkedList s = depth.get(); + + if ( s == null ) + depth.set( s = new LinkedList() ); + + return s; + } private boolean diveList(NetworkInventoryHandler networkInventoryHandler) { - if ( depth.contains( networkInventoryHandler ) ) + LinkedList cDepth = getDepth(); + if ( cDepth.contains( networkInventoryHandler ) ) return true; - depth.push( this ); + cDepth.push( this ); return false; } private boolean diveIteration(NetworkInventoryHandler networkInventoryHandler) { - if ( depth.isEmpty() ) + if ( getDepth().isEmpty() ) { currentPass++; myPass = currentPass; @@ -85,14 +96,13 @@ public class NetworkInventoryHandler> implements IMEInvent myPass = currentPass; } - depth.push( this ); + getDepth().push( this ); return false; } private void surface(NetworkInventoryHandler networkInventoryHandler) { - Object last = depth.pop(); - if ( last != this ) + if ( getDepth().pop() != this ) throw new RuntimeException( "Invalid Access to Networked Storage API detected." ); } diff --git a/parts/AEBasePart.java b/parts/AEBasePart.java index 5f4bab9a1..4e1b4265c 100644 --- a/parts/AEBasePart.java +++ b/parts/AEBasePart.java @@ -19,6 +19,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; import appeng.api.config.Upgrades; import appeng.api.implementations.IUpgradeableHost; import appeng.api.implementations.items.IMemoryCard; @@ -370,7 +371,14 @@ public class AEBasePart implements IPart, IGridProxyable, IActionHost, IUpgradea if ( memCardIS != null && useStandardMemoryCard() && memCardIS.getItem() instanceof IMemoryCard ) { IMemoryCard memc = (IMemoryCard) memCardIS.getItem(); - String name = getItemStack( PartItemStack.Network ).getUnlocalizedName(); + + ItemStack is = getItemStack( PartItemStack.Network ); + + // Blocks and parts share the same soul! + if ( AEApi.instance().parts().partInterface.sameAs( is ) ) + is = AEApi.instance().blocks().blockInterface.stack( 1 ); + + String name = is.getUnlocalizedName(); if ( player.isSneaking() ) { diff --git a/parts/CableBusContainer.java b/parts/CableBusContainer.java index 04f76723a..e96ee684f 100644 --- a/parts/CableBusContainer.java +++ b/parts/CableBusContainer.java @@ -244,7 +244,7 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer partChanged(); return ForgeDirection.UNKNOWN; } - else if ( !(bp instanceof IPartCable) && side != ForgeDirection.UNKNOWN ) + else if ( bp != null && !(bp instanceof IPartCable) && side != ForgeDirection.UNKNOWN ) { IPart cable = getPart( ForgeDirection.UNKNOWN ); if ( cable != null && !bp.canBePlacedOn( ((IPartCable) cable).supportsBuses() ) ) @@ -386,7 +386,7 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer return null; } - public Iterable getSelectedBoundingBoxsFromPool(boolean ignoreCableConnections, Entity e, boolean visual) + public Iterable getSelectedBoundingBoxsFromPool(boolean ignoreCableConnections, boolean includeFacades, Entity e, boolean visual) { List boxes = new LinkedList(); @@ -394,13 +394,6 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer { IPartCollsionHelper bch = new BusCollisionHelper( boxes, s, e, visual ); - if ( s != ForgeDirection.UNKNOWN ) - { - IFacadePart fpa = fc.getFacade( s ); - if ( fpa != null ) - fpa.getBoxes( bch ); - } - IPart part = getPart( s ); if ( part != null ) { @@ -411,7 +404,7 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer } - if ( !ignoreCableConnections && s != null && s != ForgeDirection.UNKNOWN ) + if ( includeFacades && s != null && s != ForgeDirection.UNKNOWN ) { IFacadePart fp = fc.getFacade( s ); if ( fp != null ) diff --git a/parts/PartPlacement.java b/parts/PartPlacement.java index f57c0df70..685caf646 100644 --- a/parts/PartPlacement.java +++ b/parts/PartPlacement.java @@ -6,11 +6,13 @@ import java.util.List; import net.minecraft.block.Block; import net.minecraft.block.Block.SoundType; +import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.ForgeDirection; @@ -42,7 +44,26 @@ public class PartPlacement @SubscribeEvent public void playerInteract(PlayerInteractEvent event) { - if ( event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote ) + if ( event.action == Action.RIGHT_CLICK_AIR && event.entityPlayer.worldObj.isRemote ) + { + // re-check to see if this event was already channeled, cause these two events are really stupid... + MovingObjectPosition mop = Platform.rayTrace( event.entityPlayer, true, false ); + Minecraft mc = Minecraft.getMinecraft(); + + float f = 1.0F; + double d0 = (double) mc.playerController.getBlockReachDistance(); + double d1 = d0; + Vec3 vec3 = mc.renderViewEntity.getPosition( f ); + + if ( mop != null && mop.hitVec.distanceTo( vec3 ) < d0 ) + { + World w = event.entity.worldObj; + TileEntity te = w.getTileEntity( mop.blockX, mop.blockY, mop.blockZ ); + if ( te instanceof IPartHost ) + event.setCanceled( true ); + } + } + else if ( event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote ) { if ( placing.get() != null ) return; diff --git a/parts/misc/PartInterface.java b/parts/misc/PartInterface.java index 5f8d4fd55..3fc20e63c 100644 --- a/parts/misc/PartInterface.java +++ b/parts/misc/PartInterface.java @@ -1,5 +1,7 @@ package appeng.parts.misc; +import java.util.List; + import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; @@ -22,6 +24,7 @@ import appeng.api.storage.IMEMonitor; import appeng.api.storage.IStorageMonitorable; import appeng.api.storage.data.IAEFluidStack; import appeng.api.storage.data.IAEItemStack; +import appeng.api.util.IConfigManager; import appeng.client.texture.CableBusTextures; import appeng.core.sync.GuiBridge; import appeng.helpers.DualityInterface; @@ -64,6 +67,22 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISeg duality.readFromNBT( data ); } + @Override + public void getDrops(List drops, boolean wrenched) + { + IInventory inv = duality.getInternalInventory(); + for (int l = 0; l < inv.getSizeInventory(); l++) + { + ItemStack is = inv.getStackInSlot( l ); + + if ( is != null ) + { + drops.add( is ); + inv.setInventorySlotContents( l, (ItemStack) null ); + } + } + } + @Override @SideOnly(Side.CLIENT) public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer) @@ -205,6 +224,18 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISeg return duality.getStorage().getInventoryStackLimit(); } + @Override + public IConfigManager getConfigManager() + { + return duality.getConfigManager(); + } + + @Override + public IInventory getInventoryByName(String name) + { + return duality.getInventoryByName( name ); + } + @Override public void markDirty() { diff --git a/parts/networking/PartQuartzFiber.java b/parts/networking/PartQuartzFiber.java index 8f3e62e3d..6bd5e3e75 100644 --- a/parts/networking/PartQuartzFiber.java +++ b/parts/networking/PartQuartzFiber.java @@ -37,6 +37,8 @@ public class PartQuartzFiber extends AEBasePart implements IEnergyGridProvider super( PartQuartzFiber.class, is ); proxy.setIdlePowerUsage( 0 ); proxy.setFlags( GridFlags.CANNOT_CARRY ); + outerProxy.setIdlePowerUsage( 0 ); + outerProxy.setFlags( GridFlags.CANNOT_CARRY ); } @Override diff --git a/parts/p2p/PartP2PBCPower.java b/parts/p2p/PartP2PBCPower.java index 31ddc9088..fd5db110d 100644 --- a/parts/p2p/PartP2PBCPower.java +++ b/parts/p2p/PartP2PBCPower.java @@ -13,7 +13,6 @@ import appeng.api.networking.IGridNode; import appeng.api.networking.ticking.IGridTickable; import appeng.api.networking.ticking.TickRateModulation; import appeng.api.networking.ticking.TickingRequest; -import appeng.core.AEConfig; import appeng.core.AppEng; import appeng.core.settings.TickRates; import appeng.me.GridAccessException; @@ -115,7 +114,7 @@ public class PartP2PBCPower extends PartP2PTunnel implements IPo { double toPull = currentTotal * (howmuch / totalRequiredPower); double pulled = pp.useEnergy( 0, toPull, true ); - QueueTunnelDrain( PowerUnits.MJ, pulled * AEConfig.TunnelPowerLoss ); + QueueTunnelDrain( PowerUnits.MJ, pulled ); tp.receiveEnergy( Type.PIPE, pulled, o.side.getOpposite() ); } diff --git a/parts/p2p/PartP2PIC2Power.java b/parts/p2p/PartP2PIC2Power.java index 578b7d8d3..69f42bfa2 100644 --- a/parts/p2p/PartP2PIC2Power.java +++ b/parts/p2p/PartP2PIC2Power.java @@ -8,6 +8,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.config.PowerUnits; import appeng.api.config.TunnelType; import appeng.core.AppEng; import appeng.me.GridAccessException; @@ -143,6 +144,7 @@ public class PartP2PIC2Power extends PartP2PTunnel implements i PartP2PIC2Power x = (PartP2PIC2Power) Platform.pickRandom( Options ); if ( x != null && x.OutputPacket <= 0.001 ) { + QueueTunnelDrain( PowerUnits.EU, amount ); x.OutputPacket = amount; return 0; } diff --git a/parts/p2p/PartP2PRFPower.java b/parts/p2p/PartP2PRFPower.java new file mode 100644 index 000000000..bd7922645 --- /dev/null +++ b/parts/p2p/PartP2PRFPower.java @@ -0,0 +1,252 @@ +package appeng.parts.p2p; + +import java.util.Stack; + +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.config.PowerUnits; +import appeng.api.config.TunnelType; +import appeng.core.AppEng; +import appeng.integration.modules.helpers.NullRFHandler; +import appeng.me.GridAccessException; +import appeng.transformer.annotations.integration.Interface; +import appeng.transformer.annotations.integration.InterfaceList; +import appeng.util.Platform; +import cofh.api.energy.IEnergyHandler; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@InterfaceList(value = { @Interface(iface = "cofh.api.energy.IEnergyHandler", iname = "RF") }) +public class PartP2PRFPower extends PartP2PTunnel implements cofh.api.energy.IEnergyHandler +{ + + private static final IEnergyHandler myNullHandler = new NullRFHandler(); + + boolean cachedTarget = false; + IEnergyHandler outputTarget; + + public TunnelType getTunnelType() + { + return TunnelType.RF_POWER; + } + + public PartP2PRFPower(ItemStack is) { + super( is ); + + if ( !AppEng.instance.isIntegrationEnabled( "RF" ) ) + throw new RuntimeException( "RF Not installed!" ); + } + + @Override + public void writeToNBT(NBTTagCompound tag) + { + super.writeToNBT( tag ); + } + + @Override + public void readFromNBT(NBTTagCompound tag) + { + super.readFromNBT( tag ); + } + + @Override + public void onNeighborChanged() + { + super.onNeighborChanged(); + cachedTarget = false; + } + + @SideOnly(Side.CLIENT) + public IIcon getTypeTexture() + { + return Blocks.iron_block.getBlockTextureFromSide( 0 ); + } + + @Override + public void onChange() + { + getHost().partChanged(); + } + + public float getPowerDrainPerTick() + { + return 0.5f; + } + + static final ThreadLocal> depth = new ThreadLocal>(); + + private Stack getDepth() + { + Stack s = depth.get(); + + if ( s == null ) + depth.set( s = new Stack() ); + + return s; + } + + @Override + public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) + { + if ( output ) + return 0; + + if ( isActive() ) + { + Stack stack = getDepth(); + + for (PartP2PRFPower t : stack) + if ( t == this ) + return 0; + + stack.push( this ); + + int total = 0; + + try + { + for (PartP2PRFPower t : getOutputs()) + { + if ( Platform.getRandomInt() % 2 > 0 ) + { + int recv = t.getOutput().receiveEnergy( t.side.getOpposite(), maxReceive, simulate ); + maxReceive -= recv; + total += recv; + + if ( maxReceive <= 0 ) + break; + } + } + + if ( maxReceive > 0 ) + { + for (PartP2PRFPower t : getOutputs()) + { + int recv = t.getOutput().receiveEnergy( t.side.getOpposite(), maxReceive, simulate ); + maxReceive -= recv; + total += recv; + + if ( maxReceive <= 0 ) + break; + } + } + + QueueTunnelDrain( PowerUnits.RF, total ); + } + catch (GridAccessException e) + { + } + + if ( stack.pop() != this ) + throw new RuntimeException( "Invalid Recursion detected." ); + + return total; + } + + return 0; + } + + @Override + public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) + { + return 0; + } + + @Override + public boolean canInterface(ForgeDirection from) + { + return true; + } + + @Override + public int getEnergyStored(ForgeDirection from) + { + if ( output || !isActive() ) + return 0; + + int total = 0; + + Stack stack = getDepth(); + + for (PartP2PRFPower t : stack) + if ( t == this ) + return 0; + + stack.push( this ); + + try + { + for (PartP2PRFPower t : getOutputs()) + { + total += t.getOutput().getEnergyStored( t.side.getOpposite() ); + } + } + catch (GridAccessException e) + { + return 0; + } + + if ( stack.pop() != this ) + throw new RuntimeException( "Invalid Recursion detected." ); + + return total; + } + + @Override + public int getMaxEnergyStored(ForgeDirection from) + { + if ( output || !isActive() ) + return 0; + + int total = 0; + + Stack stack = getDepth(); + + for (PartP2PRFPower t : stack) + if ( t == this ) + return 0; + + stack.push( this ); + + try + { + for (PartP2PRFPower t : getOutputs()) + { + total += t.getOutput().getMaxEnergyStored( t.side.getOpposite() ); + } + } + catch (GridAccessException e) + { + return 0; + } + + if ( stack.pop() != this ) + throw new RuntimeException( "Invalid Recursion detected." ); + + return total; + } + + private IEnergyHandler getOutput() + { + if ( output ) + { + if ( !cachedTarget ) + { + TileEntity self = getTile(); + TileEntity te = self.getWorldObj().getTileEntity( self.xCoord + side.offsetX, self.yCoord + side.offsetY, self.zCoord + side.offsetZ ); + outputTarget = te instanceof IEnergyHandler ? (IEnergyHandler) te : null; + cachedTarget = true; + } + + if ( outputTarget == null ) + return myNullHandler; + + return outputTarget; + } + return myNullHandler; + } +} diff --git a/parts/p2p/PartP2PTunnel.java b/parts/p2p/PartP2PTunnel.java index ac3c370aa..65f9732b6 100644 --- a/parts/p2p/PartP2PTunnel.java +++ b/parts/p2p/PartP2PTunnel.java @@ -10,6 +10,8 @@ import net.minecraft.util.IIcon; import net.minecraft.util.Vec3; import net.minecraftforge.common.util.ForgeDirection; import appeng.api.AEApi; +import appeng.api.config.Actionable; +import appeng.api.config.PowerMultiplier; import appeng.api.config.PowerUnits; import appeng.api.config.TunnelType; import appeng.api.implementations.items.IMemoryCard; @@ -20,6 +22,7 @@ import appeng.api.parts.IPartItem; import appeng.api.parts.IPartRenderHelper; import appeng.api.parts.PartItemStack; import appeng.client.texture.CableBusTextures; +import appeng.core.AEConfig; import appeng.me.GridAccessException; import appeng.me.cache.P2PCache; import appeng.me.cache.helpers.TunnelCollection; @@ -118,6 +121,10 @@ public class PartP2PTunnel extends PartBasicState switch (tt) { + case RF_POWER: + newType = AEApi.instance().parts().partP2PTunnelRF.stack( 1 ); + break; + case BC_POWER: newType = AEApi.instance().parts().partP2PTunnelMJ.stack( 1 ); break; @@ -317,10 +324,18 @@ public class PartP2PTunnel extends PartBasicState renderLights( x, y, z, rh, renderer ); } - protected void QueueTunnelDrain(PowerUnits mj, double f) + protected void QueueTunnelDrain(PowerUnits unit, double f) { - // TODO Auto-generated method stub + double ae_to_tax = unit.convertTo( PowerUnits.AE, f * AEConfig.TunnelPowerLoss ); + try + { + proxy.getEnergy().extractAEPower( ae_to_tax, Actionable.MODULATE, PowerMultiplier.ONE ); + } + catch (GridAccessException e) + { + // :P + } } @Override diff --git a/parts/reporting/PartStorageMonitor.java b/parts/reporting/PartStorageMonitor.java index ce9fb3678..df4b61841 100644 --- a/parts/reporting/PartStorageMonitor.java +++ b/parts/reporting/PartStorageMonitor.java @@ -15,6 +15,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; +import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraftforge.common.util.ForgeDirection; @@ -382,4 +383,10 @@ public class PartStorageMonitor extends PartMonitor implements IPartStorageMonit } } + @Override + public boolean showNetworkInfo(MovingObjectPosition where) + { + return false; + } + } diff --git a/recipes/handlers/Crusher.java b/recipes/handlers/Crusher.java new file mode 100644 index 000000000..0e59914da --- /dev/null +++ b/recipes/handlers/Crusher.java @@ -0,0 +1,71 @@ +package appeng.recipes.handlers; + +import java.util.List; + +import net.minecraft.item.ItemStack; +import appeng.api.exceptions.MissingIngredientError; +import appeng.api.exceptions.RecipeError; +import appeng.api.exceptions.RegistrationError; +import appeng.api.recipes.ICraftHandler; +import appeng.api.recipes.IIngredient; +import appeng.core.AELog; +import appeng.core.AppEng; +import appeng.integration.abstraction.IRC; +import appeng.recipes.RecipeHandler; +import appeng.util.Platform; + +public class Crusher implements ICraftHandler, IWebsiteSeralizer +{ + + IIngredient pro_input; + IIngredient pro_output[]; + + @Override + public void setup(List> input, List> output) throws RecipeError + { + if ( input.size() == 1 && output.size() == 1 ) + { + int outs = output.get( 0 ).size(); + if ( input.get( 0 ).size() == 1 && outs == 1 ) + { + pro_input = input.get( 0 ).get( 0 ); + pro_output = output.get( 0 ).toArray( new IIngredient[outs] ); + return; + } + } + new RecipeError( "Crusher must have a single input, and single output." ); + } + + @Override + public void register() throws RegistrationError, MissingIngredientError + { + if ( AppEng.instance.isIntegrationEnabled( "RC" ) ) + { + IRC rc = (IRC) AppEng.instance.getIntegration( "RC" ); + for (ItemStack is : pro_input.getItemStackSet()) + { + try + { + rc.rockCrusher( is, pro_output[0].getItemStack() ); + } + catch (java.lang.RuntimeException err) + { + AELog.info( "RC not happy - " + err.getMessage() ); + } + } + } + } + + @Override + public boolean canCraft(ItemStack output) throws RegistrationError, MissingIngredientError + { + return Platform.isSameItemPrecise( pro_output[0].getItemStack(), output ); + } + + @Override + public String getPattern(RecipeHandler h) + { + return null; + } + +} diff --git a/tile/networking/TileCableBus.java b/tile/networking/TileCableBus.java index 962fcaa84..d61879b23 100644 --- a/tile/networking/TileCableBus.java +++ b/tile/networking/TileCableBus.java @@ -41,7 +41,7 @@ public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomColl public CableBusContainer cb = new CableBusContainer( this ); private int oldLV = -1; // on re-calculate light when it changes - + class CableBusHandler extends AETileEventHandler { @@ -183,7 +183,7 @@ public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomColl @Override public Iterable getSelectedBoundingBoxsFromPool(World w, int x, int y, int z, Entity e, boolean visual) { - return cb.getSelectedBoundingBoxsFromPool( false, e, visual ); + return cb.getSelectedBoundingBoxsFromPool( false, true, e, visual ); } @Override @@ -319,9 +319,10 @@ public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomColl { return cb.getLayerFlags(); } - + @Override - public void cleanup() { + public void cleanup() + { getWorldObj().setBlock( xCoord, yCoord, zCoord, Platform.air ); } diff --git a/transformer/asm/ASMIntegration.java b/transformer/asm/ASMIntegration.java index 7c47818de..0ebfef173 100644 --- a/transformer/asm/ASMIntegration.java +++ b/transformer/asm/ASMIntegration.java @@ -31,7 +31,7 @@ public class ASMIntegration implements IClassTransformer integrationModules.add( IntegrationSide.BOTH, "Rotary Craft", "RotaryCraft", "RotaryCraft" ); integrationModules.add( IntegrationSide.BOTH, "Industrial Craft 2", "IC2", "IC2" ); - // integrationModules.add( IntegrationSide.BOTH, "Railcraft", "Railcraft", "RC" ); + integrationModules.add( IntegrationSide.BOTH, "Railcraft", "Railcraft", "RC" ); // integrationModules.add( IntegrationSide.BOTH, "Thermal Expansion", "ThermalExpansion", "TE" ); // integrationModules.add( IntegrationSide.BOTH, "Mystcraft", "Mystcraft", "Mystcraft" ); integrationModules.add( IntegrationSide.BOTH, "BuildCraft", "BuildCraft|Silicon", "BC" ); @@ -40,7 +40,7 @@ public class ASMIntegration implements IClassTransformer // integrationModules.add( IntegrationSide.BOTH, "Greg Tech", "gregtech_addon", "GT" ); // integrationModules.add( IntegrationSide.BOTH, "Universal Electricity", null, "UE" ); // integrationModules.add( IntegrationSide.BOTH, "Logistics Pipes", "LogisticsPipes|Main", "LP" ); - // integrationModules.add( IntegrationSide.CLIENT, "Inventory Tweaks", "", "InvTweaks" ); + integrationModules.add( IntegrationSide.CLIENT, "Inventory Tweaks", "", "InvTweaks" ); integrationModules.add( IntegrationSide.BOTH, "Mine Factory Reloaded", "MineFactoryReloaded", "MFR" ); integrationModules.add( IntegrationSide.BOTH, "Deep Storage Unit", null, "DSU" ); // integrationModules.add( IntegrationSide.BOTH, "Better Storage", "betterstorage" ); diff --git a/util/Platform.java b/util/Platform.java index 7caf2f3a2..8bd73d5fa 100644 --- a/util/Platform.java +++ b/util/Platform.java @@ -1595,4 +1595,54 @@ public class Platform } } + public static ItemStack extractItemsByRecipe(IEnergySource energySrc, BaseActionSource mySrc, IMEMonitor src, World w, IRecipe r, + ItemStack output, InventoryCrafting ci, ItemStack providedTemplate, int slot, IItemList 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; + } + }