2013-12-27 23:59:59 +01:00
|
|
|
package appeng.parts.reporting;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
2014-01-20 17:41:37 +01:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.FontRenderer;
|
2014-04-24 09:14:18 +02:00
|
|
|
import net.minecraft.client.renderer.GLAllocation;
|
2014-01-20 17:41:37 +01:00
|
|
|
import net.minecraft.client.renderer.OpenGlHelper;
|
|
|
|
import net.minecraft.client.renderer.RenderBlocks;
|
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-01-20 17:41:37 +01:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-05-03 09:51:56 +02:00
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
2014-01-20 17:41:37 +01:00
|
|
|
import net.minecraft.util.Vec3;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-01-20 17:41:37 +01:00
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
import org.lwjgl.opengl.GL12;
|
|
|
|
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.parts.IPartStorageMonitor;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.networking.security.BaseActionSource;
|
|
|
|
import appeng.api.networking.storage.IStackWatcher;
|
|
|
|
import appeng.api.networking.storage.IStackWatcherHost;
|
|
|
|
import appeng.api.parts.IPartRenderHelper;
|
|
|
|
import appeng.api.storage.IMEMonitor;
|
|
|
|
import appeng.api.storage.StorageChannel;
|
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.storage.data.IAEStack;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.storage.data.IItemList;
|
2014-02-20 05:20:38 +01:00
|
|
|
import appeng.client.ClientHelper;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.client.texture.CableBusTextures;
|
2014-02-07 21:37:22 +01:00
|
|
|
import appeng.core.AELog;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.core.localization.PlayerMessages;
|
|
|
|
import appeng.me.GridAccessException;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
import appeng.util.item.AEItemStack;
|
2014-02-07 06:51:19 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
public class PartStorageMonitor extends PartMonitor implements IPartStorageMonitor, IStackWatcherHost
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
IAEItemStack configuredItem;
|
|
|
|
boolean isLocked;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound data)
|
|
|
|
{
|
|
|
|
super.writeToNBT( data );
|
|
|
|
|
|
|
|
data.setBoolean( "isLocked", isLocked );
|
|
|
|
|
|
|
|
NBTTagCompound myItem = new NBTTagCompound();
|
|
|
|
if ( configuredItem != null )
|
|
|
|
configuredItem.writeToNBT( myItem );
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
data.setTag( "configuredItem", myItem );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound data)
|
|
|
|
{
|
|
|
|
super.readFromNBT( data );
|
|
|
|
|
|
|
|
isLocked = data.getBoolean( "isLocked" );
|
|
|
|
|
|
|
|
NBTTagCompound myItem = data.getCompoundTag( "configuredItem" );
|
|
|
|
configuredItem = AEItemStack.loadItemStackFromNBT( myItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void writeToStream(ByteBuf data) throws IOException
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
|
|
|
super.writeToStream( data );
|
|
|
|
|
|
|
|
data.writeByte( spin );
|
2014-02-20 04:16:41 +01:00
|
|
|
data.writeBoolean( isLocked );
|
2014-01-20 17:41:37 +01:00
|
|
|
data.writeBoolean( configuredItem != null ? true : false );
|
|
|
|
if ( configuredItem != null )
|
|
|
|
configuredItem.writeToPacket( data );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public boolean readFromStream(ByteBuf data) throws IOException
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
|
|
|
boolean stuff = super.readFromStream( data );
|
|
|
|
|
|
|
|
spin = data.readByte();
|
2014-02-20 04:16:41 +01:00
|
|
|
isLocked = data.readBoolean();
|
2014-01-20 17:41:37 +01:00
|
|
|
boolean val = data.readBoolean();
|
|
|
|
if ( val )
|
|
|
|
configuredItem = AEItemStack.loadItemStackFromPacket( data );
|
|
|
|
else
|
|
|
|
configuredItem = null;
|
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
updateList = true;
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
return stuff;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-20 06:18:49 +01:00
|
|
|
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
|
|
|
if ( Platform.isClient() )
|
|
|
|
return true;
|
|
|
|
|
2014-02-03 03:30:52 +01:00
|
|
|
if ( !proxy.isActive() )
|
|
|
|
return false;
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
TileEntity te = this.tile;
|
|
|
|
ItemStack eq = player.getCurrentEquippedItem();
|
|
|
|
if ( Platform.isWrench( player, eq, te.xCoord, te.yCoord, te.zCoord ) )
|
|
|
|
{
|
|
|
|
isLocked = !isLocked;
|
2014-02-09 02:34:52 +01:00
|
|
|
player.addChatMessage( (isLocked ? PlayerMessages.isNowLocked : PlayerMessages.isNowUnlocked).get() );
|
2014-02-20 04:16:41 +01:00
|
|
|
this.getHost().markForUpdate();
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
else if ( !isLocked )
|
|
|
|
{
|
|
|
|
configuredItem = AEItemStack.create( eq );
|
|
|
|
confgiureWatchers();
|
|
|
|
this.getHost().markForUpdate();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
extractItem( player );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void extractItem(EntityPlayer player)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
protected PartStorageMonitor(Class myClass, ItemStack is) {
|
2014-04-24 09:14:18 +02:00
|
|
|
super( myClass, is, true );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public PartStorageMonitor(ItemStack is) {
|
2014-04-24 09:14:18 +02:00
|
|
|
super( PartStorageMonitor.class, is, true );
|
2013-12-27 23:59:59 +01:00
|
|
|
frontBright = CableBusTextures.PartStorageMonitor_Bright;
|
|
|
|
frontColored = CableBusTextures.PartStorageMonitor_Colored;
|
|
|
|
frontDark = CableBusTextures.PartStorageMonitor_Dark;
|
2014-02-22 23:14:43 +01:00
|
|
|
// frontSolid = CableBusTextures.PartStorageMonitor_Solid;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-02-06 05:36:10 +01:00
|
|
|
@Override
|
|
|
|
public boolean requireDynamicRender()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
private boolean updateList;
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
private Integer dspList;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
protected void finalize() throws Throwable
|
|
|
|
{
|
|
|
|
super.finalize();
|
|
|
|
if ( dspList != null )
|
|
|
|
GLAllocation.deleteDisplayLists( dspList );
|
|
|
|
}
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
@Override
|
2014-02-07 06:51:19 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2014-01-20 17:41:37 +01:00
|
|
|
public void renderDynamic(double x, double y, double z, IPartRenderHelper rh, RenderBlocks renderer)
|
|
|
|
{
|
2014-04-24 09:14:18 +02:00
|
|
|
if ( dspList == null )
|
|
|
|
dspList = GLAllocation.generateDisplayLists( 1 );
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
Tessellator tess = Tessellator.instance;
|
2014-02-09 02:34:52 +01:00
|
|
|
if ( Platform.isDrawing( tess ) )
|
2014-01-20 17:41:37 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ( (clientFlags & (POWERED_FLAG | CHANNEL_FLAG)) != (POWERED_FLAG | CHANNEL_FLAG) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
IAEItemStack ais = (IAEItemStack) getDisplayed();
|
|
|
|
if ( ais != null )
|
|
|
|
{
|
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glTranslated( x + 0.5, y + 0.5, z + 0.5 );
|
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
if ( updateList )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2014-04-24 09:14:18 +02:00
|
|
|
updateList = false;
|
|
|
|
GL11.glNewList( dspList, GL11.GL_COMPILE_AND_EXECUTE );
|
|
|
|
tesrRenderScreen( tess, ais );
|
|
|
|
GL11.glEndList();
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
2014-04-24 09:14:18 +02:00
|
|
|
else
|
|
|
|
GL11.glCallList( dspList );
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
GL11.glPopMatrix();
|
|
|
|
}
|
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
private void tesrRenderScreen(Tessellator tess, IAEItemStack ais)
|
|
|
|
{
|
|
|
|
GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS );
|
|
|
|
ForgeDirection d = side;
|
|
|
|
GL11.glTranslated( d.offsetX * 0.76, d.offsetY * 0.76, d.offsetZ * 0.76 );
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
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 );
|
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
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 );
|
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
if ( d == ForgeDirection.EAST )
|
|
|
|
{
|
|
|
|
GL11.glScalef( -1.0f, -1.0f, -1.0f );
|
|
|
|
GL11.glRotatef( -90.0f, 0.0f, 1.0f, 0.0f );
|
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
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 );
|
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
GL11.glPushMatrix();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ItemStack sis = ais.getItemStack();
|
|
|
|
sis.stackSize = 1;
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
int br = 16 << 20 | 16 << 4;
|
|
|
|
int var11 = br % 65536;
|
|
|
|
int var12 = br / 65536;
|
|
|
|
OpenGlHelper.setLightmapTextureCoords( OpenGlHelper.lightmapTexUnit, var11 * 0.8F, var12 * 0.8F );
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
GL11.glDisable( GL11.GL_LIGHTING );
|
|
|
|
GL11.glDisable( GL12.GL_RESCALE_NORMAL );
|
|
|
|
// RenderHelper.enableGUIStandardItemLighting();
|
|
|
|
tess.setColorOpaque_F( 1.0f, 1.0f, 1.0f );
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-07-07 04:04:58 +02:00
|
|
|
ClientHelper.proxy.doRenderItem( sis, this.tile.getWorldObj() );
|
2014-02-07 21:37:22 +01:00
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
AELog.error( e );
|
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
GL11.glPopMatrix();
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
GL11.glTranslatef( 0.0f, 0.14f, -0.24f );
|
|
|
|
GL11.glScalef( 1.0f / 62.0f, 1.0f / 62.0f, 1.0f / 62.0f );
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
long qty = ais.getStackSize();
|
|
|
|
if ( qty > 999999999999L )
|
|
|
|
qty = 999999999999L;
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
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";
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-04-24 09:14:18 +02:00
|
|
|
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();
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public IAEStack getDisplayed()
|
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
return configuredItem;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isLocked()
|
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
return isLocked;
|
|
|
|
}
|
|
|
|
|
|
|
|
IStackWatcher myWatcher;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateWatcher(IStackWatcher newWatcher)
|
|
|
|
{
|
|
|
|
myWatcher = newWatcher;
|
|
|
|
confgiureWatchers();
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the system...
|
|
|
|
public void confgiureWatchers()
|
|
|
|
{
|
|
|
|
if ( myWatcher != null )
|
|
|
|
myWatcher.clear();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( configuredItem != null )
|
|
|
|
{
|
|
|
|
if ( myWatcher != null )
|
|
|
|
myWatcher.add( configuredItem );
|
|
|
|
|
|
|
|
updateReportingValue( proxy.getStorage().getItemInventory() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// >.>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateReportingValue(IMEMonitor<IAEItemStack> itemInventory)
|
|
|
|
{
|
|
|
|
if ( configuredItem != null )
|
|
|
|
{
|
|
|
|
IAEItemStack result = itemInventory.getStorageList().findPrecise( configuredItem );
|
|
|
|
if ( result == null )
|
|
|
|
configuredItem.setStackSize( 0 );
|
|
|
|
else
|
|
|
|
configuredItem.setStackSize( result.getStackSize() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStackChange(IItemList o, IAEStack fullStack, IAEStack diffStack, BaseActionSource src, StorageChannel chan)
|
|
|
|
{
|
|
|
|
if ( configuredItem != null )
|
|
|
|
{
|
|
|
|
if ( fullStack == null )
|
|
|
|
configuredItem.setStackSize( 0 );
|
|
|
|
else
|
|
|
|
configuredItem.setStackSize( fullStack.getStackSize() );
|
|
|
|
|
|
|
|
getHost().markForUpdate();
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-05-03 09:51:56 +02:00
|
|
|
@Override
|
|
|
|
public boolean showNetworkInfo(MovingObjectPosition where)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|