diff --git a/block/AEBaseBlock.java b/block/AEBaseBlock.java index ee1f840a..8088535b 100644 --- a/block/AEBaseBlock.java +++ b/block/AEBaseBlock.java @@ -289,7 +289,7 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature return null; } - final public T getTileEntity(IBlockAccess w, int x, int y, int z) + public T getTileEntity(IBlockAccess w, int x, int y, int z) { if ( !hasBlockTileEntity() ) return null; diff --git a/block/networking/BlockCableBus.java b/block/networking/BlockCableBus.java index bfa679c0..608feca0 100644 --- a/block/networking/BlockCableBus.java +++ b/block/networking/BlockCableBus.java @@ -24,8 +24,10 @@ import appeng.api.parts.PartItemStack; import appeng.api.parts.SelectedPart; import appeng.block.AEBaseBlock; import appeng.client.render.BaseBlockRender; +import appeng.client.render.BusRenderHelper; import appeng.client.render.blocks.RendererCableBus; import appeng.client.texture.ExtraTextures; +import appeng.core.AEConfig; import appeng.core.Api; import appeng.core.AppEng; import appeng.core.CommonHelper; @@ -35,12 +37,28 @@ import appeng.parts.ICableBusContainer; import appeng.parts.NullCableBusContainer; import appeng.tile.AEBaseTile; import appeng.tile.networking.TileCableBus; +import appeng.tile.networking.TileCableBusTESR; import appeng.util.Platform; public class BlockCableBus extends AEBaseBlock { static private ICableBusContainer nullCB = new NullCableBusContainer(); + static public Class noTesrTile; + static public Class tesrTile; + + public T getTileEntity(IBlockAccess w, int x, int y, int z) + { + TileEntity te = w.getTileEntity( x, y, z ); + + if ( noTesrTile.isInstance( te ) ) + return (T) te; + + if ( tesrTile.isInstance( te ) ) + return (T) te; + + return null; + } public BlockCableBus() { super( BlockCableBus.class, Material.glass ); @@ -49,6 +67,25 @@ public class BlockCableBus extends AEBaseBlock isFullSize = isOpaque = false; } + @Override + public int getRenderBlockPass() + { + if ( AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) ) + return 1; + return 0; + } + + @Override + public boolean canRenderInPass(int pass) + { + BusRenderHelper.instance.setPass( pass ); + + if ( AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) ) + return true; + + return pass == 0; + } + @Override public boolean isLadder(IBlockAccess world, int x, int y, int z, EntityLivingBase entity) { @@ -229,9 +266,12 @@ public class BlockCableBus extends AEBaseBlock public void setupTile() { - setTileEntiy( Api.instance.partHelper.getCombinedInstance( TileCableBus.class.getName() ) ); + setTileEntiy( noTesrTile = Api.instance.partHelper.getCombinedInstance( TileCableBus.class.getName() ) ); if ( Platform.isClient() ) - CommonHelper.proxy.bindTileEntitySpecialRenderer( getTileEntityClass(), this ); + { + tesrTile = Api.instance.partHelper.getCombinedInstance( TileCableBusTESR.class.getName() ); + CommonHelper.proxy.bindTileEntitySpecialRenderer( tesrTile, this ); + } } private ICableBusContainer cb(IBlockAccess w, int x, int y, int z) diff --git a/client/gui/implementations/GuiNetworkStatus.java b/client/gui/implementations/GuiNetworkStatus.java index 57c340ba..c20a7202 100644 --- a/client/gui/implementations/GuiNetworkStatus.java +++ b/client/gui/implementations/GuiNetworkStatus.java @@ -6,7 +6,6 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import net.minecraft.util.StatCollector; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; @@ -168,7 +167,7 @@ public class GuiNetworkStatus extends AEBaseGui implements ISortSource String str = Long.toString( refStack.getStackSize() ); if ( refStack.getStackSize() >= 10000 ) - str = Long.toString( refStack.getStackSize() / 1000 ) + StatCollector.translateToLocal( "AppEng.Sizes.1000" ); + str = Long.toString( refStack.getStackSize() / 1000 ) + "k"; int w = fontRendererObj.getStringWidth( str ); fontRendererObj.drawString( str, (int) ((x * sectionLength + xo + sectionLength - 19 - ((float) w * 0.5)) * 2), (int) ((y * 18 + yo + 6) * 2), diff --git a/client/render/BusRenderHelper.java b/client/render/BusRenderHelper.java index e9f24c76..6f41739e 100644 --- a/client/render/BusRenderHelper.java +++ b/client/render/BusRenderHelper.java @@ -13,6 +13,8 @@ import appeng.api.parts.IPartCollsionHelper; import appeng.api.parts.IPartRenderHelper; import appeng.api.parts.ISimplifiedBundle; import appeng.block.AEBaseBlock; +import appeng.core.AEConfig; +import appeng.core.features.AEFeature; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -103,6 +105,39 @@ public class BusRenderHelper implements IPartRenderHelper BoundBoxCalculator bbc = new BoundBoxCalculator(); + int renderingForPass = 0; + int currentPass = 0; + int itemsRendered = 0; + boolean noAlphaPass = AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) == false; + + public int getItemsRendered() + { + return itemsRendered; + } + + public void setPass(int pass) + { + renderingForPass = 0; + currentPass = pass; + itemsRendered = 0; + } + + @Override + public void renderForPass(int pass) + { + renderingForPass = pass; + } + + public boolean renderThis() + { + if ( renderingForPass == currentPass || noAlphaPass ) + { + itemsRendered++; + return true; + } + return false; + } + @Override public void normalRendering() { @@ -255,6 +290,9 @@ public class BusRenderHelper implements IPartRenderHelper @Override public void renderBlock(int x, int y, int z, RenderBlocks renderer) { + if ( !renderThis() ) + return; + AEBaseBlock blk = (AEBaseBlock) AEApi.instance().blocks().blockMultiPart.block(); BlockRenderInfo info = blk.getRendererInstance(); ForgeDirection forward = BusRenderHelper.instance.az; @@ -285,14 +323,26 @@ public class BusRenderHelper implements IPartRenderHelper bbr.renderBlockBounds( renderer, minX, minY, minZ, maxX, maxY, maxZ, ax, ay, az ); } + @Override + public void setFacesToRender(EnumSet faces) + { + BusRenderer.instance.renderer.faces = faces; + } + public void renderBlockCurrentBounds(int x, int y, int z, RenderBlocks renderer) { + if ( !renderThis() ) + return; + renderer.renderStandardBlock( renderer.blockAccess.getBlock( x, y, z ), x, y, z ); } @Override public void renderFaceCutout(int x, int y, int z, IIcon ico, ForgeDirection face, float edgeThickness, RenderBlocks renderer) { + if ( !renderThis() ) + return; + switch (face) { case DOWN: @@ -325,6 +375,9 @@ public class BusRenderHelper implements IPartRenderHelper @Override public void renderFace(int x, int y, int z, IIcon ico, ForgeDirection face, RenderBlocks renderer) { + if ( !renderThis() ) + return; + prepareBounds( renderer ); switch (face) { diff --git a/client/render/BusRenderer.java b/client/render/BusRenderer.java index 63a21117..358c3569 100644 --- a/client/render/BusRenderer.java +++ b/client/render/BusRenderer.java @@ -10,10 +10,13 @@ import net.minecraftforge.common.util.ForgeDirection; import org.lwjgl.opengl.GL11; +import appeng.api.parts.IAlphaPassItem; import appeng.api.parts.IFacadePart; import appeng.api.parts.IPart; import appeng.api.parts.IPartItem; import appeng.client.ClientHelper; +import appeng.core.AEConfig; +import appeng.core.features.AEFeature; import appeng.facade.IFacadeItem; import appeng.util.Platform; import cpw.mods.fml.relauncher.Side; @@ -63,11 +66,24 @@ public class BusRenderer implements IItemRenderer GL11.glPushMatrix(); GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); - GL11.glEnable( GL11.GL_ALPHA_TEST ); GL11.glEnable( GL11.GL_DEPTH_TEST ); GL11.glEnable( GL11.GL_TEXTURE_2D ); GL11.glEnable( GL11.GL_LIGHTING ); - GL11.glDisable( GL11.GL_BLEND ); + + if ( AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) && item.getItem() instanceof IAlphaPassItem + && ((IAlphaPassItem) item.getItem()).useAlphaPass( item ) ) + { + GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA ); + GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); + GL11.glDisable( GL11.GL_ALPHA_TEST ); + GL11.glEnable( GL11.GL_BLEND ); + } + else + { + GL11.glAlphaFunc( GL11.GL_GREATER, 0.4f ); + GL11.glEnable( GL11.GL_ALPHA_TEST ); + GL11.glDisable( GL11.GL_BLEND ); + } if ( type == ItemRenderType.EQUIPPED_FIRST_PERSON ) { @@ -79,7 +95,6 @@ public class BusRenderer implements IItemRenderer GL11.glRotatef( 90.0f, 0.0f, 1.0f, 0.0f ); GL11.glScalef( 0.8f, 0.8f, 0.8f ); GL11.glTranslatef( -0.8f, -0.87f, -0.7f ); - } if ( type == ItemRenderType.INVENTORY ) diff --git a/client/render/blocks/RendererCableBus.java b/client/render/blocks/RendererCableBus.java index 3fe3b50f..04bb15cd 100644 --- a/client/render/blocks/RendererCableBus.java +++ b/client/render/blocks/RendererCableBus.java @@ -7,6 +7,7 @@ import net.minecraft.world.IBlockAccess; import net.minecraftforge.client.IItemRenderer.ItemRenderType; import appeng.block.AEBaseBlock; import appeng.client.render.BaseBlockRender; +import appeng.client.render.BusRenderHelper; import appeng.client.render.BusRenderer; import appeng.tile.AEBaseTile; import appeng.tile.networking.TileCableBus; @@ -38,7 +39,7 @@ public class RendererCableBus extends BaseBlockRender BusRenderer.instance.renderer.renderAllFaces = false; } - return true; + return BusRenderHelper.instance.getItemsRendered() > 0; } @Override diff --git a/core/AELog.java b/core/AELog.java index 3c7956c7..743d024e 100644 --- a/core/AELog.java +++ b/core/AELog.java @@ -40,7 +40,10 @@ public class AELog public static void grinder(String o) { - log( Level.DEBUG, "grinder: " + o ); + if ( AEConfig.instance.isFeatureEnabled( AEFeature.GrinderLogging ) ) + { + log( Level.DEBUG, "grinder: " + o ); + } } public static void error(Throwable e) diff --git a/core/Registration.java b/core/Registration.java index f5ea161a..ea7e6cca 100644 --- a/core/Registration.java +++ b/core/Registration.java @@ -92,12 +92,12 @@ import appeng.hooks.AETrading; import appeng.hooks.MeteoriteWorldGen; import appeng.hooks.QuartzWorldGen; import appeng.hooks.TickHandler; -import appeng.items.materials.ItemMaterial; +import appeng.items.materials.ItemMultiMaterial; import appeng.items.materials.MaterialType; import appeng.items.misc.ItemCrystalSeed; import appeng.items.misc.ItemEncodedPattern; import appeng.items.parts.ItemFacade; -import appeng.items.parts.ItemPart; +import appeng.items.parts.ItemMultiPart; import appeng.items.parts.PartType; import appeng.items.storage.ItemBasicStorageCell; import appeng.items.storage.ItemCreativeStorageCell; @@ -126,6 +126,8 @@ import appeng.me.cache.SecurityCache; import appeng.me.cache.SpatialPylonCache; import appeng.me.cache.TickManagerCache; import appeng.me.storage.AEExternalHandler; +import appeng.migration.OldItemMaterial; +import appeng.migration.OldItemPart; import appeng.parts.PartPlacement; import appeng.recipes.AEItemResolver; import appeng.recipes.RecipeHandler; @@ -205,7 +207,7 @@ public class Registration Parts parts = appeng.core.Api.instance.parts(); Blocks blocks = appeng.core.Api.instance.blocks(); - AEItemDefinition materialItem = (AEFeatureHandler) addFeature( ItemMaterial.class ); + AEItemDefinition materialItem = (AEFeatureHandler) addFeature( ItemMultiMaterial.class ); Class materialClass = materials.getClass(); for (MaterialType mat : MaterialType.values()) @@ -213,7 +215,7 @@ public class Registration try { Field f = materialClass.getField( "material" + mat.name() ); - ItemStackSrc is = ((ItemMaterial) materialItem.item()).createMaterial( mat ); + ItemStackSrc is = ((ItemMultiMaterial) materialItem.item()).createMaterial( mat ); if ( is != null ) f.set( materials, new DamagedItemDefinition( is ) ); else @@ -226,7 +228,7 @@ public class Registration } } - AEItemDefinition partItem = (AEFeatureHandler) addFeature( ItemPart.class ); + AEItemDefinition partItem = (AEFeatureHandler) addFeature( ItemMultiPart.class ); Class partClass = parts.getClass(); for (PartType type : PartType.values()) @@ -237,7 +239,7 @@ public class Registration Enum varients[] = type.getVarients(); if ( varients == null ) { - ItemStackSrc is = ((ItemPart) partItem.item()).createPart( type, null ); + ItemStackSrc is = ((ItemMultiPart) partItem.item()).createPart( type, null ); if ( is != null ) f.set( parts, new DamagedItemDefinition( is ) ); else @@ -251,7 +253,7 @@ public class Registration for (Enum v : varients) { - ItemStackSrc is = ((ItemPart) partItem.item()).createPart( type, v ); + ItemStackSrc is = ((ItemMultiPart) partItem.item()).createPart( type, v ); if ( is != null ) def.add( (AEColor) v, is ); } @@ -358,6 +360,12 @@ public class Registration items.itemFacade = addFeature( ItemFacade.class ); items.itemCrystalSeed = addFeature( ItemCrystalSeed.class ); + if ( AEConfig.instance.isFeatureEnabled( AEFeature.AlphaMigration ) ) + { + GameRegistry.registerItem( new OldItemMaterial(), "item.ItemMaterial" ); + GameRegistry.registerItem( new OldItemPart(), "item.ItemPart" ); + } + addFeature( ToolEraser.class ); addFeature( ToolMeteoritePlacer.class ); addFeature( ToolDebugCard.class ); diff --git a/core/features/AEFeature.java b/core/features/AEFeature.java index 6857ff7b..59d6a301 100644 --- a/core/features/AEFeature.java +++ b/core/features/AEFeature.java @@ -48,9 +48,11 @@ public enum AEFeature DuplicateItems("Misc", false), Profiler("Services", false), VersionChecker("Services"), Debug("Misc", false), Creative("Misc"), - Logging("Misc"), IntegrationLogging("Misc", false), CustomRecipes("Crafting", false), WebsiteRecipes("Misc", false), + GrinderLogging("Misc",false), Logging("Misc"), IntegrationLogging("Misc", false), CustomRecipes("Crafting", false), WebsiteRecipes("Misc", false), - enableFacadeCrafting("Crafting"), inWorldSingularity("Crafting"), inWorldFluix("Crafting"), inWorldPurification("Crafting"), UpdateLogging("Misc", false); + enableFacadeCrafting("Crafting"), inWorldSingularity("Crafting"), inWorldFluix("Crafting"), inWorldPurification("Crafting"), UpdateLogging("Misc", false), + + AlphaPass("Rendering"), AlphaMigration("Migration", true); String Category; boolean visible = true; diff --git a/core/features/AEFeatureHandler.java b/core/features/AEFeatureHandler.java index f7f915c8..9376401a 100644 --- a/core/features/AEFeatureHandler.java +++ b/core/features/AEFeatureHandler.java @@ -49,6 +49,11 @@ public class AEFeatureHandler implements AEItemDefinition { String name = o.getSimpleName(); + if ( name.startsWith( "ItemMultiPart" ) ) + name = name.replace( "ItemMultiPart", "ItemPart" ); + else if ( name.startsWith( "ItemMultiMaterial" ) ) + name = name.replace( "ItemMultiMaterial", "ItemMaterial" ); + if ( subname != null ) { // simple hack to allow me to do get nice names for these without @@ -80,6 +85,11 @@ public class AEFeatureHandler implements AEItemDefinition else i.setCreativeTab( CreativeTab.instance ); + if ( name.equals( "ItemMaterial" ) ) + name = "ItemMultiMaterial"; + else if ( name.equals( "ItemPart" ) ) + name = "ItemMultiPart"; + GameRegistry.registerItem( i, "item." + name ); } diff --git a/core/features/registries/GrinderRecipeManager.java b/core/features/registries/GrinderRecipeManager.java index c108c116..96b25173 100644 --- a/core/features/registries/GrinderRecipeManager.java +++ b/core/features/registries/GrinderRecipeManager.java @@ -111,7 +111,7 @@ public class GrinderRecipeManager implements IGrinderRegistry, IOreListener } } - log( "Count not find recipe for " + Platform.getItemDisplayName( input ) ); + log( "Could not find recipe for " + Platform.getItemDisplayName( input ) ); } return null; diff --git a/facade/FacadePart.java b/facade/FacadePart.java index db3ec849..54f5ec96 100644 --- a/facade/FacadePart.java +++ b/facade/FacadePart.java @@ -8,8 +8,10 @@ import net.minecraft.client.renderer.Tessellator; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; import net.minecraftforge.common.util.ForgeDirection; import org.lwjgl.opengl.GL11; @@ -17,6 +19,7 @@ import org.lwjgl.opengl.GL11; import appeng.api.parts.IFacadeContainer; import appeng.api.parts.IFacadePart; import appeng.api.parts.IPartCollsionHelper; +import appeng.api.parts.IPartHost; import appeng.api.parts.IPartRenderHelper; import appeng.client.render.BusRenderHelper; import appeng.client.render.RenderBlocksWorkaround; @@ -89,11 +92,16 @@ public class FacadePart implements IFacadePart { ItemStack randomItem = getTexture(); + RenderBlocksWorkaround rbw = null; + if ( renderer instanceof RenderBlocksWorkaround ) + { + rbw = (RenderBlocksWorkaround) renderer; + } + if ( renderStilt && busBounds == null ) { - if ( renderer instanceof RenderBlocksWorkaround ) + if ( rbw != null ) { - RenderBlocksWorkaround rbw = (RenderBlocksWorkaround) renderer; rbw.isFacade = false; rbw.calculations = true; } @@ -127,6 +135,11 @@ public class FacadePart implements IFacadePart ItemBlock ib = (ItemBlock) randomItem.getItem(); Block blk = Block.getBlockFromItem( ib ); + if ( blk.canRenderInPass( 1 ) ) + { + instance.renderForPass( 1 ); + } + try { int color = ib.getColorFromItemStack( randomItem, 0 ); @@ -140,10 +153,8 @@ public class FacadePart implements IFacadePart instance.setBounds( 0, 0, 16 - getFacadeThickness(), 16, 16, 16 ); instance.prepareBounds( renderer ); - if ( renderer instanceof RenderBlocksWorkaround ) + if ( rbw != null ) { - RenderBlocksWorkaround rbw = (RenderBlocksWorkaround) renderer; - rbw.isFacade = true; rbw.calculations = true; @@ -152,7 +163,7 @@ public class FacadePart implements IFacadePart rbw.renderStandardBlock( blk, x, y, z ); rbw.calculations = false; - rbw.faces = EnumSet.allOf( ForgeDirection.class ); + rbw.faces = calculateFaceOpenFaces( rbw.blockAccess, fc, x, y, z, side ); ((RenderBlocksWorkaround) renderer).setTexture( blk.getIcon( ForgeDirection.DOWN.ordinal(), ib.getMetadata( randomItem.getItemDamage() ) ), @@ -248,6 +259,12 @@ public class FacadePart implements IFacadePart } } + if ( rbw != null ) + { + rbw.faces = EnumSet.allOf( ForgeDirection.class ); + } + + instance.renderForPass( 0 ); instance.setTexture( null ); Tessellator.instance.setColorOpaque_F( 1, 1, 1 ); @@ -265,6 +282,63 @@ public class FacadePart implements IFacadePart } } + private EnumSet calculateFaceOpenFaces(IBlockAccess blockAccess, IFacadeContainer fc, int x, int y, int z, ForgeDirection side) + { + EnumSet out = EnumSet.of( side, side.getOpposite() ); + IFacadePart facade = fc.getFacade( side ); + + for (ForgeDirection it : ForgeDirection.VALID_DIRECTIONS) + { + if ( !out.contains( it ) && alphaDiff( blockAccess.getTileEntity( x + it.offsetX, y + it.offsetY, z + it.offsetZ ), side, facade ) ) + { + out.add( it ); + } + } + + if ( out.contains( ForgeDirection.UP ) && (side.offsetX != 0 || side.offsetZ != 0) ) + { + IFacadePart fp = fc.getFacade( ForgeDirection.UP ); + if ( fp != null && (fp.isTransparent() == facade.isTransparent()) ) + out.remove( ForgeDirection.UP ); + } + + if ( out.contains( ForgeDirection.DOWN ) && (side.offsetX != 0 || side.offsetZ != 0) ) + { + IFacadePart fp = fc.getFacade( ForgeDirection.DOWN ); + if ( fp != null && (fp.isTransparent() == facade.isTransparent()) ) + out.remove( ForgeDirection.DOWN ); + } + + if ( out.contains( ForgeDirection.SOUTH ) && (side.offsetX != 0) ) + { + IFacadePart fp = fc.getFacade( ForgeDirection.SOUTH ); + if ( fp != null && (fp.isTransparent() == facade.isTransparent()) ) + out.remove( ForgeDirection.SOUTH ); + } + + if ( out.contains( ForgeDirection.NORTH ) && (side.offsetX != 0) ) + { + IFacadePart fp = fc.getFacade( ForgeDirection.NORTH ); + if ( fp != null && (fp.isTransparent() == facade.isTransparent()) ) + out.remove( ForgeDirection.NORTH ); + } + + return out; + } + + private boolean alphaDiff(TileEntity tileEntity, ForgeDirection side, IFacadePart facade) + { + if ( tileEntity instanceof IPartHost ) + { + IPartHost ph = (IPartHost) tileEntity; + IFacadePart fp = ph.getFacadeContainer().getFacade( side ); + + return fp == null || (fp.isTransparent() != facade.isTransparent()); + } + + return true; + } + @SideOnly(Side.CLIENT) private void renderSegmentBlockCurrentBounds(BusRenderHelper instance, int x, int y, int z, RenderBlocks renderer, double minX, double minY, double minZ, double maxX, double maxY, double maxZ) @@ -421,4 +495,15 @@ public class FacadePart implements IFacadePart { thickness = useThinFacades ? 1 : 2; } + + @Override + public boolean isTransparent() + { + ItemStack is = getTexture(); + Block blk = Block.getBlockFromItem( is.getItem() ); + if ( !blk.isOpaqueCube() ) + return true; + + return false; + } } diff --git a/fmp/CableBusPart.java b/fmp/CableBusPart.java index f4011821..244316a1 100644 --- a/fmp/CableBusPart.java +++ b/fmp/CableBusPart.java @@ -34,11 +34,14 @@ import appeng.api.parts.SelectedPart; import appeng.api.util.AECableType; import appeng.api.util.AEColor; import appeng.api.util.DimensionalCoord; +import appeng.client.render.BusRenderHelper; +import appeng.core.AEConfig; import appeng.core.AELog; -import appeng.facade.IFacadeItem; +import appeng.core.features.AEFeature; import appeng.helpers.AEMultiTile; import appeng.parts.BusCollisionHelper; import appeng.parts.CableBusContainer; +import appeng.parts.PartPlacement; import appeng.tile.networking.TileCableBus; import appeng.util.Platform; import codechicken.lib.data.MCDataInput; @@ -259,8 +262,9 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds @Override public void renderDynamic(Vector3 pos, float frame, int pass) { - if ( pass == 0 ) + if ( pass == 0 || (pass == 1 && AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass )) ) { + BusRenderHelper.instance.setPass( pass ); cb.renderDynamic( pos.x, pos.y, pos.z ); } } @@ -268,10 +272,11 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds @Override public boolean renderStatic(Vector3 pos, int pass) { - if ( pass == 0 ) + if ( pass == 0 || (pass == 1 && AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass )) ) { + BusRenderHelper.instance.setPass( pass ); cb.renderStatic( pos.x, pos.y, pos.z ); - return true; + return BusRenderHelper.instance.getItemsRendered() > 0; } return false; } @@ -285,19 +290,14 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds @Override public boolean canAddPart(ItemStack is, ForgeDirection side) { - if ( is.getItem() instanceof IFacadeItem ) + IFacadePart fp = PartPlacement.isFacade( is, side ); + if ( fp != null ) { - IFacadeItem bi = (IFacadeItem) is.getItem(); - - is = is.copy(); - is.stackSize = 1; - - IFacadePart bp = bi.createPartFromItemStack( is, side ); if ( !(side == null || side == ForgeDirection.UNKNOWN || tile() == null) ) { List boxes = new ArrayList(); IPartCollsionHelper bch = new BusCollisionHelper( boxes, side, null, true ); - bp.getBoxes( bch ); + fp.getBoxes( bch ); for (AxisAlignedBB bb : boxes) { disableFacadeOcclusion.set( true ); @@ -480,7 +480,9 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds public void markForSave() { // mark the chunk for save... - this.getTile().getWorldObj().getChunkFromBlockCoords( x(), z() ).isModified = true; + TileEntity te = getTile(); + if ( te != null && te.getWorldObj() != null ) + te.getWorldObj().getChunkFromBlockCoords( x(), z() ).isModified = true; } @Override diff --git a/integration/modules/helpers/NullRFHandler.java b/integration/modules/helpers/NullRFHandler.java index d0249d65..2174c19c 100644 --- a/integration/modules/helpers/NullRFHandler.java +++ b/integration/modules/helpers/NullRFHandler.java @@ -17,12 +17,6 @@ public class NullRFHandler implements IEnergyHandler return 0; } - @Override - public boolean canInterface(ForgeDirection from) - { - return true; - } - @Override public int getEnergyStored(ForgeDirection from) { @@ -35,4 +29,15 @@ public class NullRFHandler implements IEnergyHandler return 0; } + @Deprecated + public boolean canInterface(ForgeDirection from) + { + return true; + } + + @Override + public boolean canConnectEnergy(ForgeDirection from) { + return true; + } + } diff --git a/items/materials/ItemMaterial.java b/items/materials/ItemMultiMaterial.java similarity index 88% rename from items/materials/ItemMaterial.java rename to items/materials/ItemMultiMaterial.java index d032d0ac..dd11c342 100644 --- a/items/materials/ItemMaterial.java +++ b/items/materials/ItemMultiMaterial.java @@ -1,298 +1,306 @@ -package appeng.items.materials; - -import java.util.Collections; -import java.util.Comparator; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.Entity; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.IIcon; -import net.minecraft.world.World; -import net.minecraftforge.oredict.OreDictionary; -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; -import appeng.core.features.ItemStackSrc; -import appeng.items.AEBaseItem; -import appeng.util.Platform; - -public class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule -{ - - HashMap dmgToMaterial = new HashMap(); - - public static ItemMaterial instance; - - public ItemMaterial() { - super( ItemMaterial.class ); - setfeature( EnumSet.of( AEFeature.Core ) ); - setHasSubtypes( true ); - instance = this; - } - - class SlightlyBetterSort implements Comparator - { - - Pattern p; - - public SlightlyBetterSort(Pattern p) { - this.p = p; - } - - @Override - public int compare(String o1, String o2) - { - try - { - Matcher a = p.matcher( o1 ); - Matcher b = p.matcher( o2 ); - if ( a.find() && b.find() ) - { - int ia = Integer.parseInt( a.group( 1 ) ); - int ib = Integer.parseInt( b.group( 1 ) ); - return Integer.compare( ia, ib ); - } - } - catch (Throwable t) - { - // ek! - } - return o1.compareTo( o2 ); - } - } - - @Override - public void addInformation(ItemStack is, EntityPlayer player, List details, boolean moar) - { - super.addInformation( is, player, details, moar ); - - MaterialType mt = getTypeByStack( is ); - if ( mt == null ) - return; - - if ( mt == MaterialType.NamePress ) - { - NBTTagCompound c = Platform.openNbtData( is ); - details.add( c.getString( "InscribeName" ) ); - } - - Upgrades u = getType( is ); - if ( u != null ) - { - List textList = new LinkedList(); - for (Entry j : u.getSupported().entrySet()) - { - String name = null; - - int limit = j.getValue(); - - if ( j.getKey().getItem() instanceof IItemGroup ) - { - IItemGroup ig = (IItemGroup) j.getKey().getItem(); - String str = ig.getUnlocalizedGroupName( j.getKey() ); - if ( str != null ) - name = Platform.gui_localize( str ) + (limit > 1 ? " (" + limit + ")" : ""); - } - - if ( name == null ) - name = j.getKey().getDisplayName() + (limit > 1 ? " (" + limit + ")" : ""); - - if ( !textList.contains( name ) ) - textList.add( name ); - } - - Pattern p = Pattern.compile( "(\\d+)[^\\d]" ); - SlightlyBetterSort s = new SlightlyBetterSort( p ); - Collections.sort( textList, s ); - details.addAll( textList ); - } - } - - public ItemStackSrc createMaterial(MaterialType mat) - { - String name = mat.name(); - - if ( mat.damageValue == -1 ) - { - boolean enabled = true; - for (AEFeature f : mat.getFeature()) - enabled = enabled && AEConfig.instance.isFeatureEnabled( f ); - - if ( enabled ) - { - int newMaterialNum = AEConfig.instance.get( "materials", name, AEConfig.instance.getFreeMaterial( mat.ordinal() ) ).getInt(); - mat.damageValue = newMaterialNum; - ItemStackSrc output = new ItemStackSrc( this, newMaterialNum ); - - dmgToMaterial.put( newMaterialNum, mat ); - - if ( mat.getOreName() != null ) - OreDictionary.registerOre( mat.getOreName(), output.stack( 1 ) ); - - return output; - } - - return null; - } - else - throw new RuntimeException( "Cannot create the same material twice..." ); - } - - public MaterialType getTypeByStack(ItemStack is) - { - if ( dmgToMaterial.containsKey( is.getItemDamage() ) ) - return dmgToMaterial.get( is.getItemDamage() ); - return null; - } - - @Override - public IIcon getIconFromDamage(int dmg) - { - if ( dmgToMaterial.containsKey( dmg ) ) - return dmgToMaterial.get( dmg ).IIcon; - return new MissingIcon( this ); - } - - private String nameOf(ItemStack is) - { - if ( is == null ) - return "null"; - - MaterialType mt = getTypeByStack( is ); - if ( mt == null ) - return "null"; - - return AEFeatureHandler.getName( ItemMaterial.class, mt.name() ); - } - - @Override - public String getUnlocalizedName(ItemStack is) - { - return "item.appliedenergistics2." + nameOf( is ); - } - - @Override - public void registerIcons(IIconRegister icoRegister) - { - for (MaterialType mat : MaterialType.values()) - { - if ( mat.damageValue != -1 ) - { - String tex = "appliedenergistics2:" + nameOf( new ItemStack( this, 1, mat.damageValue ) ); - mat.IIcon = icoRegister.registerIcon( tex ); - } - } - } - - @Override - public boolean hasCustomEntity(ItemStack is) - { - return getTypeByStack( is ).hasCustomEntity(); - } - - @Override - public Entity createEntity(World w, Entity location, ItemStack itemstack) - { - Class droppedEntity = getTypeByStack( itemstack ).getCustomEntityClass(); - Entity eqi; - - try - { - eqi = droppedEntity.getConstructor( World.class, double.class, double.class, double.class, ItemStack.class ).newInstance( w, location.posX, - location.posY, location.posZ, itemstack ); - } - catch (Throwable t) - { - throw new RuntimeException( t ); - } - - eqi.motionX = location.motionX; - eqi.motionY = location.motionY; - eqi.motionZ = location.motionZ; - - if ( location instanceof EntityItem && eqi instanceof EntityItem ) - ((EntityItem) eqi).delayBeforeCanPickup = ((EntityItem) location).delayBeforeCanPickup; - - return eqi; - } - - @Override - public int getBytes(ItemStack is) - { - switch (getTypeByStack( is )) - { - case Cell1kPart: - return 1024; - case Cell4kPart: - return 1024 * 4; - case Cell16kPart: - return 1024 * 16; - case Cell64kPart: - return 1024 * 64; - default: - } - return 0; - } - - @Override - public boolean isStorageComponent(ItemStack is) - { - switch (getTypeByStack( is )) - { - case Cell1kPart: - case Cell4kPart: - case Cell16kPart: - case Cell64kPart: - return true; - default: - } - return false; - } - - @Override - public Upgrades getType(ItemStack itemstack) - { - switch (getTypeByStack( itemstack )) - { - case CardCapacity: - return Upgrades.CAPACITY; - case CardFuzzy: - return Upgrades.FUZZY; - case CardRedstone: - return Upgrades.REDSTONE; - case CardSpeed: - return Upgrades.SPEED; - case CardInverter: - return Upgrades.INVERTER; - default: - return null; - } - } - - @Override - public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List cList) - { - for (MaterialType mat : MaterialType.values()) - { - if ( mat.damageValue >= 0 ) - cList.add( new ItemStack( this, 1, mat.damageValue ) ); - } - } -} +package appeng.items.materials; + +import java.util.Collections; +import java.util.Comparator; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map.Entry; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import net.minecraftforge.oredict.OreDictionary; +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; +import appeng.core.features.ItemStackSrc; +import appeng.items.AEBaseItem; +import appeng.util.Platform; + +public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule +{ + + HashMap dmgToMaterial = new HashMap(); + + public static ItemMultiMaterial instance; + + public ItemMultiMaterial() { + super( ItemMultiMaterial.class ); + setfeature( EnumSet.of( AEFeature.Core ) ); + setHasSubtypes( true ); + instance = this; + } + + class SlightlyBetterSort implements Comparator + { + + Pattern p; + + public SlightlyBetterSort(Pattern p) { + this.p = p; + } + + @Override + public int compare(String o1, String o2) + { + try + { + Matcher a = p.matcher( o1 ); + Matcher b = p.matcher( o2 ); + if ( a.find() && b.find() ) + { + int ia = Integer.parseInt( a.group( 1 ) ); + int ib = Integer.parseInt( b.group( 1 ) ); + return Integer.compare( ia, ib ); + } + } + catch (Throwable t) + { + // ek! + } + return o1.compareTo( o2 ); + } + } + + @Override + public void addInformation(ItemStack is, EntityPlayer player, List details, boolean moar) + { + super.addInformation( is, player, details, moar ); + + MaterialType mt = getTypeByStack( is ); + if ( mt == null ) + return; + + if ( mt == MaterialType.NamePress ) + { + NBTTagCompound c = Platform.openNbtData( is ); + details.add( c.getString( "InscribeName" ) ); + } + + Upgrades u = getType( is ); + if ( u != null ) + { + List textList = new LinkedList(); + for (Entry j : u.getSupported().entrySet()) + { + String name = null; + + int limit = j.getValue(); + + if ( j.getKey().getItem() instanceof IItemGroup ) + { + IItemGroup ig = (IItemGroup) j.getKey().getItem(); + String str = ig.getUnlocalizedGroupName( j.getKey() ); + if ( str != null ) + name = Platform.gui_localize( str ) + (limit > 1 ? " (" + limit + ")" : ""); + } + + if ( name == null ) + name = j.getKey().getDisplayName() + (limit > 1 ? " (" + limit + ")" : ""); + + if ( !textList.contains( name ) ) + textList.add( name ); + } + + Pattern p = Pattern.compile( "(\\d+)[^\\d]" ); + SlightlyBetterSort s = new SlightlyBetterSort( p ); + Collections.sort( textList, s ); + details.addAll( textList ); + } + } + + public ItemStackSrc createMaterial(MaterialType mat) + { + if ( !mat.isRegistered() ) + { + boolean enabled = true; + for (AEFeature f : mat.getFeature()) + enabled = enabled && AEConfig.instance.isFeatureEnabled( f ); + + if ( enabled ) + { + int newMaterialNum = mat.damageValue; + mat.markReady(); + + ItemStackSrc output = new ItemStackSrc( this, newMaterialNum ); + + if ( dmgToMaterial.get( newMaterialNum ) == null ) + dmgToMaterial.put( newMaterialNum, mat ); + else + throw new RuntimeException( "Meta Overlap detected." ); + + if ( mat.getOreName() != null ) + OreDictionary.registerOre( mat.getOreName(), output.stack( 1 ) ); + + return output; + } + + return null; + } + else + throw new RuntimeException( "Cannot create the same material twice..." ); + } + + public ItemStack getStackByType(MaterialType mt) + { + return new ItemStack( this, 1, mt.damageValue ); + } + + public MaterialType getTypeByStack(ItemStack is) + { + if ( dmgToMaterial.containsKey( is.getItemDamage() ) ) + return dmgToMaterial.get( is.getItemDamage() ); + return null; + } + + @Override + public IIcon getIconFromDamage(int dmg) + { + if ( dmgToMaterial.containsKey( dmg ) ) + return dmgToMaterial.get( dmg ).IIcon; + return new MissingIcon( this ); + } + + private String nameOf(ItemStack is) + { + if ( is == null ) + return "null"; + + MaterialType mt = getTypeByStack( is ); + if ( mt == null ) + return "null"; + + return AEFeatureHandler.getName( ItemMultiMaterial.class, mt.name() ); + } + + @Override + public String getUnlocalizedName(ItemStack is) + { + return "item.appliedenergistics2." + nameOf( is ); + } + + @Override + public void registerIcons(IIconRegister icoRegister) + { + for (MaterialType mat : MaterialType.values()) + { + if ( mat.damageValue != -1 ) + { + String tex = "appliedenergistics2:" + nameOf( new ItemStack( this, 1, mat.damageValue ) ); + mat.IIcon = icoRegister.registerIcon( tex ); + } + } + } + + @Override + public boolean hasCustomEntity(ItemStack is) + { + return getTypeByStack( is ).hasCustomEntity(); + } + + @Override + public Entity createEntity(World w, Entity location, ItemStack itemstack) + { + Class droppedEntity = getTypeByStack( itemstack ).getCustomEntityClass(); + Entity eqi; + + try + { + eqi = droppedEntity.getConstructor( World.class, double.class, double.class, double.class, ItemStack.class ).newInstance( w, location.posX, + location.posY, location.posZ, itemstack ); + } + catch (Throwable t) + { + throw new RuntimeException( t ); + } + + eqi.motionX = location.motionX; + eqi.motionY = location.motionY; + eqi.motionZ = location.motionZ; + + if ( location instanceof EntityItem && eqi instanceof EntityItem ) + ((EntityItem) eqi).delayBeforeCanPickup = ((EntityItem) location).delayBeforeCanPickup; + + return eqi; + } + + @Override + public int getBytes(ItemStack is) + { + switch (getTypeByStack( is )) + { + case Cell1kPart: + return 1024; + case Cell4kPart: + return 1024 * 4; + case Cell16kPart: + return 1024 * 16; + case Cell64kPart: + return 1024 * 64; + default: + } + return 0; + } + + @Override + public boolean isStorageComponent(ItemStack is) + { + switch (getTypeByStack( is )) + { + case Cell1kPart: + case Cell4kPart: + case Cell16kPart: + case Cell64kPart: + return true; + default: + } + return false; + } + + @Override + public Upgrades getType(ItemStack itemstack) + { + switch (getTypeByStack( itemstack )) + { + case CardCapacity: + return Upgrades.CAPACITY; + case CardFuzzy: + return Upgrades.FUZZY; + case CardRedstone: + return Upgrades.REDSTONE; + case CardSpeed: + return Upgrades.SPEED; + case CardInverter: + return Upgrades.INVERTER; + default: + return null; + } + } + + @Override + public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List cList) + { + for (MaterialType mat : MaterialType.values()) + { + if ( mat.damageValue >= 0 && mat.isRegistered() ) + cList.add( new ItemStack( this, 1, mat.damageValue ) ); + } + } + +} diff --git a/items/materials/MaterialType.java b/items/materials/MaterialType.java index 074d7cfd..74d43a33 100644 --- a/items/materials/MaterialType.java +++ b/items/materials/MaterialType.java @@ -17,50 +17,50 @@ import cpw.mods.fml.relauncher.SideOnly; public enum MaterialType { - CertusQuartzCrystal(AEFeature.Core, "crystalCertusQuartz"), CertusQuartzCrystalCharged(AEFeature.Core, EntityChargedQuartz.class), + CertusQuartzCrystal(0, AEFeature.Core, "crystalCertusQuartz"), CertusQuartzCrystalCharged(1, AEFeature.Core, EntityChargedQuartz.class), - CertusQuartzDust(AEFeature.Core, "dustCertusQuartz"), NetherQuartzDust(AEFeature.Core, "dustNetherQuartz"), Flour(AEFeature.Flour, "dustWheat"), GoldDust( - AEFeature.Core, "dustGold"), IronDust(AEFeature.Core, "dustIron"), IronNugget(AEFeature.Core, "nuggetIron"), + CertusQuartzDust(2, AEFeature.Core, "dustCertusQuartz"), NetherQuartzDust(3, AEFeature.Core, "dustNetherQuartz"), Flour(4, AEFeature.Flour, "dustWheat"), GoldDust( + 51, AEFeature.Core, "dustGold"), IronDust(49, AEFeature.Core, "dustIron"), IronNugget(50, AEFeature.Core, "nuggetIron"), - Silicon(AEFeature.Core, "itemSilicon"), MatterBall, + Silicon(5, AEFeature.Core, "itemSilicon"), MatterBall(6), - FluixCrystal(AEFeature.Core, "crystalFluix"), FluixDust(AEFeature.Core, "dustFluix"), FluixPearl(AEFeature.Core, "pearlFluix"), + FluixCrystal(7, AEFeature.Core, "crystalFluix"), FluixDust(8, AEFeature.Core, "dustFluix"), FluixPearl(9, AEFeature.Core, "pearlFluix"), - PureifiedCertusQuartzCrystal, PureifiedNetherQuartzCrystal, PureifiedFluixCrystal, + PureifiedCertusQuartzCrystal(10), PureifiedNetherQuartzCrystal(11), PureifiedFluixCrystal(12), - CalcProcessorPress, EngProcessorPress, LogicProcessorPress, + CalcProcessorPress(13), EngProcessorPress(14), LogicProcessorPress(15), - CalcProcessorPrint, EngProcessorPrint, LogicProcessorPrint, + CalcProcessorPrint(16), EngProcessorPrint(17), LogicProcessorPrint(18), - SiliconPress, SiliconPrint, + SiliconPress(19), SiliconPrint(20), - NamePress, + NamePress(21), - LogicProcessor, CalcProcessor, EngProcessor, + LogicProcessor(22), CalcProcessor(23), EngProcessor(24), // Basic Cards - BasicCard, CardRedstone, CardCapacity, + BasicCard(25), CardRedstone(26), CardCapacity(27), // Adv Cards - AdvCard, CardFuzzy, CardSpeed, CardInverter, + AdvCard(28), CardFuzzy(29), CardSpeed(30), CardInverter(31), - Cell2SpatialPart(AEFeature.SpatialIO), Cell16SpatialPart(AEFeature.SpatialIO), Cell128SpatialPart(AEFeature.SpatialIO), + Cell2SpatialPart(32, AEFeature.SpatialIO), Cell16SpatialPart(33, AEFeature.SpatialIO), Cell128SpatialPart(34, AEFeature.SpatialIO), - Cell1kPart(AEFeature.StorageCells), Cell4kPart(AEFeature.StorageCells), Cell16kPart(AEFeature.StorageCells), Cell64kPart(AEFeature.StorageCells), EmptyStorageCell( - AEFeature.StorageCells), + Cell1kPart(35, AEFeature.StorageCells), Cell4kPart(36, AEFeature.StorageCells), Cell16kPart(37, AEFeature.StorageCells), Cell64kPart(38, + AEFeature.StorageCells), EmptyStorageCell(39, AEFeature.StorageCells), - WoodenGear(AEFeature.GrindStone, "gearWood"), + WoodenGear(40, AEFeature.GrindStone, "gearWood"), - BlankPattern, + Wireless(41, AEFeature.WirelessAccessTerminal), WirelessBooster(42, AEFeature.WirelessAccessTerminal), - Wireless(AEFeature.WirelessAccessTerminal), WirelessBooster(AEFeature.WirelessAccessTerminal), + FormationCore(43), AnnihilationCore(44), - FormationCore, AnnihilationCore, + SkyDust(45, AEFeature.Core), - SkyDust(AEFeature.Core), + EnderDust(46, AEFeature.QuantumNetworkBridge, "dustEnder", EntitySingularity.class), Singularity(47, AEFeature.QuantumNetworkBridge, + EntitySingularity.class), QESingularity(48, AEFeature.QuantumNetworkBridge, EntitySingularity.class), - EnderDust(AEFeature.QuantumNetworkBridge, "dustEnder", EntitySingularity.class), Singularity(AEFeature.QuantumNetworkBridge, EntitySingularity.class), QESingularity( - AEFeature.QuantumNetworkBridge, EntitySingularity.class); + BlankPattern(49); private String oreName; private EnumSet features; @@ -69,25 +69,30 @@ public enum MaterialType // IIcon for the material. @SideOnly(Side.CLIENT) public IIcon IIcon; - public int damageValue = -1; + final public int damageValue; + private boolean isRegistered = false; - MaterialType() { + MaterialType(int metaValue) { + damageValue = metaValue; features = EnumSet.of( AEFeature.Core ); } - MaterialType(AEFeature part) { + MaterialType(int metaValue, AEFeature part) { + damageValue = metaValue; features = EnumSet.of( part ); } - MaterialType(AEFeature part, Class c) { + MaterialType(int metaValue, AEFeature part, Class c) { features = EnumSet.of( part ); + damageValue = metaValue; droppedEntity = c; EntityRegistry.registerModEntity( droppedEntity, droppedEntity.getSimpleName(), EntityIds.get( droppedEntity ), AppEng.instance, 16, 4, true ); } - MaterialType(AEFeature part, String oreDictionary, Class c) { + MaterialType(int metaValue, AEFeature part, String oreDictionary, Class c) { features = EnumSet.of( part ); + damageValue = metaValue; oreName = oreDictionary; if ( OreDictionary.getOres( oreDictionary ).size() > 0 ) features.add( AEFeature.DuplicateItems ); @@ -96,8 +101,9 @@ public enum MaterialType EntityRegistry.registerModEntity( droppedEntity, droppedEntity.getSimpleName(), EntityIds.get( droppedEntity ), AppEng.instance, 16, 4, true ); } - MaterialType(AEFeature part, String oreDictionary) { + MaterialType(int metaValue, AEFeature part, String oreDictionary) { features = EnumSet.of( part ); + damageValue = metaValue; oreName = oreDictionary; if ( OreDictionary.getOres( oreDictionary ).size() > 0 ) features.add( AEFeature.DuplicateItems ); @@ -105,7 +111,7 @@ public enum MaterialType public ItemStack stack(int size) { - return new ItemStack( ItemMaterial.instance, size, damageValue ); + return new ItemStack( ItemMultiMaterial.instance, size, damageValue ); } public EnumSet getFeature() @@ -128,4 +134,14 @@ public enum MaterialType return droppedEntity; } + public boolean isRegistered() + { + return isRegistered; + } + + public void markReady() + { + isRegistered = true; + } + } diff --git a/items/parts/ItemFacade.java b/items/parts/ItemFacade.java index 97c51824..7ce29ec0 100644 --- a/items/parts/ItemFacade.java +++ b/items/parts/ItemFacade.java @@ -6,6 +6,7 @@ import java.util.List; import net.minecraft.block.Block; import net.minecraft.block.BlockGlass; +import net.minecraft.block.BlockStainedGlass; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; @@ -17,6 +18,7 @@ import net.minecraft.world.World; import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.common.util.ForgeDirection; import appeng.api.AEApi; +import appeng.api.parts.IAlphaPassItem; import appeng.block.solids.OreQuartz; import appeng.client.render.BusRenderer; import appeng.core.FacadeConfig; @@ -28,7 +30,7 @@ import appeng.util.Platform; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class ItemFacade extends AEBaseItem implements IFacadeItem +public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassItem { public ItemFacade() { @@ -141,7 +143,7 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem int metadata = l.getItem().getMetadata( l.getItemDamage() ); boolean hasTile = b.hasTileEntity( metadata ); - boolean enableGlass = b instanceof BlockGlass; + boolean enableGlass = b instanceof BlockGlass || b instanceof BlockStainedGlass; boolean disableOre = b instanceof OreQuartz; boolean defaultValue = (b.isOpaqueCube() && !b.getTickRandomly() && !hasTile && !disableOre) || enableGlass; @@ -207,4 +209,14 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem return super.getItemStackDisplayName( is ); } + @Override + public boolean useAlphaPass(ItemStack is) + { + ItemStack out = getTextureItem( is ); + Block blk = Block.getBlockFromItem( out.getItem() ); + if ( blk != null && blk.canRenderInPass( 1 ) ) + return true; + return false; + } + } diff --git a/items/parts/ItemPart.java b/items/parts/ItemMultiPart.java similarity index 86% rename from items/parts/ItemPart.java rename to items/parts/ItemMultiPart.java index 9299c542..823144b8 100644 --- a/items/parts/ItemPart.java +++ b/items/parts/ItemMultiPart.java @@ -1,220 +1,229 @@ -package appeng.items.parts; - -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Map.Entry; - -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import net.minecraft.world.World; -import appeng.api.AEApi; -import appeng.api.implementations.items.IItemGroup; -import appeng.api.parts.IPart; -import appeng.api.parts.IPartItem; -import appeng.core.AEConfig; -import appeng.core.features.AEFeature; -import appeng.core.features.AEFeatureHandler; -import appeng.core.features.ItemStackSrc; -import appeng.core.localization.GuiText; -import appeng.items.AEBaseItem; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class ItemPart extends AEBaseItem implements IPartItem, IItemGroup -{ - - class PartTypeIst - { - - PartType part; - int varient; - - @SideOnly(Side.CLIENT) - IIcon ico; - - }; - - HashMap dmgToPart = new HashMap(); - - public static ItemPart instance; - - public ItemPart() { - super( ItemPart.class ); - setfeature( EnumSet.of( AEFeature.Core ) ); - AEApi.instance().partHelper().setItemBusRenderer( this ); - setHasSubtypes( true ); - instance = this; - } - - public ItemStackSrc createPart(PartType mat, Enum varient) - { - try - { - // I think this still works? - ItemStack is = new ItemStack( this ); - mat.getPart().getConstructor( ItemStack.class ).newInstance( is ); - } - catch (Throwable e) - { - return null; // part not supported.. - } - - String name = varient == null ? mat.name() : mat.name() + "." + varient.name(); - int varID = varient == null ? 0 : varient.ordinal(); - - // verify - for (PartTypeIst p : dmgToPart.values()) - { - if ( p.part == mat && p.varient == varID ) - throw new RuntimeException( "Cannot create the same material twice..." ); - } - - boolean enabled = true; - for (AEFeature f : mat.getFeature()) - enabled = enabled && AEConfig.instance.isFeatureEnabled( f ); - - if ( enabled ) - { - 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(); - pti.part = mat; - pti.varient = varID; - - dmgToPart.put( newPartNum, pti ); - return output; - } - - return null; - } - - public int getDamageByType(PartType t) - { - for (Entry pt : dmgToPart.entrySet()) - { - if ( pt.getValue().part == t ) - return pt.getKey(); - } - return -1; - } - - public PartType getTypeByStack(ItemStack is) - { - if ( is == null ) - return null; - - PartTypeIst pt = dmgToPart.get( is.getItemDamage() ); - if ( pt != null ) - return pt.part; - - return null; - } - - @Override - @SideOnly(Side.CLIENT) - public int getSpriteNumber() - { - return 0; - } - - @Override - public IIcon getIconFromDamage(int dmg) - { - IIcon ico = dmgToPart.get( dmg ).ico; - return ico; - } - - @Override - public String getUnlocalizedName(ItemStack is) - { - return "item.appliedenergistics2." + getname( is ); - } - - public String getname(ItemStack is) - { - return AEFeatureHandler.getName( ItemPart.class, getTypeByStack( is ).name() ); - } - - @Override - public String getItemStackDisplayName(ItemStack is) - { - PartType pt = getTypeByStack( is ); - if ( pt == null ) - return "Unnamed"; - - Enum[] varients = pt.getVarients(); - - if ( varients != null ) - return super.getItemStackDisplayName( is ) + " - " + varients[dmgToPart.get( is.getItemDamage() ).varient].toString(); - - if ( pt.getExtraName() != null ) - return super.getItemStackDisplayName( is ) + " - " + pt.getExtraName().getLocal(); - - return super.getItemStackDisplayName( is ); - } - - @Override - public void registerIcons(IIconRegister par1IconRegister) - { - for (Entry part : dmgToPart.entrySet()) - { - String tex = "appliedenergistics2:" + getname( new ItemStack( this, 1, part.getKey() ) ); - part.getValue().ico = par1IconRegister.registerIcon( tex ); - } - } - - @Override - public boolean onItemUse(ItemStack is, EntityPlayer player, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ) - { - return AEApi.instance().partHelper().placeBus( is, x, y, z, side, player, w ); - } - - @Override - public IPart createPartFromItemStack(ItemStack is) - { - try - { - PartType t = getTypeByStack( is ); - if ( t != null ) - return t.getPart().getConstructor( ItemStack.class ).newInstance( is ); - } - catch (Throwable e) - { - throw new RuntimeException( "Unable to construct IBusPart from IBusItem : " + getTypeByStack( is ).getPart().getName() - + " ; Possibly didn't have correct constructor( ItemStack )", e ); - } - return null; - } - - @Override - public void getSubItems(Item number, CreativeTabs tab, List cList) - { - for (Entry part : dmgToPart.entrySet()) - cList.add( new ItemStack( this, 1, part.getKey() ) ); - } - - public int varientOf(int itemDamage) - { - return dmgToPart.get( itemDamage ).varient; - } - - @Override - public String getUnlocalizedGroupName(ItemStack is) - { - switch (getTypeByStack( is )) - { - case ImportBus: - case ExportBus: - return GuiText.IOBuses.getUnlocalized(); - default: - } - return null; - } - -} +package appeng.items.parts; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import appeng.api.AEApi; +import appeng.api.implementations.items.IItemGroup; +import appeng.api.parts.IPart; +import appeng.api.parts.IPartItem; +import appeng.core.AEConfig; +import appeng.core.features.AEFeature; +import appeng.core.features.AEFeatureHandler; +import appeng.core.features.ItemStackSrc; +import appeng.core.localization.GuiText; +import appeng.items.AEBaseItem; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class ItemMultiPart extends AEBaseItem implements IPartItem, IItemGroup +{ + + class PartTypeIst + { + + PartType part; + int varient; + + @SideOnly(Side.CLIENT) + IIcon ico; + }; + + HashMap dmgToPart = new HashMap(); + + public static ItemMultiPart instance; + + public ItemMultiPart() { + super( ItemMultiPart.class ); + setfeature( EnumSet.of( AEFeature.Core ) ); + AEApi.instance().partHelper().setItemBusRenderer( this ); + setHasSubtypes( true ); + instance = this; + } + + public ItemStackSrc createPart(PartType mat, Enum varient) + { + try + { + // I think this still works? + ItemStack is = new ItemStack( this ); + mat.getPart().getConstructor( ItemStack.class ).newInstance( is ); + } + catch (Throwable e) + { + return null; // part not supported.. + } + + int varID = varient == null ? 0 : varient.ordinal(); + + // verify + for (PartTypeIst p : dmgToPart.values()) + { + if ( p.part == mat && p.varient == varID ) + throw new RuntimeException( "Cannot create the same material twice..." ); + } + + boolean enabled = true; + for (AEFeature f : mat.getFeature()) + enabled = enabled && AEConfig.instance.isFeatureEnabled( f ); + + if ( enabled ) + { + int newPartNum = mat.baseDamage + varID; + ItemStackSrc output = new ItemStackSrc( this, newPartNum ); + + PartTypeIst pti = new PartTypeIst(); + pti.part = mat; + pti.varient = varID; + + if ( dmgToPart.get( newPartNum ) == null ) + { + dmgToPart.put( newPartNum, pti ); + return output; + } + else + throw new RuntimeException( "Meta Overlap detected." ); + } + + return null; + } + + public int getDamageByType(PartType t) + { + for (Entry pt : dmgToPart.entrySet()) + { + if ( pt.getValue().part == t ) + return pt.getKey(); + } + return -1; + } + + public PartType getTypeByStack(ItemStack is) + { + if ( is == null ) + return null; + + PartTypeIst pt = dmgToPart.get( is.getItemDamage() ); + if ( pt != null ) + return pt.part; + + return null; + } + + @Override + @SideOnly(Side.CLIENT) + public int getSpriteNumber() + { + return 0; + } + + @Override + public IIcon getIconFromDamage(int dmg) + { + IIcon ico = dmgToPart.get( dmg ).ico; + return ico; + } + + @Override + public String getUnlocalizedName(ItemStack is) + { + return "item.appliedenergistics2." + getname( is ); + } + + public String getname(ItemStack is) + { + return AEFeatureHandler.getName( ItemMultiPart.class, getTypeByStack( is ).name() ); + } + + @Override + public String getItemStackDisplayName(ItemStack is) + { + PartType pt = getTypeByStack( is ); + if ( pt == null ) + return "Unnamed"; + + Enum[] varients = pt.getVarients(); + + if ( varients != null ) + return super.getItemStackDisplayName( is ) + " - " + varients[dmgToPart.get( is.getItemDamage() ).varient].toString(); + + if ( pt.getExtraName() != null ) + return super.getItemStackDisplayName( is ) + " - " + pt.getExtraName().getLocal(); + + return super.getItemStackDisplayName( is ); + } + + @Override + public void registerIcons(IIconRegister par1IconRegister) + { + for (Entry part : dmgToPart.entrySet()) + { + String tex = "appliedenergistics2:" + getname( new ItemStack( this, 1, part.getKey() ) ); + part.getValue().ico = par1IconRegister.registerIcon( tex ); + } + } + + @Override + public boolean onItemUse(ItemStack is, EntityPlayer player, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ) + { + return AEApi.instance().partHelper().placeBus( is, x, y, z, side, player, w ); + } + + @Override + public IPart createPartFromItemStack(ItemStack is) + { + try + { + PartType t = getTypeByStack( is ); + if ( t != null ) + return t.getPart().getConstructor( ItemStack.class ).newInstance( is ); + } + catch (Throwable e) + { + throw new RuntimeException( "Unable to construct IBusPart from IBusItem : " + getTypeByStack( is ).getPart().getName() + + " ; Possibly didn't have correct constructor( ItemStack )", e ); + } + return null; + } + + @Override + public void getSubItems(Item number, CreativeTabs tab, List cList) + { + for (Entry part : dmgToPart.entrySet()) + cList.add( new ItemStack( this, 1, part.getKey() ) ); + } + + public int varientOf(int itemDamage) + { + if ( dmgToPart.containsKey( itemDamage ) ) + return dmgToPart.get( itemDamage ).varient; + return 0; + } + + @Override + public String getUnlocalizedGroupName(ItemStack is) + { + switch (getTypeByStack( is )) + { + case ImportBus: + case ExportBus: + return GuiText.IOBuses.getUnlocalized(); + default: + } + return null; + } + + public ItemStack getStackFromTypeAndVarient(PartType mt, int varient) + { + return new ItemStack( this, 1, mt.baseDamage + varient ); + } +} diff --git a/items/parts/PartType.java b/items/parts/PartType.java index c48a2344..5a17dbeb 100644 --- a/items/parts/PartType.java +++ b/items/parts/PartType.java @@ -39,76 +39,82 @@ import appeng.parts.reporting.PartTerminal; public enum PartType { - ToggleBus(AEFeature.Core, PartToggleBus.class), + CableGlass(0, AEFeature.Core, PartCableGlass.class), - InvertedToggleBus(AEFeature.Core, PartInvertedToggleBus.class), + CableCovered(20, AEFeature.Core, PartCableCovered.class), - CableSmart(AEFeature.Core, PartCableSmart.class), CableCovered(AEFeature.Core, PartCableCovered.class), CableGlass(AEFeature.Core, PartCableGlass.class), + CableSmart(40, AEFeature.Core, PartCableSmart.class), - CableDense(AEFeature.DenseCables, PartDenseCable.class), + CableDense(60, AEFeature.DenseCables, PartDenseCable.class), - CableAnchor(AEFeature.Core, PartCableAnchor.class), + ToggleBus(80, AEFeature.Core, PartToggleBus.class), - QuartzFiber(AEFeature.Core, PartQuartzFiber.class), + InvertedToggleBus(100, AEFeature.Core, PartInvertedToggleBus.class), - Monitor(AEFeature.Core, PartMonitor.class), + CableAnchor(120, AEFeature.Core, PartCableAnchor.class), - SemiDarkMonitor(AEFeature.Core, PartSemiDarkMonitor.class), + QuartzFiber(140, AEFeature.Core, PartQuartzFiber.class), - DarkMonitor(AEFeature.Core, PartDarkMonitor.class), + Monitor(160, AEFeature.Core, PartMonitor.class), - StorageBus(AEFeature.StorageBus, PartStorageBus.class), + SemiDarkMonitor(180, AEFeature.Core, PartSemiDarkMonitor.class), - ImportBus(AEFeature.ImportBus, PartImportBus.class), + DarkMonitor(200, AEFeature.Core, PartDarkMonitor.class), - ExportBus(AEFeature.ExportBus, PartExportBus.class), + StorageBus(220, AEFeature.StorageBus, PartStorageBus.class), - LevelEmitter(AEFeature.LevelEmiter, PartLevelEmitter.class), + ImportBus(240, AEFeature.ImportBus, PartImportBus.class), - AnnihilationPlane(AEFeature.AnnihilationPlane, PartAnnihilationPlane.class), + ExportBus(260, AEFeature.ExportBus, PartExportBus.class), - FormationPlane(AEFeature.FormationPlane, PartFormationPlane.class), + LevelEmitter(280, AEFeature.LevelEmiter, PartLevelEmitter.class), - P2PTunnelME(AEFeature.P2PTunnelME, PartP2PTunnelME.class, GuiText.METunnel), + AnnihilationPlane(300, AEFeature.AnnihilationPlane, PartAnnihilationPlane.class), - P2PTunnelRedstone(AEFeature.P2PTunnelRedstone, PartP2PRedstone.class, GuiText.RedstoneTunnel), - - P2PTunnelItems(AEFeature.P2PTunnelItems, PartP2PItems.class, GuiText.ItemTunnel), - - P2PTunnelLiquids(AEFeature.P2PTunnelLiquids, PartP2PLiquids.class, GuiText.FluidTunnel), - - P2PTunnelMJ(AEFeature.P2PTunnelMJ, PartP2PBCPower.class, GuiText.MJTunnel), - - P2PTunnelEU(AEFeature.P2PTunnelEU, PartP2PIC2Power.class, GuiText.EUTunnel), + FormationPlane(320, AEFeature.FormationPlane, PartFormationPlane.class), // CraftingMonitor(AEFeature.Crafting, PartCraftingMonitor.class), - PatternTerminal(AEFeature.CraftingTerminal, PartPatternTerminal.class), + PatternTerminal(340, AEFeature.CraftingTerminal, PartPatternTerminal.class), - CraftingTerminal(AEFeature.CraftingTerminal, PartCraftingTerminal.class), + CraftingTerminal(360, AEFeature.CraftingTerminal, PartCraftingTerminal.class), - Terminal(AEFeature.Core, PartTerminal.class), + Terminal(380, AEFeature.Core, PartTerminal.class), - StorageMonitor(AEFeature.StorageMonitor, PartStorageMonitor.class), + StorageMonitor(400, AEFeature.StorageMonitor, PartStorageMonitor.class), - ConversionMonitor(AEFeature.PartConversionMonitor, PartConversionMonitor.class), + ConversionMonitor(420, AEFeature.PartConversionMonitor, PartConversionMonitor.class), - Interface(AEFeature.Core, PartInterface.class), + Interface(440, AEFeature.Core, PartInterface.class), - P2PTunnelRF(AEFeature.P2PTunnelRF, PartP2PRFPower.class, GuiText.RFTunnel); + P2PTunnelME(460, AEFeature.P2PTunnelME, PartP2PTunnelME.class, GuiText.METunnel), + + P2PTunnelRedstone(461, AEFeature.P2PTunnelRedstone, PartP2PRedstone.class, GuiText.RedstoneTunnel), + + P2PTunnelItems(462, AEFeature.P2PTunnelItems, PartP2PItems.class, GuiText.ItemTunnel), + + P2PTunnelLiquids(463, AEFeature.P2PTunnelLiquids, PartP2PLiquids.class, GuiText.FluidTunnel), + + P2PTunnelMJ(464, AEFeature.P2PTunnelMJ, PartP2PBCPower.class, GuiText.MJTunnel), + + P2PTunnelEU(465, AEFeature.P2PTunnelEU, PartP2PIC2Power.class, GuiText.EUTunnel), + + P2PTunnelRF(466, AEFeature.P2PTunnelRF, PartP2PRFPower.class, GuiText.RFTunnel); private final EnumSet features; private final Class myPart; private final GuiText extraName; + public final int baseDamage; - PartType(AEFeature part, Class c) { - this( part, c, null ); + PartType(int baseMetaValue, AEFeature part, Class c) { + this( baseMetaValue, part, c, null ); } - PartType(AEFeature part, Class c, GuiText en) { + PartType(int baseMetaValue, AEFeature part, Class c, GuiText en) { features = EnumSet.of( part ); myPart = c; extraName = en; + baseDamage = baseMetaValue; } public Enum[] getVarients() diff --git a/migration/IItemMigrate.java b/migration/IItemMigrate.java new file mode 100644 index 00000000..e46963eb --- /dev/null +++ b/migration/IItemMigrate.java @@ -0,0 +1,10 @@ +package appeng.migration; + +import net.minecraft.item.ItemStack; + +public interface IItemMigrate +{ + + void modifyItemStack(ItemStack is); + +} diff --git a/migration/OldItemMaterial.java b/migration/OldItemMaterial.java new file mode 100644 index 00000000..40edea87 --- /dev/null +++ b/migration/OldItemMaterial.java @@ -0,0 +1,311 @@ +package appeng.migration; + +import java.util.Collections; +import java.util.Comparator; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map.Entry; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import net.minecraftforge.oredict.OreDictionary; +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; +import appeng.core.features.ItemStackSrc; +import appeng.items.AEBaseItem; +import appeng.items.materials.ItemMultiMaterial; +import appeng.items.materials.MaterialType; +import appeng.util.Platform; + +public class OldItemMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule, IItemMigrate +{ + + HashMap dmgToMaterial = new HashMap(); + + public static OldItemMaterial instance; + + public OldItemMaterial() { + super( OldItemMaterial.class ); + setfeature( EnumSet.of( AEFeature.AlphaMigration ) ); + setHasSubtypes( true ); + instance = this; + + for (OldMaterialType omt : OldMaterialType.values()) + { + createMaterial( omt ); + } + } + + class SlightlyBetterSort implements Comparator + { + + Pattern p; + + public SlightlyBetterSort(Pattern p) { + this.p = p; + } + + @Override + public int compare(String o1, String o2) + { + try + { + Matcher a = p.matcher( o1 ); + Matcher b = p.matcher( o2 ); + if ( a.find() && b.find() ) + { + int ia = Integer.parseInt( a.group( 1 ) ); + int ib = Integer.parseInt( b.group( 1 ) ); + return Integer.compare( ia, ib ); + } + } + catch (Throwable t) + { + // ek! + } + return o1.compareTo( o2 ); + } + } + + @Override + public void addInformation(ItemStack is, EntityPlayer player, List details, boolean moar) + { + super.addInformation( is, player, details, moar ); + + OldMaterialType mt = getTypeByStack( is ); + if ( mt == null ) + return; + + if ( mt == OldMaterialType.NamePress ) + { + NBTTagCompound c = Platform.openNbtData( is ); + details.add( c.getString( "InscribeName" ) ); + } + + Upgrades u = getType( is ); + if ( u != null ) + { + List textList = new LinkedList(); + for (Entry j : u.getSupported().entrySet()) + { + String name = null; + + int limit = j.getValue(); + + if ( j.getKey().getItem() instanceof IItemGroup ) + { + IItemGroup ig = (IItemGroup) j.getKey().getItem(); + String str = ig.getUnlocalizedGroupName( j.getKey() ); + if ( str != null ) + name = Platform.gui_localize( str ) + (limit > 1 ? " (" + limit + ")" : ""); + } + + if ( name == null ) + name = j.getKey().getDisplayName() + (limit > 1 ? " (" + limit + ")" : ""); + + if ( !textList.contains( name ) ) + textList.add( name ); + } + + Pattern p = Pattern.compile( "(\\d+)[^\\d]" ); + SlightlyBetterSort s = new SlightlyBetterSort( p ); + Collections.sort( textList, s ); + details.addAll( textList ); + } + } + + public ItemStackSrc createMaterial(OldMaterialType mat) + { + String name = mat.name(); + + if ( mat.damageValue == -1 ) + { + boolean enabled = true; + for (AEFeature f : mat.getFeature()) + enabled = enabled && AEConfig.instance.isFeatureEnabled( f ); + + if ( enabled ) + { + int newMaterialNum = AEConfig.instance.get( "materials", name, AEConfig.instance.getFreeMaterial( mat.ordinal() ) ).getInt(); + mat.damageValue = newMaterialNum; + ItemStackSrc output = new ItemStackSrc( this, newMaterialNum ); + + dmgToMaterial.put( newMaterialNum, mat ); + + return output; + } + + return null; + } + else + throw new RuntimeException( "Cannot create the same material twice..." ); + } + + public OldMaterialType getTypeByStack(ItemStack is) + { + if ( dmgToMaterial.containsKey( is.getItemDamage() ) ) + return dmgToMaterial.get( is.getItemDamage() ); + return null; + } + + @Override + public IIcon getIconFromDamage(int dmg) + { + if ( dmgToMaterial.containsKey( dmg ) ) + return dmgToMaterial.get( dmg ).IIcon; + return new MissingIcon( this ); + } + + @Override + public String getUnlocalizedName(ItemStack is) + { + return "AE2-OLD-ITEM"; + } + + @Override + public String getItemStackDisplayName(ItemStack par1ItemStack) { + return "AE2-OLD-ITEM"; + } + + @Override + public void registerIcons(IIconRegister icoRegister) + { + + } + + @Override + public boolean hasCustomEntity(ItemStack is) + { + return getTypeByStack( is ).hasCustomEntity(); + } + + @Override + public Entity createEntity(World w, Entity location, ItemStack itemstack) + { + Class droppedEntity = getTypeByStack( itemstack ).getCustomEntityClass(); + Entity eqi; + + try + { + eqi = droppedEntity.getConstructor( World.class, double.class, double.class, double.class, ItemStack.class ).newInstance( w, location.posX, + location.posY, location.posZ, itemstack ); + } + catch (Throwable t) + { + throw new RuntimeException( t ); + } + + eqi.motionX = location.motionX; + eqi.motionY = location.motionY; + eqi.motionZ = location.motionZ; + + if ( location instanceof EntityItem && eqi instanceof EntityItem ) + ((EntityItem) eqi).delayBeforeCanPickup = ((EntityItem) location).delayBeforeCanPickup; + + return eqi; + } + + @Override + public int getBytes(ItemStack is) + { + switch (getTypeByStack( is )) + { + case Cell1kPart: + return 1024; + case Cell4kPart: + return 1024 * 4; + case Cell16kPart: + return 1024 * 16; + case Cell64kPart: + return 1024 * 64; + default: + } + return 0; + } + + @Override + public boolean isStorageComponent(ItemStack is) + { + switch (getTypeByStack( is )) + { + case Cell1kPart: + case Cell4kPart: + case Cell16kPart: + case Cell64kPart: + return true; + default: + } + return false; + } + + @Override + public Upgrades getType(ItemStack itemstack) + { + switch (getTypeByStack( itemstack )) + { + case CardCapacity: + return Upgrades.CAPACITY; + case CardFuzzy: + return Upgrades.FUZZY; + case CardRedstone: + return Upgrades.REDSTONE; + case CardSpeed: + return Upgrades.SPEED; + case CardInverter: + return Upgrades.INVERTER; + default: + return null; + } + } + + @Override + public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List cList) + { + + } + + @Override + public void modifyItemStack(ItemStack is) + { + if ( is.getItem() == this ) + { + OldMaterialType omt = getTypeByStack( is ); + for (MaterialType mt : MaterialType.values()) + { + if ( omt != null && mt.toString().equals( omt.toString() ) ) + { + ItemStack newStack = ItemMultiMaterial.instance.getStackByType( mt ); + if ( newStack != null ) + { + NBTTagCompound tmp = new NBTTagCompound(); + newStack.stackSize = is.stackSize; + newStack.setTagCompound( is.getTagCompound() ); + + // write then read... + newStack.writeToNBT( tmp ); + is.readFromNBT( tmp ); + return; + } + } + } + } + } +} diff --git a/migration/OldItemPart.java b/migration/OldItemPart.java new file mode 100644 index 00000000..47eaaac4 --- /dev/null +++ b/migration/OldItemPart.java @@ -0,0 +1,239 @@ +package appeng.migration; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import appeng.api.AEApi; +import appeng.api.implementations.items.IItemGroup; +import appeng.api.parts.IPart; +import appeng.api.parts.IPartItem; +import appeng.core.AEConfig; +import appeng.core.features.AEFeature; +import appeng.core.features.AEFeatureHandler; +import appeng.core.features.ItemStackSrc; +import appeng.core.localization.GuiText; +import appeng.items.AEBaseItem; +import appeng.items.parts.ItemMultiPart; +import appeng.items.parts.PartType; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class OldItemPart extends AEBaseItem implements IPartItem, IItemGroup, IItemMigrate +{ + + class OldPartTypeIst + { + + OldPartType part; + int varient; + + @SideOnly(Side.CLIENT) + IIcon ico; + + }; + + HashMap dmgToPart = new HashMap(); + + public static OldItemPart instance; + + public OldItemPart() { + super( OldItemPart.class ); + setfeature( EnumSet.of( AEFeature.Core ) ); + AEApi.instance().partHelper().setItemBusRenderer( this ); + setHasSubtypes( true ); + instance = this; + + for (OldPartType omt : OldPartType.values()) + { + if ( omt.getVarients() == null ) + createPart( omt, null ); + else + { + for (Enum e : omt.getVarients()) + createPart( omt, e ); + } + } + } + + public ItemStackSrc createPart(OldPartType mat, Enum varient) + { + try + { + // I think this still works? + ItemStack is = new ItemStack( this ); + mat.getPart().getConstructor( ItemStack.class ).newInstance( is ); + } + catch (Throwable e) + { + e.printStackTrace(); + return null; // part not supported.. + } + + String name = varient == null ? mat.name() : mat.name() + "." + varient.name(); + int varID = varient == null ? 0 : varient.ordinal(); + + // verify + for (OldPartTypeIst p : dmgToPart.values()) + { + if ( p.part == mat && p.varient == varID ) + throw new RuntimeException( "Cannot create the same material twice..." ); + } + + boolean enabled = true; + for (AEFeature f : mat.getFeature()) + enabled = enabled && AEConfig.instance.isFeatureEnabled( f ); + + if ( enabled ) + { + int newPartNum = AEConfig.instance.get( "parts", name, AEConfig.instance.getFreePart( mat.ordinal() * 32 + varID ) ).getInt(); + ItemStackSrc output = new ItemStackSrc( this, newPartNum ); + + OldPartTypeIst pti = new OldPartTypeIst(); + pti.part = mat; + pti.varient = varID; + + dmgToPart.put( newPartNum, pti ); + return output; + } + + return null; + } + + public int getDamageByType(OldPartType t) + { + for (Entry pt : dmgToPart.entrySet()) + { + if ( pt.getValue().part == t ) + return pt.getKey(); + } + return -1; + } + + public OldPartType getTypeByStack(ItemStack is) + { + if ( is == null ) + return null; + + OldPartTypeIst pt = dmgToPart.get( is.getItemDamage() ); + if ( pt != null ) + return pt.part; + + return null; + } + + @Override + @SideOnly(Side.CLIENT) + public int getSpriteNumber() + { + return 0; + } + + @Override + public IIcon getIconFromDamage(int dmg) + { + IIcon ico = dmgToPart.get( dmg ).ico; + return ico; + } + + @Override + public String getUnlocalizedName(ItemStack is) + { + return "PART"; + } + + @Override + public String getItemStackDisplayName(ItemStack par1ItemStack) { + return "AE2-OLD-PART"; + } + + @Override + public void registerIcons(IIconRegister par1IconRegister) + { + + } + + @Override + public boolean onItemUse(ItemStack is, EntityPlayer player, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ) + { + return AEApi.instance().partHelper().placeBus( is, x, y, z, side, player, w ); + } + + @Override + public IPart createPartFromItemStack(ItemStack is) + { + try + { + OldPartType t = getTypeByStack( is ); + if ( t != null ) + return t.getPart().getConstructor( ItemStack.class ).newInstance( is ); + } + catch (Throwable e) + { + throw new RuntimeException( "Unable to construct IBusPart from IBusItem : " + getTypeByStack( is ).getPart().getName() + + " ; Possibly didn't have correct constructor( ItemStack )", e ); + } + return null; + } + + @Override + public void getSubItems(Item number, CreativeTabs tab, List cList) + { + + } + + public int varientOf(int itemDamage) + { + return dmgToPart.get( itemDamage ).varient; + } + + @Override + public String getUnlocalizedGroupName(ItemStack is) + { + switch (getTypeByStack( is )) + { + case ImportBus: + case ExportBus: + return GuiText.IOBuses.getUnlocalized(); + default: + } + return null; + } + + @Override + public void modifyItemStack(ItemStack is) + { + if ( is.getItem() == this ) + { + OldPartTypeIst omt = dmgToPart.get( is.getItemDamage() ); + for (PartType mt : PartType.values()) + { + if ( omt != null && omt.part != null && mt.toString().equals( omt.part.toString() ) ) + { + ItemStack newStack = ItemMultiPart.instance.getStackFromTypeAndVarient( mt, omt.varient ); + if ( newStack != null ) + { + NBTTagCompound tmp = new NBTTagCompound(); + newStack.stackSize = is.stackSize; + newStack.setTagCompound( is.getTagCompound() ); + + // write then read... + newStack.writeToNBT( tmp ); + is.readFromNBT( tmp ); + return; + } + } + } + } + } + +} diff --git a/migration/OldMaterialType.java b/migration/OldMaterialType.java new file mode 100644 index 00000000..bc47fa61 --- /dev/null +++ b/migration/OldMaterialType.java @@ -0,0 +1,126 @@ +package appeng.migration; + +import java.util.EnumSet; + +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraftforge.oredict.OreDictionary; +import appeng.core.AppEng; +import appeng.core.features.AEFeature; +import appeng.entity.EntityChargedQuartz; +import appeng.entity.EntityIds; +import appeng.entity.EntitySingularity; +import appeng.items.materials.ItemMultiMaterial; +import cpw.mods.fml.common.registry.EntityRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public enum OldMaterialType +{ + CertusQuartzCrystal(AEFeature.Core, "crystalCertusQuartz"), CertusQuartzCrystalCharged(AEFeature.Core, EntityChargedQuartz.class), + + CertusQuartzDust(AEFeature.Core, "dustCertusQuartz"), NetherQuartzDust(AEFeature.Core, "dustNetherQuartz"), Flour(AEFeature.Flour, "dustWheat"), GoldDust( + AEFeature.Core, "dustGold"), IronDust(AEFeature.Core, "dustIron"), IronNugget(AEFeature.Core, "nuggetIron"), + + Silicon(AEFeature.Core, "itemSilicon"), MatterBall, + + FluixCrystal(AEFeature.Core, "crystalFluix"), FluixDust(AEFeature.Core, "dustFluix"), FluixPearl(AEFeature.Core, "pearlFluix"), + + PureifiedCertusQuartzCrystal, PureifiedNetherQuartzCrystal, PureifiedFluixCrystal, + + CalcProcessorPress, EngProcessorPress, LogicProcessorPress, + + CalcProcessorPrint, EngProcessorPrint, LogicProcessorPrint, + + SiliconPress, SiliconPrint, + + NamePress, + + LogicProcessor, CalcProcessor, EngProcessor, + + // Basic Cards + BasicCard, CardRedstone, CardCapacity, + + // Adv Cards + AdvCard, CardFuzzy, CardSpeed, CardInverter, + + Cell2SpatialPart(AEFeature.SpatialIO), Cell16SpatialPart(AEFeature.SpatialIO), Cell128SpatialPart(AEFeature.SpatialIO), + + Cell1kPart(AEFeature.StorageCells), Cell4kPart(AEFeature.StorageCells), Cell16kPart(AEFeature.StorageCells), Cell64kPart(AEFeature.StorageCells), EmptyStorageCell( + AEFeature.StorageCells), + + WoodenGear(AEFeature.GrindStone, "gearWood"), + + Wireless(AEFeature.WirelessAccessTerminal), WirelessBooster(AEFeature.WirelessAccessTerminal), + + FormationCore, AnnihilationCore, + + SkyDust(AEFeature.Core), + + EnderDust(AEFeature.QuantumNetworkBridge, "dustEnder", EntitySingularity.class), Singularity(AEFeature.QuantumNetworkBridge, EntitySingularity.class), QESingularity( + AEFeature.QuantumNetworkBridge, EntitySingularity.class); + + private String oreName; + private EnumSet features; + private Class droppedEntity; + + // IIcon for the material. + @SideOnly(Side.CLIENT) + public IIcon IIcon; + public int damageValue = -1; + + OldMaterialType() { + features = EnumSet.of( AEFeature.Core ); + } + + OldMaterialType(AEFeature part) { + features = EnumSet.of( part ); + } + + OldMaterialType(AEFeature part, Class c) { + features = EnumSet.of( part ); + droppedEntity = c; + + EntityRegistry.registerModEntity( droppedEntity, droppedEntity.getSimpleName(), EntityIds.get( droppedEntity ), AppEng.instance, 16, 4, true ); + } + + OldMaterialType(AEFeature part, String oreDictionary, Class c) { + features = EnumSet.of( part ); + oreName = oreDictionary; + + droppedEntity = c; + EntityRegistry.registerModEntity( droppedEntity, droppedEntity.getSimpleName(), EntityIds.get( droppedEntity ), AppEng.instance, 16, 4, true ); + } + + OldMaterialType(AEFeature part, String oreDictionary) { + features = EnumSet.of( part ); + oreName = oreDictionary; + } + + public ItemStack stack(int size) + { + return new ItemStack( ItemMultiMaterial.instance, size, damageValue ); + } + + public EnumSet getFeature() + { + return features; + } + + public String getOreName() + { + return oreName; + } + + public boolean hasCustomEntity() + { + return droppedEntity != null; + } + + public Class getCustomEntityClass() + { + return droppedEntity; + } + +} diff --git a/migration/OldPartType.java b/migration/OldPartType.java new file mode 100644 index 00000000..618127fa --- /dev/null +++ b/migration/OldPartType.java @@ -0,0 +1,134 @@ +package appeng.migration; + +import java.util.EnumSet; + +import appeng.api.parts.IPart; +import appeng.api.util.AEColor; +import appeng.core.features.AEFeature; +import appeng.core.localization.GuiText; +import appeng.parts.automation.PartAnnihilationPlane; +import appeng.parts.automation.PartExportBus; +import appeng.parts.automation.PartFormationPlane; +import appeng.parts.automation.PartImportBus; +import appeng.parts.automation.PartLevelEmitter; +import appeng.parts.misc.PartCableAnchor; +import appeng.parts.misc.PartInterface; +import appeng.parts.misc.PartInvertedToggleBus; +import appeng.parts.misc.PartStorageBus; +import appeng.parts.misc.PartToggleBus; +import appeng.parts.networking.PartCableCovered; +import appeng.parts.networking.PartCableGlass; +import appeng.parts.networking.PartCableSmart; +import appeng.parts.networking.PartDenseCable; +import appeng.parts.networking.PartQuartzFiber; +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; +import appeng.parts.reporting.PartCraftingTerminal; +import appeng.parts.reporting.PartDarkMonitor; +import appeng.parts.reporting.PartMonitor; +import appeng.parts.reporting.PartPatternTerminal; +import appeng.parts.reporting.PartSemiDarkMonitor; +import appeng.parts.reporting.PartStorageMonitor; +import appeng.parts.reporting.PartTerminal; + +public enum OldPartType +{ + ToggleBus(AEFeature.Core, PartToggleBus.class), + + InvertedToggleBus(AEFeature.Core, PartInvertedToggleBus.class), + + CableSmart(AEFeature.Core, PartCableSmart.class), CableCovered(AEFeature.Core, PartCableCovered.class), CableGlass(AEFeature.Core, PartCableGlass.class), + + CableDense(AEFeature.DenseCables, PartDenseCable.class), + + CableAnchor(AEFeature.Core, PartCableAnchor.class), + + QuartzFiber(AEFeature.Core, PartQuartzFiber.class), + + Monitor(AEFeature.Core, PartMonitor.class), + + SemiDarkMonitor(AEFeature.Core, PartSemiDarkMonitor.class), + + DarkMonitor(AEFeature.Core, PartDarkMonitor.class), + + StorageBus(AEFeature.StorageBus, PartStorageBus.class), + + ImportBus(AEFeature.ImportBus, PartImportBus.class), + + ExportBus(AEFeature.ExportBus, PartExportBus.class), + + LevelEmitter(AEFeature.LevelEmiter, PartLevelEmitter.class), + + AnnihilationPlane(AEFeature.AnnihilationPlane, PartAnnihilationPlane.class), + + FormationPlane(AEFeature.FormationPlane, PartFormationPlane.class), + + P2PTunnelME(AEFeature.P2PTunnelME, PartP2PTunnelME.class, GuiText.METunnel), + + P2PTunnelRedstone(AEFeature.P2PTunnelRedstone, PartP2PRedstone.class, GuiText.RedstoneTunnel), + + P2PTunnelItems(AEFeature.P2PTunnelItems, PartP2PItems.class, GuiText.ItemTunnel), + + P2PTunnelLiquids(AEFeature.P2PTunnelLiquids, PartP2PLiquids.class, GuiText.FluidTunnel), + + P2PTunnelMJ(AEFeature.P2PTunnelMJ, PartP2PBCPower.class, GuiText.MJTunnel), + + P2PTunnelEU(AEFeature.P2PTunnelEU, PartP2PIC2Power.class, GuiText.EUTunnel), + + // CraftingMonitor(AEFeature.Crafting, PartCraftingMonitor.class), + + PatternTerminal(AEFeature.CraftingTerminal, PartPatternTerminal.class), + + CraftingTerminal(AEFeature.CraftingTerminal, PartCraftingTerminal.class), + + Terminal(AEFeature.Core, PartTerminal.class), + + StorageMonitor(AEFeature.StorageMonitor, PartStorageMonitor.class), + + ConversionMonitor(AEFeature.PartConversionMonitor, PartConversionMonitor.class), + + Interface(AEFeature.Core, PartInterface.class), + + P2PTunnelRF(AEFeature.P2PTunnelRF, PartP2PRFPower.class, GuiText.RFTunnel); + + private final EnumSet features; + private final Class myPart; + private final GuiText extraName; + + OldPartType(AEFeature part, Class c) { + this( part, c, null ); + } + + OldPartType(AEFeature part, Class c, GuiText en) { + features = EnumSet.of( part ); + myPart = c; + extraName = en; + } + + public Enum[] getVarients() + { + return (this == CableSmart || this == CableCovered || this == CableGlass || this == CableDense) ? AEColor.values() : null; + } + + public EnumSet getFeature() + { + return features; + } + + public Class getPart() + { + return myPart; + } + + public GuiText getExtraName() + { + return extraName; + } + +} diff --git a/parts/CableBusContainer.java b/parts/CableBusContainer.java index e96ee684..a955fd86 100644 --- a/parts/CableBusContainer.java +++ b/parts/CableBusContainer.java @@ -41,7 +41,6 @@ import appeng.api.util.DimensionalCoord; import appeng.client.render.BusRenderHelper; import appeng.client.render.CableRenderHelper; import appeng.facade.FacadeContainer; -import appeng.facade.IFacadeItem; import appeng.helpers.AEMultiTile; import appeng.me.GridConnection; import appeng.util.Platform; @@ -141,7 +140,7 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer @Override public boolean canAddPart(ItemStack is, ForgeDirection side) { - if ( is.getItem() instanceof IFacadeItem ) + if ( PartPlacement.isFacade( is, side ) != null ) return true; if ( is.getItem() instanceof IPartItem ) diff --git a/parts/PartPlacement.java b/parts/PartPlacement.java index 4502b7af..f942ce4c 100644 --- a/parts/PartPlacement.java +++ b/parts/PartPlacement.java @@ -377,16 +377,18 @@ public class PartPlacement return true; } - private static IFacadePart isFacade(ItemStack held, ForgeDirection side) + public static IFacadePart isFacade(ItemStack held, ForgeDirection side) { if ( held.getItem() instanceof IFacadeItem ) return ((IFacadeItem) held.getItem()).createPartFromItemStack( held, side ); + if ( AppEng.instance.isIntegrationEnabled( "BC" ) ) { IBC bc = (IBC) AppEng.instance.getIntegration( "BC" ); if ( bc.isFacade( held ) ) return bc.createFacadePart( held, side ); } + return null; } diff --git a/parts/misc/PartStorageBus.java b/parts/misc/PartStorageBus.java index f004d0f8..fa40f8e3 100644 --- a/parts/misc/PartStorageBus.java +++ b/parts/misc/PartStorageBus.java @@ -154,6 +154,9 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC if ( monitor != null ) monitor.onTick(); + if ( host == null || host.getTile() == null || host.getTile().getWorldObj() == null ) + return; + IMEInventory in = getHandler(); IItemList before = AEApi.instance().storage().createItemList(); if ( in != null ) diff --git a/parts/networking/PartCable.java b/parts/networking/PartCable.java index e6fea62c..2782d94e 100644 --- a/parts/networking/PartCable.java +++ b/parts/networking/PartCable.java @@ -34,9 +34,10 @@ import appeng.block.AEBaseBlock; import appeng.client.texture.CableBusTextures; import appeng.client.texture.FlipableIcon; import appeng.client.texture.TaughtIcon; -import appeng.items.parts.ItemPart; +import appeng.items.parts.ItemMultiPart; import appeng.me.GridAccessException; import appeng.me.helpers.AENetworkProxy; +import appeng.migration.OldItemPart; import appeng.parts.AEBasePart; import appeng.util.Platform; import cpw.mods.fml.relauncher.Side; @@ -53,7 +54,10 @@ public class PartCable extends AEBasePart implements IPartCable public PartCable(Class c, ItemStack is) { super( c, is ); proxy.setIdlePowerUsage( 0.0 ); - proxy.myColor = AEColor.values()[((ItemPart) is.getItem()).varientOf( is.getItemDamage() )]; + if ( is.getItem() instanceof OldItemPart ) + proxy.myColor = AEColor.values()[((OldItemPart) is.getItem()).varientOf( is.getItemDamage() )]; + else + proxy.myColor = AEColor.values()[((ItemMultiPart) is.getItem()).varientOf( is.getItemDamage() )]; } @Override @@ -377,6 +381,8 @@ public class PartCable extends AEBasePart implements IPartCable IPartHost ccph = te instanceof IPartHost ? (IPartHost) te : null; IGridHost gh = te instanceof IGridHost ? (IGridHost) te : null; + rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of, of.getOpposite() ) ) ); + if ( gh != null && ccph != null && gh.getCableConnectionType( of ) == AECableType.GLASS && ccph.getColor() != AEColor.Transparent && ccph.getPart( of.getOpposite() ) == null ) rh.setTexture( getTexture( ccph.getColor() ) ); @@ -406,8 +412,8 @@ public class PartCable extends AEBasePart implements IPartCable default: return; } - rh.renderBlock( x, y, z, renderer ); + rh.renderBlock( x, y, z, renderer ); rh.setTexture( getTexture( getCableColor() ) ); } else @@ -436,7 +442,9 @@ public class PartCable extends AEBasePart implements IPartCable default: return; } + rh.renderBlock( x, y, z, renderer ); + rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); } protected CableBusTextures getChannelTex(int i, boolean b) @@ -486,6 +494,7 @@ public class PartCable extends AEBasePart implements IPartCable IGridHost ghh = te instanceof IGridHost ? (IGridHost) te : null; boolean isSmart = false; + rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of, of.getOpposite() ) ) ); if ( ghh != null && ccph != null && ghh.getCableConnectionType( of.getOpposite() ) == AECableType.GLASS && ccph.getPart( of.getOpposite() ) == null && ccph.getColor() != AEColor.Transparent ) rh.setTexture( getGlassTexture( ccph.getColor() ) ); @@ -515,6 +524,7 @@ public class PartCable extends AEBasePart implements IPartCable default: return; } + rh.renderBlock( x, y, z, renderer ); rh.setTexture( getTexture( getCableColor() ) ); @@ -554,6 +564,7 @@ public class PartCable extends AEBasePart implements IPartCable } rh.renderBlock( x, y, z, renderer ); + rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); if ( isSmart ) { @@ -571,14 +582,16 @@ public class PartCable extends AEBasePart implements IPartCable Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); Tessellator.instance.setColorOpaque_I( getCableColor().mediumVariant ); rh.setTexture( defa, defa, defa, defa, defa, defa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); rh.setTexture( defb, defb, defb, defb, defb, defb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; } + + rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); } @SideOnly(Side.CLIENT) @@ -590,6 +603,8 @@ public class PartCable extends AEBasePart implements IPartCable boolean isGlass = false; AEColor myColor = getCableColor(); + rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of, of.getOpposite() ) ) ); + if ( ghh != null && ccph != null && ghh.getCableConnectionType( of.getOpposite() ) == AECableType.GLASS && ccph.getPart( of.getOpposite() ) == null && ccph.getColor() != AEColor.Transparent ) { @@ -640,11 +655,11 @@ public class PartCable extends AEBasePart implements IPartCable Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); Tessellator.instance.setColorOpaque_I( myColor.mediumVariant ); rh.setTexture( defa, defa, defa, defa, defa, defa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); Tessellator.instance.setColorOpaque_I( myColor.whiteVariant ); rh.setTexture( defb, defb, defb, defb, defb, defb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; } @@ -683,6 +698,7 @@ public class PartCable extends AEBasePart implements IPartCable } rh.renderBlock( x, y, z, renderer ); + rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); if ( !isGlass ) { @@ -694,14 +710,15 @@ public class PartCable extends AEBasePart implements IPartCable Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); Tessellator.instance.setColorOpaque_I( myColor.mediumVariant ); rh.setTexture( defa, defa, defa, defa, defa, defa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); Tessellator.instance.setColorOpaque_I( myColor.whiteVariant ); rh.setTexture( defb, defb, defb, defb, defb, defb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; } + } @SideOnly(Side.CLIENT) @@ -737,17 +754,20 @@ public class PartCable extends AEBasePart implements IPartCable break; } + } @SideOnly(Side.CLIENT) - protected void renderAllFaces(AEBaseBlock blk, int x, int y, int z, RenderBlocks renderer) + protected void renderAllFaces(AEBaseBlock blk, int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) { - renderer.renderFaceXNeg( blk, x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.WEST ) ); - renderer.renderFaceXPos( blk, x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.EAST ) ); - renderer.renderFaceZNeg( blk, x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.NORTH ) ); - renderer.renderFaceZPos( blk, x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.SOUTH ) ); - renderer.renderFaceYNeg( blk, x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.DOWN ) ); - renderer.renderFaceYPos( blk, x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.UP ) ); + rh.setBounds( (float) renderer.renderMinX * 16.0f, (float) renderer.renderMinY * 16.0f, (float) renderer.renderMinZ * 16.0f, + (float) renderer.renderMaxX * 16.0f, (float) renderer.renderMaxY * 16.0f, (float) renderer.renderMaxZ * 16.0f ); + rh.renderFace( x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.WEST ), ForgeDirection.WEST, renderer ); + rh.renderFace( x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.EAST ), ForgeDirection.EAST, renderer ); + rh.renderFace( x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.NORTH ), ForgeDirection.NORTH, renderer ); + rh.renderFace( x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.SOUTH ), ForgeDirection.SOUTH, renderer ); + rh.renderFace( x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.DOWN ), ForgeDirection.DOWN, renderer ); + rh.renderFace( x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.UP ), ForgeDirection.UP, renderer ); } @Override @@ -852,6 +872,7 @@ public class PartCable extends AEBasePart implements IPartCable for (ForgeDirection of : connections) { + rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of, of.getOpposite() ) ) ); switch (of) { case DOWN: @@ -874,9 +895,10 @@ public class PartCable extends AEBasePart implements IPartCable } } - renderer.renderStandardBlock( rh.getBlock(), x, y, z ); + rh.renderBlockCurrentBounds( x, y, z, renderer ); } + rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); rh.setTexture( null ); } diff --git a/parts/networking/PartCableCovered.java b/parts/networking/PartCableCovered.java index 33bf5e86..b84b7555 100644 --- a/parts/networking/PartCableCovered.java +++ b/parts/networking/PartCableCovered.java @@ -229,7 +229,7 @@ public class PartCableCovered extends PartCable } } - renderer.renderStandardBlock( rh.getBlock(), x, y, z ); + rh.renderBlockCurrentBounds( x, y, z, renderer ); } renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; diff --git a/parts/networking/PartCableSmart.java b/parts/networking/PartCableSmart.java index 4177e94b..2c8b5176 100644 --- a/parts/networking/PartCableSmart.java +++ b/parts/networking/PartCableSmart.java @@ -216,11 +216,11 @@ public class PartCableSmart extends PartCable Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); Tessellator.instance.setColorOpaque_I( getCableColor().mediumVariant ); rh.setTexture( defa, defa, defa, defa, defa, defa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); rh.setTexture( defb, defb, defb, defb, defb, defb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; @@ -266,7 +266,8 @@ public class PartCableSmart extends PartCable case UP: renderer.setRenderBounds( 5 / 16.0, 0, 5 / 16.0, 11 / 16.0, 16 / 16.0, 11 / 16.0 ); rh.setTexture( def, def, off, off, off, off ); - renderer.renderStandardBlock( rh.getBlock(), x, y, z ); + rh.renderBlockCurrentBounds( x, y, z, renderer ); + renderer.uvRotateTop = 0; renderer.uvRotateBottom = 0; renderer.uvRotateSouth = 3; @@ -276,11 +277,11 @@ public class PartCableSmart extends PartCable Tessellator.instance.setColorOpaque_I( getCableColor().mediumVariant ); rh.setTexture( defa, defa, offa, offa, offa, offa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); rh.setTexture( defb, defb, offb, offb, offb, offb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); break; case EAST: case WEST: @@ -297,17 +298,17 @@ public class PartCableSmart extends PartCable ico.setFlip( false, true ); renderer.setRenderBounds( 0, 5 / 16.0, 5 / 16.0, 16 / 16.0, 11 / 16.0, 11 / 16.0 ); - renderer.renderStandardBlock( rh.getBlock(), x, y, z ); + rh.renderBlockCurrentBounds( x, y, z, renderer ); Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); Tessellator.instance.setColorOpaque_I( getCableColor().mediumVariant ); rh.setTexture( offa, offa, offa, offa, defa, defa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); rh.setTexture( offb, offb, offb, offb, defb, defb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); break; case NORTH: case SOUTH: @@ -318,17 +319,17 @@ public class PartCableSmart extends PartCable renderer.uvRotateSouth = 2; renderer.uvRotateWest = 1; renderer.setRenderBounds( 5 / 16.0, 5 / 16.0, 0, 11 / 16.0, 11 / 16.0, 16 / 16.0 ); - renderer.renderStandardBlock( rh.getBlock(), x, y, z ); + rh.renderBlockCurrentBounds( x, y, z, renderer ); Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); Tessellator.instance.setColorOpaque_I( getCableColor().mediumVariant ); rh.setTexture( offa, offa, defa, defa, offa, offa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); rh.setTexture( offb, offb, defb, defb, offb, offb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); break; default: break; diff --git a/parts/networking/PartDenseCable.java b/parts/networking/PartDenseCable.java index 50dcedf5..0ab22939 100644 --- a/parts/networking/PartDenseCable.java +++ b/parts/networking/PartDenseCable.java @@ -258,6 +258,7 @@ public class PartDenseCable extends PartCable * rh.setTexture( getTexture( getCableColor() ) ); } */ + rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of, of.getOpposite() ) ) ); if ( ghh != null && ccph != null && ghh.getCableConnectionType( of ) != AECableType.GLASS && ccph.getColor() != AEColor.Transparent && ccph.getPart( of.getOpposite() ) == null ) rh.setTexture( getTexture( myColor = ccph.getColor() ) ); @@ -290,6 +291,7 @@ public class PartDenseCable extends PartCable rh.renderBlock( x, y, z, renderer ); + rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); if ( !isGlass ) { setSmartConnectionRotations( of, renderer ); @@ -300,11 +302,11 @@ public class PartDenseCable extends PartCable Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); Tessellator.instance.setColorOpaque_I( myColor.mediumVariant ); rh.setTexture( defa, defa, defa, defa, defa, defa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); Tessellator.instance.setColorOpaque_I( myColor.whiteVariant ); rh.setTexture( defb, defb, defb, defb, defb, defb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; } @@ -367,7 +369,8 @@ public class PartDenseCable extends PartCable case UP: renderer.setRenderBounds( 3 / 16.0, 0, 3 / 16.0, 13 / 16.0, 16 / 16.0, 13 / 16.0 ); rh.setTexture( def, def, off, off, off, off ); - renderer.renderStandardBlock( rh.getBlock(), x, y, z ); + rh.renderBlockCurrentBounds( x, y, z, renderer ); + renderer.uvRotateTop = 0; renderer.uvRotateBottom = 0; renderer.uvRotateSouth = 3; @@ -377,11 +380,11 @@ public class PartDenseCable extends PartCable Tessellator.instance.setColorOpaque_I( getCableColor().mediumVariant ); rh.setTexture( defa, defa, offa, offa, offa, offa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); rh.setTexture( defb, defb, offb, offb, offb, offb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); break; case EAST: case WEST: @@ -398,17 +401,17 @@ public class PartDenseCable extends PartCable ico.setFlip( false, true ); renderer.setRenderBounds( 0, 3 / 16.0, 3 / 16.0, 16 / 16.0, 13 / 16.0, 13 / 16.0 ); - renderer.renderStandardBlock( rh.getBlock(), x, y, z ); + rh.renderBlockCurrentBounds( x, y, z, renderer ); Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); Tessellator.instance.setColorOpaque_I( getCableColor().mediumVariant ); rh.setTexture( offa, offa, offa, offa, defa, defa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); rh.setTexture( offb, offb, offb, offb, defb, defb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); break; case NORTH: case SOUTH: @@ -419,17 +422,17 @@ public class PartDenseCable extends PartCable renderer.uvRotateSouth = 2; renderer.uvRotateWest = 1; renderer.setRenderBounds( 3 / 16.0, 3 / 16.0, 0, 13 / 16.0, 13 / 16.0, 16 / 16.0 ); - renderer.renderStandardBlock( rh.getBlock(), x, y, z ); + rh.renderBlockCurrentBounds( x, y, z, renderer ); Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); Tessellator.instance.setColorOpaque_I( getCableColor().mediumVariant ); rh.setTexture( offa, offa, defa, defa, offa, offa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); rh.setTexture( offb, offb, defb, defb, offb, offb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); break; default: break; diff --git a/parts/p2p/PartP2PRFPower.java b/parts/p2p/PartP2PRFPower.java index bd792264..2cab3fe6 100644 --- a/parts/p2p/PartP2PRFPower.java +++ b/parts/p2p/PartP2PRFPower.java @@ -156,12 +156,6 @@ public class PartP2PRFPower extends PartP2PTunnel implements cof return 0; } - @Override - public boolean canInterface(ForgeDirection from) - { - return true; - } - @Override public int getEnergyStored(ForgeDirection from) { @@ -249,4 +243,15 @@ public class PartP2PRFPower extends PartP2PTunnel implements cof } return myNullHandler; } + + @Deprecated + public boolean canInterface(ForgeDirection from) + { + return true; + } + + @Override + public boolean canConnectEnergy(ForgeDirection from) { + return true; + } } diff --git a/recipes/AEItemResolver.java b/recipes/AEItemResolver.java index e052b398..5155a4ba 100644 --- a/recipes/AEItemResolver.java +++ b/recipes/AEItemResolver.java @@ -10,7 +10,7 @@ import appeng.api.util.AEColoredItemDefinition; import appeng.core.AppEng; import appeng.items.materials.MaterialType; import appeng.items.misc.ItemCrystalSeed; -import appeng.items.parts.ItemPart; +import appeng.items.parts.ItemMultiPart; import appeng.items.parts.PartType; public class AEItemResolver implements ISubItemResolver @@ -78,19 +78,19 @@ public class AEItemResolver implements ISubItemResolver { String materialName = itemName.substring( itemName.indexOf( "." ) + 1 ); MaterialType mt = MaterialType.valueOf( materialName ); - itemName = itemName.substring( 0, itemName.indexOf( "." ) ); + //itemName = itemName.substring( 0, itemName.indexOf( "." ) ); if ( mt.damageValue >= 0 ) - return new ResolverResult( itemName, mt.damageValue ); + return new ResolverResult( "ItemMultiMaterial", mt.damageValue ); } if ( itemName.startsWith( "ItemPart." ) ) { String partName = itemName.substring( itemName.indexOf( "." ) + 1 ); PartType pt = PartType.valueOf( partName ); - itemName = itemName.substring( 0, itemName.indexOf( "." ) ); - int dVal = ItemPart.instance.getDamageByType( pt ); + //itemName = itemName.substring( 0, itemName.indexOf( "." ) ); + int dVal = ItemMultiPart.instance.getDamageByType( pt ); if ( dVal >= 0 ) - return new ResolverResult( itemName, dVal ); + return new ResolverResult( "ItemMultiPart", dVal ); } } @@ -111,6 +111,6 @@ public class AEItemResolver implements ISubItemResolver } ItemStack is = partType.stack( col, 1 ); - return new ResolverResult( "ItemPart", is.getItemDamage() ); + return new ResolverResult( "ItemMultiPart", is.getItemDamage() ); } } diff --git a/recipes/RecipeHandler.java b/recipes/RecipeHandler.java index 0e100543..f775bab5 100644 --- a/recipes/RecipeHandler.java +++ b/recipes/RecipeHandler.java @@ -25,9 +25,9 @@ import appeng.core.AEConfig; import appeng.core.AELog; import appeng.core.AppEng; import appeng.core.features.AEFeature; -import appeng.items.materials.ItemMaterial; +import appeng.items.materials.ItemMultiMaterial; import appeng.items.misc.ItemCrystalSeed; -import appeng.items.parts.ItemPart; +import appeng.items.parts.ItemMultiPart; import appeng.recipes.handlers.IWebsiteSeralizer; import appeng.recipes.handlers.OreRegistration; import cpw.mods.fml.common.registry.GameRegistry; @@ -245,10 +245,10 @@ public class RecipeHandler implements IRecipeHandler default: } } - else if ( is.getItem() instanceof ItemMaterial ) - realName += "." + ((ItemMaterial) is.getItem()).getTypeByStack( is ).name(); - else if ( is.getItem() instanceof ItemPart ) - realName += "." + ((ItemPart) is.getItem()).getTypeByStack( is ).name(); + else if ( is.getItem() instanceof ItemMultiMaterial ) + realName += "." + ((ItemMultiMaterial) is.getItem()).getTypeByStack( is ).name(); + else if ( is.getItem() instanceof ItemMultiPart ) + realName += "." + ((ItemMultiPart) is.getItem()).getTypeByStack( is ).name(); else if ( is.getItemDamage() > 0 ) realName += "." + is.getItemDamage(); diff --git a/tile/networking/TileCableBus.java b/tile/networking/TileCableBus.java index d61879b2..4a230d4a 100644 --- a/tile/networking/TileCableBus.java +++ b/tile/networking/TileCableBus.java @@ -26,6 +26,7 @@ import appeng.api.parts.SelectedPart; import appeng.api.util.AECableType; import appeng.api.util.AEColor; import appeng.api.util.DimensionalCoord; +import appeng.block.networking.BlockCableBus; import appeng.helpers.AEMultiTile; import appeng.helpers.ICustomCollision; import appeng.hooks.TickHandler; @@ -74,6 +75,7 @@ public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomColl // worldObj.updateAllLightTypes( xCoord, yCoord, zCoord ); } + updateTileSetting(); return ret; } @@ -85,6 +87,32 @@ public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomColl }; + protected void updateTileSetting() + { + if ( cb.requiresDynamicRender ) + { + TileCableBus tcb; + try + { + tcb = (TileCableBus) BlockCableBus.tesrTile.newInstance(); + tcb.copyFrom( this ); + getWorldObj().setTileEntity( xCoord, yCoord, zCoord, tcb ); + } + catch (Throwable t) + { + + } + } + } + + protected void copyFrom(TileCableBus oldTile) + { + CableBusContainer tmpCB = cb; + cb = oldTile.cb; + oldLV = oldTile.oldLV; + oldTile.cb = tmpCB; + } + @Override public void onReady() { @@ -128,6 +156,12 @@ public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomColl return false; } + @Override + public double getMaxRenderDistanceSquared() + { + return 900.0; + } + @Override public void getDrops(World w, int x, int y, int z, ArrayList drops) { diff --git a/tile/networking/TileCableBusTESR.java b/tile/networking/TileCableBusTESR.java new file mode 100644 index 00000000..2879c2ce --- /dev/null +++ b/tile/networking/TileCableBusTESR.java @@ -0,0 +1,27 @@ +package appeng.tile.networking; + +import appeng.block.networking.BlockCableBus; + +public class TileCableBusTESR extends TileCableBus +{ + + @Override + protected void updateTileSetting() + { + if ( !cb.requiresDynamicRender ) + { + TileCableBus tcb; + try + { + tcb = (TileCableBus) BlockCableBus.noTesrTile.newInstance(); + tcb.copyFrom( this ); + getWorldObj().setTileEntity( xCoord, yCoord, zCoord, tcb ); + } + catch (Throwable t) + { + + } + } + } + +} diff --git a/tile/powersink/RedstoneFlux.java b/tile/powersink/RedstoneFlux.java index a2ac0e8f..5faebb49 100644 --- a/tile/powersink/RedstoneFlux.java +++ b/tile/powersink/RedstoneFlux.java @@ -34,8 +34,13 @@ public abstract class RedstoneFlux extends RotaryCraft implements IEnergyHandler return 0; } - @Override + @Deprecated final public boolean canInterface(ForgeDirection from) + { + return canConnectEnergy(from); + } + + final public boolean canConnectEnergy(ForgeDirection from) { return internalCanAcceptPower && getPowerSides().contains( from ); } diff --git a/transformer/AppEngCore.java b/transformer/AppEngCore.java index e70f3b70..56209093 100644 --- a/transformer/AppEngCore.java +++ b/transformer/AppEngCore.java @@ -47,7 +47,7 @@ public class AppEngCore extends DummyModContainer implements IFMLLoadingPlugin @Override public String[] getASMTransformerClass() { - return new String[] { "appeng.transformer.asm.ASMIntegration" }; + return new String[] { "appeng.transformer.asm.ASMIntegration", "appeng.transformer.asm.ASMMigration" }; } @Override diff --git a/transformer/asm/ASMMigration.java b/transformer/asm/ASMMigration.java new file mode 100644 index 00000000..70b8f6d7 --- /dev/null +++ b/transformer/asm/ASMMigration.java @@ -0,0 +1,153 @@ +package appeng.transformer.asm; + +import java.io.InputStream; +import java.util.Iterator; + +import net.minecraft.item.ItemStack; +import net.minecraft.launchwrapper.IClassTransformer; + +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.tree.AbstractInsnNode; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.FieldInsnNode; +import org.objectweb.asm.tree.LabelNode; +import org.objectweb.asm.tree.LineNumberNode; +import org.objectweb.asm.tree.MethodInsnNode; +import org.objectweb.asm.tree.MethodNode; + +import appeng.migration.IItemMigrate; + +public class ASMMigration implements IClassTransformer +{ + + @Override + public byte[] transform(String name, String transformedName, byte[] basicClass) + { + try + { + + if ( transformedName != null && transformedName.equals( "net.minecraft.item.ItemStack" ) ) + { + ClassNode classNode = new ClassNode(); + ClassReader classReader = new ClassReader( basicClass ); + classReader.accept( classNode, 0 ); + + ClassNode srcNode = new ClassNode(); + InputStream is = getClass().getResourceAsStream( "/appeng/transformer/template/ItemStackTemplate.class" ); + ClassReader srcReader = new ClassReader( is ); + srcReader.accept( srcNode, 0 ); + + // MD: net/minecraft/item/ItemStack/readFromNBT (Lnet/minecraft/nbt/NBTTagCompound;)V + // abp/c (Ldg;)V + for (MethodNode mn : classNode.methods) + { + boolean signatureMatch = mn.desc.equals( "(Ldg;)V" ) || mn.desc.equals( "(Lnet/minecraft/nbt/NBTTagCompound;)V" ); + boolean nameMatch = mn.name.equals( "readFromNBT" ) || mn.name.equals( "c" ) || mn.name.equals( "func_77963_c" ); + + if ( nameMatch && signatureMatch ) + { + for (MethodNode smn : srcNode.methods) + { + if ( smn.name.equals( "readFromNBT" ) ) + handleChunkAddition( classNode, srcNode.name, mn, smn, false ); + } + } + } + + ClassWriter writer = new ClassWriter( ClassWriter.COMPUTE_MAXS ); + classNode.accept( writer ); + return writer.toByteArray(); + } + + } + catch (Throwable t) + { + t.printStackTrace(); + } + + return basicClass; + } + + private void handleChunkAddition(ClassNode classNode, String from, MethodNode tmn, MethodNode mn, boolean atbeginning) + { + Iterator i = mn.instructions.iterator(); + while (i.hasNext()) + { + processNode( i.next(), from, classNode.name ); + } + + Iterator g = mn.instructions.iterator(); + while (g.hasNext()) + { + AbstractInsnNode ain = g.next(); + if ( ain instanceof LineNumberNode ) + g.remove(); + else if ( ain instanceof LabelNode ) + g.remove(); + } + + AbstractInsnNode finalReturn = mn.instructions.getLast(); + while (!isReturn( finalReturn.getOpcode() )) + { + mn.instructions.remove( finalReturn ); + finalReturn = mn.instructions.getLast(); + } + mn.instructions.remove( finalReturn ); + + if ( atbeginning ) + tmn.instructions.insert( mn.instructions ); + else + { + AbstractInsnNode node = tmn.instructions.getLast(); + + while (!isReturn( node.getOpcode() )) + node = node.getPrevious(); + + tmn.instructions.insertBefore( node.getPrevious(), mn.instructions ); + } + } + + private boolean isReturn(int opcode) + { + switch (opcode) + { + case Opcodes.ARETURN: + case Opcodes.DRETURN: + case Opcodes.FRETURN: + case Opcodes.LRETURN: + case Opcodes.IRETURN: + case Opcodes.RETURN: + return true; + } + return false; + } + + private void processNode(AbstractInsnNode next, String from, String nePar) + { + if ( next instanceof FieldInsnNode ) + { + FieldInsnNode min = (FieldInsnNode) next; + if ( min.owner.equals( from ) ) + { + min.owner = nePar; + } + } + if ( next instanceof MethodInsnNode ) + { + MethodInsnNode min = (MethodInsnNode) next; + if ( min.owner.equals( from ) ) + { + min.owner = nePar; + } + } + } + + public static void handleMigration(Object itemStackTemplate) + { + ItemStack is = (ItemStack) itemStackTemplate; + if ( is.getItem() != null && is.getItem() instanceof IItemMigrate ) + ((IItemMigrate) is.getItem()).modifyItemStack( (ItemStack) itemStackTemplate ); + } +} \ No newline at end of file diff --git a/transformer/template/ItemStackTemplate.java b/transformer/template/ItemStackTemplate.java new file mode 100644 index 00000000..3be6d305 --- /dev/null +++ b/transformer/template/ItemStackTemplate.java @@ -0,0 +1,15 @@ +package appeng.transformer.template; + +import net.minecraft.nbt.NBTTagCompound; +import appeng.transformer.asm.ASMMigration; + +public class ItemStackTemplate +{ + + public void readFromNBT(NBTTagCompound par1NBTTagCompound) + { + ASMMigration.handleMigration( this ); + return; + } + +} diff --git a/util/Platform.java b/util/Platform.java index 7caf2f3a..cb22f106 100644 --- a/util/Platform.java +++ b/util/Platform.java @@ -59,6 +59,7 @@ import appeng.api.implementations.items.IAEItemPowerStorage; import appeng.api.implementations.items.IAEWrench; import appeng.api.implementations.tiles.ITileStorageMonitorable; import appeng.api.networking.IGrid; +import appeng.api.networking.IGridNode; import appeng.api.networking.energy.IEnergyGrid; import appeng.api.networking.energy.IEnergySource; import appeng.api.networking.security.BaseActionSource; @@ -1522,6 +1523,33 @@ public class Platform player.rotationYaw = player.prevCameraYaw = player.cameraYaw = yaw; } + public static boolean canAccess(AENetworkProxy gridProxy, BaseActionSource src) + { + try + { + if ( src.isPlayer() ) + { + return gridProxy.getSecurity().hasPermission( ((PlayerSource) src).player, SecurityPermissions.BUILD ); + } + else if ( src.isMachine() ) + { + IActionHost te = ((MachineSource) src).via; + IGridNode n = te.getActionableNode(); + if ( n == null ) + return false; + + int playerID = n.getPlayerID(); + return gridProxy.getSecurity().hasPermission( playerID, SecurityPermissions.BUILD ); + } + else + return false; + } + catch (GridAccessException gae) + { + return false; + } + } + public static ItemStack extractItemsByRecipe(IEnergySource energySrc, BaseActionSource mySrc, IMEMonitor src, World w, IRecipe r, ItemStack output, InventoryCrafting ci, ItemStack providedTemplate, int slot, IItemList aitems) { @@ -1572,27 +1600,4 @@ public class Platform return null; } - public static boolean canAccess(AENetworkProxy gridProxy, BaseActionSource src) - { - try - { - if ( src.isPlayer() ) - { - return gridProxy.getSecurity().hasPermission( ((PlayerSource) src).player, SecurityPermissions.BUILD ); - } - else if ( src.isMachine() ) - { - IActionHost te = ((MachineSource) src).via; - int playerID = te.getActionableNode().getPlayerID(); - return gridProxy.getSecurity().hasPermission( playerID, SecurityPermissions.BUILD ); - } - else - return false; - } - catch (GridAccessException gae) - { - return false; - } - } - } diff --git a/util/inv/IMEAdaptor.java b/util/inv/IMEAdaptor.java index 27829634..26e4d1c7 100644 --- a/util/inv/IMEAdaptor.java +++ b/util/inv/IMEAdaptor.java @@ -18,6 +18,7 @@ public class IMEAdaptor extends InventoryAdaptor IMEInventory target; BaseActionSource src; + int maxSlots = 0; public IMEAdaptor(IMEInventory input, BaseActionSource src) { target = input; @@ -32,7 +33,7 @@ public class IMEAdaptor extends InventoryAdaptor @Override public Iterator iterator() { - return new IMEAdaptorIterator( getList() ); + return new IMEAdaptorIterator( this, getList() ); } public ItemStack doRemoveItemsFuzzy(int how_many, ItemStack Filter, IInventoryDestination destination, Actionable type, FuzzyMode fuzzyMode) diff --git a/util/inv/IMEAdaptorIterator.java b/util/inv/IMEAdaptorIterator.java index 4f75defa..c4bdb474 100644 --- a/util/inv/IMEAdaptorIterator.java +++ b/util/inv/IMEAdaptorIterator.java @@ -11,23 +11,40 @@ public class IMEAdaptorIterator implements Iterator Iterator stack; ItemSlot slot = new ItemSlot(); int offset = 0; + boolean hasNext; - public IMEAdaptorIterator(IItemList availableItems) { + final IMEAdaptor parent; + final int containerSize; + + public IMEAdaptorIterator(IMEAdaptor parent, IItemList availableItems) { stack = availableItems.iterator(); + containerSize = parent.maxSlots; + this.parent = parent; } @Override public boolean hasNext() { - return stack.hasNext(); + hasNext = stack.hasNext(); + return offset < containerSize || hasNext; } @Override public ItemSlot next() { - IAEItemStack item = stack.next(); - slot.setAEItemStack( item ); slot.slot = offset++; + + if ( parent.maxSlots < offset ) + parent.maxSlots = offset; + + if ( hasNext ) + { + IAEItemStack item = stack.next(); + slot.setAEItemStack( item ); + return slot; + } + + slot.setItemStack( null ); return slot; }