Fully Implemented Crafting CPU Monitors
This commit is contained in:
parent
42840d6936
commit
d5989750b4
5 changed files with 269 additions and 8 deletions
|
@ -6,6 +6,10 @@ import net.minecraft.creativetab.CreativeTabs;
|
|||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.client.render.BaseBlockRender;
|
||||
import appeng.client.render.blocks.RenderBlockCraftingMonitor;
|
||||
import appeng.client.texture.ExtraBlockTextures;
|
||||
import appeng.tile.crafting.TileCraftingMonitorTile;
|
||||
|
||||
|
@ -17,9 +21,18 @@ public class BlockCraftingMonitor extends BlockCraftingUnit
|
|||
setTileEntiy( TileCraftingMonitorTile.class );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends BaseBlockRender> getRenderer()
|
||||
{
|
||||
return RenderBlockCraftingMonitor.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(int direction, int metadata)
|
||||
{
|
||||
if ( direction != ForgeDirection.SOUTH.ordinal() )
|
||||
return AEApi.instance().blocks().blockCraftingUnit.block().getIcon( direction, metadata );
|
||||
|
||||
switch (metadata)
|
||||
{
|
||||
default:
|
||||
|
|
|
@ -9,6 +9,7 @@ import net.minecraft.util.IIcon;
|
|||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.block.AEBaseBlock;
|
||||
import appeng.block.crafting.BlockCraftingMonitor;
|
||||
import appeng.block.crafting.BlockCraftingUnit;
|
||||
|
@ -32,9 +33,7 @@ public class RenderBlockCrafting extends BaseBlockRender
|
|||
@Override
|
||||
public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj)
|
||||
{
|
||||
renderer.setOverrideBlockTexture( blk.getIcon( 0, is.getItemDamage() ) );
|
||||
super.renderInventory( blk, is, renderer, type, obj );
|
||||
renderer.setOverrideBlockTexture( null );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,7 +52,11 @@ public class RenderBlockCrafting extends BaseBlockRender
|
|||
int meta = w.getBlockMetadata( x, y, z ) & 3;
|
||||
|
||||
boolean isMonitor = blk.getClass() == BlockCraftingMonitor.class;
|
||||
theIcon = blk.getIcon( 0, meta | (formed ? 8 : 0) );
|
||||
theIcon = blk.getIcon( ForgeDirection.SOUTH.ordinal(), meta | (formed ? 8 : 0) );
|
||||
|
||||
IIcon nonForward = theIcon;
|
||||
if ( blk instanceof BlockCraftingMonitor )
|
||||
nonForward = AEApi.instance().blocks().blockCraftingUnit.block().getIcon( 0, meta | (formed ? 8 : 0) );
|
||||
|
||||
if ( formed )
|
||||
{
|
||||
|
@ -97,7 +100,7 @@ public class RenderBlockCrafting extends BaseBlockRender
|
|||
fso( side, highX, ForgeDirection.EAST ), fso( side, highY, ForgeDirection.UP ), fso( side, highZ, ForgeDirection.SOUTH ) );
|
||||
i.prepareBounds( renderer );
|
||||
|
||||
handleSide( blk, meta, x, y, z, i, renderer, theIcon, emitsLight, isMonitor, side, w );
|
||||
handleSide( blk, meta, x, y, z, i, renderer, ct.getForward().equals( side ) ? theIcon : nonForward, emitsLight, isMonitor, side, w );
|
||||
}
|
||||
|
||||
i.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) );
|
||||
|
@ -107,12 +110,10 @@ public class RenderBlockCrafting extends BaseBlockRender
|
|||
}
|
||||
else
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -164,6 +165,8 @@ public class RenderBlockCrafting extends BaseBlockRender
|
|||
return;
|
||||
|
||||
i.setFacesToRender( EnumSet.of( side ) );
|
||||
renderer = BusRenderer.instance.renderer;
|
||||
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateWest = renderer.uvRotateTop = 0;
|
||||
|
||||
if ( meta == 0 && blk.getClass() == BlockCraftingUnit.class )
|
||||
{
|
||||
|
|
|
@ -1,9 +1,24 @@
|
|||
package appeng.client.render.blocks;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.GLAllocation;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.block.AEBaseBlock;
|
||||
import appeng.client.ClientHelper;
|
||||
import appeng.core.AELog;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.tile.crafting.TileCraftingMonitorTile;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class RenderBlockCraftingMonitor extends RenderBlockCrafting
|
||||
{
|
||||
|
@ -15,7 +30,138 @@ public class RenderBlockCraftingMonitor extends RenderBlockCrafting
|
|||
@Override
|
||||
public void renderTile(AEBaseBlock block, AEBaseTile tile, Tessellator tess, double x, double y, double z, float f, RenderBlocks renderer)
|
||||
{
|
||||
if ( Platform.isDrawing( tess ) )
|
||||
return;
|
||||
|
||||
if ( tile instanceof TileCraftingMonitorTile )
|
||||
{
|
||||
TileCraftingMonitorTile cmt = (TileCraftingMonitorTile) tile;
|
||||
IAEItemStack ais = (IAEItemStack) cmt.getJobProgress();
|
||||
|
||||
if ( cmt.dspList == null )
|
||||
{
|
||||
cmt.updateList = true;
|
||||
cmt.dspList = GLAllocation.generateDisplayLists( 1 );
|
||||
}
|
||||
|
||||
if ( ais != null )
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated( x + 0.5, y + 0.5, z + 0.5 );
|
||||
|
||||
if ( cmt.updateList )
|
||||
{
|
||||
cmt.updateList = false;
|
||||
GL11.glNewList( cmt.dspList, GL11.GL_COMPILE_AND_EXECUTE );
|
||||
tesrRenderScreen( tess, cmt, ais );
|
||||
GL11.glEndList();
|
||||
}
|
||||
else
|
||||
GL11.glCallList( cmt.dspList );
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void tesrRenderScreen(Tessellator tess, TileCraftingMonitorTile cmt, IAEItemStack ais)
|
||||
{
|
||||
ForgeDirection side = cmt.getForward();
|
||||
int spin = 0;
|
||||
|
||||
GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS );
|
||||
ForgeDirection d = side;
|
||||
GL11.glTranslated( d.offsetX * 0.69, d.offsetY * 0.69, d.offsetZ * 0.69 );
|
||||
|
||||
float scale = 0.7f;
|
||||
GL11.glScalef( scale, scale, scale );
|
||||
|
||||
if ( d == ForgeDirection.UP )
|
||||
{
|
||||
GL11.glScalef( 1.0f, -1.0f, 1.0f );
|
||||
GL11.glRotatef( 90.0f, 1.0f, 0.0f, 0.0f );
|
||||
GL11.glRotatef( (float) spin * 90.0F, 0, 0, 1 );
|
||||
}
|
||||
|
||||
if ( d == ForgeDirection.DOWN )
|
||||
{
|
||||
GL11.glScalef( 1.0f, -1.0f, 1.0f );
|
||||
GL11.glRotatef( -90.0f, 1.0f, 0.0f, 0.0f );
|
||||
GL11.glRotatef( (float) spin * -90.0F, 0, 0, 1 );
|
||||
}
|
||||
|
||||
if ( d == ForgeDirection.EAST )
|
||||
{
|
||||
GL11.glScalef( -1.0f, -1.0f, -1.0f );
|
||||
GL11.glRotatef( -90.0f, 0.0f, 1.0f, 0.0f );
|
||||
}
|
||||
|
||||
if ( d == ForgeDirection.WEST )
|
||||
{
|
||||
GL11.glScalef( -1.0f, -1.0f, -1.0f );
|
||||
GL11.glRotatef( 90.0f, 0.0f, 1.0f, 0.0f );
|
||||
}
|
||||
|
||||
if ( d == ForgeDirection.NORTH )
|
||||
{
|
||||
GL11.glScalef( -1.0f, -1.0f, -1.0f );
|
||||
}
|
||||
|
||||
if ( d == ForgeDirection.SOUTH )
|
||||
{
|
||||
GL11.glScalef( -1.0f, -1.0f, -1.0f );
|
||||
GL11.glRotatef( 180.0f, 0.0f, 1.0f, 0.0f );
|
||||
}
|
||||
|
||||
GL11.glPushMatrix();
|
||||
try
|
||||
{
|
||||
ItemStack sis = ais.getItemStack();
|
||||
sis.stackSize = 1;
|
||||
|
||||
int br = 16 << 20 | 16 << 4;
|
||||
int var11 = br % 65536;
|
||||
int var12 = br / 65536;
|
||||
OpenGlHelper.setLightmapTextureCoords( OpenGlHelper.lightmapTexUnit, var11 * 0.8F, var12 * 0.8F );
|
||||
|
||||
GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
|
||||
GL11.glDisable( GL11.GL_LIGHTING );
|
||||
GL11.glDisable( GL12.GL_RESCALE_NORMAL );
|
||||
// RenderHelper.enableGUIStandardItemLighting();
|
||||
tess.setColorOpaque_F( 1.0f, 1.0f, 1.0f );
|
||||
|
||||
ClientHelper.proxy.doRenderItem( sis, cmt.getWorldObj() );
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
|
||||
GL11.glTranslatef( 0.0f, 0.14f, -0.24f );
|
||||
GL11.glScalef( 1.0f / 62.0f, 1.0f / 62.0f, 1.0f / 62.0f );
|
||||
|
||||
long qty = ais.getStackSize();
|
||||
if ( qty > 999999999999L )
|
||||
qty = 999999999999L;
|
||||
|
||||
String msg = Long.toString( qty );
|
||||
if ( qty > 1000000000 )
|
||||
msg = Long.toString( qty / 1000000000 ) + "B";
|
||||
else if ( qty > 1000000 )
|
||||
msg = Long.toString( qty / 1000000 ) + "M";
|
||||
else if ( qty > 9999 )
|
||||
msg = Long.toString( qty / 1000 ) + "K";
|
||||
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
int width = fr.getStringWidth( msg );
|
||||
GL11.glTranslatef( -0.5f * width, 0.0f, -1.0f );
|
||||
fr.drawString( msg, 0, 0, 0 );
|
||||
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ import appeng.crafting.CraftingLink;
|
|||
import appeng.crafting.MECraftingInventory;
|
||||
import appeng.me.cache.CraftingGridCache;
|
||||
import appeng.me.cluster.IAECluster;
|
||||
import appeng.tile.crafting.TileCraftingMonitorTile;
|
||||
import appeng.tile.crafting.TileCraftingTile;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
@ -76,7 +77,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
|||
// instance sate
|
||||
private LinkedList<TileCraftingTile> tiles = new LinkedList();
|
||||
private LinkedList<TileCraftingTile> storage = new LinkedList<TileCraftingTile>();
|
||||
private LinkedList<TileCraftingTile> status = new LinkedList<TileCraftingTile>();
|
||||
private LinkedList<TileCraftingMonitorTile> status = new LinkedList<TileCraftingMonitorTile>();
|
||||
|
||||
long availableStorage = 0;
|
||||
public ICraftingLink myLastLink;
|
||||
|
@ -251,7 +252,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
|||
storage.add( te );
|
||||
}
|
||||
else if ( te.isStatus() )
|
||||
status.add( te );
|
||||
status.add( (TileCraftingMonitorTile) te );
|
||||
else if ( te.isAccelerator() )
|
||||
accelerator++;
|
||||
}
|
||||
|
@ -335,6 +336,8 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
|||
if ( finalOutput.getStackSize() <= 0 )
|
||||
completeJob();
|
||||
|
||||
updateCPU();
|
||||
|
||||
if ( myLastLink != null )
|
||||
return ((CraftingLink) myLastLink).injectItems( (IAEItemStack) input, type );
|
||||
|
||||
|
@ -357,6 +360,8 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
|||
if ( finalOutput.getStackSize() <= 0 )
|
||||
completeJob();
|
||||
|
||||
updateCPU();
|
||||
|
||||
if ( myLastLink != null )
|
||||
{
|
||||
what.add( ((CraftingLink) myLastLink).injectItems( (IAEItemStack) insert.copy(), type ) );
|
||||
|
@ -379,6 +384,12 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
|||
return input;
|
||||
}
|
||||
|
||||
private void updateCPU()
|
||||
{
|
||||
for (TileCraftingMonitorTile t : status)
|
||||
t.setJob( finalOutput );
|
||||
}
|
||||
|
||||
public IGrid getGrid()
|
||||
{
|
||||
for (TileCraftingTile r : tiles)
|
||||
|
@ -704,6 +715,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
|||
isComplete = false;
|
||||
markDirty();
|
||||
|
||||
updateCPU();
|
||||
String craftID = generateCraftingID();
|
||||
|
||||
myLastLink = new CraftingLink( generateLinkData( craftID, requestingMachine == null, false ), this );
|
||||
|
@ -952,6 +964,8 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
|||
readFromNBT( core.previousState );
|
||||
core.previousState = null;
|
||||
}
|
||||
|
||||
updateCPU();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,8 +1,65 @@
|
|||
package appeng.tile.crafting;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.tile.events.AETileEventHandler;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class TileCraftingMonitorTile extends TileCraftingTile
|
||||
{
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Integer dspList;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean updateList;
|
||||
|
||||
IAEItemStack dspPlay;
|
||||
|
||||
class CraftingMonitorHandler extends AETileEventHandler
|
||||
{
|
||||
|
||||
public CraftingMonitorHandler() {
|
||||
super( TileEventType.NETWORK );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream(ByteBuf data) throws IOException
|
||||
{
|
||||
boolean hasItem = data.readBoolean();
|
||||
|
||||
if ( hasItem )
|
||||
dspPlay = AEItemStack.loadItemStackFromPacket( data );
|
||||
else
|
||||
dspPlay = null;
|
||||
|
||||
updateList = true;
|
||||
return false; // tesr!
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(ByteBuf data) throws IOException
|
||||
{
|
||||
if ( dspPlay == null )
|
||||
data.writeBoolean( false );
|
||||
else
|
||||
{
|
||||
data.writeBoolean( true );
|
||||
dspPlay.writeToPacket( data );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public TileCraftingMonitorTile() {
|
||||
addNewHandler( new CraftingMonitorHandler() );
|
||||
}
|
||||
|
||||
public boolean isAccelerator()
|
||||
{
|
||||
return false;
|
||||
|
@ -13,4 +70,32 @@ public class TileCraftingMonitorTile extends TileCraftingTile
|
|||
return true;
|
||||
}
|
||||
|
||||
public void setJob(IAEItemStack is)
|
||||
{
|
||||
if ( (is == null) != (dspPlay == null) )
|
||||
{
|
||||
dspPlay = is == null ? null : is.copy();
|
||||
markForUpdate();
|
||||
}
|
||||
else if ( is != null && dspPlay != null )
|
||||
{
|
||||
if ( is.getStackSize() != dspPlay.getStackSize() )
|
||||
{
|
||||
dspPlay = is == null ? null : is.copy();
|
||||
markForUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IAEItemStack getJobProgress()
|
||||
{
|
||||
return dspPlay;// AEItemStack.create( new ItemStack( Items.diamond, 64 ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresTESR()
|
||||
{
|
||||
return getJobProgress() != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue