Started work on Crafting CPU Gui

This commit is contained in:
AlgorithmX2 2014-06-25 20:49:37 -05:00
parent fdf3272fe0
commit 4ab4b335c3
5 changed files with 422 additions and 0 deletions

View file

@ -6,16 +6,20 @@ import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
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 net.minecraftforge.common.util.ForgeDirection;
import appeng.block.AEBaseBlock;
import appeng.client.render.BaseBlockRender;
import appeng.client.render.blocks.RenderBlockCrafting;
import appeng.client.texture.ExtraBlockTextures;
import appeng.core.features.AEFeature;
import appeng.core.sync.GuiBridge;
import appeng.tile.crafting.TileCraftingTile;
import appeng.util.Platform;
public class BlockCraftingUnit extends AEBaseBlock
{
@ -34,6 +38,18 @@ public class BlockCraftingUnit extends AEBaseBlock
setTileEntiy( TileCraftingTile.class );
}
@Override
public boolean onActivated(World w, int x, int y, int z, EntityPlayer p, int side, float hitX, float hitY, float hitZ)
{
TileCraftingTile tg = getTileEntity( w, x, y, z );
if ( tg != null && !p.isSneaking() && tg.isFormed() && tg.isActive() )
{
Platform.openGUI( p, tg, ForgeDirection.getOrientation( side ), GuiBridge.GUI_CRAFTING_CPU );
return true;
}
return false;
}
@Override
public int getDamageValue(World w, int x, int y, int z)
{

View file

@ -0,0 +1,275 @@
package appeng.client.gui.implementations;
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.config.SortDir;
import appeng.api.config.SortOrder;
import appeng.api.config.ViewItems;
import appeng.api.storage.data.IAEItemStack;
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;
import appeng.util.Platform;
public class GuiCraftingCPU extends AEBaseGui implements ISortSource
{
ItemRepo repo;
GuiImgButton units;
int rows = 4;
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
protected void actionPerformed(GuiButton btn)
{
super.actionPerformed( btn );
}
@Override
public void initGui()
{
super.initGui();
}
public void postUpdate(List<IAEItemStack> list)
{
repo.clear();
for (IAEItemStack is : list)
repo.postUpdate( is );
repo.updateView();
setScrollBar();
}
private void setScrollBar()
{
int size = repo.size();
myScrollBar.setTop( 39 ).setLeft( 175 ).setHeight( 78 );
myScrollBar.setRange( 0, (size + 4) / 5 - rows, 1 );
}
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY)
{
bindTexture( "guis/craftingcpu.png" );
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize );
}
int tooltip = -1;
@Override
public void drawScreen(int mouse_x, int mouse_y, float btn)
{
int x = 0;
int y = 0;
int gx = (width - xSize) / 2;
int gy = (height - ySize) / 2;
tooltip = -1;
for (int z = 0; z <= 4 * 5; z++)
{
int minX = gx + 14 + x * 31;
int minY = gy + 41 + y * 18;
if ( minX < mouse_x && minX + 28 > mouse_x )
{
if ( minY < mouse_y && minY + 20 > mouse_y )
{
tooltip = z;
break;
}
}
x++;
if ( x > 4 )
{
y++;
x = 0;
}
}
super.drawScreen( mouse_x, mouse_y, btn );
}
@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;
int x = 0;
int y = 0;
int xo = 0 + 12;
int yo = 0 + 42;
int viewStart = 0;// myScrollBar.getCurrentScroll() * 5;
int viewEnd = viewStart + 5 * 4;
String ToolTip = "";
int toolPosX = 0;
int toolPosY = 0;
for (int z = viewStart; z < Math.min( viewEnd, repo.size() ); z++)
{
IAEItemStack refStack = repo.getRefrenceItem( z );
if ( refStack != null )
{
GL11.glPushMatrix();
GL11.glScaled( 0.5, 0.5, 0.5 );
String str = Long.toString( refStack.getStackSize() );
if ( refStack.getStackSize() >= 10000 )
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),
4210752 );
GL11.glPopMatrix();
int posX = x * sectionLength + xo + sectionLength - 18;
int posY = y * 18 + yo;
if ( tooltip == z - viewStart )
{
ToolTip = Platform.getItemDisplayName( repo.getItem( z ) );
ToolTip = ToolTip + ("\n" + GuiText.Installed.getLocal() + ": " + (refStack.getStackSize()));
if ( refStack.getCountRequestable() > 0 )
ToolTip = ToolTip + ("\n" + GuiText.EnergyDrain.getLocal() + ": " + Platform.formatPowerLong( refStack.getCountRequestable(), true ));
toolPosX = x * sectionLength + xo + sectionLength - 8;
toolPosY = y * 18 + yo;
}
drawItem( posX, posY, repo.getItem( z ) );
x++;
if ( x > 4 )
{
y++;
x = 0;
}
}
}
if ( tooltip >= 0 && ToolTip.length() > 0 )
{
GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS );
drawTooltip( toolPosX, toolPosY + 10, 0, ToolTip );
GL11.glPopAttrib();
}
}
// @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()
{
return SortOrder.NAME;
}
@Override
public Enum getSortDir()
{
return SortDir.ASCENDING;
}
@Override
public Enum getSortDisplay()
{
return ViewItems.ALL;
}
}

