minor cpu gui work.

This commit is contained in:
AlgorithmX2 2014-06-26 21:47:26 -05:00
parent 5cec61d4f2
commit 2a8c028ab9
4 changed files with 131 additions and 110 deletions

View file

@ -1,24 +1,24 @@
package appeng.client.gui.implementations;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
import appeng.api.AEApi;
import appeng.api.config.SortDir;
import appeng.api.config.SortOrder;
import appeng.api.config.ViewItems;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiScrollbar;
import appeng.client.gui.widgets.ISortSource;
import appeng.client.me.ItemRepo;
import appeng.client.me.SlotME;
import appeng.container.implementations.ContainerCraftingCPU;
import appeng.core.localization.GuiText;
import appeng.tile.crafting.TileCraftingTile;
@ -27,18 +27,19 @@ import appeng.util.Platform;
public class GuiCraftingCPU extends AEBaseGui implements ISortSource
{
ItemRepo repo;
GuiImgButton units;
int rows = 6;
int rows = 4;
IItemList<IAEItemStack> storage = AEApi.instance().storage().createItemList();
IItemList<IAEItemStack> active = AEApi.instance().storage().createItemList();
IItemList<IAEItemStack> pending = AEApi.instance().storage().createItemList();
List<IAEItemStack> visual = new ArrayList();
public GuiCraftingCPU(InventoryPlayer inventoryPlayer, TileCraftingTile te) {
super( new ContainerCraftingCPU( inventoryPlayer, te ) );
this.ySize = 153;
this.xSize = 195;
myScrollBar = new GuiScrollbar();
repo = new ItemRepo( myScrollBar, this );
repo.rowSize = 5;
}
@Override
@ -53,20 +54,116 @@ public class GuiCraftingCPU extends AEBaseGui implements ISortSource
super.initGui();
}
public void postUpdate(List<IAEItemStack> list)
private long getTotal(IAEItemStack is)
{
repo.clear();
IAEItemStack a = storage.findPrecise( is );
IAEItemStack b = active.findPrecise( is );
IAEItemStack c = pending.findPrecise( is );
for (IAEItemStack is : list)
repo.postUpdate( is );
long total = 0;
if ( a != null )
total += a.getStackSize();
if ( b != null )
total += b.getStackSize();
if ( c != null )
total += c.getStackSize();
return total;
}
public void postUpdate(List<IAEItemStack> list, byte ref)
{
switch (ref)
{
case 0:
for (IAEItemStack l : list)
handleInput( storage, l );
break;
case 1:
for (IAEItemStack l : list)
handleInput( active, l );
break;
case 2:
for (IAEItemStack l : list)
handleInput( pending, l );
break;
}
for (IAEItemStack l : list)
{
long amt = getTotal( l );
if ( amt <= 0 )
deleteVisualStack( l );
else
{
IAEItemStack is = findVisualStack( l );
is.setStackSize( amt );
}
}
repo.updateView();
setScrollBar();
}
private void handleInput(IItemList<IAEItemStack> s, IAEItemStack l)
{
IAEItemStack a = s.findPrecise( l );
if ( l.getStackSize() <= 0 )
{
a.reset();
}
else
{
if ( a == null )
{
s.add( l.copy() );
a = s.findPrecise( l );
}
}
}
private IAEItemStack findVisualStack(IAEItemStack l)
{
Iterator<IAEItemStack> i = visual.iterator();
while (i.hasNext())
{
IAEItemStack o = i.next();
if ( o.equals( l ) )
return o;
}
IAEItemStack stack = l.copy();
visual.add( stack );
return stack;
}
private void deleteVisualStack(IAEItemStack l)
{
Iterator<IAEItemStack> i = visual.iterator();
while (i.hasNext())
{
IAEItemStack o = i.next();
if ( o.equals( l ) )
{
i.remove();
return;
}
}
}
private void setScrollBar()
{
int size = repo.size();
int size = 0;
for (IAEItemStack l : visual)
size++;
myScrollBar.setTop( 39 ).setLeft( 175 ).setHeight( 78 );
myScrollBar.setRange( 0, (size + 4) / 5 - rows, 1 );
}
@ -121,8 +218,6 @@ public class GuiCraftingCPU extends AEBaseGui implements ISortSource
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY)
{
ContainerCraftingCPU ns = (ContainerCraftingCPU) inventorySlots;
fontRendererObj.drawString( GuiText.NetworkDetails.getLocal(), 8, 7, 4210752 );
int sectionLength = 30;
@ -138,9 +233,9 @@ public class GuiCraftingCPU extends AEBaseGui implements ISortSource
int toolPosX = 0;
int toolPosY = 0;
for (int z = viewStart; z < Math.min( viewEnd, repo.size() ); z++)
for (int z = viewStart; z < Math.min( viewEnd, visual.size() ); z++)
{
IAEItemStack refStack = repo.getRefrenceItem( z );
IAEItemStack refStack = visual.get( z );// repo.getRefrenceItem( z );
if ( refStack != null )
{
GL11.glPushMatrix();
@ -158,9 +253,11 @@ public class GuiCraftingCPU extends AEBaseGui implements ISortSource
int posX = x * sectionLength + xo + sectionLength - 18;
int posY = y * 18 + yo;
ItemStack is = refStack.copy().getItemStack();
if ( tooltip == z - viewStart )
{
ToolTip = Platform.getItemDisplayName( repo.getItem( z ) );
ToolTip = Platform.getItemDisplayName( is );
ToolTip = ToolTip + ("\n" + GuiText.Installed.getLocal() + ": " + (refStack.getStackSize()));
if ( refStack.getCountRequestable() > 0 )
@ -170,7 +267,7 @@ public class GuiCraftingCPU extends AEBaseGui implements ISortSource
toolPosY = y * 18 + yo;
}
drawItem( posX, posY, repo.getItem( z ) );
drawItem( posX, posY, is );
x++;
@ -192,69 +289,6 @@ public class GuiCraftingCPU extends AEBaseGui implements ISortSource
}
// @Override - NEI
public List<String> handleItemTooltip(ItemStack stack, int mousex, int mousey, List<String> currenttip)
{
if ( stack != null )
{
Slot s = getSlot( mousex, mousey );
if ( s instanceof SlotME )
{
IAEItemStack myStack = null;
try
{
SlotME theSlotField = (SlotME) s;
myStack = theSlotField.getAEStack();
}
catch (Throwable _)
{
}
if ( myStack != null )
{
while (currenttip.size() > 1)
currenttip.remove( 1 );
}
}
}
return currenttip;
}
// Vanillia version...
protected void drawItemStackTooltip(ItemStack stack, int x, int y)
{
Slot s = getSlot( x, y );
if ( s instanceof SlotME && stack != null )
{
IAEItemStack myStack = null;
try
{
SlotME theSlotField = (SlotME) s;
myStack = theSlotField.getAEStack();
}
catch (Throwable _)
{
}
if ( myStack != null )
{
List currenttip = stack.getTooltip( this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips );
while (currenttip.size() > 1)
currenttip.remove( 1 );
currenttip.add( GuiText.Installed.getLocal() + ": " + (myStack.getStackSize()) );
currenttip.add( GuiText.EnergyDrain.getLocal() + ": " + Platform.formatPowerLong( myStack.getCountRequestable(), true ) );
drawTooltip( x, y, 0, join( currenttip, "\n" ) );
}
}
// super.drawItemStackTooltip( stack, x, y );
}
@Override
public Enum getSortBy()
{

View file

@ -12,11 +12,9 @@ import appeng.api.networking.IGrid;
import appeng.api.networking.IGridBlock;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMEInventoryUpdate;
import appeng.tile.crafting.TileCraftingTile;
@ -55,15 +53,6 @@ public class ContainerCraftingCPU extends AEBaseContainer
int delay = 40;
@GuiSync(0)
public long avgAddition;
@GuiSync(1)
public long powerUsage;
@GuiSync(2)
public long currentPower;
@GuiSync(3)
public long maxPower;
@Override
public void detectAndSendChanges()
{
@ -72,15 +61,6 @@ public class ContainerCraftingCPU extends AEBaseContainer
{
delay = 0;
IEnergyGrid eg = network.getCache( IEnergyGrid.class );
if ( eg != null )
{
avgAddition = (long) (100.0 * eg.getAvgPowerInjection());
powerUsage = (long) (100.0 * eg.getAvgPowerUsage());
currentPower = (long) (100.0 * eg.getStoredPower());
maxPower = (long) (100.0 * eg.getMaxStoredPower());
}
PacketMEInventoryUpdate piu;
try
{

View file

@ -31,6 +31,7 @@ public class PacketMEInventoryUpdate extends AppEngPacket
{
// output...
final private byte ref;
final private ByteBuf data;
final private GZIPOutputStream compressFrame;
@ -46,6 +47,7 @@ public class PacketMEInventoryUpdate extends AppEngPacket
data = null;
compressFrame = null;
list = new LinkedList();
ref = stream.readByte();
// int originalBytes = stream.readableBytes();
@ -88,7 +90,7 @@ public class PacketMEInventoryUpdate extends AppEngPacket
GuiScreen gs = Minecraft.getMinecraft().currentScreen;
if ( gs instanceof GuiCraftingCPU )
((GuiCraftingCPU) gs).postUpdate( list );
((GuiCraftingCPU) gs).postUpdate( list, ref );
if ( gs instanceof GuiMEMonitorable )
((GuiMEMonitorable) gs).postUpdate( list );
@ -117,9 +119,15 @@ public class PacketMEInventoryUpdate extends AppEngPacket
// api
public PacketMEInventoryUpdate() throws IOException {
this( (byte) 0 );
}
// api
public PacketMEInventoryUpdate(byte ref) throws IOException {
data = Unpooled.buffer( 2048 );
data.writeInt( getPacketID() );
data.writeByte( this.ref = ref );
compressFrame = new GZIPOutputStream( new OutputStream() {

View file

@ -133,7 +133,7 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell
double d3 = 32.0D;
Vec3 vec31 = vec3.addVector( (double) f7 * d3, (double) f6 * d3, (double) f8 * d3 );
Vec3 direction = w.getWorldVec3Pool().getVecFromPool( (double) f7 * d3, (double) f6 * d3, (double) f8 * d3 );
Vec3 direction = vec3.createVectorHelper( (double) f7 * d3, (double) f6 * d3, (double) f8 * d3 );
float penitration = AEApi.instance().registries().matterCannon().getPenetration( ammo ); // 196.96655f;
if ( penitration <= 0 )
@ -174,10 +174,9 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell
{
hasDestroyedSomething = false;
AxisAlignedBB bb = AxisAlignedBB
.getBoundingBox( Math.min( vec3.xCoord, vec31.xCoord ), Math.min( vec3.yCoord, vec31.yCoord ), Math.min( vec3.zCoord, vec31.zCoord ),
Math.max( vec3.xCoord, vec31.xCoord ), Math.max( vec3.yCoord, vec31.yCoord ), Math.max( vec3.zCoord, vec31.zCoord ) )
.expand( 16, 16, 16 );
AxisAlignedBB bb = AxisAlignedBB.getBoundingBox( Math.min( vec3.xCoord, vec31.xCoord ), Math.min( vec3.yCoord, vec31.yCoord ),
Math.min( vec3.zCoord, vec31.zCoord ), Math.max( vec3.xCoord, vec31.xCoord ), Math.max( vec3.yCoord, vec31.yCoord ),
Math.max( vec3.zCoord, vec31.zCoord ) ).expand( 16, 16, 16 );
Entity entity = null;
List list = w.getEntitiesWithinAABBExcludingEntity( p, bb );