mirror of
https://github.com/GTNewHorizons/WirelessCraftingTerminal.git
synced 2026-11-22 04:52:16 +00:00
Switch GuiCraft{Amount,Confirm} to the AE2 versions
This commit is contained in:
1 parent
166b353332
commit
71c0304f09
11 files changed
+97
-1186
No files matched your search
+5
-146
@@ -4,47 +4,29 @@ import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IDefinitions;
|
||||
import appeng.api.definitions.IParts;
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.container.implementations.ContainerCraftAmount;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.util.calculators.ArithHelper;
|
||||
import appeng.util.calculators.Calculator;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiTabButton;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftAmount;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketCraftRequest;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis;
|
||||
import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject;
|
||||
import net.p455w0rd.wirelesscraftingterminal.items.ItemEnum;
|
||||
import net.p455w0rd.wirelesscraftingterminal.items.ItemWirelessCraftingTerminal;
|
||||
import net.p455w0rd.wirelesscraftingterminal.reference.Reference;
|
||||
|
||||
public class GuiCraftAmount extends WCTBaseGui {
|
||||
private GuiTextField amountToCraft;
|
||||
public class GuiCraftAmount extends appeng.client.gui.implementations.GuiCraftAmount {
|
||||
private GuiTabButton originalGuiBtn;
|
||||
|
||||
private GuiButton next;
|
||||
|
||||
private GuiButton plus1;
|
||||
private GuiButton plus10;
|
||||
private GuiButton plus100;
|
||||
private GuiButton plus1000;
|
||||
private GuiButton minus1;
|
||||
private GuiButton minus10;
|
||||
private GuiButton minus100;
|
||||
private GuiButton minus1000;
|
||||
|
||||
private ItemStack myIcon;
|
||||
|
||||
private int originalGui;
|
||||
|
||||
@Reflected
|
||||
public GuiCraftAmount(final InventoryPlayer inventoryPlayer, final ITerminalHost te) {
|
||||
super(new ContainerCraftAmount(inventoryPlayer, te));
|
||||
super(inventoryPlayer, te);
|
||||
ItemStack is = new ItemStack(ItemEnum.WIRELESS_CRAFTING_TERMINAL.getItem());
|
||||
((ItemWirelessCraftingTerminal) is.getItem()).injectAEPower(is, 6400001);
|
||||
myIcon = is;
|
||||
@@ -55,23 +37,6 @@ public class GuiCraftAmount extends WCTBaseGui {
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
final int a = AEConfig.instance.craftItemsByStackAmounts(0);
|
||||
final int b = AEConfig.instance.craftItemsByStackAmounts(1);
|
||||
final int c = AEConfig.instance.craftItemsByStackAmounts(2);
|
||||
final int d = AEConfig.instance.craftItemsByStackAmounts(3);
|
||||
|
||||
this.buttonList.add(this.plus1 = new GuiButton(0, this.guiLeft + 20, this.guiTop + 26, 22, 20, "+" + a));
|
||||
this.buttonList.add(this.plus10 = new GuiButton(0, this.guiLeft + 48, this.guiTop + 26, 28, 20, "+" + b));
|
||||
this.buttonList.add(this.plus100 = new GuiButton(0, this.guiLeft + 82, this.guiTop + 26, 32, 20, "+" + c));
|
||||
this.buttonList.add(this.plus1000 = new GuiButton(0, this.guiLeft + 120, this.guiTop + 26, 38, 20, "+" + d));
|
||||
|
||||
this.buttonList.add(this.minus1 = new GuiButton(0, this.guiLeft + 20, this.guiTop + 75, 22, 20, "-" + a));
|
||||
this.buttonList.add(this.minus10 = new GuiButton(0, this.guiLeft + 48, this.guiTop + 75, 28, 20, "-" + b));
|
||||
this.buttonList.add(this.minus100 = new GuiButton(0, this.guiLeft + 82, this.guiTop + 75, 32, 20, "-" + c));
|
||||
this.buttonList.add(this.minus1000 = new GuiButton(0, this.guiLeft + 120, this.guiTop + 75, 38, 20, "-" + d));
|
||||
|
||||
this.buttonList.add(
|
||||
this.next = new GuiButton(0, this.guiLeft + 128, this.guiTop + 51, 38, 20, GuiText.Next.getLocal()));
|
||||
final Object target = ((ContainerCraftAmount) this.inventorySlots).getTarget();
|
||||
final IDefinitions definitions = AEApi.instance().definitions();
|
||||
final IParts parts = definitions.parts();
|
||||
@@ -85,120 +50,14 @@ public class GuiCraftAmount extends WCTBaseGui {
|
||||
this.originalGuiBtn = new GuiTabButton(
|
||||
this.guiLeft + 154, this.guiTop - 4, myIcon, myIcon.getDisplayName(), itemRender));
|
||||
}
|
||||
|
||||
this.amountToCraft = new GuiTextField(
|
||||
this.fontRendererObj, this.guiLeft + 62, this.guiTop + 57, 59, this.fontRendererObj.FONT_HEIGHT);
|
||||
this.amountToCraft.setEnableBackgroundDrawing(false);
|
||||
this.amountToCraft.setMaxStringLength(16);
|
||||
this.amountToCraft.setTextColor(0xFFFFFF);
|
||||
this.amountToCraft.setVisible(true);
|
||||
this.amountToCraft.setFocused(true);
|
||||
this.amountToCraft.setText("1");
|
||||
this.amountToCraft.setSelectionPos(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
|
||||
this.fontRendererObj.drawString(GuiText.SelectAmount.getLocal(), 8, 6, 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
|
||||
this.next.displayString = isShiftKeyDown() ? GuiText.Start.getLocal() : GuiText.Next.getLocal();
|
||||
|
||||
this.bindTexture("appliedenergistics2", "guis/craftAmt.png");
|
||||
this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize);
|
||||
|
||||
try {
|
||||
String out = this.amountToCraft.getText();
|
||||
|
||||
double resultD = Calculator.conversion(out);
|
||||
|
||||
int resultI = roundDouble(resultD);
|
||||
|
||||
this.next.enabled = resultI > 0;
|
||||
} catch (final NumberFormatException e) {
|
||||
this.next.enabled = false;
|
||||
}
|
||||
|
||||
this.amountToCraft.drawTextBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(final char character, final int key) {
|
||||
if (!this.checkHotbarKeys(key)) {
|
||||
if (key == 28) {
|
||||
this.actionPerformed(this.next);
|
||||
}
|
||||
this.amountToCraft.textboxKeyTyped(character, key);
|
||||
super.keyTyped(character, key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(final GuiButton btn) {
|
||||
super.actionPerformed(btn);
|
||||
|
||||
try {
|
||||
|
||||
if (btn == this.originalGuiBtn) {
|
||||
NetworkHandler.instance.sendToServer(new PacketSwitchGuis(this.originalGui));
|
||||
}
|
||||
|
||||
if (btn == this.next && btn.enabled) {
|
||||
double resultD = Calculator.conversion(this.amountToCraft.getText());
|
||||
|
||||
int resultI = roundDouble(resultD);
|
||||
|
||||
NetworkHandler.instance.sendToServer(new PacketCraftRequest(resultI, isShiftKeyDown()));
|
||||
}
|
||||
} catch (final NumberFormatException e) {
|
||||
// nope..
|
||||
this.amountToCraft.setText("1");
|
||||
}
|
||||
|
||||
final boolean isPlus = btn == this.plus1 || btn == this.plus10 || btn == this.plus100 || btn == this.plus1000;
|
||||
final boolean isMinus =
|
||||
btn == this.minus1 || btn == this.minus10 || btn == this.minus100 || btn == this.minus1000;
|
||||
|
||||
if (isPlus || isMinus) {
|
||||
this.addQty(this.getQty(btn));
|
||||
}
|
||||
}
|
||||
|
||||
private void addQty(final int i) {
|
||||
try {
|
||||
String out = this.amountToCraft.getText();
|
||||
|
||||
double resultD = Calculator.conversion(out);
|
||||
|
||||
int resultI = roundDouble(resultD);
|
||||
|
||||
if (resultI == 1 && i > 1) {
|
||||
resultI = 0;
|
||||
}
|
||||
|
||||
resultI += i;
|
||||
if (resultI < 1) {
|
||||
resultI = 1;
|
||||
}
|
||||
|
||||
out = Integer.toString(resultI);
|
||||
this.amountToCraft.setText(out);
|
||||
} catch (final NumberFormatException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
protected String getBackground() {
|
||||
return "guis/craftAmt.png";
|
||||
}
|
||||
|
||||
private int roundDouble(double num) {
|
||||
if (num <= 0 || Double.isNaN(num)) {
|
||||
return 0;
|
||||
} else {
|
||||
return (int) ArithHelper.round(num, 0);
|
||||
if (btn == this.originalGuiBtn) {
|
||||
NetworkHandler.instance.sendToServer(new PacketSwitchGuis(this.originalGui));
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-497
@@ -1,514 +1,21 @@
|
||||
package net.p455w0rd.wirelesscraftingterminal.client.gui;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.util.Platform;
|
||||
import com.google.common.base.Joiner;
|
||||
import java.io.IOException;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiScrollbar;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketValueConfig;
|
||||
import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject;
|
||||
import net.p455w0rd.wirelesscraftingterminal.reference.Reference;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class GuiCraftConfirm extends WCTBaseGui {
|
||||
|
||||
private final ContainerCraftConfirm ccc;
|
||||
|
||||
private final int rows = 5;
|
||||
|
||||
private final IItemList<IAEItemStack> storage = AEApi.instance().storage().createItemList();
|
||||
private final IItemList<IAEItemStack> pending = AEApi.instance().storage().createItemList();
|
||||
private final IItemList<IAEItemStack> missing = AEApi.instance().storage().createItemList();
|
||||
|
||||
private final List<IAEItemStack> visual = new ArrayList<IAEItemStack>();
|
||||
|
||||
private int OriginalGui = 0;
|
||||
private GuiButton cancel;
|
||||
private GuiButton start;
|
||||
private GuiButton selectCPU;
|
||||
private int tooltip = -1;
|
||||
InventoryPlayer inventoryPlayer;
|
||||
private static int jobBytes;
|
||||
private static int currCPUAvailBytes;
|
||||
private static int currCPUCoCPUs;
|
||||
|
||||
public class GuiCraftConfirm extends appeng.client.gui.implementations.GuiCraftConfirm {
|
||||
public GuiCraftConfirm(final InventoryPlayer inventoryPlayer, final ITerminalHost te) {
|
||||
super(new ContainerCraftConfirm(inventoryPlayer, te));
|
||||
this.xSize = 238;
|
||||
this.ySize = 206;
|
||||
|
||||
final GuiScrollbar scrollbar = new GuiScrollbar();
|
||||
this.setScrollBar(scrollbar);
|
||||
|
||||
this.ccc = (ContainerCraftConfirm) this.inventorySlots;
|
||||
this.inventoryPlayer = inventoryPlayer;
|
||||
|
||||
if (te instanceof WirelessTerminalGuiObject) {
|
||||
this.OriginalGui = Reference.GUI_WCT;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isAutoStart() {
|
||||
return ((ContainerCraftConfirm) this.inventorySlots).isAutoStart();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
this.start =
|
||||
new GuiButton(0, this.guiLeft + 162, this.guiTop + this.ySize - 25, 50, 20, GuiText.Start.getLocal());
|
||||
this.start.enabled = false;
|
||||
this.buttonList.add(this.start);
|
||||
|
||||
this.selectCPU = new GuiButton(
|
||||
0,
|
||||
this.guiLeft + (219 - 180) / 2,
|
||||
this.guiTop + this.ySize - 68,
|
||||
180,
|
||||
20,
|
||||
GuiText.CraftingCPU.getLocal() + ": " + GuiText.Automatic);
|
||||
this.selectCPU.enabled = false;
|
||||
this.buttonList.add(this.selectCPU);
|
||||
|
||||
if (this.OriginalGui > 0) {
|
||||
this.cancel = new GuiButton(
|
||||
0, this.guiLeft + 6, this.guiTop + this.ySize - 25, 50, 20, GuiText.Cancel.getLocal());
|
||||
}
|
||||
|
||||
this.buttonList.add(this.cancel);
|
||||
super(inventoryPlayer, te);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(final int mouseX, final int mouseY, final float btn) {
|
||||
this.updateCPUButtonText();
|
||||
|
||||
this.start.enabled = !(this.ccc.hasNoCPU() || this.isSimulation());
|
||||
this.selectCPU.enabled = !this.isSimulation();
|
||||
|
||||
final int gx = (this.width - this.xSize) / 2;
|
||||
final int gy = (this.height - this.ySize) / 2;
|
||||
|
||||
this.tooltip = -1;
|
||||
|
||||
final int offY = 23;
|
||||
int y = 0;
|
||||
int x = 0;
|
||||
for (int z = 0; z <= 4 * 5; z++) {
|
||||
final int minX = gx + 9 + x * 67;
|
||||
final int minY = gy + 22 + y * offY;
|
||||
|
||||
if (minX < mouseX && minX + 67 > mouseX) {
|
||||
if (minY < mouseY && minY + offY - 2 > mouseY) {
|
||||
this.tooltip = z;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
x++;
|
||||
|
||||
if (x > 2) {
|
||||
y++;
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
super.drawScreen(mouseX, mouseY, btn);
|
||||
}
|
||||
|
||||
private void updateCPUButtonText() {
|
||||
String btnTextText = GuiText.CraftingCPU.getLocal() + ": " + GuiText.Automatic.getLocal();
|
||||
if (this.ccc.getSelectedCpu() >= 0) // && status.selectedCpu < status.cpus.size() )
|
||||
{
|
||||
if (this.ccc.getName().length() > 0) {
|
||||
final String name = this.ccc
|
||||
.getName()
|
||||
.substring(0, Math.min(20, this.ccc.getName().length()));
|
||||
btnTextText = GuiText.CraftingCPU.getLocal() + ": " + name;
|
||||
} else {
|
||||
btnTextText = GuiText.CraftingCPU.getLocal() + ": #" + this.ccc.getSelectedCpu();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.ccc.hasNoCPU()) {
|
||||
btnTextText = GuiText.NoCraftingCPUs.getLocal();
|
||||
}
|
||||
|
||||
this.selectCPU.displayString = btnTextText;
|
||||
}
|
||||
|
||||
private boolean isSimulation() {
|
||||
return ((ContainerCraftConfirm) this.inventorySlots).isSimulation();
|
||||
}
|
||||
|
||||
public int getJobBytes() {
|
||||
return GuiCraftConfirm.jobBytes;
|
||||
}
|
||||
|
||||
public static void setJobBytes(int numBytes) {
|
||||
jobBytes = numBytes;
|
||||
}
|
||||
|
||||
public int getCurrentCPUAvailBytes() {
|
||||
return GuiCraftConfirm.currCPUAvailBytes;
|
||||
}
|
||||
|
||||
public static void setCurrentCPUAvailBytes(int numBytes) {
|
||||
currCPUAvailBytes = numBytes;
|
||||
}
|
||||
|
||||
public int getCurrentCPUCoCPUs() {
|
||||
return GuiCraftConfirm.currCPUCoCPUs;
|
||||
}
|
||||
|
||||
public static void setCurrentCPUCoCPUs(int coCPUs) {
|
||||
currCPUCoCPUs = coCPUs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
|
||||
int bytesUsed = this.getJobBytes();
|
||||
int availBytes = this.getCurrentCPUAvailBytes();
|
||||
int availCoCPUs = this.getCurrentCPUCoCPUs();
|
||||
String byteUsed = NumberFormat.getInstance().format(bytesUsed);
|
||||
|
||||
final String Add =
|
||||
bytesUsed > 0 ? (byteUsed + ' ' + GuiText.BytesUsed.getLocal()) : GuiText.CalculatingWait.getLocal();
|
||||
this.fontRendererObj.drawString(GuiText.CraftingPlan.getLocal() + " -- " + Add, 8, 7, 4210752);
|
||||
|
||||
String dsp = null;
|
||||
|
||||
if (this.isSimulation()) {
|
||||
dsp = GuiText.Simulation.getLocal();
|
||||
} else {
|
||||
dsp = availBytes > 0
|
||||
? (GuiText.Bytes.getLocal() + ": " + availBytes + " : " + GuiText.CoProcessors.getLocal() + ": "
|
||||
+ availCoCPUs)
|
||||
: GuiText.Bytes.getLocal() + ": N/A : " + GuiText.CoProcessors.getLocal() + ": N/A";
|
||||
}
|
||||
|
||||
final int offset = (219 - this.fontRendererObj.getStringWidth(dsp)) / 2;
|
||||
this.fontRendererObj.drawString(dsp, offset, 165, 4210752);
|
||||
|
||||
final int sectionLength = 67;
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
final int xo = 9;
|
||||
final int yo = 22;
|
||||
final int viewStart = this.getScrollBar().getCurrentScroll() * 3;
|
||||
final int viewEnd = viewStart + 3 * this.rows;
|
||||
|
||||
String dspToolTip = "";
|
||||
final List<String> lineList = new LinkedList<String>();
|
||||
int toolPosX = 0;
|
||||
int toolPosY = 0;
|
||||
|
||||
final int offY = 23;
|
||||
|
||||
for (int z = viewStart; z < Math.min(viewEnd, this.visual.size()); z++) {
|
||||
final IAEItemStack refStack = this.visual.get(z); // repo.getReferenceItem( z );
|
||||
if (refStack != null) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glScaled(0.5, 0.5, 0.5);
|
||||
|
||||
final IAEItemStack stored = this.storage.findPrecise(refStack);
|
||||
final IAEItemStack pendingStack = this.pending.findPrecise(refStack);
|
||||
final IAEItemStack missingStack = this.missing.findPrecise(refStack);
|
||||
|
||||
int lines = 0;
|
||||
|
||||
if (stored != null && stored.getStackSize() > 0) {
|
||||
lines++;
|
||||
}
|
||||
if (pendingStack != null && pendingStack.getStackSize() > 0) {
|
||||
lines++;
|
||||
}
|
||||
if (pendingStack != null && pendingStack.getStackSize() > 0) {
|
||||
lines++;
|
||||
}
|
||||
|
||||
final int negY = ((lines - 1) * 5) / 2;
|
||||
int downY = 0;
|
||||
|
||||
if (stored != null && stored.getStackSize() > 0) {
|
||||
String str = Long.toString(stored.getStackSize());
|
||||
if (stored.getStackSize() >= 10000) {
|
||||
str = Long.toString(stored.getStackSize() / 1000) + 'k';
|
||||
}
|
||||
if (stored.getStackSize() >= 10000000) {
|
||||
str = Long.toString(stored.getStackSize() / 1000000) + 'm';
|
||||
}
|
||||
|
||||
str = GuiText.FromStorage.getLocal() + ": " + str;
|
||||
final int w = 4 + this.fontRendererObj.getStringWidth(str);
|
||||
this.fontRendererObj.drawString(
|
||||
str,
|
||||
(int) ((x * (1 + sectionLength) + xo + sectionLength - 19 - (w * 0.5)) * 2),
|
||||
(y * offY + yo + 6 - negY + downY) * 2,
|
||||
4210752);
|
||||
|
||||
if (this.tooltip == z - viewStart) {
|
||||
lineList.add(GuiText.FromStorage.getLocal() + ": " + Long.toString(stored.getStackSize()));
|
||||
}
|
||||
|
||||
downY += 5;
|
||||
}
|
||||
|
||||
boolean red = false;
|
||||
if (missingStack != null && missingStack.getStackSize() > 0) {
|
||||
String str = Long.toString(missingStack.getStackSize());
|
||||
if (missingStack.getStackSize() >= 10000) {
|
||||
str = Long.toString(missingStack.getStackSize() / 1000) + 'k';
|
||||
}
|
||||
if (missingStack.getStackSize() >= 10000000) {
|
||||
str = Long.toString(missingStack.getStackSize() / 1000000) + 'm';
|
||||
}
|
||||
|
||||
str = GuiText.Missing.getLocal() + ": " + str;
|
||||
final int w = 4 + this.fontRendererObj.getStringWidth(str);
|
||||
this.fontRendererObj.drawString(
|
||||
str,
|
||||
(int) ((x * (1 + sectionLength) + xo + sectionLength - 19 - (w * 0.5)) * 2),
|
||||
(y * offY + yo + 6 - negY + downY) * 2,
|
||||
4210752);
|
||||
|
||||
if (this.tooltip == z - viewStart) {
|
||||
lineList.add(GuiText.Missing.getLocal() + ": " + Long.toString(missingStack.getStackSize()));
|
||||
}
|
||||
|
||||
red = true;
|
||||
downY += 5;
|
||||
}
|
||||
|
||||
if (pendingStack != null && pendingStack.getStackSize() > 0) {
|
||||
String str = Long.toString(pendingStack.getStackSize());
|
||||
if (pendingStack.getStackSize() >= 10000) {
|
||||
str = Long.toString(pendingStack.getStackSize() / 1000) + 'k';
|
||||
}
|
||||
if (pendingStack.getStackSize() >= 10000000) {
|
||||
str = Long.toString(pendingStack.getStackSize() / 1000000) + 'm';
|
||||
}
|
||||
|
||||
str = GuiText.ToCraft.getLocal() + ": " + str;
|
||||
final int w = 4 + this.fontRendererObj.getStringWidth(str);
|
||||
this.fontRendererObj.drawString(
|
||||
str,
|
||||
(int) ((x * (1 + sectionLength) + xo + sectionLength - 19 - (w * 0.5)) * 2),
|
||||
(y * offY + yo + 6 - negY + downY) * 2,
|
||||
4210752);
|
||||
|
||||
if (this.tooltip == z - viewStart) {
|
||||
lineList.add(GuiText.ToCraft.getLocal() + ": " + Long.toString(pendingStack.getStackSize()));
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
final int posX = x * (1 + sectionLength) + xo + sectionLength - 19;
|
||||
final int posY = y * offY + yo;
|
||||
|
||||
final ItemStack is = refStack.copy().getItemStack();
|
||||
|
||||
if (this.tooltip == z - viewStart) {
|
||||
dspToolTip = Platform.getItemDisplayName(is);
|
||||
|
||||
if (lineList.size() > 0) {
|
||||
addItemTooltip(is, lineList);
|
||||
dspToolTip = dspToolTip + '\n' + Joiner.on("\n").join(lineList);
|
||||
}
|
||||
|
||||
toolPosX = x * (1 + sectionLength) + xo + sectionLength - 8;
|
||||
toolPosY = y * offY + yo;
|
||||
}
|
||||
|
||||
this.drawItem(posX, posY, is);
|
||||
|
||||
if (red) {
|
||||
final int startX = x * (1 + sectionLength) + xo;
|
||||
final int startY = posY - 4;
|
||||
drawRect(startX, startY, startX + sectionLength, startY + offY, 0x1AFF0000);
|
||||
}
|
||||
|
||||
x++;
|
||||
|
||||
if (x > 2) {
|
||||
y++;
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.tooltip >= 0 && dspToolTip.length() > 0) {
|
||||
this.drawTooltip(toolPosX, toolPosY + 10, 0, dspToolTip);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
|
||||
this.setScrollBar();
|
||||
this.bindTexture("appliedenergistics2", "guis/craftingreport.png");
|
||||
this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize);
|
||||
}
|
||||
|
||||
private void setScrollBar() {
|
||||
final int size = this.visual.size();
|
||||
|
||||
this.getScrollBar().setTop(19).setLeft(218).setHeight(114);
|
||||
this.getScrollBar().setRange(0, (size + 2) / 3 - this.rows, 1);
|
||||
}
|
||||
|
||||
public void postUpdate(final List<IAEItemStack> list, final byte ref) {
|
||||
switch (ref) {
|
||||
case 0:
|
||||
for (final IAEItemStack l : list) {
|
||||
this.handleInput(this.storage, l);
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
for (final IAEItemStack l : list) {
|
||||
this.handleInput(this.pending, l);
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
for (final IAEItemStack l : list) {
|
||||
this.handleInput(this.missing, l);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
for (final IAEItemStack l : list) {
|
||||
final long amt = this.getTotal(l);
|
||||
|
||||
if (amt <= 0) {
|
||||
this.deleteVisualStack(l);
|
||||
} else {
|
||||
final IAEItemStack is = this.findVisualStack(l);
|
||||
is.setStackSize(amt);
|
||||
}
|
||||
}
|
||||
|
||||
this.setScrollBar();
|
||||
}
|
||||
|
||||
private void handleInput(final IItemList<IAEItemStack> s, final IAEItemStack l) {
|
||||
IAEItemStack a = s.findPrecise(l);
|
||||
|
||||
if (l.getStackSize() <= 0) {
|
||||
if (a != null) {
|
||||
a.reset();
|
||||
}
|
||||
} else {
|
||||
if (a == null) {
|
||||
s.add(l.copy());
|
||||
a = s.findPrecise(l);
|
||||
}
|
||||
|
||||
if (a != null) {
|
||||
a.setStackSize(l.getStackSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private long getTotal(final IAEItemStack is) {
|
||||
final IAEItemStack a = this.storage.findPrecise(is);
|
||||
final IAEItemStack c = this.pending.findPrecise(is);
|
||||
final IAEItemStack m = this.missing.findPrecise(is);
|
||||
|
||||
long total = 0;
|
||||
|
||||
if (a != null) {
|
||||
total += a.getStackSize();
|
||||
}
|
||||
|
||||
if (c != null) {
|
||||
total += c.getStackSize();
|
||||
}
|
||||
|
||||
if (m != null) {
|
||||
total += m.getStackSize();
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
private void deleteVisualStack(final IAEItemStack l) {
|
||||
final Iterator<IAEItemStack> i = this.visual.iterator();
|
||||
while (i.hasNext()) {
|
||||
final IAEItemStack o = i.next();
|
||||
if (o.equals(l)) {
|
||||
i.remove();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IAEItemStack findVisualStack(final IAEItemStack l) {
|
||||
for (final IAEItemStack o : this.visual) {
|
||||
if (o.equals(l)) {
|
||||
return o;
|
||||
}
|
||||
}
|
||||
|
||||
final IAEItemStack stack = l.copy();
|
||||
this.visual.add(stack);
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(final char character, final int key) {
|
||||
if (!this.checkHotbarKeys(key)) {
|
||||
if (key == 28) {
|
||||
this.actionPerformed(this.start);
|
||||
}
|
||||
super.keyTyped(character, key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(final GuiButton btn) {
|
||||
super.actionPerformed(btn);
|
||||
|
||||
final boolean backwards = Mouse.isButtonDown(1);
|
||||
|
||||
if (btn == this.selectCPU) {
|
||||
try {
|
||||
NetworkHandler.instance.sendToServer(
|
||||
new PacketValueConfig("Terminal.Cpu", backwards ? "Prev" : "Next"));
|
||||
} catch (final IOException e) {
|
||||
WCTLog.debug(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (btn == this.cancel) {
|
||||
NetworkHandler.instance.sendToServer(new PacketSwitchGuis(this.OriginalGui));
|
||||
}
|
||||
|
||||
if (btn == this.start) {
|
||||
try {
|
||||
NetworkHandler.instance.sendToServer(new PacketValueConfig("Terminal.Start", "Start"));
|
||||
} catch (final Throwable e) {
|
||||
WCTLog.debug(e.getMessage());
|
||||
}
|
||||
}
|
||||
public void switchToOriginalGUI() {
|
||||
NetworkHandler.instance.sendToServer(new PacketSwitchGuis(Reference.GUI_WCT));
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,13 @@ package net.p455w0rd.wirelesscraftingterminal.common;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.implementations.guiobjects.IPortableCell;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.ContainerOpenContext;
|
||||
import appeng.container.implementations.ContainerCraftingStatus;
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTermHandler;
|
||||
import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftAmount;
|
||||
import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftConfirm;
|
||||
@@ -37,19 +40,47 @@ public class WCTGuiHandler implements IGuiHandler {
|
||||
final IPortableCell terminal = obj;
|
||||
|
||||
if (guiId == Reference.GUI_WCT) {
|
||||
return new ContainerWirelessCraftingTerminal(player, player.inventory);
|
||||
return updateGui(
|
||||
new ContainerWirelessCraftingTerminal(player, player.inventory),
|
||||
world,
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
ForgeDirection.UNKNOWN,
|
||||
obj);
|
||||
}
|
||||
|
||||
if (guiId == Reference.GUI_CRAFTING_STATUS) {
|
||||
return new ContainerCraftingStatus(player.inventory, terminal);
|
||||
return updateGui(
|
||||
new ContainerCraftingStatus(player.inventory, terminal),
|
||||
world,
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
ForgeDirection.UNKNOWN,
|
||||
obj);
|
||||
}
|
||||
|
||||
if (guiId == Reference.GUI_CRAFT_AMOUNT) {
|
||||
return new ContainerCraftAmount(player.inventory, terminal);
|
||||
return updateGui(
|
||||
new ContainerCraftAmount(player, terminal),
|
||||
world,
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
ForgeDirection.UNKNOWN,
|
||||
obj);
|
||||
}
|
||||
|
||||
if (guiId == Reference.GUI_CRAFT_CONFIRM) {
|
||||
return new ContainerCraftConfirm(player.inventory, terminal);
|
||||
return updateGui(
|
||||
new ContainerCraftConfirm(player, terminal),
|
||||
world,
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
ForgeDirection.UNKNOWN,
|
||||
obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,4 +132,25 @@ public class WCTGuiHandler implements IGuiHandler {
|
||||
final int ID, final EntityPlayer player, final World world, final int x, final int y, final int z) {
|
||||
player.openGui(WirelessCraftingTerminal.INSTANCE, ID, world, x, y, z);
|
||||
}
|
||||
|
||||
private Object updateGui(
|
||||
final Object newContainer,
|
||||
final World w,
|
||||
final int x,
|
||||
final int y,
|
||||
final int z,
|
||||
final ForgeDirection side,
|
||||
final Object myItem) {
|
||||
if (newContainer instanceof AEBaseContainer) {
|
||||
final AEBaseContainer bc = (AEBaseContainer) newContainer;
|
||||
bc.setOpenContext(new ContainerOpenContext(myItem));
|
||||
bc.getOpenContext().setWorld(w);
|
||||
bc.getOpenContext().setX(x);
|
||||
bc.getOpenContext().setY(y);
|
||||
bc.getOpenContext().setZ(z);
|
||||
bc.getOpenContext().setSide(side);
|
||||
}
|
||||
|
||||
return newContainer;
|
||||
}
|
||||
}
|
||||
+16
-50
@@ -1,58 +1,24 @@
|
||||
package net.p455w0rd.wirelesscraftingterminal.common.container;
|
||||
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.world.World;
|
||||
import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTIActionHost;
|
||||
import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTPlayerSource;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotInaccessible;
|
||||
import appeng.api.implementations.guiobjects.IPortableCell;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis;
|
||||
import net.p455w0rd.wirelesscraftingterminal.reference.Reference;
|
||||
|
||||
public class ContainerCraftAmount extends WCTBaseContainer {
|
||||
|
||||
private final Slot craftingItem;
|
||||
private IAEItemStack itemToCreate;
|
||||
|
||||
public ContainerCraftAmount(final InventoryPlayer ip, final ITerminalHost te) {
|
||||
super(ip, te);
|
||||
|
||||
this.craftingItem = new SlotInaccessible(new AppEngInternalInventory(null, 1), 0, 34, 53);
|
||||
this.addSlotToContainer(this.getCraftingItem());
|
||||
public class ContainerCraftAmount extends appeng.container.implementations.ContainerCraftAmount {
|
||||
public ContainerCraftAmount(EntityPlayer player, IPortableCell terminal) {
|
||||
super(player.inventory, terminal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
this.verifyPermissions(SecurityPermissions.CRAFT, false);
|
||||
}
|
||||
|
||||
public IGrid getGrid() {
|
||||
return this.obj2.getTargetGrid();
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return this.getPlayerInv().player.worldObj;
|
||||
}
|
||||
|
||||
public BaseActionSource getActionSrc() {
|
||||
return new WCTPlayerSource(this.getPlayerInv().player, (WCTIActionHost) this.getTarget());
|
||||
}
|
||||
|
||||
public Slot getCraftingItem() {
|
||||
return this.craftingItem;
|
||||
}
|
||||
|
||||
public IAEItemStack getItemToCraft() {
|
||||
return this.itemToCreate;
|
||||
}
|
||||
|
||||
public void setItemToCraft(@Nonnull final IAEItemStack itemToCreate) {
|
||||
this.itemToCreate = itemToCreate;
|
||||
public void openConfirmationGUI(EntityPlayer player, TileEntity te) {
|
||||
int x = (int) player.posX;
|
||||
int y = (int) player.posY;
|
||||
int z = (int) player.posZ;
|
||||
WCTGuiHandler.launchGui(Reference.GUI_CRAFT_CONFIRM, player, player.worldObj, x, y, z);
|
||||
}
|
||||
}
|
||||
+11
-402
@@ -1,417 +1,26 @@
|
||||
package net.p455w0rd.wirelesscraftingterminal.common.container;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.crafting.ICraftingCPU;
|
||||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.crafting.ICraftingJob;
|
||||
import appeng.api.networking.crafting.ICraftingLink;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.storage.IStorageGrid;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.util.Platform;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Future;
|
||||
import javax.annotation.Nonnull;
|
||||
import appeng.api.implementations.guiobjects.IPortableCell;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.world.World;
|
||||
import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTIActionHost;
|
||||
import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTPlayerSource;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.container.guisync.GuiSync;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketMEInventoryUpdate;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSetJobBytes;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketUpdateCPUInfo;
|
||||
import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject;
|
||||
import net.p455w0rd.wirelesscraftingterminal.reference.Reference;
|
||||
|
||||
public class ContainerCraftConfirm extends WCTBaseContainer {
|
||||
public class ContainerCraftConfirm extends appeng.container.implementations.ContainerCraftConfirm {
|
||||
private final EntityPlayer player;
|
||||
|
||||
public final ArrayList<CraftingCPURecord> cpus = new ArrayList<CraftingCPURecord>();
|
||||
private Future<ICraftingJob> job;
|
||||
private ICraftingJob result;
|
||||
|
||||
@GuiSync(0)
|
||||
public long bytesUsed;
|
||||
|
||||
@GuiSync(1)
|
||||
public long cpuBytesAvail;
|
||||
|
||||
@GuiSync(2)
|
||||
public int cpuCoProcessors;
|
||||
|
||||
@GuiSync(3)
|
||||
public boolean autoStart = false;
|
||||
|
||||
@GuiSync(4)
|
||||
public boolean simulation = true;
|
||||
|
||||
@GuiSync(5)
|
||||
public int selectedCpu = -1;
|
||||
|
||||
@GuiSync(6)
|
||||
public boolean noCPU = true;
|
||||
|
||||
@GuiSync(7)
|
||||
public String myName = "";
|
||||
|
||||
InventoryPlayer inventoryPlayer;
|
||||
|
||||
public ContainerCraftConfirm(final InventoryPlayer ip, final ITerminalHost te) {
|
||||
super(ip, te);
|
||||
inventoryPlayer = ip;
|
||||
}
|
||||
|
||||
public void cycleCpu(final boolean next) {
|
||||
if (next) {
|
||||
this.setSelectedCpu(this.getSelectedCpu() + 1);
|
||||
} else {
|
||||
this.setSelectedCpu(this.getSelectedCpu() - 1);
|
||||
}
|
||||
|
||||
if (this.getSelectedCpu() < -1) {
|
||||
this.setSelectedCpu(this.cpus.size() - 1);
|
||||
} else if (this.getSelectedCpu() >= this.cpus.size()) {
|
||||
this.setSelectedCpu(-1);
|
||||
}
|
||||
|
||||
if (this.getSelectedCpu() == -1) {
|
||||
this.setCpuAvailableBytes(0);
|
||||
this.setCpuCoProcessors(0);
|
||||
this.setName("");
|
||||
try {
|
||||
NetworkHandler.instance.sendTo(
|
||||
new PacketUpdateCPUInfo(0, 0), (EntityPlayerMP) this.getPlayerInv().player);
|
||||
} catch (IOException e) {
|
||||
//
|
||||
}
|
||||
} else {
|
||||
this.setName(this.cpus.get(this.getSelectedCpu()).getName());
|
||||
this.setCpuAvailableBytes(this.cpus.get(this.getSelectedCpu()).getSize());
|
||||
this.setCpuCoProcessors(this.cpus.get(this.getSelectedCpu()).getProcessors());
|
||||
|
||||
try {
|
||||
NetworkHandler.instance.sendTo(
|
||||
new PacketUpdateCPUInfo((int) this.getCpuAvailableBytes(), (int) this.getCpuCoProcessors()),
|
||||
(EntityPlayerMP) this.getPlayerInv().player);
|
||||
} catch (IOException e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
public ContainerCraftConfirm(EntityPlayer player, IPortableCell terminal) {
|
||||
super(player.inventory, terminal);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
if (Platform.isClient()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ICraftingGrid cc = this.getGrid().getCache(ICraftingGrid.class);
|
||||
final ImmutableSet<ICraftingCPU> cpuSet = cc.getCpus();
|
||||
|
||||
int matches = 0;
|
||||
boolean changed = false;
|
||||
for (final ICraftingCPU c : cpuSet) {
|
||||
boolean found = false;
|
||||
for (final CraftingCPURecord ccr : this.cpus) {
|
||||
if (ccr.getCpu() == c) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
final boolean matched = this.cpuMatches(c);
|
||||
|
||||
if (matched) {
|
||||
matches++;
|
||||
}
|
||||
|
||||
if (found == !matched) {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed || this.cpus.size() != matches) {
|
||||
this.cpus.clear();
|
||||
for (final ICraftingCPU c : cpuSet) {
|
||||
if (this.cpuMatches(c)) {
|
||||
this.cpus.add(new CraftingCPURecord(c.getAvailableStorage(), c.getCoProcessors(), c));
|
||||
}
|
||||
}
|
||||
|
||||
this.sendCPUs();
|
||||
}
|
||||
|
||||
this.setNoCPU(this.cpus.isEmpty());
|
||||
|
||||
super.detectAndSendChanges();
|
||||
|
||||
if (this.getJob() != null && this.getJob().isDone()) {
|
||||
try {
|
||||
this.result = this.getJob().get();
|
||||
|
||||
if (!this.result.isSimulation()) {
|
||||
this.setSimulation(false);
|
||||
if (this.isAutoStart()) {
|
||||
this.startJob();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
this.setSimulation(true);
|
||||
}
|
||||
|
||||
try {
|
||||
final PacketMEInventoryUpdate a = new PacketMEInventoryUpdate((byte) 0);
|
||||
final PacketMEInventoryUpdate b = new PacketMEInventoryUpdate((byte) 1);
|
||||
final PacketMEInventoryUpdate c =
|
||||
this.result.isSimulation() ? new PacketMEInventoryUpdate((byte) 2) : null;
|
||||
|
||||
final IItemList<IAEItemStack> plan =
|
||||
AEApi.instance().storage().createItemList();
|
||||
this.result.populatePlan(plan);
|
||||
|
||||
try {
|
||||
NetworkHandler.instance.sendTo(
|
||||
new PacketSetJobBytes((int) this.result.getByteTotal()),
|
||||
(EntityPlayerMP) this.getPlayerInv().player);
|
||||
} catch (IOException e) {
|
||||
//
|
||||
}
|
||||
|
||||
this.setUsedBytes(this.result.getByteTotal());
|
||||
|
||||
for (final IAEItemStack out : plan) {
|
||||
|
||||
IAEItemStack o = out.copy();
|
||||
o.reset();
|
||||
o.setStackSize(out.getStackSize());
|
||||
|
||||
final IAEItemStack p = out.copy();
|
||||
p.reset();
|
||||
p.setStackSize(out.getCountRequestable());
|
||||
|
||||
final IStorageGrid sg = this.getGrid().getCache(IStorageGrid.class);
|
||||
final IMEInventory<IAEItemStack> items = sg.getItemInventory();
|
||||
|
||||
IAEItemStack m = null;
|
||||
if (c != null && this.result.isSimulation()) {
|
||||
m = o.copy();
|
||||
o = items.extractItems(o, Actionable.SIMULATE, this.getActionSource());
|
||||
|
||||
if (o == null) {
|
||||
o = m.copy();
|
||||
o.setStackSize(0);
|
||||
}
|
||||
|
||||
m.setStackSize(m.getStackSize() - o.getStackSize());
|
||||
}
|
||||
|
||||
if (o.getStackSize() > 0) {
|
||||
a.appendItem(o);
|
||||
}
|
||||
|
||||
if (p.getStackSize() > 0) {
|
||||
b.appendItem(p);
|
||||
}
|
||||
|
||||
if (c != null && m != null && m.getStackSize() > 0) {
|
||||
c.appendItem(m);
|
||||
}
|
||||
}
|
||||
|
||||
for (final Object g : this.crafters) {
|
||||
if (g instanceof EntityPlayer) {
|
||||
NetworkHandler.instance.sendTo(a, (EntityPlayerMP) g);
|
||||
NetworkHandler.instance.sendTo(b, (EntityPlayerMP) g);
|
||||
if (c != null) {
|
||||
NetworkHandler.instance.sendTo(c, (EntityPlayerMP) g);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
// :P
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
this.getPlayerInv().player.addChatMessage(new ChatComponentText("Error: " + e.toString()));
|
||||
WCTLog.debug(e.getMessage());
|
||||
this.setValidContainer(false);
|
||||
this.result = null;
|
||||
}
|
||||
|
||||
this.setJob(null);
|
||||
}
|
||||
this.verifyPermissions(SecurityPermissions.CRAFT, false);
|
||||
}
|
||||
|
||||
private IGrid getGrid() {
|
||||
return this.obj2.getTargetGrid();
|
||||
}
|
||||
|
||||
private boolean cpuMatches(final ICraftingCPU c) {
|
||||
return c.getAvailableStorage() >= this.getUsedBytes() && !c.isBusy();
|
||||
}
|
||||
|
||||
private void sendCPUs() {
|
||||
Collections.sort(this.cpus);
|
||||
|
||||
if (this.getSelectedCpu() >= this.cpus.size()) {
|
||||
this.setSelectedCpu(-1);
|
||||
this.setCpuAvailableBytes(0);
|
||||
this.setCpuCoProcessors(0);
|
||||
this.setName("");
|
||||
} else if (this.getSelectedCpu() != -1) {
|
||||
this.setName(this.cpus.get(this.getSelectedCpu()).getName());
|
||||
this.setCpuAvailableBytes(this.cpus.get(this.getSelectedCpu()).getSize());
|
||||
this.setCpuCoProcessors(this.cpus.get(this.getSelectedCpu()).getProcessors());
|
||||
}
|
||||
}
|
||||
|
||||
public void startJob() {
|
||||
int originalGui = 0;
|
||||
|
||||
final WCTIActionHost ah = this.getActionHost();
|
||||
if (ah instanceof WirelessTerminalGuiObject) {
|
||||
originalGui = Reference.GUI_WCT;
|
||||
}
|
||||
|
||||
if (this.result != null && !this.isSimulation()) {
|
||||
final ICraftingGrid cc = this.getGrid().getCache(ICraftingGrid.class);
|
||||
final ICraftingLink g = cc.submitJob(
|
||||
this.result,
|
||||
null,
|
||||
this.getSelectedCpu() == -1
|
||||
? null
|
||||
: this.cpus.get(this.getSelectedCpu()).getCpu(),
|
||||
true,
|
||||
this.getActionSrc());
|
||||
this.setAutoStart(false);
|
||||
if (g != null && originalGui > 0) // && this.getOpenContext() != null )
|
||||
{
|
||||
NetworkHandler.instance.sendTo(
|
||||
new PacketSwitchGuis(originalGui), (EntityPlayerMP) this.getInventoryPlayer().player);
|
||||
|
||||
// final TileEntity te = this.getOpenContext().getTile();
|
||||
// Platform.openGUI( this.getInventoryPlayer().player, te, this.getOpenContext().getSide(), originalGui
|
||||
// );
|
||||
EntityPlayerMP player = (EntityPlayerMP) this.getInventoryPlayer().player;
|
||||
World world = player.worldObj;
|
||||
int x = (int) player.posX;
|
||||
int y = (int) player.posY;
|
||||
int z = (int) player.posZ;
|
||||
WCTGuiHandler.launchGui(originalGui, player, world, x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BaseActionSource getActionSrc() {
|
||||
return new WCTPlayerSource(this.getPlayerInv().player, (WCTIActionHost) this.getTarget());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCraftingFromCrafters(final ICrafting c) {
|
||||
super.removeCraftingFromCrafters(c);
|
||||
if (this.getJob() != null) {
|
||||
this.getJob().cancel(true);
|
||||
this.setJob(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(final EntityPlayer par1EntityPlayer) {
|
||||
super.onContainerClosed(par1EntityPlayer);
|
||||
if (this.getJob() != null) {
|
||||
this.getJob().cancel(true);
|
||||
this.setJob(null);
|
||||
}
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return this.getPlayerInv().player.worldObj;
|
||||
}
|
||||
|
||||
public boolean isAutoStart() {
|
||||
return this.autoStart;
|
||||
}
|
||||
|
||||
public void setAutoStart(final boolean autoStart) {
|
||||
this.autoStart = autoStart;
|
||||
}
|
||||
|
||||
public long getUsedBytes() {
|
||||
return this.bytesUsed;
|
||||
}
|
||||
|
||||
private void setUsedBytes(final long bytesUsed) {
|
||||
this.bytesUsed = bytesUsed;
|
||||
}
|
||||
|
||||
public long getCpuAvailableBytes() {
|
||||
return this.cpuBytesAvail;
|
||||
}
|
||||
|
||||
private void setCpuAvailableBytes(final long cpuBytesAvail) {
|
||||
this.cpuBytesAvail = cpuBytesAvail;
|
||||
}
|
||||
|
||||
public int getCpuCoProcessors() {
|
||||
return this.cpuCoProcessors;
|
||||
}
|
||||
|
||||
private void setCpuCoProcessors(final int cpuCoProcessors) {
|
||||
this.cpuCoProcessors = cpuCoProcessors;
|
||||
}
|
||||
|
||||
public int getSelectedCpu() {
|
||||
return this.selectedCpu;
|
||||
}
|
||||
|
||||
private void setSelectedCpu(final int selectedCpu) {
|
||||
this.selectedCpu = selectedCpu;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.myName;
|
||||
}
|
||||
|
||||
private void setName(@Nonnull final String myName) {
|
||||
this.myName = myName;
|
||||
}
|
||||
|
||||
public boolean hasNoCPU() {
|
||||
return this.noCPU;
|
||||
}
|
||||
|
||||
private void setNoCPU(final boolean noCPU) {
|
||||
this.noCPU = noCPU;
|
||||
}
|
||||
|
||||
public boolean isSimulation() {
|
||||
return this.simulation;
|
||||
}
|
||||
|
||||
private void setSimulation(final boolean simulation) {
|
||||
this.simulation = simulation;
|
||||
}
|
||||
|
||||
public Future<ICraftingJob> getJob() {
|
||||
return this.job;
|
||||
}
|
||||
|
||||
public void setJob(final Future<ICraftingJob> job) {
|
||||
this.job = job;
|
||||
public void switchToOriginalGUI() {
|
||||
int x = (int) player.posX;
|
||||
int y = (int) player.posY;
|
||||
int z = (int) player.posZ;
|
||||
WCTGuiHandler.launchGui(Reference.GUI_WCT, player, player.worldObj, x, y, z);
|
||||
}
|
||||
}
|
||||
+1
-7
@@ -15,11 +15,9 @@ import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketMagnetFilte
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketNEIRecipe;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketOpenGui;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketPartialItem;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSetJobBytes;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSetMagnet;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwapSlots;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketUpdateCPUInfo;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketValueConfig;
|
||||
|
||||
public class WCTPacketHandlerBase {
|
||||
@@ -51,11 +49,7 @@ public class WCTPacketHandlerBase {
|
||||
|
||||
PACKET_EMPTY_TRASH(PacketEmptyTrash.class),
|
||||
|
||||
PACKET_SYNC_CONFIGS(PacketConfigSync.class),
|
||||
|
||||
PACKET_SET_JOB(PacketSetJobBytes.class),
|
||||
|
||||
PACKET_UPDATECPUINFO(PacketUpdateCPUInfo.class);
|
||||
PACKET_SYNC_CONFIGS(PacketConfigSync.class);
|
||||
|
||||
private final Class<? extends WCTPacket> packetClass;
|
||||
private final Constructor<? extends WCTPacket> packetConstructor;
|
||||
|
||||
+3
-3
@@ -4,13 +4,13 @@ import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.crafting.ICraftingJob;
|
||||
import appeng.container.implementations.ContainerCraftAmount;
|
||||
import appeng.container.implementations.ContainerCraftConfirm;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import java.util.concurrent.Future;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftAmount;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo;
|
||||
import net.p455w0rd.wirelesscraftingterminal.reference.Reference;
|
||||
@@ -44,7 +44,7 @@ public class PacketCraftRequest extends WCTPacket {
|
||||
final ContainerCraftAmount cca = (ContainerCraftAmount) player.openContainer;
|
||||
final Object target = cca.getTarget();
|
||||
if (target instanceof IGridHost) {
|
||||
final IGrid g = cca.obj2.getTargetGrid();
|
||||
final IGrid g = cca.getGrid();
|
||||
if (g == null || cca.getItemToCraft() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,6 +2,7 @@ package net.p455w0rd.wirelesscraftingterminal.core.sync.packets;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.ClientHelper;
|
||||
import appeng.container.implementations.ContainerCraftAmount;
|
||||
import appeng.helpers.InventoryAction;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
@@ -12,7 +13,6 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftAmount;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerOpenContext;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer;
|
||||
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
package net.p455w0rd.wirelesscraftingterminal.core.sync.packets;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import java.io.IOException;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftConfirm;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo;
|
||||
|
||||
public class PacketSetJobBytes extends WCTPacket {
|
||||
|
||||
private final int bytez;
|
||||
|
||||
// automatic.
|
||||
public PacketSetJobBytes(final ByteBuf stream) throws IOException, ClassNotFoundException {
|
||||
this.bytez = stream.readInt();
|
||||
}
|
||||
|
||||
public PacketSetJobBytes(int numBytes) throws IOException {
|
||||
this.bytez = numBytes;
|
||||
final ByteBuf data = Unpooled.buffer();
|
||||
data.writeInt(this.getPacketID());
|
||||
data.writeInt(this.bytez);
|
||||
this.configureWrite(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clientPacketData(final INetworkInfo network, final WCTPacket packet, final EntityPlayer player) {
|
||||
GuiCraftConfirm.setJobBytes(this.bytez);
|
||||
}
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package net.p455w0rd.wirelesscraftingterminal.core.sync.packets;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import java.io.IOException;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftConfirm;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket;
|
||||
import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo;
|
||||
|
||||
public class PacketUpdateCPUInfo extends WCTPacket {
|
||||
|
||||
private final int bytez;
|
||||
private final int coCPUz;
|
||||
|
||||
// automatic.
|
||||
public PacketUpdateCPUInfo(final ByteBuf stream) throws IOException, ClassNotFoundException {
|
||||
this.bytez = stream.readInt();
|
||||
this.coCPUz = stream.readInt();
|
||||
}
|
||||
|
||||
public PacketUpdateCPUInfo(int numBytes, int numCoCPUs) throws IOException {
|
||||
this.bytez = numBytes;
|
||||
this.coCPUz = numCoCPUs;
|
||||
final ByteBuf data = Unpooled.buffer();
|
||||
data.writeInt(this.getPacketID());
|
||||
data.writeInt(this.bytez);
|
||||
data.writeInt(this.coCPUz);
|
||||
this.configureWrite(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clientPacketData(final INetworkInfo network, final WCTPacket packet, final EntityPlayer player) {
|
||||
GuiCraftConfirm.setCurrentCPUAvailBytes(this.bytez);
|
||||
GuiCraftConfirm.setCurrentCPUCoCPUs(this.coCPUz);
|
||||
}
|
||||
}
|
||||
-7
@@ -14,7 +14,6 @@ import java.io.IOException;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils;
|
||||
@@ -61,12 +60,6 @@ public class PacketValueConfig extends WCTPacket {
|
||||
final ItemStack is = RandomUtils.getWirelessTerm(player.inventory);
|
||||
final IMouseWheelItem si = (IMouseWheelItem) is.getItem();
|
||||
si.onWheel(is, this.Value.equals("WheelUp"));
|
||||
} else if (this.Name.equals("Terminal.Cpu") && c instanceof ContainerCraftConfirm) {
|
||||
final ContainerCraftConfirm qk = (ContainerCraftConfirm) c;
|
||||
qk.cycleCpu(this.Value.equals("Next"));
|
||||
} else if (this.Name.equals("Terminal.Start") && c instanceof ContainerCraftConfirm) {
|
||||
final ContainerCraftConfirm qk = (ContainerCraftConfirm) c;
|
||||
qk.startJob();
|
||||
} else if (c instanceof IConfigurableObject) {
|
||||
final IConfigManager cm = ((IConfigurableObject) c).getConfigManager();
|
||||
|
||||
|
||||
Reference in new issue
Block a user