craft confirm screen add cpu select support (#99)

* craft confirm screen add cpu select support

* fix bug
This commit is contained in:
asdflj authored and GitHub committed 2023-03-13 12:58:20 +08:00
1 parent b9724d9369
commit 399c5f53dd
7 files changed
+30 -901

No files matched your search

@@ -1,68 +1,27 @@
package com.glodblock.github.client.gui;
import java.text.NumberFormat;
import java.util.*;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import appeng.api.AEApi;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiScrollbar;
import appeng.core.AELog;
import appeng.core.localization.GuiText;
import appeng.integration.modules.NEI;
import appeng.util.Platform;
import appeng.client.gui.implementations.GuiCraftConfirm;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.ContainerFluidCraftConfirm;
import com.glodblock.github.common.item.ItemWirelessUltraTerminal;
import com.glodblock.github.common.parts.PartFluidPatternTerminal;
import com.glodblock.github.common.parts.PartFluidPatternTerminalEx;
import com.glodblock.github.coremod.hooker.CoreModHooks;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.IWirelessTerminal;
import com.glodblock.github.inventory.item.WirelessPatternTerminalInventory;
import com.glodblock.github.network.CPacketFluidPatternTermBtns;
import com.glodblock.github.network.CPacketSwitchGuis;
import com.glodblock.github.util.ModAndClassUtil;
import com.google.common.base.Joiner;
public class GuiFluidCraftConfirm extends AEBaseGui {
private final ContainerFluidCraftConfirm 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>();
public class GuiFluidCraftConfirm extends GuiCraftConfirm {
private GuiType OriginalGui;
private GuiButton cancel;
private GuiButton start;
private GuiButton selectCPU;
private int tooltip = -1;
private ItemStack hoveredStack;
public GuiFluidCraftConfirm(final InventoryPlayer inventoryPlayer, final ITerminalHost te) {
super(new ContainerFluidCraftConfirm(inventoryPlayer, te));
this.xSize = 238;
this.ySize = 206;
final GuiScrollbar scrollbar = new GuiScrollbar();
this.setScrollBar(scrollbar);
this.ccc = (ContainerFluidCraftConfirm) this.inventorySlots;
super(inventoryPlayer, te);
if (te instanceof PartFluidPatternTerminal) {
this.OriginalGui = GuiType.FLUID_PATTERN_TERMINAL;
} else if (te instanceof PartFluidPatternTerminalEx) {
@@ -74,483 +33,8 @@ public class GuiFluidCraftConfirm extends AEBaseGui {
}
}
boolean isAutoStart() {
return ((ContainerFluidCraftConfirm) this.inventorySlots).isAutoStart();
}
@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 != null) {
this.cancel = new GuiButton(
0,
this.guiLeft + 6,
this.guiTop + this.ySize - 25,
50,
20,
GuiText.Cancel.getLocal());
}
this.buttonList.add(this.cancel);
}
@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 ((ContainerFluidCraftConfirm) this.inventorySlots).isSimulation();
}
@Override
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
final long BytesUsed = this.ccc.getUsedBytes();
final 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 = this.ccc.getCpuAvailableBytes() > 0
? (GuiText.Bytes.getLocal() + ": "
+ this.ccc.getCpuAvailableBytes()
+ " : "
+ GuiText.CoProcessors.getLocal()
+ ": "
+ this.ccc.getCpuCoProcessors())
: 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;
hoveredStack = null;
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() + ": " + 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() + ": " + 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 = CoreModHooks.displayFluid(refStack.copy());
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;
hoveredStack = is;
}
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("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.sortItems();
this.setScrollBar();
}
Comparator<IAEItemStack> comparator = (i1, i2) -> {
if (missing.findPrecise(i1) != null) {
if (missing.findPrecise(i2) != null) return 0;
return -1;
} else if (missing.findPrecise(i2) != null) {
return 1;
} else {
return 0;
}
};
private void sortItems() {
if (!this.missing.isEmpty()) {
this.visual.sort(comparator);
}
}
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) {
FluidCraft.proxy.netHandler
.sendToServer(new CPacketFluidPatternTermBtns("Terminal.Cpu", backwards ? "Prev" : "Next"));
}
if (btn == this.cancel) {
this.addMissingItemsToBookMark();
FluidCraft.proxy.netHandler.sendToServer(new CPacketSwitchGuis(this.OriginalGui));
}
if (btn == this.start) {
try {
FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidPatternTermBtns("Terminal.Start", "Start"));
} catch (final Throwable e) {
AELog.debug(e);
}
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void addItemTooltip(ItemStack is, List<String> lineList) {
if (isShiftKeyDown()) {
List l = is.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips);
if (!l.isEmpty()) l.remove(0);
lineList.addAll(l);
} else if (ModAndClassUtil.isShiftTooltip) {
lineList.add(GuiText.HoldShiftForTooltip.getLocal());
}
}
public ItemStack getHoveredStack() {
return hoveredStack;
}
protected void addMissingItemsToBookMark() {
if (!this.missing.isEmpty() && isShiftKeyDown()) {
for (IAEItemStack iaeItemStack : this.missing) {
NEI.instance.addItemToBookMark(iaeItemStack.getItemStack());
}
}
}
public IItemList<IAEItemStack> getStorage() {
return this.storage;
}
public IItemList<IAEItemStack> getPending() {
return this.pending;
}
public IItemList<IAEItemStack> getMissing() {
return this.missing;
public void switchToOriginalGUI() {
FluidCraft.proxy.netHandler.sendToServer(new CPacketSwitchGuis(this.OriginalGui));
}
}
@@ -1,269 +1,31 @@
package com.glodblock.github.client.gui.container;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects;
import java.util.concurrent.Future;
import javax.annotation.Nonnull;
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.item.ItemStack;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
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.security.IActionHost;
import appeng.api.networking.security.PlayerSource;
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.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.implementations.CraftingCPURecord;
import appeng.core.AELog;
import appeng.util.Platform;
import appeng.container.implementations.ContainerCraftConfirm;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.item.ItemBaseWirelessTerminal;
import com.glodblock.github.common.parts.PartFluidPatternTerminal;
import com.glodblock.github.common.parts.PartFluidPatternTerminalEx;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.IWirelessTerminal;
import com.glodblock.github.network.SPacketMEInventoryUpdate;
import com.glodblock.github.util.Ae2Reflect;
import com.glodblock.github.util.BlockPos;
import com.google.common.collect.ImmutableSet;
public class ContainerFluidCraftConfirm extends AEBaseContainer {
private 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 = "";
public class ContainerFluidCraftConfirm extends ContainerCraftConfirm {
public ContainerFluidCraftConfirm(final InventoryPlayer ip, final ITerminalHost te) {
super(ip, te);
}
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("");
} else {
this.setName(Ae2Reflect.getName(this.cpus.get(this.getSelectedCpu())));
this.setCpuAvailableBytes(Ae2Reflect.getSize(this.cpus.get(this.getSelectedCpu())));
this.setCpuCoProcessors(Ae2Reflect.getProcessors(this.cpus.get(this.getSelectedCpu())));
}
}
@Override
public void detectAndSendChanges() {
if (Platform.isClient()) {
return;
}
if (getGrid() == null) 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 (Ae2Reflect.getCPU(ccr) == 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);
}
final SPacketMEInventoryUpdate a = new SPacketMEInventoryUpdate((byte) 0);
final SPacketMEInventoryUpdate b = new SPacketMEInventoryUpdate((byte) 1);
final SPacketMEInventoryUpdate c = this.result.isSimulation() ? new SPacketMEInventoryUpdate((byte) 2)
: null;
final IItemList<IAEItemStack> plan = AEApi.instance().storage().createItemList();
this.result.populatePlan(plan);
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) {
FluidCraft.proxy.netHandler.sendTo(a, (EntityPlayerMP) g);
FluidCraft.proxy.netHandler.sendTo(b, (EntityPlayerMP) g);
if (c != null) {
FluidCraft.proxy.netHandler.sendTo(c, (EntityPlayerMP) g);
}
}
}
} catch (final Throwable e) {
this.getPlayerInv().player.addChatMessage(new ChatComponentText("Error: " + e.toString()));
AELog.debug(e);
this.setValidContainer(false);
this.result = null;
}
this.setJob(null);
}
this.verifyPermissions(SecurityPermissions.CRAFT, false);
}
private IGrid getGrid() {
final IActionHost h = ((IActionHost) this.getTarget());
if (h == null || h.getActionableNode() == null) return null;
return h.getActionableNode().getGrid();
}
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(Ae2Reflect.getName(this.cpus.get(this.getSelectedCpu())));
this.setCpuAvailableBytes(Ae2Reflect.getSize(this.cpus.get(this.getSelectedCpu())));
this.setCpuCoProcessors(Ae2Reflect.getProcessors(this.cpus.get(this.getSelectedCpu())));
}
}
public void startJob() {
public void switchToOriginalGUI() {
GuiType originalGui = null;
final IActionHost ah = this.getActionHost();
@@ -279,131 +41,20 @@ public class ContainerFluidCraftConfirm extends AEBaseContainer {
originalGui = ((ItemBaseWirelessTerminal) terminal.getItem()).guiGuiType(terminal);
}
}
if (this.result != null && !this.isSimulation() && getGrid() != null) {
final ICraftingGrid cc = this.getGrid().getCache(ICraftingGrid.class);
final ICraftingLink g = cc.submitJob(
this.result,
null,
this.getSelectedCpu() == -1 ? null : Ae2Reflect.getCPU(this.cpus.get(this.getSelectedCpu())),
true,
this.getActionSrc());
this.setAutoStart(false);
if (g != null && originalGui != null) {
if (ah instanceof IWirelessTerminal) {
InventoryHandler.openGui(
this.getInventoryPlayer().player,
getWorld(),
new BlockPos(((IWirelessTerminal) ah).getInventorySlot(), 0, 0),
ForgeDirection.UNKNOWN,
originalGui);
} else if (this.getOpenContext() != null) {
InventoryHandler.openGui(
this.getInventoryPlayer().player,
getWorld(),
new BlockPos(this.getOpenContext().getTile()),
Objects.requireNonNull(this.getOpenContext().getSide()),
originalGui);
}
}
if (ah instanceof IWirelessTerminal) {
InventoryHandler.openGui(
this.getInventoryPlayer().player,
getWorld(),
new BlockPos(((IWirelessTerminal) ah).getInventorySlot(), 0, 0),
ForgeDirection.UNKNOWN,
originalGui);
} else if (this.getOpenContext() != null) {
InventoryHandler.openGui(
this.getInventoryPlayer().player,
getWorld(),
new BlockPos(this.getOpenContext().getTile()),
Objects.requireNonNull(this.getOpenContext().getSide()),
originalGui);
}
}
private BaseActionSource getActionSrc() {
return new PlayerSource(this.getPlayerInv().player, (IActionHost) 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;
}
private Future<ICraftingJob> getJob() {
return this.job;
}
public void setJob(final Future<ICraftingJob> job) {
this.job = job;
}
}
@@ -18,6 +18,7 @@ public class FluidFilter {
}
private static boolean filter(IAEStack<?> stack, TypeFilter typeFilter) {
if (typeFilter == ALL) return true;
if (stack instanceof IAEItemStack) {
Item item = ((IAEItemStack) stack).getItem();
if (item != null) {
@@ -16,9 +16,9 @@ import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingJob;
import appeng.container.ContainerOpenContext;
import appeng.container.implementations.ContainerCraftAmount;
import appeng.container.implementations.ContainerCraftConfirm;
import appeng.core.AELog;
import com.glodblock.github.client.gui.container.ContainerFluidCraftConfirm;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.IWirelessTerminal;
@@ -107,8 +107,8 @@ public class CPacketCraftRequest implements IMessage {
GuiType.FLUID_CRAFTING_CONFIRM_ITEM);
}
if (player.openContainer instanceof ContainerFluidCraftConfirm) {
final ContainerFluidCraftConfirm ccc = (ContainerFluidCraftConfirm) player.openContainer;
if (player.openContainer instanceof ContainerCraftConfirm) {
final ContainerCraftConfirm ccc = (ContainerCraftConfirm) player.openContainer;
ccc.setAutoStart(message.heldShift);
ccc.setJob(futureJob);
cca.detectAndSendChanges();
@@ -2,7 +2,6 @@ package com.glodblock.github.network;
import net.minecraft.inventory.Container;
import com.glodblock.github.client.gui.container.ContainerFluidCraftConfirm;
import com.glodblock.github.client.gui.container.ContainerFluidStorageBus;
import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal;
@@ -121,12 +120,6 @@ public class CPacketFluidPatternTermBtns implements IMessage {
break;
}
cpt.getPatternTerminal().saveSettings();
} else if (Name.equals("Terminal.Cpu") && c instanceof ContainerFluidCraftConfirm) {
final ContainerFluidCraftConfirm qk = (ContainerFluidCraftConfirm) c;
qk.cycleCpu(Value.equals("Next"));
} else if (Name.equals("Terminal.Start") && c instanceof ContainerFluidCraftConfirm) {
final ContainerFluidCraftConfirm qk = (ContainerFluidCraftConfirm) c;
qk.startJob();
} else if (Name.startsWith("StorageBus.") && c instanceof ContainerFluidStorageBus) {
final ContainerFluidStorageBus ccw = (ContainerFluidStorageBus) c;
if (Name.equals("StorageBus.Action")) {