diff --git a/block/crafting/BlockCraftingUnit.java b/block/crafting/BlockCraftingUnit.java index eda5b12aa..1a2d53353 100644 --- a/block/crafting/BlockCraftingUnit.java +++ b/block/crafting/BlockCraftingUnit.java @@ -10,11 +10,13 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.IIcon; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; import appeng.block.AEBaseBlock; import appeng.client.render.BaseBlockRender; import appeng.client.render.blocks.RenderBlockCrafting; +import appeng.client.texture.ExtraTextures; import appeng.core.features.AEFeature; import appeng.tile.crafting.TileCraftingTile; @@ -38,6 +40,34 @@ public class BlockCraftingUnit extends AEBaseBlock setTileEntiy( TileCraftingTile.class ); } + @Override + public IIcon getIcon(int direction, int metadata) + { + switch (metadata) + { + case BASE_MONITOR: + if ( direction == 0 ) + return ExtraTextures.BlockCraftingStorageMonitor.getIcon(); + break; + case BASE_STORAGE: + return ExtraTextures.BlockCraftingStorage1k.getIcon(); + case BASE_ACCELERATOR: + return ExtraTextures.BlockCraftingAccelerator.getIcon(); + case BASE_MONITOR | 8: + if ( direction == 0 ) + return ExtraTextures.BlockCraftingStorageMonitorFit.getIcon(); + break; + case BASE_STORAGE | 8: + return ExtraTextures.BlockCraftingStorage1kFit.getIcon(); + case BASE_ACCELERATOR | 8: + return ExtraTextures.BlockCraftingAcceleratorFit.getIcon(); + case BASE_DAMAGE | 8: + return ExtraTextures.BlockCraftingUnitFit.getIcon(); + } + + return super.getIcon( direction, metadata ); + } + @Override protected Class getRenderer() { diff --git a/client/render/BusRenderHelper.java b/client/render/BusRenderHelper.java index 8308878c8..5b4ffc32a 100644 --- a/client/render/BusRenderHelper.java +++ b/client/render/BusRenderHelper.java @@ -8,7 +8,7 @@ import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.IIcon; import net.minecraftforge.common.util.ForgeDirection; import appeng.api.AEApi; -import appeng.api.parts.IPart; +import appeng.api.parts.IBoxProvider; import appeng.api.parts.IPartCollsionHelper; import appeng.api.parts.IPartRenderHelper; import appeng.api.parts.ISimplifiedBundle; @@ -148,7 +148,7 @@ public class BusRenderHelper implements IPartRenderHelper } @Override - public ISimplifiedBundle useSimpliedRendering(int x, int y, int z, IPart p, ISimplifiedBundle sim) + public ISimplifiedBundle useSimpliedRendering(int x, int y, int z, IBoxProvider p, ISimplifiedBundle sim) { RenderBlocksWorkaround rbw = BusRenderer.instance.renderer; @@ -167,21 +167,29 @@ public class BusRenderHelper implements IPartRenderHelper rbw.faces.clear(); bbc.started = false; - p.getBoxes( bbc ); + if ( p == null ) + { + bbc.minX = bbc.minY = bbc.minZ = 0; + bbc.maxX = bbc.maxY = bbc.maxZ = 16; + } + else + { + p.getBoxes( bbc ); - if ( bbc.minX < 1 ) - bbc.minX = 1; - if ( bbc.minY < 1 ) - bbc.minY = 1; - if ( bbc.minZ < 1 ) - bbc.minZ = 1; + if ( bbc.minX < 1 ) + bbc.minX = 1; + if ( bbc.minY < 1 ) + bbc.minY = 1; + if ( bbc.minZ < 1 ) + bbc.minZ = 1; - if ( bbc.maxX > 15 ) - bbc.maxX = 15; - if ( bbc.maxY > 15 ) - bbc.maxY = 15; - if ( bbc.maxZ > 15 ) - bbc.maxZ = 15; + if ( bbc.maxX > 15 ) + bbc.maxX = 15; + if ( bbc.maxY > 15 ) + bbc.maxY = 15; + if ( bbc.maxZ > 15 ) + bbc.maxZ = 15; + } setBounds( bbc.minX, bbc.minY, bbc.minZ, bbc.maxX, bbc.maxY, bbc.maxZ ); @@ -207,6 +215,29 @@ public class BusRenderHelper implements IPartRenderHelper maxZ = maxz; } + public double getBound(ForgeDirection side) + { + switch (side) + { + default: + case UNKNOWN: + return 0.5; + case DOWN: + return minY; + case EAST: + return maxX; + case NORTH: + return minZ; + case SOUTH: + return maxZ; + case UP: + return maxY; + case WEST: + return minX; + + } + } + @Override public void setInvColor(int newColor) { diff --git a/client/render/RenderBlocksWorkaround.java b/client/render/RenderBlocksWorkaround.java index 80b470835..8bd9c0445 100644 --- a/client/render/RenderBlocksWorkaround.java +++ b/client/render/RenderBlocksWorkaround.java @@ -665,7 +665,10 @@ public class RenderBlocksWorkaround extends RenderBlocks for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++) for (int k = -1; k <= 1; k++) + { + lightHashTmp[o++] = blk.getMixedBrightnessForBlock( this.blockAccess, x + i, y + j, z + k ); + } return Arrays.hashCode( lightHashTmp ); } diff --git a/client/render/blocks/RenderBlockCrafting.java b/client/render/blocks/RenderBlockCrafting.java index e3b367d67..b69c628e9 100644 --- a/client/render/blocks/RenderBlockCrafting.java +++ b/client/render/blocks/RenderBlockCrafting.java @@ -1,11 +1,19 @@ package appeng.client.render.blocks; +import java.util.EnumSet; + import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import net.minecraftforge.common.util.ForgeDirection; import appeng.block.AEBaseBlock; +import appeng.block.crafting.BlockCraftingUnit; +import appeng.block.crafting.ItemBlockCraftingUnit; import appeng.client.render.BaseBlockRender; +import appeng.client.render.BusRenderHelper; +import appeng.client.render.BusRenderer; import appeng.client.texture.ExtraTextures; import appeng.tile.crafting.TileCraftingTile; @@ -19,30 +27,244 @@ public class RenderBlockCrafting extends BaseBlockRender @Override public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) { - renderer.setOverrideBlockTexture( blk.getIcon( 0, 0 ) ); + if ( is.getItemDamage() == BlockCraftingUnit.BASE_STORAGE ) + { + ItemBlockCraftingUnit ibcu = (ItemBlockCraftingUnit) is.getItem(); + int bytes = (int) ibcu.getStorageBytes( is ); + final int k = 1024; + switch (bytes) + { + case k: + renderer.setOverrideBlockTexture( ExtraTextures.BlockCraftingStorage1k.getIcon() ); + break; + case 4 * k: + renderer.setOverrideBlockTexture( ExtraTextures.BlockCraftingStorage4k.getIcon() ); + break; + case 16 * k: + renderer.setOverrideBlockTexture( ExtraTextures.BlockCraftingStorage16k.getIcon() ); + break; + case 64 * k: + renderer.setOverrideBlockTexture( ExtraTextures.BlockCraftingStorage64k.getIcon() ); + break; + } + } + else + renderer.setOverrideBlockTexture( blk.getIcon( 0, is.getItemDamage() ) ); + super.renderInventory( blk, is, renderer, type, obj ); renderer.setOverrideBlockTexture( null ); } @Override - public boolean renderInWorld(AEBaseBlock blk, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + public boolean renderInWorld(AEBaseBlock blk, IBlockAccess w, int x, int y, int z, RenderBlocks renderer) { - TileCraftingTile ct = blk.getTileEntity( world, x, y, z ); - if ( ct != null && ct.isFormed() ) - { - renderer.overrideBlockTexture = ExtraTextures.BlockControllerConflict.getIcon(); - boolean out = renderer.renderStandardBlock( blk, x, y, z ); - renderer.overrideBlockTexture = null; + IIcon theIcon = null; + boolean formed = false; - return out; + TileCraftingTile ct = blk.getTileEntity( w, x, y, z ); + if ( ct != null && ct.isFormed() ) + formed = true; + + int meta = w.getBlockMetadata( x, y, z ) & 7; + + if ( meta == BlockCraftingUnit.BASE_STORAGE ) + { + TileCraftingTile tct = (TileCraftingTile) blk.getTileEntity( w, x, y, z ); + + final int k = 1024; + switch ((int) tct.getStorageBytes()) + { + case k: + theIcon = formed ? ExtraTextures.BlockCraftingStorage1kFit.getIcon() : ExtraTextures.BlockCraftingStorage1k.getIcon(); + break; + case 4 * k: + theIcon = formed ? ExtraTextures.BlockCraftingStorage4kFit.getIcon() : ExtraTextures.BlockCraftingStorage4k.getIcon(); + break; + case 16 * k: + theIcon = formed ? ExtraTextures.BlockCraftingStorage16kFit.getIcon() : ExtraTextures.BlockCraftingStorage16k.getIcon(); + break; + case 64 * k: + theIcon = formed ? ExtraTextures.BlockCraftingStorage64kFit.getIcon() : ExtraTextures.BlockCraftingStorage64k.getIcon(); + break; + } + } + else + theIcon = blk.getIcon( 0, meta | (formed ? 8 : 0) ); + + if ( formed ) + { + renderer = BusRenderer.instance.renderer; + BusRenderHelper i = BusRenderHelper.instance; + renderer.blockAccess = w; + i.setPass( 0 ); + i.ax = ForgeDirection.EAST; + i.ay = ForgeDirection.UP; + i.az = ForgeDirection.SOUTH; + + try + { + ct.lightCache = i.useSimpliedRendering( x, y, z, null, ct.lightCache ); + } + catch (Throwable t) + { + t.printStackTrace(); + + } + float highX = isConnected( w, x, y, z, ForgeDirection.EAST ) ? 16 : 13.01f; + float lowX = isConnected( w, x, y, z, ForgeDirection.WEST ) ? 0 : 2.99f; + + float highY = isConnected( w, x, y, z, ForgeDirection.UP ) ? 16 : 13.01f; + float lowY = isConnected( w, x, y, z, ForgeDirection.DOWN ) ? 0 : 2.99f; + + float highZ = isConnected( w, x, y, z, ForgeDirection.SOUTH ) ? 16 : 13.01f; + float lowZ = isConnected( w, x, y, z, ForgeDirection.NORTH ) ? 0 : 2.99f; + + renderCorner( i, renderer, w, x, y, z, ForgeDirection.UP, ForgeDirection.EAST, ForgeDirection.NORTH ); + renderCorner( i, renderer, w, x, y, z, ForgeDirection.UP, ForgeDirection.EAST, ForgeDirection.SOUTH ); + renderCorner( i, renderer, w, x, y, z, ForgeDirection.UP, ForgeDirection.WEST, ForgeDirection.NORTH ); + renderCorner( i, renderer, w, x, y, z, ForgeDirection.UP, ForgeDirection.WEST, ForgeDirection.SOUTH ); + renderCorner( i, renderer, w, x, y, z, ForgeDirection.DOWN, ForgeDirection.EAST, ForgeDirection.NORTH ); + renderCorner( i, renderer, w, x, y, z, ForgeDirection.DOWN, ForgeDirection.EAST, ForgeDirection.SOUTH ); + renderCorner( i, renderer, w, x, y, z, ForgeDirection.DOWN, ForgeDirection.WEST, ForgeDirection.NORTH ); + renderCorner( i, renderer, w, x, y, z, ForgeDirection.DOWN, ForgeDirection.WEST, ForgeDirection.SOUTH ); + + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + { + i.setBounds( fso( side, lowX, ForgeDirection.WEST ), fso( side, lowY, ForgeDirection.DOWN ), fso( side, lowZ, ForgeDirection.NORTH ), + fso( side, highX, ForgeDirection.EAST ), fso( side, highY, ForgeDirection.UP ), fso( side, highZ, ForgeDirection.SOUTH ) ); + i.prepareBounds( renderer ); + + handleSide( x, y, z, i, renderer, theIcon, side, w ); + } + + i.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); + i.normalRendering(); + + return true; } else { - renderer.overrideBlockTexture = blk.getIcon( 0, 0 ); + renderer.setOverrideBlockTexture( theIcon ); + double a = 0.0 / 16.0; + double o = 16.0 / 16.0; + renderer.setRenderBounds( a, a, a, o, o, o ); boolean out = renderer.renderStandardBlock( blk, x, y, z ); renderer.overrideBlockTexture = null; return out; } } + + private void renderCorner(BusRenderHelper i, RenderBlocks renderer, IBlockAccess w, int x, int y, int z, ForgeDirection up, ForgeDirection east, + ForgeDirection south) + { + if ( isConnected( w, x, y, z, up ) ) + return; + if ( isConnected( w, x, y, z, east ) ) + return; + if ( isConnected( w, x, y, z, south ) ) + return; + + i.setBounds( gso( east, 3, ForgeDirection.WEST ), gso( up, 3, ForgeDirection.DOWN ), gso( south, 3, ForgeDirection.NORTH ), + gso( east, 13, ForgeDirection.EAST ), gso( up, 13, ForgeDirection.UP ), gso( south, 13, ForgeDirection.SOUTH ) ); + i.prepareBounds( renderer ); + i.setTexture( ExtraTextures.BlockCraftingUnitRing.getIcon() ); + i.renderBlockCurrentBounds( x, y, z, renderer ); + } + + private float gso(ForgeDirection side, float def, ForgeDirection target) + { + if ( side != target ) + { + if ( side.offsetX > 0 || side.offsetY > 0 || side.offsetZ > 0 ) + return 16; + return 0; + } + return def; + } + + private float fso(ForgeDirection side, float def, ForgeDirection target) + { + if ( side == target ) + { + if ( side.offsetX > 0 || side.offsetY > 0 || side.offsetZ > 0 ) + return 16; + return 0; + } + return def; + } + + private void handleSide(int x, int y, int z, BusRenderHelper i, RenderBlocks renderer, IIcon theIcon, ForgeDirection side, IBlockAccess w) + { + if ( isConnected( w, x, y, z, side ) ) + return; + + i.setFacesToRender( EnumSet.of( side ) ); + i.setTexture( ExtraTextures.BlockCraftingHeatVent.getIcon() ); + i.renderBlockCurrentBounds( x, y, z, renderer ); + + i.setTexture( ExtraTextures.BlockCraftingUnitRingLong.getIcon() ); + for (ForgeDirection a : ForgeDirection.VALID_DIRECTIONS) + { + if ( a == side || a == side.getOpposite() ) + continue; + + double width = 3.0 / 16.0; + + if ( !(i.getBound( a ) < 0.001 || i.getBound( a ) > 15.999) ) + { + switch (a) + { + case DOWN: + renderer.renderMinY = 0; + renderer.renderMaxY = width; + break; + case EAST: + renderer.renderMaxX = 1; + renderer.renderMinX = 1.0 - width; + renderer.uvRotateTop = 1; + renderer.uvRotateBottom = 1; + renderer.uvRotateWest = 1; + renderer.uvRotateEast = 1; + break; + case NORTH: + renderer.renderMinZ = 0; + renderer.renderMaxZ = width; + renderer.uvRotateWest = 1; + renderer.uvRotateNorth = 1; + renderer.uvRotateSouth = 1; + break; + case SOUTH: + renderer.renderMaxZ = 1; + renderer.renderMinZ = 1.0 - width; + renderer.uvRotateNorth = 1; + renderer.uvRotateSouth = 1; + break; + case UP: + renderer.renderMaxY = 1; + renderer.renderMinY = 1.0 - width; + break; + case WEST: + renderer.renderMinX = 0; + renderer.renderMaxX = width; + renderer.uvRotateTop = 1; + renderer.uvRotateBottom = 1; + renderer.uvRotateWest = 1; + renderer.uvRotateEast = 1; + break; + case UNKNOWN: + default: + } + + i.renderBlockCurrentBounds( x, y, z, renderer ); + i.prepareBounds( renderer ); + renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateWest = renderer.uvRotateTop = 0; + } + } + } + + private boolean isConnected(IBlockAccess w, int x, int y, int z, ForgeDirection side) + { + return w.getTileEntity( x + side.offsetX, y + side.offsetY, z + side.offsetZ ) instanceof TileCraftingTile; + } } diff --git a/client/texture/ExtraTextures.java b/client/texture/ExtraTextures.java index 5d323f1d2..e8d6313b6 100644 --- a/client/texture/ExtraTextures.java +++ b/client/texture/ExtraTextures.java @@ -52,7 +52,21 @@ public enum ExtraTextures BlockQuartzGrowthAcceleratorOn("BlockQuartzGrowthAcceleratorOn"), BlockQuartzGrowthAcceleratorSideOn("BlockQuartzGrowthAcceleratorSideOn"), - BlockWirelessInside("BlockWirelessInside"); + BlockWirelessInside("BlockWirelessInside"), + + BlockCraftingAccelerator("BlockCraftingAccelerator"), BlockCraftingStorageMonitor("BlockCraftingStorageMonitor"), + + BlockCraftingStorage1k("BlockCraftingStorage1k"), BlockCraftingStorage4k("BlockCraftingStorage4k"), BlockCraftingStorage16k("BlockCraftingStorage16k"), BlockCraftingStorage64k( + "BlockCraftingStorage64k"), + + BlockCraftingAcceleratorFit("BlockCraftingAcceleratorFit"), BlockCraftingStorageMonitorFit("BlockCraftingStorageMonitorFit"), + + BlockCraftingStorage1kFit("BlockCraftingStorage1kFit"), BlockCraftingStorage4kFit("BlockCraftingStorage4kFit"), BlockCraftingStorage16kFit( + "BlockCraftingStorage16kFit"), BlockCraftingStorage64kFit("BlockCraftingStorage64kFit"), + + BlockCraftingUnitRing("BlockCraftingUnitRing"), BlockCraftingUnitRingLong("BlockCraftingUnitRingLong"), BlockCraftingUnitFit("BlockCraftingUnitFit"), + + BlockCraftingHeatVent("BlockCraftingHeatVent"); final private String name; public IIcon IIcon; diff --git a/tile/crafting/TileCraftingTile.java b/tile/crafting/TileCraftingTile.java index 72a18aaec..10b9332ba 100644 --- a/tile/crafting/TileCraftingTile.java +++ b/tile/crafting/TileCraftingTile.java @@ -8,6 +8,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import appeng.api.AEApi; import appeng.api.networking.GridFlags; +import appeng.api.parts.ISimplifiedBundle; import appeng.block.crafting.BlockCraftingUnit; import appeng.me.cluster.IAECluster; import appeng.me.cluster.IAEMultiBlock; @@ -25,6 +26,7 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock private long storageBytes = 0; CraftingCPUCluster clust; final CraftingCPUCalculator calc = new CraftingCPUCalculator( this ); + public ISimplifiedBundle lightCache; @Override protected AENetworkProxy createProxy()