View file

@ -0,0 +1,123 @@
package appeng.container.implementations;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.AEApi;
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;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
public class ContainerCraftingCPU extends AEBaseContainer
{
IGrid network;
public ContainerCraftingCPU(InventoryPlayer ip, TileCraftingTile te) {
super( ip, null, null );
IGridHost host = te;// .getGridHost();
if ( host != null )
{
findNode( host, ForgeDirection.UNKNOWN );
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS)
findNode( host, d );
}
if ( network == null && Platform.isServer() )
isContainerValid = false;
}
private void findNode(IGridHost host, ForgeDirection d)
{
if ( network == null )
{
IGridNode node = host.getGridNode( d );
if ( node != null )
network = node.getGrid();
}
}
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()
{
delay++;
if ( Platform.isServer() && delay > 15 && network != null )
{
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
{
piu = new PacketMEInventoryUpdate();
for (Class<? extends IGridHost> machineClass : network.getMachinesClasses())
{
IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
for (IGridNode machine : network.getMachines( machineClass ))
{
IGridBlock blk = machine.getGridBlock();
ItemStack is = blk.getMachineRepresentation();
if ( is != null && is.getItem() != null )
{
IAEItemStack ais = AEItemStack.create( is );
ais.setStackSize( 1 );
ais.setCountRequestable( (long) (blk.getIdlePowerUsage() * 100.0) );
list.add( ais );
}
}
for (IAEItemStack ais : list)
piu.appendItem( ais );
}
for (Object c : this.crafters)
{
if ( c instanceof EntityPlayer )
NetworkHandler.instance.sendTo( piu, (EntityPlayerMP) c );
}
}
catch (IOException e)
{
// :P
}
}
super.detectAndSendChanges();
}
}

View file

@ -37,6 +37,7 @@ import appeng.container.implementations.ContainerChest;
import appeng.container.implementations.ContainerCondenser;
import appeng.container.implementations.ContainerCraftAmount;
import appeng.container.implementations.ContainerCraftConfirm;
import appeng.container.implementations.ContainerCraftingCPU;
import appeng.container.implementations.ContainerCraftingTerm;
import appeng.container.implementations.ContainerDrive;
import appeng.container.implementations.ContainerFormationPlane;
@ -72,6 +73,7 @@ import appeng.parts.misc.PartStorageBus;
import appeng.parts.reporting.PartCraftingTerminal;
import appeng.parts.reporting.PartPatternTerminal;
import appeng.server.AccessType;
import appeng.tile.crafting.TileCraftingTile;
import appeng.tile.crafting.TileMolecularAssembler;
import appeng.tile.grindstone.TileGrinder;
import appeng.tile.misc.TileCellWorkbench;
@ -112,6 +114,8 @@ public enum GuiBridge implements IGuiHandler
GUI_NETWORK_STATUS(ContainerNetworkStatus.class, INetworkTool.class, ITEM, null),
GUI_CRAFTING_CPU(ContainerCraftingCPU.class, TileCraftingTile.class, WORLD, SecurityPermissions.CRAFT),
GUI_NETWORK_TOOL(ContainerNetworkTool.class, INetworkTool.class, ITEM, null),
GUI_QUARTZ_KNIFE(ContainerQuartzKnife.class, QuartzKnifeObj.class, ITEM, null),

View file

@ -16,6 +16,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.implementations.GuiCraftingCPU;
import appeng.client.gui.implementations.GuiMEMonitorable;
import appeng.client.gui.implementations.GuiNetworkStatus;
import appeng.core.AELog;
@ -86,6 +87,9 @@ public class PacketMEInventoryUpdate extends AppEngPacket
{
GuiScreen gs = Minecraft.getMinecraft().currentScreen;
if ( gs instanceof GuiCraftingCPU )
((GuiCraftingCPU) gs).postUpdate( list );
if ( gs instanceof GuiMEMonitorable )
((GuiMEMonitorable) gs).postUpdate( list );