refactor 1

This commit is contained in:
GlodBlock committed 2023-01-20 22:45:58 +08:00
1 parent 510cd6d4bd
commit a70ace4742
19 files changed
+431 -1393

No files matched your search

@@ -18,7 +18,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import org.lwjgl.input.Keyboard;
public class GuiBaseFluidPatternTerminal extends GuiFCBaseMonitor {
public class GuiBaseFluidPatternTerminal extends GuiItemMonitor {
private static final String SUBSITUTION_DISABLE = "0";
private static final String SUBSITUTION_ENABLE = "1";
@@ -16,7 +16,7 @@ import net.minecraft.util.StatCollector;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
public class GuiBaseFluidPatternTerminalEx extends GuiFCBaseMonitor {
public class GuiBaseFluidPatternTerminalEx extends GuiItemMonitor {
private static final String SUBSITUTION_DISABLE = "0";
private static final String SUBSITUTION_ENABLE = "1";
@@ -2,18 +2,18 @@ package com.glodblock.github.client.gui;
import appeng.api.storage.ITerminalHost;
import appeng.container.slot.AppEngSlot;
import com.glodblock.github.client.gui.container.FCBaseFluidMonitorContain;
import com.glodblock.github.client.gui.container.ContainerFluidMonitor;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
public class GuiBaseFluidTerminal extends GuiFCBaseFluidMonitor {
public class GuiBaseFluidTerminal extends GuiFluidMonitor {
protected EntityPlayer player;
public GuiBaseFluidTerminal(InventoryPlayer inventoryPlayer, ITerminalHost te, FCBaseFluidMonitorContain c) {
super(inventoryPlayer, te, new FCBaseFluidMonitorContain(inventoryPlayer, te));
public GuiBaseFluidTerminal(InventoryPlayer inventoryPlayer, ITerminalHost te, ContainerFluidMonitor c) {
super(inventoryPlayer, te, new ContainerFluidMonitor(inventoryPlayer, te));
player = inventoryPlayer.player;
}
@@ -1,797 +0,0 @@
package com.glodblock.github.client.gui;
import appeng.api.config.*;
import appeng.api.implementations.tiles.IViewCellStorage;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.client.gui.AEBaseMEGui;
import appeng.client.gui.widgets.*;
import appeng.client.me.InternalSlotME;
import appeng.client.me.SlotDisconnected;
import appeng.client.me.SlotME;
import appeng.container.AEBaseContainer;
import appeng.container.slot.*;
import appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.core.localization.ButtonToolTips;
import appeng.core.localization.GuiText;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketInventoryAction;
import appeng.core.sync.packets.PacketSwitchGuis;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.helpers.InventoryAction;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import codechicken.nei.LayoutManager;
import codechicken.nei.util.TextHistory;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.FCBaseFluidMonitorContain;
import com.glodblock.github.client.me.FluidRepo;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.network.CPacketInventoryAction;
import com.glodblock.github.util.Ae2ReflectClient;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.NameConst;
import com.glodblock.github.util.Util;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
public class GuiFCBaseFluidMonitor extends AEBaseMEGui
implements ISortSource, IConfigManagerHost, IDropToFillTextField {
public static int craftingGridOffsetX;
public static int craftingGridOffsetY;
private static String memoryText = "";
private final FluidRepo repo;
private final int offsetX = 9;
private final int lowerTextureOffset = 0;
private final boolean viewCell;
private final ItemStack[] myCurrentViewCells = new ItemStack[5];
public IConfigManager configSrc;
public FCBaseFluidMonitorContain monitorableContainer;
public GuiTabButton craftingStatusBtn;
private GuiImgButton craftingStatusImgBtn;
private FCGuiTextField searchField;
private int perRow = 9;
private int reservedSpace = 0;
private boolean customSortOrder = true;
private int rows = 0;
private int maxRows = Integer.MAX_VALUE;
private int standardSize;
private GuiImgButton ViewBox;
private GuiImgButton SortByBox;
private GuiImgButton SortDirBox;
private GuiImgButton searchBoxSettings;
private GuiImgButton terminalStyleBox;
private GuiImgButton searchStringSave;
public GuiFCBaseFluidMonitor(
final InventoryPlayer inventoryPlayer, final ITerminalHost te, final FCBaseFluidMonitorContain c) {
super(c);
final GuiScrollbar scrollbar = new GuiScrollbar();
this.setScrollBar(scrollbar);
this.repo = new FluidRepo(scrollbar, this);
this.xSize = 195;
this.ySize = 204;
this.standardSize = this.xSize;
this.configSrc = ((IConfigurableObject) this.inventorySlots).getConfigManager();
(this.monitorableContainer = (FCBaseFluidMonitorContain) this.inventorySlots).setGui(this);
this.viewCell = te instanceof IViewCellStorage;
}
public void postUpdate(final List<IAEFluidStack> list) {
for (final IAEFluidStack is : list) {
IAEItemStack stack = AEItemStack.create(ItemFluidDrop.newDisplayStack(is.getFluidStack()));
stack.setStackSize(is.getStackSize());
this.repo.postUpdate(stack);
}
this.repo.updateView();
this.setScrollBar();
}
private void setScrollBar() {
this.getScrollBar().setTop(18).setLeft(175).setHeight(this.rows * 18 - 2);
this.getScrollBar()
.setRange(
0, (this.repo.size() + this.perRow - 1) / this.perRow - this.rows, Math.max(1, this.rows / 6));
}
@Override
protected void actionPerformed(final GuiButton btn) {
if (btn == this.craftingStatusBtn || btn == this.craftingStatusImgBtn) {
NetworkHandler.instance.sendToServer(new PacketSwitchGuis(GuiBridge.GUI_CRAFTING_STATUS));
}
if (btn instanceof GuiImgButton) {
final boolean backwards = Mouse.isButtonDown(1);
final GuiImgButton iBtn = (GuiImgButton) btn;
if (iBtn.getSetting() != Settings.ACTIONS) {
final Enum<?> cv = iBtn.getCurrentValue();
final Enum<?> next =
Platform.rotateEnum(cv, backwards, iBtn.getSetting().getPossibleValues());
if (btn == this.terminalStyleBox) {
AEConfig.instance.settings.putSetting(iBtn.getSetting(), next);
} else if (btn == this.searchBoxSettings) {
AEConfig.instance.settings.putSetting(iBtn.getSetting(), next);
} else if (ModAndClassUtil.isSaveText && btn == this.searchStringSave) {
AEConfig.instance.preserveSearchBar = next == YesNo.YES;
} else {
try {
NetworkHandler.instance.sendToServer(
new PacketValueConfig(iBtn.getSetting().name(), next.name()));
} catch (final IOException e) {
AELog.debug(e);
}
}
iBtn.set(next);
if (next.getClass() == SearchBoxMode.class || next.getClass() == TerminalStyle.class) {
this.reinitalize();
}
}
}
}
private void reinitalize() {
this.buttonList.clear();
this.initGui();
}
@Override
@SuppressWarnings("unchecked")
public void initGui() {
Keyboard.enableRepeatEvents(true);
this.maxRows = this.getMaxRows();
this.perRow = AEConfig.instance.getConfigManager().getSetting(Settings.TERMINAL_STYLE) != TerminalStyle.FULL
? 9
: 9 + ((this.width - this.standardSize) / 18);
final boolean hasNEI = IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.NEI);
final int NEI = hasNEI ? 0 : 0;
int top = hasNEI ? 22 : 0;
final int magicNumber = 114 + 1;
final int extraSpace = this.height - magicNumber - NEI - top - this.reservedSpace;
this.rows = (int) Math.floor(extraSpace / 18.0);
if (this.rows > this.maxRows) {
top += (this.rows - this.maxRows) * 18 / 2;
this.rows = this.maxRows;
}
if (hasNEI) {
this.rows--;
}
if (this.rows < 3) {
this.rows = 3;
}
this.getMeSlots().clear();
for (int y = 0; y < this.rows; y++) {
for (int x = 0; x < this.perRow; x++) {
this.getMeSlots()
.add(new InternalSlotME(this.repo, x + y * this.perRow, this.offsetX + x * 18, 18 + y * 18));
}
}
if (AEConfig.instance.getConfigManager().getSetting(Settings.TERMINAL_STYLE) != TerminalStyle.FULL) {
this.xSize = this.standardSize + ((this.perRow - 9) * 18);
} else {
this.xSize = this.standardSize;
}
super.initGui();
// full size : 204
// extra slots : 72
// slot 18
this.ySize = magicNumber + this.rows * 18 + this.reservedSpace;
// this.guiTop = top;
final int unusedSpace = this.height - this.ySize;
this.guiTop = (int) Math.floor(unusedSpace / (unusedSpace < 0 ? 3.8f : 2.0f));
int offset = this.guiTop + 8;
if (this.customSortOrder) {
this.buttonList.add(
this.SortByBox = new GuiImgButton(
this.guiLeft - 18, offset, Settings.SORT_BY, this.configSrc.getSetting(Settings.SORT_BY)));
offset += 20;
}
// this.buttonList.add( this.ViewBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.VIEW_MODE,
// this.configSrc.getSetting( Settings.VIEW_MODE ) ) );
// offset += 20;
this.buttonList.add(
this.SortDirBox = new GuiImgButton(
this.guiLeft - 18,
offset,
Settings.SORT_DIRECTION,
this.configSrc.getSetting(Settings.SORT_DIRECTION)));
offset += 20;
this.buttonList.add(
this.searchBoxSettings = new GuiImgButton(
this.guiLeft - 18,
offset,
Settings.SEARCH_MODE,
AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE)));
offset += 20;
if (ModAndClassUtil.isSaveText) {
this.buttonList.add(
this.searchStringSave = new GuiImgButton(
this.guiLeft - 18,
offset,
Settings.SAVE_SEARCH,
AEConfig.instance.preserveSearchBar ? YesNo.YES : YesNo.NO));
offset += 20;
}
this.buttonList.add(
this.terminalStyleBox = new GuiImgButton(
this.guiLeft - 18,
offset,
Settings.TERMINAL_STYLE,
AEConfig.instance.settings.getSetting(Settings.TERMINAL_STYLE)));
offset += 20;
this.searchField = new FCGuiTextField(
this.fontRendererObj, this.guiLeft + Math.max(80, this.offsetX), this.guiTop + 4, 90, 12);
this.searchField.setEnableBackgroundDrawing(false);
this.searchField.setMaxStringLength(25);
this.searchField.setTextColor(0xFFFFFF);
this.searchField.setVisible(true);
if (ModAndClassUtil.isSearchStringTooltip)
searchField.setMessage(ButtonToolTips.SearchStringTooltip.getLocal());
if (this.viewCell) {
if (ModAndClassUtil.isCraftStatus
&& AEConfig.instance
.getConfigManager()
.getSetting(Settings.CRAFTING_STATUS)
.equals(CraftingStatus.BUTTON)) {
this.buttonList.add(
this.craftingStatusImgBtn = new GuiImgButton(
this.guiLeft - 18,
offset,
Settings.CRAFTING_STATUS,
AEConfig.instance.settings.getSetting(Settings.CRAFTING_STATUS)));
} else {
this.buttonList.add(
this.craftingStatusBtn = new GuiTabButton(
this.guiLeft + 170,
this.guiTop - 4,
2 + 11 * 16,
GuiText.CraftingStatus.getLocal(),
itemRender));
this.craftingStatusBtn.setHideEdge(13); // GuiTabButton implementation //
}
}
// Enum setting = AEConfig.INSTANCE.getSetting( "Terminal", SearchBoxMode.class, SearchBoxMode.AUTOSEARCH );
final Enum<?> setting = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE);
this.searchField.setFocused(SearchBoxMode.AUTOSEARCH == setting || SearchBoxMode.NEI_AUTOSEARCH == setting);
if (ModAndClassUtil.isSearchBar && (AEConfig.instance.preserveSearchBar || this.isSubGui())) {
setSearchString(memoryText, false);
}
if (this.isSubGui()) {
this.repo.updateView();
this.setScrollBar();
}
craftingGridOffsetX = Integer.MAX_VALUE;
craftingGridOffsetY = Integer.MAX_VALUE;
for (final Object s : this.inventorySlots.inventorySlots) {
if (s instanceof AppEngSlot) {
if (((Slot) s).xDisplayPosition < 195) {
this.repositionSlot((AppEngSlot) s);
}
}
if (s instanceof SlotCraftingMatrix || s instanceof SlotFakeCraftingMatrix) {
final Slot g = (Slot) s;
if (g.xDisplayPosition > 0 && g.yDisplayPosition > 0) {
craftingGridOffsetX = Math.min(craftingGridOffsetX, g.xDisplayPosition);
craftingGridOffsetY = Math.min(craftingGridOffsetY, g.yDisplayPosition);
}
}
}
craftingGridOffsetX -= 25;
craftingGridOffsetY -= 6;
}
public void setSearchString(String memoryText, boolean updateView) {
this.searchField.setText(memoryText);
this.repo.setSearchString(memoryText);
if (updateView) {
this.repo.updateView();
this.setScrollBar();
}
}
@Override
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
this.fontRendererObj.drawString(
this.getGuiDisplayName(I18n.format(NameConst.GUI_FLUID_TERMINAL)), 8, 6, 4210752);
this.fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752);
}
@Override
protected void mouseClicked(final int xCoord, final int yCoord, final int btn) {
final Enum<?> searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE);
if (searchMode != SearchBoxMode.AUTOSEARCH && searchMode != SearchBoxMode.NEI_AUTOSEARCH) {
this.searchField.mouseClicked(xCoord, yCoord, btn);
}
if (btn == 1 && this.searchField.isMouseIn(xCoord, yCoord)) {
setSearchString("", true);
}
super.mouseClicked(xCoord, yCoord, btn);
}
@Override
public void handleMouseInput() {
final int wheel = Mouse.getEventDWheel();
final int x = Mouse.getEventX() * this.width / this.mc.displayWidth;
final int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight;
if (wheel != 0 && this.searchField.isMouseIn(x, y) && isCtrlKeyDown()) {
final Enum<?> searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE);
if (searchMode == SearchBoxMode.NEI_MANUAL_SEARCH || searchMode == SearchBoxMode.NEI_AUTOSEARCH) {
try {
Field cls = LayoutManager.searchField.getClass().getDeclaredField("history");
cls.setAccessible(true);
TextHistory history = ((TextHistory) cls.get("get"));
TextHistory.Direction direction;
if (wheel > 0) {
direction = TextHistory.Direction.PREVIOUS;
} else {
direction = TextHistory.Direction.NEXT;
}
history.get(direction, this.searchField.getText())
.map(newText -> {
setSearchString(newText, true);
return true;
})
.orElse(false);
return;
} catch (NoSuchFieldException | IllegalAccessException e) {
}
}
}
super.handleMouseInput();
}
@Override
protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int mouseButton) {
final EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if (mouseButton == 3) {
if (slot instanceof OptionalSlotFake || slot instanceof SlotFakeCraftingMatrix) {
if (slot.getHasStack()) {
InventoryAction action = InventoryAction.valueOf("SET_PATTERN_VALUE");
IAEItemStack stack = AEItemStack.create(slot.getStack());
((AEBaseContainer) this.inventorySlots).setTargetStack(stack);
FluidCraft.proxy.netHandler.sendToServer(new CPacketInventoryAction(
action, Ae2ReflectClient.getInventorySlots(this).size(), 0, stack));
return;
}
}
}
if (slot instanceof SlotFake) {
InventoryAction action =
ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN;
if (Keyboard.isKeyDown(Keyboard.KEY_LMENU) || Keyboard.isKeyDown(Keyboard.KEY_RMENU)) {
if (action == InventoryAction.SPLIT_OR_PLACE_SINGLE) {
action = InventoryAction.MOVE_REGION;
} else {
action = InventoryAction.PICKUP_SINGLE;
}
}
if (Ae2ReflectClient.getDragClick(this).size() > 1) {
return;
}
final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0);
NetworkHandler.instance.sendToServer(p);
return;
}
if (slot instanceof SlotPatternTerm) {
if (mouseButton == 6) {
return; // prevent weird double clicks..
}
try {
NetworkHandler.instance.sendToServer(((SlotPatternTerm) slot).getRequest(isShiftKeyDown()));
} catch (final IOException e) {
AELog.debug(e);
}
} else if (slot instanceof SlotCraftingTerm) {
if (mouseButton == 6) {
return; // prevent weird double clicks..
}
InventoryAction action;
if (isShiftKeyDown()) {
action = InventoryAction.CRAFT_SHIFT;
} else {
// Craft stack on right-click, craft single on left-click
action = (mouseButton == 1) ? InventoryAction.CRAFT_STACK : InventoryAction.CRAFT_ITEM;
}
final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0);
NetworkHandler.instance.sendToServer(p);
return;
}
if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
if (this.enableSpaceClicking() && !(slot instanceof SlotPatternTerm)) {
IAEItemStack stack = null;
if (slot instanceof SlotME) {
stack = ((SlotME) slot).getAEStack();
}
int slotNum = Ae2ReflectClient.getInventorySlots(this).size();
if (!(slot instanceof SlotME) && slot != null) {
slotNum = slot.slotNumber;
}
((AEBaseContainer) this.inventorySlots).setTargetStack(stack);
final PacketInventoryAction p = new PacketInventoryAction(InventoryAction.MOVE_REGION, slotNum, 0);
NetworkHandler.instance.sendToServer(p);
return;
}
}
if (slot instanceof SlotDisconnected) {
if (Ae2ReflectClient.getDragClick(this).size() > 1) {
return;
}
InventoryAction action = null;
switch (mouseButton) {
case 0: // pickup / set-down.
{
ItemStack heldStack = player.inventory.getItemStack();
if (slot.getStack() == null && heldStack != null)
action = InventoryAction.SPLIT_OR_PLACE_SINGLE;
else if (slot.getStack() != null && (heldStack == null || heldStack.stackSize <= 1))
action = InventoryAction.PICKUP_OR_SET_DOWN;
}
break;
case 1:
action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK;
break;
case 3: // creative dupe:
if (player.capabilities.isCreativeMode) {
action = InventoryAction.CREATIVE_DUPLICATE;
}
break;
default:
case 4: // drop item:
case 6:
}
if (action != null) {
final PacketInventoryAction p = new PacketInventoryAction(
action,
slot.getSlotIndex(),
((SlotDisconnected) slot).getSlot().getId());
NetworkHandler.instance.sendToServer(p);
}
return;
}
if (slot instanceof SlotME) {
InventoryAction action = null;
IAEItemStack stack = null;
switch (mouseButton) {
case 0: // pickup / set-down.
action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN;
stack = ((SlotME) slot).getAEStack();
if (stack != null
&& action == InventoryAction.PICKUP_OR_SET_DOWN
&& stack.getStackSize() == 0
&& player.inventory.getItemStack() == null) {
action = InventoryAction.AUTO_CRAFT;
}
break;
case 1:
action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK;
stack = ((SlotME) slot).getAEStack();
break;
case 3: // creative dupe:
stack = ((SlotME) slot).getAEStack();
if (stack.getItem() instanceof ItemFluidDrop) {
stack = ItemFluidDrop.newAeStack(ItemFluidDrop.getAeFluidStack(stack));
}
if (stack != null && stack.isCraftable()) {
action = InventoryAction.AUTO_CRAFT;
} else if (player.capabilities.isCreativeMode) {
final IAEItemStack slotItem = ((SlotME) slot).getAEStack();
if (slotItem != null) {
action = InventoryAction.CREATIVE_DUPLICATE;
}
}
break;
default:
case 4: // drop item:
case 6:
}
if (action == InventoryAction.AUTO_CRAFT) {
((AEBaseContainer) this.inventorySlots).setTargetStack(stack);
FluidCraft.proxy.netHandler.sendToServer(new CPacketInventoryAction(
action, Ae2ReflectClient.getInventorySlots(this).size(), 0, stack));
} else if (action != null) {
((AEBaseContainer) this.inventorySlots).setTargetStack(stack);
final PacketInventoryAction p = new PacketInventoryAction(
action, Ae2ReflectClient.getInventorySlots(this).size(), 0);
NetworkHandler.instance.sendToServer(p);
}
return;
}
super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton);
}
@Override
public void onGuiClosed() {
super.onGuiClosed();
Keyboard.enableRepeatEvents(false);
memoryText = this.searchField.getText();
}
public void bindTextureBack(final String file) {
final ResourceLocation loc = new ResourceLocation(FluidCraft.MODID, "textures/" + file);
this.mc.getTextureManager().bindTexture(loc);
}
@Override
public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
this.bindTextureBack(this.getBackground());
final int x_width = 195;
this.drawTexturedModalRect(offsetX, offsetY, 0, 0, x_width, 18);
if (this.viewCell) {
this.drawTexturedModalRect(offsetX + x_width, offsetY, x_width, 0, 46, 128);
}
for (int x = 0; x < this.rows; x++) {
this.drawTexturedModalRect(offsetX, offsetY + 18 + x * 18, 0, 18, x_width, 18);
}
this.drawTexturedModalRect(
offsetX,
offsetY + 16 + this.rows * 18 + this.lowerTextureOffset,
0,
106 - 18 - 18,
x_width,
99 + this.reservedSpace - this.lowerTextureOffset);
if (this.viewCell) {
boolean update = false;
for (int i = 0; i < 5; i++) {
if (this.myCurrentViewCells[i]
!= this.monitorableContainer.getCellViewSlot(i).getStack()) {
update = true;
this.myCurrentViewCells[i] =
this.monitorableContainer.getCellViewSlot(i).getStack();
}
}
if (update) {
this.repo.setViewCell(this.myCurrentViewCells);
}
}
if (this.searchField != null) {
this.searchField.drawTextBox();
}
}
protected String getBackground() {
return "gui/terminal.png";
}
@Override
protected boolean isPowered() {
return this.repo.hasPower();
}
int getMaxRows() {
return AEConfig.instance.getConfigManager().getSetting(Settings.TERMINAL_STYLE) == TerminalStyle.SMALL
? 6
: Integer.MAX_VALUE;
}
protected void repositionSlot(final AppEngSlot s) {
s.yDisplayPosition = s.getY() + this.ySize - 78 - 5;
}
@Override
protected void keyTyped(final char character, final int key) {
if (!this.checkHotbarKeys(key)) {
if (character == ' ' && this.searchField.getText().isEmpty()) {
return;
}
if (this.searchField.textboxKeyTyped(character, key)) {
this.repo.setSearchString(this.searchField.getText());
this.repo.updateView();
this.setScrollBar();
} else {
super.keyTyped(character, key);
}
}
}
@Override
public void updateScreen() {
this.repo.setPower(this.monitorableContainer.isPowered());
super.updateScreen();
}
@Override
public Enum<?> getSortBy() {
return this.configSrc.getSetting(Settings.SORT_BY);
}
@Override
public Enum<?> getSortDir() {
return this.configSrc.getSetting(Settings.SORT_DIRECTION);
}
@Override
public Enum<?> getSortDisplay() {
return this.configSrc.getSetting(Settings.VIEW_MODE);
}
@Override
public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) {
if (this.SortByBox != null) {
this.SortByBox.set(this.configSrc.getSetting(Settings.SORT_BY));
}
if (this.SortDirBox != null) {
this.SortDirBox.set(this.configSrc.getSetting(Settings.SORT_DIRECTION));
}
if (this.ViewBox != null) {
this.ViewBox.set(this.configSrc.getSetting(Settings.VIEW_MODE));
}
this.repo.updateView();
}
public int getReservedSpace() {
return this.reservedSpace;
}
public void setReservedSpace(final int reservedSpace) {
this.reservedSpace = reservedSpace;
}
public boolean isCustomSortOrder() {
return this.customSortOrder;
}
public void setCustomSortOrder(final boolean customSortOrder) {
this.customSortOrder = customSortOrder;
}
public int getStandardSize() {
return this.standardSize;
}
public void setStandardSize(final int standardSize) {
this.standardSize = standardSize;
}
@Override
public void drawScreen(final int mouseX, final int mouseY, final float btn) {
super.drawScreen(mouseX, mouseY, btn);
if (ModAndClassUtil.isSearchBar && AEConfig.instance.preserveSearchBar && searchField != null)
handleTooltip(mouseX, mouseY, searchField.new TooltipProvider());
}
public boolean isOverSearchField(int x, int y) {
return searchField.isMouseIn(x, y);
}
public boolean hideItemPanelSlot(int tx, int ty, int tw, int th) {
if (this.viewCell) {
int rw = 33;
int rh = 14 + myCurrentViewCells.length * 18;
if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) {
return false;
}
int rx = this.guiLeft + this.xSize;
int ry = this.guiTop + 0;
rw += rx;
rh += ry;
tw += tx;
th += ty;
// overflow || intersect
return (rw < rx || rw > tx) && (rh < ry || rh > ty) && (tw < tx || tw > rx) && (th < ty || th > ry);
}
return false;
}
@Override
public boolean isOverTextField(int mousex, int mousey) {
return searchField.isMouseIn(mousex, mousey);
}
@Override
public void setTextFieldValue(String displayName, int mousex, int mousey, ItemStack stack) {
if (Util.getFluidFromItem(stack) != null) {
setSearchString(Util.getFluidFromItem(stack).getFluid().getLocalizedName(), true);
}
}
}
@@ -0,0 +1,56 @@
package com.glodblock.github.client.gui;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.localization.GuiText;
import appeng.util.item.AEItemStack;
import com.glodblock.github.client.gui.base.FCGuiMonitor;
import com.glodblock.github.client.gui.container.ContainerFluidMonitor;
import com.glodblock.github.client.me.FluidRepo;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.util.Util;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import java.util.List;
public class GuiFluidMonitor extends FCGuiMonitor<IAEFluidStack> {
public GuiFluidMonitor(
final InventoryPlayer inventoryPlayer, final ITerminalHost te, final ContainerFluidMonitor c) {
super(inventoryPlayer, te, c);
this.repo = new FluidRepo(getScrollBar(), this);
}
public void postUpdate(final List<IAEFluidStack> list) {
for (final IAEFluidStack is : list) {
IAEItemStack stack = AEItemStack.create(ItemFluidDrop.newDisplayStack(is.getFluidStack()));
stack.setStackSize(is.getStackSize());
this.repo.postUpdate(stack);
}
this.repo.updateView();
this.setScrollBar();
}
@Override
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
this.fontRendererObj.drawString(this.getGuiDisplayName(GuiText.Terminal.getLocal()), 8, 6, 4210752);
this.fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752);
}
@Override
protected IAEItemStack transformItem(IAEItemStack stack) {
if (stack.getItem() instanceof ItemFluidDrop) {
return ItemFluidDrop.newAeStack(ItemFluidDrop.getAeFluidStack(stack));
}
return stack;
}
@Override
public void setTextFieldValue(String displayName, int mousex, int mousey, ItemStack stack) {
if (Util.getFluidFromItem(stack) != null) {
setSearchString(Util.getFluidFromItem(stack).getLocalizedName(), true);
}
}
}
@@ -6,8 +6,7 @@ import appeng.api.storage.data.IAEItemStack;
import appeng.client.me.SlotME;
import appeng.client.render.AppEngRenderItem;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.ContainerFluidTerminal;
import com.glodblock.github.client.gui.container.FCBaseFluidMonitorContain;
import com.glodblock.github.client.gui.container.ContainerFluidMonitor;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.network.CPacketFluidUpdate;
import com.glodblock.github.util.Ae2ReflectClient;
@@ -25,11 +24,11 @@ import org.lwjgl.opengl.GL11;
public class GuiFluidTerminal extends GuiBaseFluidTerminal {
private final AppEngRenderItem stackSizeRenderer = Ae2ReflectClient.getStackSizeRenderer(this);
public ContainerFluidTerminal container;
public ContainerFluidMonitor container;
public GuiFluidTerminal(InventoryPlayer inventoryPlayer, ITerminalHost te) {
super(inventoryPlayer, te, new FCBaseFluidMonitorContain(inventoryPlayer, te));
this.container = new ContainerFluidTerminal(inventoryPlayer, te);
super(inventoryPlayer, te, new ContainerFluidMonitor(inventoryPlayer, te));
this.container = new ContainerFluidMonitor(inventoryPlayer, te);
}
@Override
@@ -0,0 +1,59 @@
package com.glodblock.github.client.gui;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.me.ItemRepo;
import appeng.core.AEConfig;
import appeng.core.localization.GuiText;
import com.glodblock.github.client.gui.base.FCGuiMonitor;
import com.glodblock.github.client.gui.container.ContainerItemMonitor;
import com.glodblock.github.util.ModAndClassUtil;
import java.util.List;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class GuiItemMonitor extends FCGuiMonitor<IAEItemStack> {
public GuiItemMonitor(final InventoryPlayer inventoryPlayer, final ITerminalHost te, final ContainerItemMonitor c) {
super(inventoryPlayer, te, c);
this.repo = new ItemRepo(getScrollBar(), this);
}
public void postUpdate(final List<IAEItemStack> list) {
for (final IAEItemStack is : list) {
this.repo.postUpdate(is);
}
this.repo.updateView();
this.setScrollBar();
}
@Override
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
this.fontRendererObj.drawString(this.getGuiDisplayName(GuiText.Terminal.getLocal()), 8, 6, 4210752);
this.fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752);
}
@Override
protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int mouseButton) {
if (mouseButton == 3) {
if (this instanceof GuiBaseFluidPatternTerminal
&& ((GuiBaseFluidPatternTerminal) this).container.isCraftingMode()) {
return;
}
}
super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton);
}
@Override
public void drawScreen(final int mouseX, final int mouseY, final float btn) {
super.drawScreen(mouseX, mouseY, btn);
if (ModAndClassUtil.isSearchBar && AEConfig.instance.preserveSearchBar && searchField != null)
handleTooltip(mouseX, mouseY, searchField.new TooltipProvider());
}
@Override
public void setTextFieldValue(String displayName, int mousex, int mousey, ItemStack stack) {
setSearchString(displayName, true);
}
}
@@ -1,9 +1,10 @@
package com.glodblock.github.client.gui;
package com.glodblock.github.client.gui.base;
import appeng.api.config.*;
import appeng.api.implementations.tiles.IViewCellStorage;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.client.gui.AEBaseMEGui;
@@ -32,7 +33,8 @@ import appeng.util.item.AEItemStack;
import codechicken.nei.LayoutManager;
import codechicken.nei.util.TextHistory;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.FCBaseMonitorContain;
import com.glodblock.github.client.gui.FCGuiTextField;
import com.glodblock.github.client.gui.container.base.FCContainerMonitor;
import com.glodblock.github.network.CPacketInventoryAction;
import com.glodblock.github.util.Ae2ReflectClient;
import com.glodblock.github.util.ModAndClassUtil;
@@ -49,65 +51,51 @@ import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfigManagerHost, IDropToFillTextField {
public abstract class FCGuiMonitor<T extends IAEStack<T>> extends AEBaseMEGui
implements ISortSource, IConfigManagerHost, IDropToFillTextField {
public static int craftingGridOffsetX;
public static int craftingGridOffsetY;
private static String memoryText = "";
private final ItemRepo repo;
private final int offsetX = 9;
private final int lowerTextureOffset = 0;
protected static String memoryText = "";
protected final int offsetX = 9;
protected final int lowerTextureOffset = 0;
public IConfigManager configSrc;
private final boolean viewCell;
private final ItemStack[] myCurrentViewCells = new ItemStack[5];
public FCBaseMonitorContain monitorableContainer;
protected final boolean viewCell;
protected final ItemStack[] myCurrentViewCells = new ItemStack[5];
public FCContainerMonitor<T> monitorableContainer;
public GuiTabButton craftingStatusBtn;
private GuiImgButton craftingStatusImgBtn;
private FCGuiTextField searchField;
private int perRow = 9;
private int reservedSpace = 0;
private boolean customSortOrder = true;
private int rows = 0;
private int maxRows = Integer.MAX_VALUE;
private int standardSize;
private GuiImgButton ViewBox;
private GuiImgButton SortByBox;
private GuiImgButton SortDirBox;
private GuiImgButton searchBoxSettings;
private GuiImgButton terminalStyleBox;
private GuiImgButton searchStringSave;
public GuiFCBaseMonitor(
final InventoryPlayer inventoryPlayer, final ITerminalHost te, final FCBaseMonitorContain c) {
protected ItemRepo repo;
protected GuiImgButton craftingStatusImgBtn;
protected FCGuiTextField searchField;
protected int perRow = 9;
protected int reservedSpace = 0;
protected boolean customSortOrder = true;
protected int rows = 0;
protected int maxRows = Integer.MAX_VALUE;
protected int standardSize;
protected GuiImgButton ViewBox;
protected GuiImgButton SortByBox;
protected GuiImgButton SortDirBox;
protected GuiImgButton searchBoxSettings;
protected GuiImgButton terminalStyleBox;
protected GuiImgButton searchStringSave;
@SuppressWarnings("unchecked")
public FCGuiMonitor(final InventoryPlayer inventoryPlayer, final ITerminalHost te, final FCContainerMonitor<T> c) {
super(c);
final GuiScrollbar scrollbar = new GuiScrollbar();
this.setScrollBar(scrollbar);
this.repo = new ItemRepo(scrollbar, this);
this.xSize = 195;
this.ySize = 204;
this.standardSize = this.xSize;
this.configSrc = ((IConfigurableObject) this.inventorySlots).getConfigManager();
(this.monitorableContainer = (FCBaseMonitorContain) this.inventorySlots).setGui(this);
(this.monitorableContainer = (FCContainerMonitor<T>) this.inventorySlots).setGui(this);
this.viewCell = te instanceof IViewCellStorage;
}
public void postUpdate(final List<IAEItemStack> list) {
for (final IAEItemStack is : list) {
this.repo.postUpdate(is);
}
public abstract void postUpdate(final List<T> list);
this.repo.updateView();
this.setScrollBar();
}
private void setScrollBar() {
protected void setScrollBar() {
this.getScrollBar().setTop(18).setLeft(175).setHeight(this.rows * 18 - 2);
this.getScrollBar()
.setRange(
@@ -116,20 +104,17 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
@Override
protected void actionPerformed(final GuiButton btn) {
if (btn == this.craftingStatusBtn || btn == this.craftingStatusImgBtn) {
NetworkHandler.instance.sendToServer(new PacketSwitchGuis(GuiBridge.GUI_CRAFTING_STATUS));
}
if (btn instanceof GuiImgButton) {
final boolean backwards = Mouse.isButtonDown(1);
final GuiImgButton iBtn = (GuiImgButton) btn;
if (iBtn.getSetting() != Settings.ACTIONS) {
final Enum<?> cv = iBtn.getCurrentValue();
final Enum<?> next =
Platform.rotateEnum(cv, backwards, iBtn.getSetting().getPossibleValues());
if (btn == this.terminalStyleBox) {
AEConfig.instance.settings.putSetting(iBtn.getSetting(), next);
} else if (btn == this.searchBoxSettings) {
@@ -144,17 +129,15 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
AELog.debug(e);
}
}
iBtn.set(next);
if (next.getClass() == SearchBoxMode.class || next.getClass() == TerminalStyle.class) {
this.reinitalize();
this.reInitalize();
}
}
}
}
private void reinitalize() {
protected void reInitalize() {
this.buttonList.clear();
this.initGui();
}
@@ -171,7 +154,7 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
final boolean hasNEI = IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.NEI);
final int NEI = hasNEI ? 0 : 0;
final int NEI = 0;
int top = hasNEI ? 22 : 0;
final int magicNumber = 114 + 1;
@@ -179,7 +162,6 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
this.rows = (int) Math.floor(extraSpace / 18.0);
if (this.rows > this.maxRows) {
top += (this.rows - this.maxRows) * 18 / 2;
this.rows = this.maxRows;
}
@@ -211,7 +193,6 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
// slot 18
this.ySize = magicNumber + this.rows * 18 + this.reservedSpace;
// this.guiTop = top;
final int unusedSpace = this.height - this.ySize;
this.guiTop = (int) Math.floor(unusedSpace / (unusedSpace < 0 ? 3.8f : 2.0f));
@@ -224,45 +205,6 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
offset += 20;
}
this.buttonList.add(
this.ViewBox = new GuiImgButton(
this.guiLeft - 18, offset, Settings.VIEW_MODE, this.configSrc.getSetting(Settings.VIEW_MODE)));
offset += 20;
this.buttonList.add(
this.SortDirBox = new GuiImgButton(
this.guiLeft - 18,
offset,
Settings.SORT_DIRECTION,
this.configSrc.getSetting(Settings.SORT_DIRECTION)));
offset += 20;
this.buttonList.add(
this.searchBoxSettings = new GuiImgButton(
this.guiLeft - 18,
offset,
Settings.SEARCH_MODE,
AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE)));
offset += 20;
if (ModAndClassUtil.isSaveText) {
this.buttonList.add(
this.searchStringSave = new GuiImgButton(
this.guiLeft - 18,
offset,
Settings.SAVE_SEARCH,
AEConfig.instance.preserveSearchBar ? YesNo.YES : YesNo.NO));
offset += 20;
}
this.buttonList.add(
this.terminalStyleBox = new GuiImgButton(
this.guiLeft - 18,
offset,
Settings.TERMINAL_STYLE,
AEConfig.instance.settings.getSetting(Settings.TERMINAL_STYLE)));
offset += 20;
this.searchField = new FCGuiTextField(
this.fontRendererObj, this.guiLeft + Math.max(80, this.offsetX), this.guiTop + 4, 90, 12);
this.searchField.setEnableBackgroundDrawing(false);
@@ -296,7 +238,6 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
}
}
// Enum setting = AEConfig.INSTANCE.getSetting( "Terminal", SearchBoxMode.class, SearchBoxMode.AUTOSEARCH );
final Enum<?> setting = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE);
this.searchField.setFocused(SearchBoxMode.AUTOSEARCH == setting || SearchBoxMode.NEI_AUTOSEARCH == setting);
@@ -340,24 +281,15 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
}
}
@Override
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
this.fontRendererObj.drawString(this.getGuiDisplayName(GuiText.Terminal.getLocal()), 8, 6, 4210752);
this.fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752);
}
@Override
protected void mouseClicked(final int xCoord, final int yCoord, final int btn) {
final Enum<?> searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE);
final EntityPlayer player = Minecraft.getMinecraft().thePlayer;
ItemStack is = player.inventory.getItemStack();
if (searchMode != SearchBoxMode.AUTOSEARCH && searchMode != SearchBoxMode.NEI_AUTOSEARCH) {
this.searchField.mouseClicked(xCoord, yCoord, btn);
}
if (btn == 1 && this.searchField.isMouseIn(xCoord, yCoord)) {
setSearchString("", true);
}
super.mouseClicked(xCoord, yCoord, btn);
}
@@ -387,7 +319,7 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
})
.orElse(false);
return;
} catch (NoSuchFieldException | IllegalAccessException e) {
} catch (NoSuchFieldException | IllegalAccessException ignore) {
}
}
}
@@ -397,17 +329,11 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
@Override
protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int mouseButton) {
final EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if (mouseButton == 3) {
if (this instanceof GuiBaseFluidPatternTerminal
&& ((GuiBaseFluidPatternTerminal) this).container.isCraftingMode()) {
return;
}
if (slot instanceof OptionalSlotFake || slot instanceof SlotFakeCraftingMatrix) {
if (slot.getHasStack()) {
InventoryAction action = InventoryAction.valueOf("SET_PATTERN_VALUE");
InventoryAction action = InventoryAction.SET_PATTERN_VALUE;
IAEItemStack stack = AEItemStack.create(slot.getStack());
((AEBaseContainer) this.inventorySlots).setTargetStack(stack);
FluidCraft.proxy.netHandler.sendToServer(new CPacketInventoryAction(
action, Ae2ReflectClient.getInventorySlots(this).size(), 0, stack));
@@ -419,7 +345,6 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
if (slot instanceof SlotFake) {
InventoryAction action =
ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN;
if (Keyboard.isKeyDown(Keyboard.KEY_LMENU) || Keyboard.isKeyDown(Keyboard.KEY_RMENU)) {
if (action == InventoryAction.SPLIT_OR_PLACE_SINGLE) {
action = InventoryAction.MOVE_REGION;
@@ -427,14 +352,11 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
action = InventoryAction.PICKUP_SINGLE;
}
}
if (Ae2ReflectClient.getDragClick(this).size() > 1) {
return;
}
final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0);
NetworkHandler.instance.sendToServer(p);
return;
}
@@ -442,7 +364,6 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
if (mouseButton == 6) {
return; // prevent weird double clicks..
}
try {
NetworkHandler.instance.sendToServer(((SlotPatternTerm) slot).getRequest(isShiftKeyDown()));
} catch (final IOException e) {
@@ -452,7 +373,6 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
if (mouseButton == 6) {
return; // prevent weird double clicks..
}
InventoryAction action;
if (isShiftKeyDown()) {
action = InventoryAction.CRAFT_SHIFT;
@@ -460,10 +380,8 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
// Craft stack on right-click, craft single on left-click
action = (mouseButton == 1) ? InventoryAction.CRAFT_STACK : InventoryAction.CRAFT_ITEM;
}
final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0);
NetworkHandler.instance.sendToServer(p);
return;
}
@@ -473,13 +391,10 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
if (slot instanceof SlotME) {
stack = ((SlotME) slot).getAEStack();
}
int slotNum = Ae2ReflectClient.getInventorySlots(this).size();
if (!(slot instanceof SlotME) && slot != null) {
slotNum = slot.slotNumber;
}
((AEBaseContainer) this.inventorySlots).setTargetStack(stack);
final PacketInventoryAction p = new PacketInventoryAction(InventoryAction.MOVE_REGION, slotNum, 0);
NetworkHandler.instance.sendToServer(p);
@@ -491,9 +406,7 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
if (Ae2ReflectClient.getDragClick(this).size() > 1) {
return;
}
InventoryAction action = null;
switch (mouseButton) {
case 0: // pickup / set-down.
{
@@ -507,19 +420,15 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
case 1:
action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK;
break;
case 3: // creative dupe:
if (player.capabilities.isCreativeMode) {
action = InventoryAction.CREATIVE_DUPLICATE;
}
break;
default:
case 4: // drop item:
case 6:
}
if (action != null) {
final PacketInventoryAction p = new PacketInventoryAction(
action,
@@ -527,34 +436,30 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
((SlotDisconnected) slot).getSlot().getId());
NetworkHandler.instance.sendToServer(p);
}
return;
}
if (slot instanceof SlotME) {
InventoryAction action = null;
IAEItemStack stack = null;
switch (mouseButton) {
case 0: // pickup / set-down.
action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN;
stack = ((SlotME) slot).getAEStack();
if (stack != null
&& action == InventoryAction.PICKUP_OR_SET_DOWN
&& stack.getStackSize() == 0
&& player.inventory.getItemStack() == null) {
action = InventoryAction.AUTO_CRAFT;
}
break;
case 1:
action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK;
stack = ((SlotME) slot).getAEStack();
break;
case 3: // creative dupe:
stack = ((SlotME) slot).getAEStack();
stack = transformItem(stack); // for fluid terminal
if (stack != null && stack.isCraftable()) {
action = InventoryAction.AUTO_CRAFT;
} else if (player.capabilities.isCreativeMode) {
@@ -564,12 +469,10 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
}
}
break;
default:
case 4: // drop item:
case 6:
}
if (action == InventoryAction.AUTO_CRAFT) {
((AEBaseContainer) this.inventorySlots).setTargetStack(stack);
FluidCraft.proxy.netHandler.sendToServer(new CPacketInventoryAction(
@@ -587,6 +490,10 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton);
}
protected IAEItemStack transformItem(IAEItemStack stack) {
return stack;
}
@Override
public void onGuiClosed() {
super.onGuiClosed();
@@ -601,19 +508,15 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
@Override
public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
this.bindTextureBack(this.getBackground());
final int x_width = 195;
this.drawTexturedModalRect(offsetX, offsetY, 0, 0, x_width, 18);
if (this.viewCell) {
this.drawTexturedModalRect(offsetX + x_width, offsetY, x_width, 0, 46, 128);
}
for (int x = 0; x < this.rows; x++) {
this.drawTexturedModalRect(offsetX, offsetY + 18 + x * 18, 0, 18, x_width, 18);
}
this.drawTexturedModalRect(
offsetX,
offsetY + 16 + this.rows * 18 + this.lowerTextureOffset,
@@ -621,10 +524,8 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
106 - 18 - 18,
x_width,
99 + this.reservedSpace - this.lowerTextureOffset);
if (this.viewCell) {
boolean update = false;
for (int i = 0; i < 5; i++) {
if (this.myCurrentViewCells[i]
!= this.monitorableContainer.getCellViewSlot(i).getStack()) {
@@ -633,12 +534,10 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
this.monitorableContainer.getCellViewSlot(i).getStack();
}
}
if (update) {
this.repo.setViewCell(this.myCurrentViewCells);
}
}
if (this.searchField != null) {
this.searchField.drawTextBox();
}
@@ -653,7 +552,7 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
return this.repo.hasPower();
}
int getMaxRows() {
protected int getMaxRows() {
return AEConfig.instance.getConfigManager().getSetting(Settings.TERMINAL_STYLE) == TerminalStyle.SMALL
? 6
: Integer.MAX_VALUE;
@@ -754,27 +653,25 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
}
public boolean hideItemPanelSlot(int tx, int ty, int tw, int th) {
if (this.viewCell) {
int rw = 33;
int rh = 14 + myCurrentViewCells.length * 18;
if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) {
if (tw <= 0 || th <= 0) {
return false;
}
int rx = this.guiLeft + this.xSize;
int ry = this.guiTop + 0;
int ry = this.guiTop;
rw += rx;
rh += ry;
tw += tx;
th += ty;
// overflow || intersect
// overflow || intersect
return (rw < rx || rw > tx) && (rh < ry || rh > ty) && (tw < tx || tw > rx) && (th < ty || th > ry);
}
return false;
}
@@ -782,9 +679,4 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
public boolean isOverTextField(int mousex, int mousey) {
return searchField.isMouseIn(mousex, mousey);
}
@Override
public void setTextFieldValue(String displayName, int mousex, int mousey, ItemStack stack) {
setSearchString(displayName, true);
}
}
@@ -1,7 +1,7 @@
package com.glodblock.github.client.gui.container;
import appeng.api.AEApi;
import appeng.api.config.*;
import appeng.api.config.Actionable;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.implementations.tiles.IMEChest;
import appeng.api.implementations.tiles.IViewCellStorage;
@@ -12,95 +12,53 @@ import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.parts.IPart;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotPlayerHotBar;
import appeng.container.slot.SlotPlayerInv;
import appeng.container.slot.SlotRestrictedInput;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.me.helpers.ChannelPowerSrc;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import appeng.util.item.AEFluidStack;
import appeng.util.item.AEItemStack;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.base.FCContainerMonitor;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.network.CPacketFluidUpdate;
import com.glodblock.github.network.SPacketFluidUpdate;
import com.glodblock.github.network.SPacketMEInventoryUpdate;
import com.glodblock.github.util.Util;
import java.io.IOException;
import java.nio.BufferOverflowException;
import java.util.HashMap;
import java.util.Map;
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.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.IFluidContainerItem;
import org.apache.commons.lang3.tuple.MutablePair;
public class FCBaseFluidMonitorContain extends AEBaseContainer
implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEFluidStack> {
private final SlotRestrictedInput[] cellView = new SlotRestrictedInput[5];
private final IMEMonitor<IAEFluidStack> monitor;
import java.nio.BufferOverflowException;
import java.util.HashMap;
import java.util.Map;
public class ContainerFluidMonitor extends FCContainerMonitor<IAEFluidStack> {
private final IItemList<IAEFluidStack> items = AEApi.instance().storage().createFluidList();
private final IConfigManager clientCM;
private final ITerminalHost host;
@GuiSync(99)
public boolean canAccessViewCells = false;
@GuiSync(98)
public boolean hasPower = false;
private IConfigManagerHost gui;
private IConfigManager serverCM;
private IGridNode networkNode;
public FCBaseFluidMonitorContain(final InventoryPlayer ip, final ITerminalHost monitorable) {
public ContainerFluidMonitor(final InventoryPlayer ip, final ITerminalHost monitorable) {
this(ip, monitorable, true);
}
protected FCBaseFluidMonitorContain(
protected ContainerFluidMonitor(
final InventoryPlayer ip, final ITerminalHost monitorable, final boolean bindInventory) {
super(
ip,
monitorable instanceof TileEntity ? (TileEntity) monitorable : null,
monitorable instanceof IPart ? (IPart) monitorable : null);
this.host = monitorable;
this.clientCM = new ConfigManager(this);
this.clientCM.registerSetting(Settings.SORT_BY, SortOrder.NAME);
this.clientCM.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
this.clientCM.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
super(ip, monitorable, bindInventory);
if (Platform.isServer()) {
this.serverCM = monitorable.getConfigManager();
this.monitor = monitorable.getFluidInventory();
if (this.monitor != null) {
this.monitor.addListener(this, null);
// this.setCellInventory( this.monitor );
if (monitorable instanceof IPortableCell) {
this.setPowerSource((IEnergySource) monitorable);
} else if (monitorable instanceof IMEChest) {
@@ -142,10 +100,6 @@ public class FCBaseFluidMonitorContain extends AEBaseContainer
}
}
public IGridNode getNetworkNode() {
return this.networkNode;
}
@Override
public ItemStack transferStackInSlot(final EntityPlayer p, final int idx) {
if (Platform.isClient()) {
@@ -164,106 +118,40 @@ public class FCBaseFluidMonitorContain extends AEBaseContainer
}
@Override
public void detectAndSendChanges() {
if (Platform.isServer()) {
if (this.monitor != this.host.getFluidInventory()) {
this.setValidContainer(false);
}
protected void processItemList() {
if (!this.items.isEmpty()) {
final IItemList<IAEFluidStack> monitorCache = this.monitor.getStorageList();
final SPacketMEInventoryUpdate piu = new SPacketMEInventoryUpdate(true);
for (final Settings set : this.serverCM.getSettings()) {
final Enum<?> sideLocal = this.serverCM.getSetting(set);
final Enum<?> sideRemote = this.clientCM.getSetting(set);
if (sideLocal != sideRemote) {
this.clientCM.putSetting(set, sideLocal);
for (final Object crafter : this.crafters) {
try {
NetworkHandler.instance.sendTo(
new PacketValueConfig(set.name(), sideLocal.name()), (EntityPlayerMP) crafter);
} catch (final IOException e) {
AELog.debug(e);
}
}
for (final IAEFluidStack is : this.items) {
final IAEFluidStack send = monitorCache.findPrecise(is);
if (send == null) {
is.setStackSize(0);
piu.appendFluid(is);
} else {
piu.appendFluid(send);
}
}
if (!this.items.isEmpty()) {
final IItemList<IAEFluidStack> monitorCache = this.monitor.getStorageList();
if (!piu.isEmpty()) {
this.items.resetStatus();
final SPacketMEInventoryUpdate piu = new SPacketMEInventoryUpdate(true);
for (final IAEFluidStack is : this.items) {
final IAEFluidStack send = monitorCache.findPrecise(is);
if (send == null) {
is.setStackSize(0);
piu.appendFluid(is);
} else {
piu.appendFluid(send);
}
}
if (!piu.isEmpty()) {
this.items.resetStatus();
for (final Object c : this.crafters) {
if (c instanceof EntityPlayer) {
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
}
for (final Object c : this.crafters) {
if (c instanceof EntityPlayer) {
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
}
}
}
this.updatePowerStatus();
final boolean oldAccessible = this.canAccessViewCells;
this.canAccessViewCells =
this.host instanceof WirelessTerminalGuiObject || this.hasAccess(SecurityPermissions.BUILD, false);
if (this.canAccessViewCells != oldAccessible) {
for (int y = 0; y < 5; y++) {
if (this.cellView[y] != null) {
this.cellView[y].setAllowEdit(this.canAccessViewCells);
}
}
}
super.detectAndSendChanges();
}
}
protected void updatePowerStatus() {
try {
if (this.networkNode != null) {
this.setPowered(this.networkNode.isActive());
} else if (this.getPowerSource() instanceof IEnergyGrid) {
this.setPowered(((IEnergyGrid) this.getPowerSource()).isNetworkPowered());
} else {
this.setPowered(
this.getPowerSource().extractAEPower(1, Actionable.SIMULATE, PowerMultiplier.CONFIG) > 0.8);
}
} catch (final Throwable t) {
// :P
}
}
@Override
public void onUpdate(final String field, final Object oldValue, final Object newValue) {
if (field.equals("canAccessViewCells")) {
for (int y = 0; y < 5; y++) {
if (this.cellView[y] != null) {
this.cellView[y].setAllowEdit(this.canAccessViewCells);
}
}
}
super.onUpdate(field, oldValue, newValue);
protected boolean isInvalid() {
return this.monitor != this.host.getFluidInventory();
}
@Override
public void addCraftingToCrafters(final ICrafting c) {
super.addCraftingToCrafters(c);
this.queueInventory(c);
}
private void queueInventory(final ICrafting c) {
protected void queueInventory(final ICrafting c) {
if (Platform.isServer() && c instanceof EntityPlayer && this.monitor != null) {
SPacketMEInventoryUpdate piu = new SPacketMEInventoryUpdate(true);
final IItemList<IAEFluidStack> monitorCache = this.monitor.getStorageList();
@@ -273,7 +161,6 @@ public class FCBaseFluidMonitorContain extends AEBaseContainer
piu.appendFluid(send);
} catch (final BufferOverflowException boe) {
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
piu = new SPacketMEInventoryUpdate(true);
piu.appendFluid(send);
}
@@ -282,57 +169,6 @@ public class FCBaseFluidMonitorContain extends AEBaseContainer
}
}
@Override
public void onContainerClosed(final EntityPlayer player) {
super.onContainerClosed(player);
if (this.monitor != null) {
this.monitor.removeListener(this);
}
}
@Override
public IConfigManager getConfigManager() {
if (Platform.isServer()) {
return this.serverCM;
}
return this.clientCM;
}
public ItemStack[] getViewCells() {
final ItemStack[] list = new ItemStack[this.cellView.length];
for (int x = 0; x < this.cellView.length; x++) {
list[x] = this.cellView[x].getStack();
}
return list;
}
public SlotRestrictedInput getCellViewSlot(final int index) {
return this.cellView[index];
}
public boolean isPowered() {
return this.hasPower;
}
private void setPowered(final boolean isPowered) {
this.hasPower = isPowered;
}
private IConfigManagerHost getGui() {
return this.gui;
}
public void setGui(@Nonnull final IConfigManagerHost gui) {
this.gui = gui;
}
@Override
public boolean isValid(Object verificationToken) {
return true;
}
@Override
public void postChange(
IBaseMonitor<IAEFluidStack> monitor, Iterable<IAEFluidStack> change, BaseActionSource actionSource) {
@@ -376,7 +212,7 @@ public class FCBaseFluidMonitorContain extends AEBaseContainer
ItemStack out = fluidContainer.copy();
out.stackSize = 1;
if (Util.FluidUtil.isEmpty(fluidContainer) && fluid != null) {
// add fluid to tanks
// add fluid to tanks
if (nfluid.getStackSize() <= 0) continue;
final IAEFluidStack toExtract = nfluid.copy();
MutablePair<Integer, ItemStack> fillStack = Util.FluidUtil.fillStack(out, toExtract.getFluidStack());
@@ -403,7 +239,7 @@ public class FCBaseFluidMonitorContain extends AEBaseContainer
this.host.getFluidInventory().extractItems(toExtract, Actionable.MODULATE, this.getActionSource());
}
} else if (!Util.FluidUtil.isEmpty(fluidContainer)) {
// add fluid to ae network
// add fluid to ae network
AEFluidStack fluidStack = Util.getAEFluidFromItem(fluidContainer);
final IAEFluidStack aeFluidStack = fluidStack.copy();
// simulate result is incorrect. so I'm using other solution and ec2 both mod have same issues
@@ -475,20 +311,4 @@ public class FCBaseFluidMonitorContain extends AEBaseContainer
this.detectAndSendChanges();
}
@Override
public void onListUpdate() {
for (final Object c : this.crafters) {
if (c instanceof ICrafting) {
final ICrafting cr = (ICrafting) c;
this.queueInventory(cr);
}
}
}
@Override
public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) {
if (this.getGui() != null) {
this.getGui().updateSetting(manager, settingName, newValue);
}
}
}
@@ -1,10 +0,0 @@
package com.glodblock.github.client.gui.container;
import appeng.api.storage.ITerminalHost;
import net.minecraft.entity.player.InventoryPlayer;
public class ContainerFluidTerminal extends FCBaseFluidMonitorContain {
public ContainerFluidTerminal(InventoryPlayer ip, ITerminalHost monitorable) {
super(ip, monitorable);
}
}
@@ -0,0 +1,151 @@
package com.glodblock.github.client.gui.container;
import appeng.api.AEApi;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.implementations.tiles.IMEChest;
import appeng.api.implementations.tiles.IViewCellStorage;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.slot.SlotRestrictedInput;
import appeng.me.helpers.ChannelPowerSrc;
import appeng.util.Platform;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.base.FCContainerMonitor;
import com.glodblock.github.network.SPacketMEInventoryUpdate;
import java.nio.BufferOverflowException;
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.minecraftforge.common.util.ForgeDirection;
public class ContainerItemMonitor extends FCContainerMonitor<IAEItemStack> {
private final IItemList<IAEItemStack> items = AEApi.instance().storage().createItemList();
public ContainerItemMonitor(final InventoryPlayer ip, final ITerminalHost monitorable) {
this(ip, monitorable, true);
}
protected ContainerItemMonitor(
final InventoryPlayer ip, final ITerminalHost monitorable, final boolean bindInventory) {
super(ip, monitorable, bindInventory);
if (Platform.isServer()) {
this.serverCM = monitorable.getConfigManager();
this.monitor = monitorable.getItemInventory();
if (this.monitor != null) {
this.monitor.addListener(this, null);
this.setCellInventory(this.monitor);
if (monitorable instanceof IPortableCell) {
this.setPowerSource((IEnergySource) monitorable);
} else if (monitorable instanceof IMEChest) {
this.setPowerSource((IEnergySource) monitorable);
} else if (monitorable instanceof IGridHost) {
final IGridNode node = ((IGridHost) monitorable).getGridNode(ForgeDirection.UNKNOWN);
if (node != null) {
this.networkNode = node;
final IGrid g = node.getGrid();
if (g != null) {
this.setPowerSource(new ChannelPowerSrc(this.networkNode, g.getCache(IEnergyGrid.class)));
}
}
}
} else {
this.setValidContainer(false);
}
} else {
this.monitor = null;
}
this.canAccessViewCells = false;
if (monitorable instanceof IViewCellStorage) {
for (int y = 0; y < 5; y++) {
this.cellView[y] = new SlotRestrictedInput(
SlotRestrictedInput.PlacableItemType.VIEW_CELL,
((IViewCellStorage) monitorable).getViewCellStorage(),
y,
206,
y * 18 + 8,
this.getInventoryPlayer());
this.cellView[y].setAllowEdit(this.canAccessViewCells);
this.addSlotToContainer(this.cellView[y]);
}
}
if (bindInventory) {
this.bindPlayerInventory(ip, 0, 0);
}
}
@Override
protected void processItemList() {
if (!this.items.isEmpty()) {
final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();
final SPacketMEInventoryUpdate piu = new SPacketMEInventoryUpdate();
for (final IAEItemStack is : this.items) {
final IAEItemStack send = monitorCache.findPrecise(is);
if (send == null) {
is.setStackSize(0);
piu.appendItem(is);
} else {
piu.appendItem(send);
}
}
if (!piu.isEmpty()) {
this.items.resetStatus();
for (final Object c : this.crafters) {
if (c instanceof EntityPlayer) {
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
}
}
}
}
}
@Override
protected void queueInventory(final ICrafting c) {
if (Platform.isServer() && c instanceof EntityPlayer && this.monitor != null) {
SPacketMEInventoryUpdate piu = new SPacketMEInventoryUpdate();
final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();
for (final IAEItemStack send : monitorCache) {
try {
piu.appendItem(send);
} catch (final BufferOverflowException boe) {
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
piu = new SPacketMEInventoryUpdate();
piu.appendItem(send);
}
}
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
}
}
@Override
public void removeCraftingFromCrafters(final ICrafting c) {
super.removeCraftingFromCrafters(c);
if (this.crafters.isEmpty() && this.monitor != null) {
this.monitor.removeListener(this);
}
}
@Override
public void postChange(
final IBaseMonitor<IAEItemStack> monitor,
final Iterable<IAEItemStack> change,
final BaseActionSource source) {
for (final IAEItemStack is : change) {
this.items.add(is);
}
}
}
@@ -43,7 +43,7 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
public class FCBasePartContainer extends FCBaseMonitorContain
public class FCBasePartContainer extends ContainerItemMonitor
implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket {
private final PartFluidPatternTerminal patternTerminal;
@@ -32,7 +32,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.fluids.FluidStack;
public class FCBasePartContainerEx extends FCBaseMonitorContain
public class FCBasePartContainerEx extends ContainerItemMonitor
implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket {
private static final int CRAFTING_GRID_PAGES = 2;
@@ -1,23 +1,13 @@
package com.glodblock.github.client.gui.container;
package com.glodblock.github.client.gui.container.base;
import appeng.api.AEApi;
import appeng.api.config.*;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.implementations.tiles.IMEChest;
import appeng.api.implementations.tiles.IViewCellStorage;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.parts.IPart;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.api.storage.data.IAEStack;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.container.AEBaseContainer;
@@ -27,14 +17,10 @@ import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.me.helpers.ChannelPowerSrc;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.network.SPacketMEInventoryUpdate;
import java.io.IOException;
import java.nio.BufferOverflowException;
import javax.annotation.Nonnull;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
@@ -42,94 +28,39 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class FCBaseMonitorContain extends AEBaseContainer
implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEItemStack> {
private final SlotRestrictedInput[] cellView = new SlotRestrictedInput[5];
private final IMEMonitor<IAEItemStack> monitor;
private final IItemList<IAEItemStack> items = AEApi.instance().storage().createItemList();
private final IConfigManager clientCM;
private final ITerminalHost host;
public abstract class FCContainerMonitor<T extends IAEStack<T>> extends AEBaseContainer
implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<T> {
protected final SlotRestrictedInput[] cellView = new SlotRestrictedInput[5];
protected final IConfigManager clientCM;
protected final ITerminalHost host;
@GuiSync(99)
public boolean canAccessViewCells = false;
@GuiSync(98)
public boolean hasPower = false;
private IConfigManagerHost gui;
private IConfigManager serverCM;
private IGridNode networkNode;
protected IConfigManagerHost gui;
protected IConfigManager serverCM;
protected IGridNode networkNode;
protected IMEMonitor<T> monitor;
public FCBaseMonitorContain(final InventoryPlayer ip, final ITerminalHost monitorable) {
public FCContainerMonitor(final InventoryPlayer ip, final ITerminalHost monitorable) {
this(ip, monitorable, true);
}
protected FCBaseMonitorContain(
protected FCContainerMonitor(
final InventoryPlayer ip, final ITerminalHost monitorable, final boolean bindInventory) {
super(
ip,
monitorable instanceof TileEntity ? (TileEntity) monitorable : null,
monitorable instanceof IPart ? (IPart) monitorable : null);
this.host = monitorable;
this.clientCM = new ConfigManager(this);
this.clientCM.registerSetting(Settings.SORT_BY, SortOrder.NAME);
this.clientCM.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
this.clientCM.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
if (Platform.isServer()) {
this.serverCM = monitorable.getConfigManager();
this.monitor = monitorable.getItemInventory();
if (this.monitor != null) {
this.monitor.addListener(this, null);
this.setCellInventory(this.monitor);
if (monitorable instanceof IPortableCell) {
this.setPowerSource((IEnergySource) monitorable);
} else if (monitorable instanceof IMEChest) {
this.setPowerSource((IEnergySource) monitorable);
} else if (monitorable instanceof IGridHost) {
final IGridNode node = ((IGridHost) monitorable).getGridNode(ForgeDirection.UNKNOWN);
if (node != null) {
this.networkNode = node;
final IGrid g = node.getGrid();
if (g != null) {
this.setPowerSource(new ChannelPowerSrc(
this.networkNode, (IEnergySource) g.getCache(IEnergyGrid.class)));
}
}
}
} else {
this.setValidContainer(false);
}
} else {
this.monitor = null;
}
this.canAccessViewCells = false;
if (monitorable instanceof IViewCellStorage) {
for (int y = 0; y < 5; y++) {
this.cellView[y] = new SlotRestrictedInput(
SlotRestrictedInput.PlacableItemType.VIEW_CELL,
((IViewCellStorage) monitorable).getViewCellStorage(),
y,
206,
y * 18 + 8,
this.getInventoryPlayer());
this.cellView[y].setAllowEdit(this.canAccessViewCells);
this.addSlotToContainer(this.cellView[y]);
}
}
if (bindInventory) {
this.bindPlayerInventory(ip, 0, 0);
}
}
public IGridNode getNetworkNode() {
@@ -139,10 +70,9 @@ public class FCBaseMonitorContain extends AEBaseContainer
@Override
public void detectAndSendChanges() {
if (Platform.isServer()) {
if (this.monitor != this.host.getItemInventory()) {
if (isInvalid()) {
this.setValidContainer(false);
}
for (final Settings set : this.serverCM.getSettings()) {
final Enum<?> sideLocal = this.serverCM.getSetting(set);
final Enum<?> sideRemote = this.clientCM.getSetting(set);
@@ -159,35 +89,8 @@ public class FCBaseMonitorContain extends AEBaseContainer
}
}
}
if (!this.items.isEmpty()) {
final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();
final SPacketMEInventoryUpdate piu = new SPacketMEInventoryUpdate();
for (final IAEItemStack is : this.items) {
final IAEItemStack send = monitorCache.findPrecise(is);
if (send == null) {
is.setStackSize(0);
piu.appendItem(is);
} else {
piu.appendItem(send);
}
}
if (!piu.isEmpty()) {
this.items.resetStatus();
for (final Object c : this.crafters) {
if (c instanceof EntityPlayer) {
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
}
}
}
}
processItemList();
this.updatePowerStatus();
final boolean oldAccessible = this.canAccessViewCells;
this.canAccessViewCells =
this.host instanceof WirelessTerminalGuiObject || this.hasAccess(SecurityPermissions.BUILD, false);
@@ -198,11 +101,16 @@ public class FCBaseMonitorContain extends AEBaseContainer
}
}
}
super.detectAndSendChanges();
}
}
protected abstract void processItemList();
protected boolean isInvalid() {
return this.monitor != this.host.getItemInventory();
}
protected void updatePowerStatus() {
try {
if (this.networkNode != null) {
@@ -213,8 +121,7 @@ public class FCBaseMonitorContain extends AEBaseContainer
this.setPowered(
this.getPowerSource().extractAEPower(1, Actionable.SIMULATE, PowerMultiplier.CONFIG) > 0.8);
}
} catch (final Throwable t) {
// :P
} catch (final Throwable ignore) {
}
}
@@ -227,7 +134,6 @@ public class FCBaseMonitorContain extends AEBaseContainer
}
}
}
super.onUpdate(field, oldValue, newValue);
}
@@ -237,33 +143,7 @@ public class FCBaseMonitorContain extends AEBaseContainer
this.queueInventory(c);
}
private void queueInventory(final ICrafting c) {
if (Platform.isServer() && c instanceof EntityPlayer && this.monitor != null) {
SPacketMEInventoryUpdate piu = new SPacketMEInventoryUpdate();
final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();
for (final IAEItemStack send : monitorCache) {
try {
piu.appendItem(send);
} catch (final BufferOverflowException boe) {
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
piu = new SPacketMEInventoryUpdate();
piu.appendItem(send);
}
}
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
}
}
@Override
public void removeCraftingFromCrafters(final ICrafting c) {
super.removeCraftingFromCrafters(c);
if (this.crafters.isEmpty() && this.monitor != null) {
this.monitor.removeListener(this);
}
}
protected abstract void queueInventory(final ICrafting c);
@Override
public void onContainerClosed(final EntityPlayer player) {
@@ -274,18 +154,44 @@ public class FCBaseMonitorContain extends AEBaseContainer
}
@Override
public boolean isValid(final Object verificationToken) {
return true;
public IConfigManager getConfigManager() {
if (Platform.isServer()) {
return this.serverCM;
}
return this.clientCM;
}
public ItemStack[] getViewCells() {
final ItemStack[] list = new ItemStack[this.cellView.length];
for (int x = 0; x < this.cellView.length; x++) {
list[x] = this.cellView[x].getStack();
}
return list;
}
public SlotRestrictedInput getCellViewSlot(final int index) {
return this.cellView[index];
}
public boolean isPowered() {
return this.hasPower;
}
protected void setPowered(final boolean isPowered) {
this.hasPower = isPowered;
}
protected IConfigManagerHost getGui() {
return this.gui;
}
public void setGui(@Nonnull final IConfigManagerHost gui) {
this.gui = gui;
}
@Override
public void postChange(
final IBaseMonitor<IAEItemStack> monitor,
final Iterable<IAEItemStack> change,
final BaseActionSource source) {
for (final IAEItemStack is : change) {
this.items.add(is);
}
public boolean isValid(Object verificationToken) {
return true;
}
@Override
@@ -304,42 +210,4 @@ public class FCBaseMonitorContain extends AEBaseContainer
this.getGui().updateSetting(manager, settingName, newValue);
}
}
@Override
public IConfigManager getConfigManager() {
if (Platform.isServer()) {
return this.serverCM;
}
return this.clientCM;
}
public ItemStack[] getViewCells() {
final ItemStack[] list = new ItemStack[this.cellView.length];
for (int x = 0; x < this.cellView.length; x++) {
list[x] = this.cellView[x].getStack();
}
return list;
}
public SlotRestrictedInput getCellViewSlot(final int index) {
return this.cellView[index];
}
public boolean isPowered() {
return this.hasPower;
}
private void setPowered(final boolean isPowered) {
this.hasPower = isPowered;
}
private IConfigManagerHost getGui() {
return this.gui;
}
public void setGui(@Nonnull final IConfigManagerHost gui) {
this.gui = gui;
}
}
@@ -189,7 +189,7 @@ public enum GuiType {
FLUID_TERMINAL(new PartGuiFactory<ITerminalHost>(ITerminalHost.class) {
@Override
protected Object createServerGui(EntityPlayer player, ITerminalHost inv) {
return new ContainerFluidTerminal(player.inventory, inv);
return new ContainerFluidMonitor(player.inventory, inv);
}
@Override
@@ -1,18 +1,18 @@
package com.glodblock.github.nei;
import codechicken.nei.api.INEIGuiAdapter;
import com.glodblock.github.client.gui.GuiFCBaseFluidMonitor;
import com.glodblock.github.client.gui.GuiFCBaseMonitor;
import com.glodblock.github.client.gui.GuiFluidMonitor;
import com.glodblock.github.client.gui.GuiItemMonitor;
import net.minecraft.client.gui.inventory.GuiContainer;
public class NEIGuiHandler extends INEIGuiAdapter {
@Override
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
if (gui instanceof GuiFCBaseMonitor) {
return ((GuiFCBaseMonitor) gui).hideItemPanelSlot(x, y, w, h);
} else if (gui instanceof GuiFCBaseFluidMonitor) {
return ((GuiFCBaseFluidMonitor) gui).hideItemPanelSlot(x, y, w, h);
if (gui instanceof GuiItemMonitor) {
return ((GuiItemMonitor) gui).hideItemPanelSlot(x, y, w, h);
} else if (gui instanceof GuiFluidMonitor) {
return ((GuiFluidMonitor) gui).hideItemPanelSlot(x, y, w, h);
}
return false;
}
@@ -3,7 +3,7 @@ package com.glodblock.github.network;
import appeng.api.storage.data.IAEFluidStack;
import appeng.util.item.AEFluidStack;
import appeng.util.item.AEItemStack;
import com.glodblock.github.client.gui.container.FCBaseFluidMonitorContain;
import com.glodblock.github.client.gui.container.ContainerFluidMonitor;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
@@ -94,11 +94,11 @@ public class CPacketFluidUpdate implements IMessage {
public IMessage onMessage(CPacketFluidUpdate message, MessageContext ctx) {
Container container = ctx.getServerHandler().playerEntity.openContainer;
EntityPlayer player = ctx.getServerHandler().playerEntity;
if (container instanceof FCBaseFluidMonitorContain) {
if (container instanceof ContainerFluidMonitor) {
ItemStack item = player.inventory.getItemStack();
((FCBaseFluidMonitorContain) container)
((ContainerFluidMonitor) container)
.postChange(
new ArrayList<IAEFluidStack>(message.list.values()),
new ArrayList<>(message.list.values()),
message.itemStack == null ? item : message.itemStack,
player,
message.slotIndex);
@@ -109,7 +109,7 @@ public class CPacketInventoryAction implements IMessage {
cca.detectAndSendChanges();
}
}
} else if (message.action == InventoryAction.valueOf("SET_PATTERN_VALUE")) {
} else if (message.action == InventoryAction.SET_PATTERN_VALUE) {
final ContainerOpenContext context = baseContainer.getOpenContext();
if (context != null) {
final TileEntity te = context.getTile();
@@ -4,9 +4,9 @@ import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.util.item.AEFluidStack;
import appeng.util.item.AEItemStack;
import com.glodblock.github.client.gui.GuiFCBaseFluidMonitor;
import com.glodblock.github.client.gui.GuiFCBaseMonitor;
import com.glodblock.github.client.gui.GuiFluidCraftConfirm;
import com.glodblock.github.client.gui.GuiFluidMonitor;
import com.glodblock.github.client.gui.GuiItemMonitor;
import com.glodblock.github.client.gui.GuiLevelMaintainer;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
@@ -96,10 +96,10 @@ public class SPacketMEInventoryUpdate implements IMessage {
@Override
public IMessage onMessage(SPacketMEInventoryUpdate message, MessageContext ctx) {
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
if (gs instanceof GuiFCBaseFluidMonitor) {
((GuiFCBaseFluidMonitor) gs).postUpdate((List<IAEFluidStack>) (List<?>) message.list);
} else if (gs instanceof GuiFCBaseMonitor) {
((GuiFCBaseMonitor) gs).postUpdate((List<IAEItemStack>) (List<?>) message.list);
if (gs instanceof GuiFluidMonitor) {
((GuiFluidMonitor) gs).postUpdate((List<IAEFluidStack>) (List<?>) message.list);
} else if (gs instanceof GuiItemMonitor) {
((GuiItemMonitor) gs).postUpdate((List<IAEItemStack>) (List<?>) message.list);
} else if (gs instanceof GuiFluidCraftConfirm) {
((GuiFluidCraftConfirm) gs).postUpdate((List<IAEItemStack>) (List<?>) message.list, message.ref);
} else if (gs instanceof GuiLevelMaintainer) {