add wireless interface terminal

This commit is contained in:
asdflj committed 2023-02-08 12:07:15 +08:00
1 parent c2ccede395
commit d2c420d193
20 files changed
+1554 -55

No files matched your search

@@ -54,6 +54,7 @@ public class GuiFCImgButton extends GuiButton implements ITooltip {
this.registerApp(11, "CRAFT_TEM", "YES", "craft_terminal_w");
this.registerApp(12, "PATTERN_TEM", "YES", "pattern_terminal_w");
this.registerApp(13, "ESSENTIA_TEM", "YES", "essentia_terminal_w");
this.registerApp(14, "INTERFACE_TEM", "YES", "interface_terminal_w");
}
}
@@ -0,0 +1,716 @@
package com.glodblock.github.client.gui;
import java.util.*;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.world.World;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import appeng.api.AEApi;
import appeng.api.config.ActionItems;
import appeng.api.config.Settings;
import appeng.api.config.TerminalStyle;
import appeng.api.config.YesNo;
import appeng.api.util.DimensionalCoord;
import appeng.api.util.WorldCoord;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiScrollbar;
import appeng.client.gui.widgets.IDropToFillTextField;
import appeng.client.gui.widgets.MEGuiTextField;
import appeng.client.me.ClientDCInternalInv;
import appeng.client.me.SlotDisconnected;
import appeng.client.render.BlockPosHighlighter;
import appeng.container.slot.AppEngSlot;
import appeng.core.AEConfig;
import appeng.core.CommonHelper;
import appeng.core.localization.ButtonToolTips;
import appeng.core.localization.GuiColors;
import appeng.core.localization.GuiText;
import appeng.core.localization.PlayerMessages;
import appeng.helpers.PatternHelper;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.util.Platform;
import com.glodblock.github.client.gui.base.FCBaseMEGui;
import com.glodblock.github.client.gui.container.ContainerInterfaceWireless;
import com.glodblock.github.inventory.item.IWirelessTerminal;
import com.glodblock.github.util.ModAndClassUtil;
import com.google.common.collect.HashMultimap;
public class GuiInterfaceTerminalWireless extends FCBaseMEGui implements IDropToFillTextField {
protected int offsetY;
private static final int MAGIC_HEIGHT_NUMBER = 52 + 99;
private static final int offsetX = 21;
private final HashMap<Long, ClientDCInternalInv> byId = new HashMap<>();
private final HashMultimap<String, ClientDCInternalInv> byName = HashMultimap.create();
private final HashMap<ClientDCInternalInv, DimensionalCoord> blockPosHashMap = new HashMap<>();
private final HashMap<GuiButton, ClientDCInternalInv> guiButtonHashMap = new HashMap<>();
private final ArrayList<String> names = new ArrayList<>();
private final ArrayList<Object> lines = new ArrayList<>();
private final Set<Object> matchedStacks = new HashSet<>();
private final Map<String, Set<Object>> cachedSearches = new WeakHashMap<>();
protected static String searchFieldOutputsText = "";
protected static String searchFieldInputsText = "";
protected static String searchFieldNamesText = "";
private final MEGuiTextField searchFieldOutputs;
private final MEGuiTextField searchFieldInputs;
private final MEGuiTextField searchFieldNames;
private final GuiImgButton guiButtonHideFull;
private final GuiImgButton guiButtonAssemblersOnly;
private final GuiImgButton guiButtonBrokenRecipes;
private GuiImgButton searchStringSave;
private GuiImgButton terminalStyleBox;
private boolean refreshList = false;
protected static boolean onlyMolecularAssemblers = false;
protected static boolean onlyBrokenRecipes = false;
// private final IConfigManager configSrc;
private int rows = 3;
private static final String MOLECULAR_ASSEMBLER = "tile.appliedenergistics2.BlockMolecularAssembler";
public GuiInterfaceTerminalWireless(final InventoryPlayer inventoryPlayer, final IWirelessTerminal te) {
super(inventoryPlayer, new ContainerInterfaceWireless(inventoryPlayer, te));
this.setScrollBar(new GuiScrollbar());
this.xSize = 208;
this.ySize = 255;
searchFieldInputs = new MEGuiTextField(86, 12, ButtonToolTips.SearchFieldInputs.getLocal()) {
@Override
public void onTextChange(final String oldText) {
refreshList();
}
};
searchFieldOutputs = new MEGuiTextField(86, 12, ButtonToolTips.SearchFieldOutputs.getLocal()) {
@Override
public void onTextChange(final String oldText) {
refreshList();
}
};
searchFieldNames = new MEGuiTextField(71, 12, ButtonToolTips.SearchFieldNames.getLocal()) {
@Override
public void onTextChange(final String oldText) {
refreshList();
}
};
searchFieldNames.setFocused(true);
guiButtonAssemblersOnly = new GuiImgButton(0, 0, Settings.ACTIONS, null);
guiButtonHideFull = new GuiImgButton(0, 0, Settings.ACTIONS, null);
guiButtonBrokenRecipes = new GuiImgButton(0, 0, Settings.ACTIONS, null);
}
@Override
public int getOffsetY() {
return this.offsetY;
}
@Override
public void setOffsetY(int y) {
this.offsetY = y;
}
private void setScrollBar() {
this.getScrollBar().setTop(52).setLeft(189).setHeight(this.rows * 18 - 2);
this.getScrollBar().setRange(0, this.lines.size() - this.rows, 2);
}
@Override
public void initGui() {
super.initGui();
this.rows = calculateRowsCount();
this.ySize = MAGIC_HEIGHT_NUMBER + this.rows * 18;
final int unusedSpace = this.height - this.ySize;
this.guiTop = (int) Math.floor(unusedSpace / (unusedSpace < 0 ? 3.8f : 2.0f));
this.offsetY = this.guiTop + 8;
this.buttonList.add(
this.terminalStyleBox = new GuiImgButton(
this.guiLeft - 18,
this.offsetY,
Settings.TERMINAL_STYLE,
AEConfig.instance.settings.getSetting(Settings.TERMINAL_STYLE)));
this.offsetY += 20;
this.buttonList.add(
this.searchStringSave = new GuiImgButton(
this.guiLeft - 18,
this.offsetY,
Settings.SAVE_SEARCH,
AEConfig.instance.settings.getSetting(Settings.SAVE_SEARCH)));
this.offsetY += 20;
searchFieldInputs.x = guiLeft + Math.max(32, offsetX);
searchFieldInputs.y = guiTop + 25;
searchFieldOutputs.x = guiLeft + Math.max(32, offsetX);
searchFieldOutputs.y = guiTop + 38;
searchFieldNames.x = guiLeft + Math.max(32, offsetX) + 99;
searchFieldNames.y = guiTop + 38;
guiButtonAssemblersOnly.xPosition = guiLeft + Math.max(32, offsetX) + 99;
guiButtonAssemblersOnly.yPosition = guiTop + 20;
guiButtonHideFull.xPosition = guiButtonAssemblersOnly.xPosition + 18;
guiButtonHideFull.yPosition = guiTop + 20;
guiButtonBrokenRecipes.xPosition = guiButtonHideFull.xPosition + 18;
guiButtonBrokenRecipes.yPosition = guiTop + 20;
terminalStyleBox.xPosition = guiLeft - 18;
terminalStyleBox.yPosition = guiTop + 8;
if (ModAndClassUtil.isSearchBar && (AEConfig.instance.preserveSearchBar || this.isSubGui())) {
setSearchString();
}
this.setScrollBar();
this.repositionSlots();
this.initGuiDone();
}
@Override
public void onGuiClosed() {
super.onGuiClosed();
searchFieldOutputsText = this.searchFieldOutputs.getText();
searchFieldInputsText = this.searchFieldInputs.getText();
searchFieldNamesText = this.searchFieldNames.getText();
}
public void setSearchString() {
this.searchFieldOutputs.setText(searchFieldOutputsText);
this.searchFieldInputs.setText(searchFieldInputsText);
this.searchFieldNames.setText(searchFieldNamesText);
}
protected void repositionSlots() {
for (final Object obj : this.inventorySlots.inventorySlots) {
if (obj instanceof AppEngSlot) {
final AppEngSlot slot = (AppEngSlot) obj;
slot.yDisplayPosition = this.ySize + slot.getY() - 78 - 7;
}
}
}
protected int calculateRowsCount() {
final int maxRows = this.getMaxRows();
final boolean hasNEI = IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.NEI);
final int NEIPadding = hasNEI ? 22 /* input */ + 18 /* top panel */ : 0;
final int extraSpace = this.height - MAGIC_HEIGHT_NUMBER - NEIPadding;
return Math.max(3, Math.min(maxRows, extraSpace / 18));
}
@Override
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
fontRendererObj.drawString(
getGuiDisplayName(GuiText.InterfaceTerminal.getLocal()),
8,
6,
GuiColors.InterfaceTerminalTitle.getColor());
fontRendererObj.drawString(
GuiText.inventory.getLocal(),
GuiInterfaceTerminalWireless.offsetX + 2,
this.ySize - 96,
GuiColors.InterfaceTerminalInventory.getColor());
int offset = 51;
final int ex = getScrollBar().getCurrentScroll();
for (int x = 0; x < this.rows && ex + x < this.lines.size(); x++) {
final Object lineObj = this.lines.get(ex + x);
if (lineObj instanceof ClientDCInternalInv) {
final ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
for (int z = 0; z < inv.getInventory().getSizeInventory(); z++) {
if (this.matchedStacks.contains(inv.getInventory().getStackInSlot(z))) drawRect(
z * 18 + 22,
1 + offset,
z * 18 + 22 + 16,
1 + offset + 16,
GuiColors.InterfaceTerminalMatch.getColor());
}
} else if (lineObj instanceof String) {
String name = (String) lineObj;
final int rows = this.byName.get(name).size();
String postfix = "";
if (rows > 1) {
postfix = " (" + rows + ')';
}
while (name.length() > 2 && this.fontRendererObj.getStringWidth(name + postfix) > 158) {
name = name.substring(0, name.length() - 1);
}
this.fontRendererObj.drawString(
name + postfix,
GuiInterfaceTerminalWireless.offsetX + 3,
6 + offset,
GuiColors.InterfaceTerminalName.getColor());
}
offset += 18;
}
}
@Override
public void drawScreen(final int mouseX, final int mouseY, final float btn) {
buttonList.clear();
inventorySlots.inventorySlots.removeIf(slot -> slot instanceof SlotDisconnected);
guiButtonAssemblersOnly.set(
onlyMolecularAssemblers ? ActionItems.MOLECULAR_ASSEMBLEERS_ON : ActionItems.MOLECULAR_ASSEMBLEERS_OFF);
guiButtonHideFull.set(
AEConfig.instance.showOnlyInterfacesWithFreeSlotsInInterfaceTerminal
? ActionItems.TOGGLE_SHOW_FULL_INTERFACES_OFF
: ActionItems.TOGGLE_SHOW_FULL_INTERFACES_ON);
guiButtonBrokenRecipes.set(
onlyBrokenRecipes ? ActionItems.TOGGLE_SHOW_ONLY_INVALID_PATTERN_OFF
: ActionItems.TOGGLE_SHOW_ONLY_INVALID_PATTERN_ON);
terminalStyleBox.set(AEConfig.instance.settings.getSetting(Settings.TERMINAL_STYLE));
buttonList.add(guiButtonAssemblersOnly);
buttonList.add(guiButtonHideFull);
buttonList.add(guiButtonBrokenRecipes);
buttonList.add(terminalStyleBox);
buttonList.add(searchStringSave);
addSwitchGuiBtns();
int offset = 51;
final int ex = this.getScrollBar().getCurrentScroll();
for (int x = 0; x < this.rows && ex + x < this.lines.size(); x++) {
final Object lineObj = this.lines.get(ex + x);
if (lineObj instanceof ClientDCInternalInv) {
final ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
for (int z = 0; z < inv.getInventory().getSizeInventory(); z++) {
inventorySlots.inventorySlots.add(new SlotDisconnected(inv, z, z * 18 + 22, 1 + offset));
}
GuiButton guiButton = new GuiImgButton(
guiLeft + 4,
guiTop + offset + 1,
Settings.ACTIONS,
ActionItems.HIGHLIGHT_INTERFACE);
guiButtonHashMap.put(guiButton, inv);
buttonList.add(guiButton);
}
offset += 18;
}
super.drawScreen(mouseX, mouseY, btn);
handleTooltip(mouseX, mouseY, searchFieldInputs);
handleTooltip(mouseX, mouseY, searchFieldOutputs);
handleTooltip(mouseX, mouseY, searchFieldNames);
}
@Override
protected void mouseClicked(final int xCoord, final int yCoord, final int btn) {
searchFieldInputs.mouseClicked(xCoord, yCoord, btn);
searchFieldOutputs.mouseClicked(xCoord, yCoord, btn);
searchFieldNames.mouseClicked(xCoord, yCoord, btn);
super.mouseClicked(xCoord, yCoord, btn);
}
@Override
protected void actionPerformed(final GuiButton btn) {
if (guiButtonHashMap.containsKey(btn)) {
DimensionalCoord blockPos = blockPosHashMap.get(guiButtonHashMap.get(btn));
WorldCoord blockPos2 = new WorldCoord(
(int) mc.thePlayer.posX,
(int) mc.thePlayer.posY,
(int) mc.thePlayer.posZ);
if (mc.theWorld.provider.dimensionId != blockPos.getDimension()) {
mc.thePlayer.addChatMessage(
new ChatComponentTranslation(
PlayerMessages.InterfaceInOtherDim.getName(),
blockPos.getDimension()));
} else {
BlockPosHighlighter.highlightBlock(
blockPos,
System.currentTimeMillis() + 500 * WorldCoord.getTaxicabDistance(blockPos, blockPos2));
mc.thePlayer.addChatMessage(
new ChatComponentTranslation(
PlayerMessages.InterfaceHighlighted.getName(),
blockPos.x,
blockPos.y,
blockPos.z));
}
mc.thePlayer.closeScreen();
} else if (btn == guiButtonHideFull) {
AEConfig.instance.showOnlyInterfacesWithFreeSlotsInInterfaceTerminal = !AEConfig.instance.showOnlyInterfacesWithFreeSlotsInInterfaceTerminal;
this.refreshList();
} else if (btn == guiButtonAssemblersOnly) {
onlyMolecularAssemblers = !onlyMolecularAssemblers;
this.refreshList();
} else if (btn == guiButtonBrokenRecipes) {
onlyBrokenRecipes = !onlyBrokenRecipes;
this.refreshList();
} else if (ModAndClassUtil.isSaveText && btn == searchStringSave) {
final boolean backwards = Mouse.isButtonDown(1);
final GuiImgButton iBtn = (GuiImgButton) btn;
final Enum<?> cv = iBtn.getCurrentValue();
final Enum<?> next = Platform.rotateEnum(cv, backwards, iBtn.getSetting().getPossibleValues());
AEConfig.instance.preserveSearchBar = next == YesNo.YES;
AEConfig.instance.settings.putSetting(Settings.SAVE_SEARCH, next);
this.searchStringSave.set(next);
} else if (btn instanceof GuiImgButton) {
final GuiImgButton iBtn = (GuiImgButton) btn;
if (iBtn.getSetting() != Settings.ACTIONS) {
final Enum cv = iBtn.getCurrentValue();
final boolean backwards = Mouse.isButtonDown(1);
final Enum next = Platform.rotateEnum(cv, backwards, iBtn.getSetting().getPossibleValues());
if (btn == this.terminalStyleBox) {
AEConfig.instance.settings.putSetting(iBtn.getSetting(), next);
this.reinitialize();
}
iBtn.set(next);
}
}
super.actionPerformed(btn);
}
private void reinitialize() {
this.buttonList.clear();
this.initGui();
}
@Override
public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
this.bindTexture("guis/newinterfaceterminal.png");
this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, 53);
int offset = 51;
final int ex = this.getScrollBar().getCurrentScroll();
for (int x = 0; x < this.rows; x++) {
this.drawTexturedModalRect(offsetX, offsetY + 53 + x * 18, 0, 52, this.xSize, 18);
}
for (int x = 0; x < this.rows && ex + x < this.lines.size(); x++) {
final Object lineObj = this.lines.get(ex + x);
if (lineObj instanceof ClientDCInternalInv) {
final ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
GL11.glColor4f(1, 1, 1, 1);
final int width = inv.getInventory().getSizeInventory() * 18;
this.drawTexturedModalRect(offsetX + 20, offsetY + offset, 20, 173, width, 18);
}
offset += 18;
}
this.drawTexturedModalRect(offsetX, offsetY + 50 + this.rows * 18, 0, 158, this.xSize, 99);
searchFieldInputs.drawTextBox();
searchFieldOutputs.drawTextBox();
searchFieldNames.drawTextBox();
}
@Override
protected void keyTyped(final char character, final int key) {
if (!checkHotbarKeys(key)) {
if (character == ' ') {
if ((searchFieldInputs.getText().isEmpty() && searchFieldInputs.isFocused())
|| (searchFieldOutputs.getText().isEmpty() && searchFieldOutputs.isFocused())
|| (searchFieldNames.getText().isEmpty() && searchFieldNames.isFocused()))
return;
} else if (character == '\t') {
if (handleTab()) return;
}
if (searchFieldInputs.textboxKeyTyped(character, key) || searchFieldOutputs.textboxKeyTyped(character, key)
|| searchFieldNames.textboxKeyTyped(character, key)) {
refreshList();
} else {
super.keyTyped(character, key);
}
}
}
private boolean handleTab() {
if (searchFieldInputs.isFocused()) {
searchFieldInputs.setFocused(false);
if (isShiftKeyDown()) searchFieldNames.setFocused(true);
else searchFieldOutputs.setFocused(true);
return true;
} else if (searchFieldOutputs.isFocused()) {
searchFieldOutputs.setFocused(false);
if (isShiftKeyDown()) searchFieldInputs.setFocused(true);
else searchFieldNames.setFocused(true);
return true;
} else if (searchFieldNames.isFocused()) {
searchFieldNames.setFocused(false);
if (isShiftKeyDown()) searchFieldOutputs.setFocused(true);
else searchFieldInputs.setFocused(true);
return true;
}
return false;
}
public void postUpdate(final NBTTagCompound in) {
if (in.getBoolean("clear")) {
this.byId.clear();
this.refreshList = true;
}
for (final Object oKey : in.func_150296_c()) {
final String key = (String) oKey;
if (key.startsWith("=")) {
try {
final long id = Long.parseLong(key.substring(1), Character.MAX_RADIX);
final NBTTagCompound invData = in.getCompoundTag(key);
final ClientDCInternalInv current = this
.getById(id, invData.getLong("sortBy"), invData.getString("un"));
int X = invData.getInteger("x");
int Y = invData.getInteger("y");
int Z = invData.getInteger("z");
int dim = invData.getInteger("dim");
blockPosHashMap.put(current, new DimensionalCoord(X, Y, Z, dim));
for (int x = 0; x < current.getInventory().getSizeInventory(); x++) {
final String which = Integer.toString(x);
if (invData.hasKey(which)) {
current.getInventory().setInventorySlotContents(
x,
ItemStack.loadItemStackFromNBT(invData.getCompoundTag(which)));
}
}
} catch (final NumberFormatException ignored) {}
}
}
if (this.refreshList) {
this.refreshList = false;
// invalid caches on refresh
this.cachedSearches.clear();
this.refreshList();
}
}
/**
* Rebuilds the list of interfaces.
* <p>
* Respects a search term if present (ignores case) and adding only matching patterns.
*/
private void refreshList() {
this.byName.clear();
this.buttonList.clear();
this.matchedStacks.clear();
final String searchFieldInputs = this.searchFieldInputs.getText().toLowerCase();
final String searchFieldOutputs = this.searchFieldOutputs.getText().toLowerCase();
final String searchFieldNames = this.searchFieldNames.getText().toLowerCase();
final Set<Object> cachedSearch = this.getCacheForSearchTerm(
"IN:" + searchFieldInputs
+ "OUT:"
+ searchFieldOutputs
+ "NAME:"
+ searchFieldNames
+ AEConfig.instance.showOnlyInterfacesWithFreeSlotsInInterfaceTerminal
+ onlyMolecularAssemblers
+ onlyBrokenRecipes);
final boolean rebuild = cachedSearch.isEmpty();
for (final ClientDCInternalInv entry : this.byId.values()) {
// ignore inventory if not doing a full rebuild and cache already marks it as miss.
if (!rebuild && !cachedSearch.contains(entry)) {
continue;
}
// Shortcut to skip any filter if search term is ""/empty
boolean found = searchFieldInputs.isEmpty() && searchFieldOutputs.isEmpty();
boolean interfaceHasFreeSlots = false;
boolean interfaceHasBrokenRecipes = false;
// Search if the current inventory holds a pattern containing the search term.
if (!found || AEConfig.instance.showOnlyInterfacesWithFreeSlotsInInterfaceTerminal || onlyBrokenRecipes) {
for (final ItemStack itemStack : entry.getInventory()) {
// If only Interfaces with empty slots should be shown, check that here
if (itemStack == null) {
interfaceHasFreeSlots = true;
continue;
}
if (onlyBrokenRecipes && recipeIsBroken(itemStack)) {
interfaceHasBrokenRecipes = true;
}
if ((!searchFieldInputs.isEmpty() && itemStackMatchesSearchTerm(itemStack, searchFieldInputs, 0))
|| (!searchFieldOutputs.isEmpty()
&& itemStackMatchesSearchTerm(itemStack, searchFieldOutputs, 1))) {
found = true;
matchedStacks.add(itemStack);
}
}
}
if ((found && entry.getName().toLowerCase().contains(searchFieldNames))
&& (!onlyMolecularAssemblers || entry.getUnlocalizedName().contains(MOLECULAR_ASSEMBLER))
&& (!AEConfig.instance.showOnlyInterfacesWithFreeSlotsInInterfaceTerminal || interfaceHasFreeSlots)
&& (!onlyBrokenRecipes || interfaceHasBrokenRecipes)) {
this.byName.put(entry.getName(), entry);
cachedSearch.add(entry);
} else {
cachedSearch.remove(entry);
}
}
this.names.clear();
this.names.addAll(this.byName.keySet());
Collections.sort(this.names);
this.lines.clear();
this.lines.ensureCapacity(this.names.size() + this.byId.size());
for (final String n : this.names) {
this.lines.add(n);
final ArrayList<ClientDCInternalInv> clientInventories = new ArrayList<>(this.byName.get(n));
Collections.sort(clientInventories);
this.lines.addAll(clientInventories);
}
this.setScrollBar();
}
private boolean itemStackMatchesSearchTerm(final ItemStack itemStack, final String searchTerm, int pass) {
if (itemStack == null) {
return false;
}
final NBTTagCompound encodedValue = itemStack.getTagCompound();
if (encodedValue == null) {
return false;
}
final NBTTagList tags = encodedValue.getTagList(pass == 0 ? "in" : "out", 10);
final boolean containsInvalidDisplayName = GuiText.UnknownItem.getLocal().toLowerCase().contains(searchTerm);
for (int i = 0; i < tags.tagCount(); i++) {
final NBTTagCompound tag = tags.getCompoundTagAt(i);
final ItemStack parsedItemStack = ItemStack.loadItemStackFromNBT(tag);
if (parsedItemStack != null) {
final String displayName = Platform
.getItemDisplayName(AEApi.instance().storage().createItemStack(parsedItemStack)).toLowerCase();
if (displayName.contains(searchTerm)) {
return true;
}
} else if (containsInvalidDisplayName && !tag.hasNoTags()) {
return true;
}
}
return false;
}
private boolean recipeIsBroken(final ItemStack itemStack) {
if (itemStack == null) {
return false;
}
final NBTTagCompound encodedValue = itemStack.getTagCompound();
if (encodedValue == null) {
return true;
}
final World w = CommonHelper.proxy.getWorld();
if (w == null) {
return false;
}
try {
new PatternHelper(itemStack, w);
return false;
} catch (final Throwable t) {
return true;
}
}
/**
* Tries to retrieve a cache for a with search term as keyword.
* <p>
* If this cache should be empty, it will populate it with an earlier cache if available or at least the cache for
* the empty string.
*
* @param searchTerm the corresponding search
* @return a Set matching a superset of the search term
*/
private Set<Object> getCacheForSearchTerm(final String searchTerm) {
if (!this.cachedSearches.containsKey(searchTerm)) {
this.cachedSearches.put(searchTerm, new HashSet<>());
}
final Set<Object> cache = this.cachedSearches.get(searchTerm);
if (cache.isEmpty() && searchTerm.length() > 1) {
cache.addAll(this.getCacheForSearchTerm(searchTerm.substring(0, searchTerm.length() - 1)));
return cache;
}
return cache;
}
private int getMaxRows() {
return AEConfig.instance.getConfigManager().getSetting(Settings.TERMINAL_STYLE) == TerminalStyle.SMALL
? AEConfig.instance.InterfaceTerminalSmallSize
: Integer.MAX_VALUE;
}
private ClientDCInternalInv getById(final long id, final long sortBy, final String unlocalizedName) {
ClientDCInternalInv o = this.byId.get(id);
if (o == null) {
this.byId.put(id, o = new ClientDCInternalInv(9, id, sortBy, unlocalizedName));
this.refreshList = true;
}
return o;
}
public boolean isOverTextField(final int mousex, final int mousey) {
return searchFieldInputs.isMouseIn(mousex, mousey) || searchFieldOutputs.isMouseIn(mousex, mousey)
|| searchFieldNames.isMouseIn(mousex, mousey);
}
public void setTextFieldValue(final String displayName, final int mousex, final int mousey, final ItemStack stack) {
if (searchFieldInputs.isMouseIn(mousex, mousey)) {
searchFieldInputs.setText(displayName);
} else if (searchFieldOutputs.isMouseIn(mousex, mousey)) {
searchFieldOutputs.setText(displayName);
} else if (searchFieldNames.isMouseIn(mousex, mousey)) {
searchFieldNames.setText(displayName);
}
}
}
@@ -0,0 +1,135 @@
package com.glodblock.github.client.gui.base;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import appeng.client.gui.AEBaseMEGui;
import com.glodblock.github.client.gui.*;
import com.glodblock.github.common.item.ItemWirelessUltraTerminal;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.Util;
public abstract class FCBaseMEGui extends AEBaseMEGui {
protected GuiFCImgButton FluidTerminal;
protected GuiFCImgButton CraftingTerminal;
protected GuiFCImgButton PatternTerminal;
protected GuiFCImgButton EssentiaTerminal;
protected GuiFCImgButton InterfaceTerminal;
protected List<GuiFCImgButton> termBtns = new ArrayList<>();
protected boolean drawSwitchGuiBtn;
public FCBaseMEGui(final InventoryPlayer inventoryPlayer, Container container) {
super(container);
if (inventoryPlayer.getCurrentItem() != null
&& inventoryPlayer.getCurrentItem().getItem() instanceof ItemWirelessUltraTerminal)
this.drawSwitchGuiBtn = true;
}
@Override
public void onGuiClosed() {
super.onGuiClosed();
Util.MouseHandler.saveMousePos();
}
protected void initGuiDone() {
if (drawSwitchGuiBtn) {
drawSwitchGuiBtns();
Util.MouseHandler.loadMousePos();
}
}
public abstract int getOffsetY();
public abstract void setOffsetY(int y);
@SuppressWarnings("unchecked")
protected void drawSwitchGuiBtns() {
if (!drawSwitchGuiBtn) return;
if (!(this instanceof GuiFluidCraftingWireless)) {
this.buttonList.add(
this.CraftingTerminal = new GuiFCImgButton(
this.guiLeft - 18,
this.getOffsetY(),
"CRAFT_TEM",
"YES"));
this.setOffsetY(this.getOffsetY() + 20);
termBtns.add(this.CraftingTerminal);
}
if (!(this instanceof GuiFluidPatternWireless)) {
this.buttonList.add(
this.PatternTerminal = new GuiFCImgButton(
this.guiLeft - 18,
this.getOffsetY(),
"PATTERN_TEM",
"YES"));
this.setOffsetY(this.getOffsetY() + 20);
termBtns.add(this.PatternTerminal);
}
if (!(this instanceof GuiFluidPortableCell)) {
this.buttonList.add(
this.FluidTerminal = new GuiFCImgButton(this.guiLeft - 18, this.getOffsetY(), "FLUID_TEM", "YES"));
this.setOffsetY(this.getOffsetY() + 20);
termBtns.add(this.FluidTerminal);
}
if (!(this instanceof GuiInterfaceTerminalWireless)) {
this.buttonList.add(
this.InterfaceTerminal = new GuiFCImgButton(
this.guiLeft - 18,
this.getOffsetY(),
"INTERFACE_TEM",
"YES"));
this.setOffsetY(this.getOffsetY() + 20);
termBtns.add(this.InterfaceTerminal);
}
if (ModAndClassUtil.ThE && !(this instanceof GuiEssentiaTerminal)) {
this.buttonList.add(
this.EssentiaTerminal = new GuiFCImgButton(
this.guiLeft - 18,
this.getOffsetY(),
"ESSENTIA_TEM",
"YES"));
this.setOffsetY(this.getOffsetY() + 20);
termBtns.add(this.EssentiaTerminal);
}
}
protected void addSwitchGuiBtns() {
if (!drawSwitchGuiBtn) return;
this.buttonList.addAll(termBtns);
}
@Override
protected void actionPerformed(final GuiButton btn) {
if (btn instanceof GuiFCImgButton) {
if (btn == this.FluidTerminal) {
ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_FLUID_TERMINAL);
} else if (btn == this.CraftingTerminal) {
ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_CRAFTING_TERMINAL);
} else if (btn == this.EssentiaTerminal) {
ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_ESSENTIA_TERMINAL);
} else if (btn == this.PatternTerminal) {
ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_FLUID_PATTERN_TERMINAL);
} else if (btn == this.InterfaceTerminal) {
ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_INTERFACE_TERMINAL);
}
}
super.actionPerformed(btn);
}
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
}
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
}
}
@@ -22,7 +22,6 @@ 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;
import appeng.client.gui.widgets.*;
import appeng.client.me.InternalSlotME;
import appeng.client.me.ItemRepo;
@@ -51,14 +50,11 @@ import codechicken.nei.util.TextHistory;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.*;
import com.glodblock.github.client.gui.container.base.FCContainerMonitor;
import com.glodblock.github.common.item.ItemWirelessUltraTerminal;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.network.CPacketInventoryAction;
import com.glodblock.github.util.Ae2ReflectClient;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.Util;
public abstract class FCGuiMonitor<T extends IAEStack<T>> extends AEBaseMEGui
public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
implements ISortSource, IConfigManagerHost, IDropToFillTextField {
public static int craftingGridOffsetX;
@@ -88,15 +84,10 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends AEBaseMEGui
protected GuiImgButton searchBoxSettings;
protected GuiImgButton terminalStyleBox;
protected GuiImgButton searchStringSave;
protected GuiFCImgButton FluidTerminal;
protected GuiFCImgButton CraftingTerminal;
protected GuiFCImgButton PatternTerminal;
protected GuiFCImgButton EssentiaTerminal;
protected boolean drawSwitchGuiBtn;
@SuppressWarnings("unchecked")
public FCGuiMonitor(final InventoryPlayer inventoryPlayer, final ITerminalHost te, final FCContainerMonitor<T> c) {
super(c);
super(inventoryPlayer, c);
final GuiScrollbar scrollbar = new GuiScrollbar();
this.setScrollBar(scrollbar);
this.xSize = 195;
@@ -105,9 +96,14 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends AEBaseMEGui
this.configSrc = ((IConfigurableObject) this.inventorySlots).getConfigManager();
(this.monitorableContainer = (FCContainerMonitor<T>) this.inventorySlots).setGui(this);
this.viewCell = te instanceof IViewCellStorage;
if (inventoryPlayer.getCurrentItem() != null
&& inventoryPlayer.getCurrentItem().getItem() instanceof ItemWirelessUltraTerminal)
this.drawSwitchGuiBtn = true;
}
public int getOffsetY() {
return offsetY;
}
public void setOffsetY(int y) {
offsetY = y;
}
public abstract void postUpdate(final List<T> list);
@@ -125,17 +121,6 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends AEBaseMEGui
if (btn == this.craftingStatusBtn || btn == this.craftingStatusImgBtn) {
NetworkHandler.instance.sendToServer(new PacketSwitchGuis(GuiBridge.GUI_CRAFTING_STATUS));
}
if (btn instanceof GuiFCImgButton) {
if (btn == this.FluidTerminal) {
ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_FLUID_TERMINAL);
} else if (btn == this.CraftingTerminal) {
ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_CRAFTING_TERMINAL);
} else if (btn == this.EssentiaTerminal) {
ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_ESSENTIA_TERMINAL);
} else if (btn == this.PatternTerminal) {
ItemWirelessUltraTerminal.switchTerminal(this.mc.thePlayer, GuiType.WIRELESS_FLUID_PATTERN_TERMINAL);
}
}
if (btn instanceof GuiImgButton) {
final boolean backwards = Mouse.isButtonDown(1);
final GuiImgButton iBtn = (GuiImgButton) btn;
@@ -162,6 +147,7 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends AEBaseMEGui
}
}
}
super.actionPerformed(btn);
}
protected void reInitalize() {
@@ -344,34 +330,7 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends AEBaseMEGui
craftingGridOffsetX -= 25;
craftingGridOffsetY -= 6;
if (drawSwitchGuiBtn) {
drawSwitchGuiBtns();
Util.MouseHandler.loadMousePos();
}
}
@SuppressWarnings("unchecked")
private void drawSwitchGuiBtns() {
if (!(this instanceof GuiFluidCraftingWireless)) {
this.buttonList.add(
this.CraftingTerminal = new GuiFCImgButton(this.guiLeft - 18, this.offsetY, "CRAFT_TEM", "YES"));
this.offsetY += 20;
}
if (!(this instanceof GuiFluidPatternWireless)) {
this.buttonList.add(
this.PatternTerminal = new GuiFCImgButton(this.guiLeft - 18, this.offsetY, "PATTERN_TEM", "YES"));
this.offsetY += 20;
}
if (!(this instanceof GuiFluidPortableCell)) {
this.buttonList
.add(this.FluidTerminal = new GuiFCImgButton(this.guiLeft - 18, this.offsetY, "FLUID_TEM", "YES"));
this.offsetY += 20;
}
if (ModAndClassUtil.ThE && !(this instanceof GuiEssentiaTerminal)) {
this.buttonList.add(
this.EssentiaTerminal = new GuiFCImgButton(this.guiLeft - 18, this.offsetY, "ESSENTIA_TEM", "YES"));
this.offsetY += 20;
}
initGuiDone();
}
public void setSearchString(String memoryText, boolean updateView) {
@@ -601,7 +560,6 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends AEBaseMEGui
super.onGuiClosed();
Keyboard.enableRepeatEvents(false);
memoryText = this.searchField.getText();
Util.MouseHandler.saveMousePos();
}
public void bindTextureBack(final String file) {
@@ -0,0 +1,415 @@
package com.glodblock.github.client.gui.container;
import java.io.IOException;
import java.util.*;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.config.YesNo;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.IActionHost;
import appeng.container.AEBaseContainer;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketCompressedNBT;
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
import appeng.helpers.InventoryAction;
import appeng.items.misc.ItemEncodedPattern;
import appeng.parts.misc.PartInterface;
import appeng.parts.p2p.PartP2PInterface;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.misc.TileInterface;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorIInventory;
import appeng.util.inv.AdaptorPlayerHand;
import appeng.util.inv.ItemSlot;
import appeng.util.inv.WrapperInvSlot;
import com.glodblock.github.common.parts.PartFluidInterface;
import com.glodblock.github.common.tile.TileFluidInterface;
import com.glodblock.github.inventory.item.IWirelessTerminal;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
public class ContainerInterfaceWireless extends AEBaseContainer {
/**
* this stuff is all server side..
*/
private static long autoBase = Long.MIN_VALUE;
private final Multimap<IInterfaceHost, ContainerInterfaceWireless.InvTracker> diList = HashMultimap.create();
private final Map<Long, ContainerInterfaceWireless.InvTracker> byId = new HashMap<Long, ContainerInterfaceWireless.InvTracker>();
// private final Map<Long, InvTracker> byId = new HashMap<>();
private IGrid grid;
private NBTTagCompound data = new NBTTagCompound();
public ContainerInterfaceWireless(final InventoryPlayer ip, final IWirelessTerminal anchor) {
super(ip, anchor);
if (Platform.isServer()) {
this.grid = anchor.getActionableNode().getGrid();
}
this.bindPlayerInventory(ip, 14, 0);
}
private Set<IGridNode> getMachineNodes() {
Set<IGridNode> union = new HashSet<>();
this.grid.getMachines(TileFluidInterface.class).forEach(union::add);
this.grid.getMachines(TileInterface.class).forEach(union::add);
this.grid.getMachines(PartFluidInterface.class).forEach(union::add);
this.grid.getMachines(PartInterface.class).forEach(union::add);
this.grid.getMachines(PartP2PInterface.class).forEach(union::add);
return union;
}
@Override
public void detectAndSendChanges() {
if (Platform.isClient()) {
return;
}
super.detectAndSendChanges();
if (this.grid == null) {
return;
}
int total = 0;
boolean missing = false;
final IActionHost host = this.getActionHost();
if (host != null) {
final IGridNode agn = host.getActionableNode();
if (agn != null && agn.isActive()) {
for (final IGridNode gn : this.getMachineNodes()) {
ContainerInterfaceWireless.InterfaceCheck interfaceCheck = new ContainerInterfaceWireless.InterfaceCheck()
.invoke(gn);
total += interfaceCheck.getTotal();
missing |= interfaceCheck.isMissing();
}
}
}
if (total != this.diList.size() || missing) {
this.regenList(this.data);
} else {
for (final ContainerInterfaceWireless.InvTracker inv : diList.values()) {
for (int x = 0; x < inv.client.getSizeInventory(); x++) {
if (this.isDifferent(inv.server.getStackInSlot(inv.offset + x), inv.client.getStackInSlot(x))) {
this.addItems(this.data, inv, x, 1);
}
}
}
}
if (!this.data.hasNoTags()) {
try {
NetworkHandler.instance
.sendTo(new PacketCompressedNBT(this.data), (EntityPlayerMP) this.getPlayerInv().player);
} catch (final IOException e) {
// :P
}
this.data = new NBTTagCompound();
}
}
@Override
public void doAction(final EntityPlayerMP player, final InventoryAction action, final int slot, final long id) {
final ContainerInterfaceWireless.InvTracker inv = this.byId.get(id);
if (inv != null) {
final ItemStack is = inv.server.getStackInSlot(slot + inv.offset);
final boolean hasItemInHand = player.inventory.getItemStack() != null;
final InventoryAdaptor playerHand = new AdaptorPlayerHand(player);
final WrapperInvSlot slotInv = new ContainerInterfaceWireless.PatternInvSlot(inv.server);
final IInventory theSlot = slotInv.getWrapper(slot + inv.offset);
final InventoryAdaptor interfaceSlot = new AdaptorIInventory(theSlot);
IInventory interfaceHandler = inv.server;
boolean canInsert = true;
switch (action) {
case PICKUP_OR_SET_DOWN:
if (hasItemInHand) {
for (int s = 0; s < interfaceHandler.getSizeInventory(); s++) {
if (Platform.isSameItemPrecise(
interfaceHandler.getStackInSlot(s),
player.inventory.getItemStack())) {
canInsert = false;
break;
}
}
if (canInsert) {
ItemStack inSlot = theSlot.getStackInSlot(0);
if (inSlot == null) {
player.inventory.setItemStack(interfaceSlot.addItems(player.inventory.getItemStack()));
} else {
inSlot = inSlot.copy();
final ItemStack inHand = player.inventory.getItemStack().copy();
theSlot.setInventorySlotContents(0, null);
player.inventory.setItemStack(null);
player.inventory.setItemStack(interfaceSlot.addItems(inHand.copy()));
if (player.inventory.getItemStack() == null) {
player.inventory.setItemStack(inSlot);
} else {
player.inventory.setItemStack(inHand);
theSlot.setInventorySlotContents(0, inSlot);
}
}
}
} else {
final IInventory mySlot = slotInv.getWrapper(slot + inv.offset);
mySlot.setInventorySlotContents(0, playerHand.addItems(mySlot.getStackInSlot(0)));
}
break;
case SPLIT_OR_PLACE_SINGLE:
if (hasItemInHand) {
for (int s = 0; s < interfaceHandler.getSizeInventory(); s++) {
if (Platform.isSameItemPrecise(
interfaceHandler.getStackInSlot(s),
player.inventory.getItemStack())) {
canInsert = false;
break;
}
}
if (canInsert) {
ItemStack extra = playerHand.removeItems(1, null, null);
if (extra != null && !interfaceSlot.containsItems()) {
extra = interfaceSlot.addItems(extra);
}
if (extra != null) {
playerHand.addItems(extra);
}
}
} else if (is != null) {
ItemStack extra = interfaceSlot.removeItems((is.stackSize + 1) / 2, null, null);
if (extra != null) {
extra = playerHand.addItems(extra);
}
if (extra != null) {
interfaceSlot.addItems(extra);
}
}
break;
case SHIFT_CLICK:
final IInventory mySlot = slotInv.getWrapper(slot + inv.offset);
final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN);
mySlot.setInventorySlotContents(0, mergeToPlayerInventory(playerInv, mySlot.getStackInSlot(0)));
break;
case MOVE_REGION:
final InventoryAdaptor playerInvAd = InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN);
for (int x = 0; x < inv.client.getSizeInventory(); x++) {
inv.server.setInventorySlotContents(
x + inv.offset,
mergeToPlayerInventory(playerInvAd, inv.server.getStackInSlot(x + inv.offset)));
}
break;
case CREATIVE_DUPLICATE:
if (player.capabilities.isCreativeMode && !hasItemInHand) {
player.inventory.setItemStack(is == null ? null : is.copy());
}
break;
default:
return;
}
this.updateHeld(player);
}
}
private ItemStack mergeToPlayerInventory(InventoryAdaptor playerInv, ItemStack stack) {
if (stack == null) return null;
for (ItemSlot slot : playerInv) {
if (Platform.isSameItemPrecise(slot.getItemStack(), stack)) {
if (slot.getItemStack().stackSize < slot.getItemStack().getMaxStackSize()) {
++slot.getItemStack().stackSize;
return null;
}
}
}
return playerInv.addItems(stack);
}
private void regenList(final NBTTagCompound data) {
this.byId.clear();
this.diList.clear();
final IActionHost host = this.getActionHost();
if (host != null) {
final IGridNode agn = host.getActionableNode();
if (agn != null && agn.isActive()) {
for (final IGridNode gn : this.getMachineNodes()) {
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
final DualityInterface dual = ih.getInterfaceDuality();
if (gn.isActive() && dual.getConfigManager().getSetting(Settings.INTERFACE_TERMINAL) == YesNo.YES) {
for (int i = 0; i <= dual.getInstalledUpgrades(Upgrades.PATTERN_CAPACITY); ++i) {
this.diList.put(
ih,
new ContainerInterfaceWireless.InvTracker(
dual,
dual.getPatterns(),
dual.getTermName(),
i * 9,
9));
}
}
}
}
}
data.setBoolean("clear", true);
for (final ContainerInterfaceWireless.InvTracker inv : this.diList.values()) {
this.byId.put(inv.which, inv);
this.addItems(data, inv, 0, inv.client.getSizeInventory());
}
}
private boolean isDifferent(final ItemStack a, final ItemStack b) {
if (a == null && b == null) {
return false;
}
if (a == null || b == null) {
return true;
}
return !ItemStack.areItemStacksEqual(a, b);
}
private void addItems(final NBTTagCompound data, final ContainerInterfaceWireless.InvTracker inv, final int offset,
final int length) {
final String name = '=' + Long.toString(inv.which, Character.MAX_RADIX);
final NBTTagCompound tag = data.getCompoundTag(name);
if (tag.hasNoTags()) {
tag.setLong("sortBy", inv.sortBy);
tag.setString("un", inv.unlocalizedName);
tag.setInteger("x", inv.X);
tag.setInteger("y", inv.Y);
tag.setInteger("z", inv.Z);
tag.setInteger("dim", inv.dim);
}
for (int x = 0; x < length; x++) {
final NBTTagCompound itemNBT = new NBTTagCompound();
final ItemStack is = inv.server.getStackInSlot(x + offset + inv.offset);
// "update" client side.
inv.client.setInventorySlotContents(offset + x, is == null ? null : is.copy());
if (is != null) {
is.writeToNBT(itemNBT);
}
tag.setTag(Integer.toString(x + offset), itemNBT);
}
data.setTag(name, tag);
}
private static class InvTracker {
private final long sortBy;
private final long which = autoBase++;
private final String unlocalizedName;
private final IInventory client;
private final IInventory server;
private final int offset;
private final int X;
private final int Y;
private final int Z;
private final int dim;
public InvTracker(final DualityInterface dual, final IInventory patterns, final String unlocalizedName,
int offset, int size) {
this.server = patterns;
this.client = new AppEngInternalInventory(null, size);
this.unlocalizedName = unlocalizedName;
this.sortBy = dual.getSortValue() + offset << 16;
this.offset = offset;
X = dual.getLocation().x;
Y = dual.getLocation().y;
Z = dual.getLocation().z;
dim = dual.getLocation().getDimension();
}
}
private static class PatternInvSlot extends WrapperInvSlot {
public PatternInvSlot(final IInventory inv) {
super(inv);
}
@Override
public boolean isItemValid(final ItemStack itemstack) {
return itemstack != null && itemstack.getItem() instanceof ItemEncodedPattern;
}
}
private class InterfaceCheck {
int total = 0;
boolean missing = false;
public InterfaceCheck() {}
public int getTotal() {
return total;
}
public boolean isMissing() {
return missing;
}
public ContainerInterfaceWireless.InterfaceCheck invoke(IGridNode gn) {
if (gn.isActive()) {
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
if (ih.getInterfaceDuality().getConfigManager().getSetting(Settings.INTERFACE_TERMINAL) == YesNo.NO
|| ih instanceof PartP2PInterface && ((PartP2PInterface) ih).isOutput()) {
return this;
}
final Collection<ContainerInterfaceWireless.InvTracker> t = ContainerInterfaceWireless.this.diList
.get(ih);
if (t.isEmpty()) {
missing = true;
} else {
final DualityInterface dual = ih.getInterfaceDuality();
for (ContainerInterfaceWireless.InvTracker it : t) {
if (!it.unlocalizedName.equals(dual.getTermName())) {
missing = true;
}
}
}
total += (ih.getInterfaceDuality().getInstalledUpgrades(Upgrades.PATTERN_CAPACITY) + 1);
}
return this;
}
}
}
@@ -0,0 +1,54 @@
package com.glodblock.github.common.item;
import java.util.EnumSet;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.networking.IGridNode;
import appeng.core.features.AEFeature;
import appeng.core.localization.PlayerMessages;
import appeng.util.Platform;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.tabs.FluidCraftingTabs;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.WirelessInterfaceTerminalInventory;
import com.glodblock.github.loader.IRegister;
import com.glodblock.github.util.NameConst;
import com.glodblock.github.util.Util;
import cpw.mods.fml.common.registry.GameRegistry;
public class ItemWirelessInterfaceTerminal extends ItemBaseWirelessTerminal
implements IRegister<ItemWirelessInterfaceTerminal> {
public ItemWirelessInterfaceTerminal() {
super(GuiType.WIRELESS_INTERFACE_TERMINAL);
AEApi.instance().registries().wireless().registerWirelessHandler(this);
this.setFeature(EnumSet.of(AEFeature.WirelessAccessTerminal, AEFeature.PoweredTools));
setUnlocalizedName(NameConst.ITEM_WIRELESS_INTERFACE_TERMINAL);
setTextureName(FluidCraft.resource(NameConst.ITEM_WIRELESS_INTERFACE_TERMINAL).toString());
}
@Override
public ItemWirelessInterfaceTerminal register() {
GameRegistry.registerItem(this, NameConst.ITEM_WIRELESS_INTERFACE_TERMINAL, FluidCraft.MODID);
setCreativeTab(FluidCraftingTabs.INSTANCE);
return this;
}
@Override
public Object getInventory(ItemStack stack, World world, int x, int y, int z, EntityPlayer player) {
try {
IGridNode gridNode = Util.getWirelessGrid(stack);
if (gridNode != null) {
return new WirelessInterfaceTerminalInventory(stack, x, gridNode, player);
}
} catch (Exception e) {
if (Platform.isClient()) player.addChatMessage(PlayerMessages.OutOfRange.get());
}
return null;
}
}
@@ -25,6 +25,7 @@ import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.WirelessCraftingTerminalInventory;
import com.glodblock.github.inventory.item.WirelessFluidTerminalInventory;
import com.glodblock.github.inventory.item.WirelessInterfaceTerminalInventory;
import com.glodblock.github.inventory.item.WirelessPatternTerminalInventory;
import com.glodblock.github.loader.IRegister;
import com.glodblock.github.network.CPacketSwitchGuis;
@@ -52,6 +53,7 @@ public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal
guis.add(GuiType.WIRELESS_CRAFTING_TERMINAL);
guis.add(GuiType.WIRELESS_FLUID_PATTERN_TERMINAL);
guis.add(GuiType.WIRELESS_FLUID_TERMINAL);
guis.add(GuiType.WIRELESS_INTERFACE_TERMINAL);
if (ModAndClassUtil.ThE) {
guis.add(GuiType.WIRELESS_ESSENTIA_TERMINAL);
}
@@ -102,6 +104,8 @@ public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal
return new WirelessFluidTerminalInventory(stack, x, gridNode, player);
} else if (gui == GuiType.WIRELESS_FLUID_TERMINAL) {
return new WirelessFluidTerminalInventory(stack, x, gridNode, player);
} else if (gui == GuiType.WIRELESS_INTERFACE_TERMINAL) {
return new WirelessInterfaceTerminalInventory(stack, x, gridNode, player);
} else {
this.setMode(GuiType.WIRELESS_FLUID_TERMINAL, stack); // set as default mode
return new WirelessFluidTerminalInventory(stack, x, gridNode, player);
@@ -37,6 +37,9 @@ public class FCClassTransformer implements IClassTransformer {
case "appeng.core.features.registries.ExternalStorageRegistry":
tform = ExternalStorageRegistryTransformer.INSTANCE;
break;
case "appeng.core.sync.packets.PacketCompressedNBT":
tform = PacketCompressedNBTTransformer.INSTANCE;
break;
default:
return code;
}
@@ -5,9 +5,12 @@ import java.util.Set;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
@@ -29,6 +32,7 @@ import appeng.tile.misc.TileInterface;
import appeng.util.InventoryAdaptor;
import com.glodblock.github.client.gui.GuiFluidCraftConfirm;
import com.glodblock.github.client.gui.GuiInterfaceTerminalWireless;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.parts.PartFluidInterface;
@@ -188,4 +192,11 @@ public class CoreModHooks {
}
return true;
}
public static void clientPacketData(NBTTagCompound data) {
GuiScreen gs = Minecraft.getMinecraft().currentScreen;
if (gs instanceof GuiInterfaceTerminalWireless) {
((GuiInterfaceTerminalWireless) gs).postUpdate(data);
}
}
}
@@ -0,0 +1,61 @@
package com.glodblock.github.coremod.transform;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import com.glodblock.github.coremod.FCClassTransformer;
public class PacketCompressedNBTTransformer extends FCClassTransformer.ClassMapper {
public static final PacketCompressedNBTTransformer INSTANCE = new PacketCompressedNBTTransformer();
private PacketCompressedNBTTransformer() {
// NO-OP
}
@Override
protected ClassVisitor getClassMapper(ClassVisitor downstream) {
return new TransformPacketCompressedNBT(Opcodes.ASM5, downstream);
}
private static class TransformPacketCompressedNBT extends ClassVisitor {
TransformPacketCompressedNBT(int api, ClassVisitor cv) {
super(api, cv);
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if (name.equals("clientPacketData")) {
return new TransformClientPacketData(api, super.visitMethod(access, name, desc, signature, exceptions));
}
return super.visitMethod(access, name, desc, signature, exceptions);
}
}
private static class TransformClientPacketData extends MethodVisitor {
TransformClientPacketData(int api, MethodVisitor mv) {
super(api, mv);
}
@Override
public void visitInsn(int opcode) {
super.visitVarInsn(Opcodes.ALOAD, 0);
super.visitFieldInsn(
Opcodes.GETFIELD,
"appeng/core/sync/packets/PacketCompressedNBT",
"in",
"Lnet/minecraft/nbt/NBTTagCompound;");
super.visitMethodInsn(
Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"clientPacketData",
"(Lnet/minecraft/nbt/NBTTagCompound;)V",
false);
super.visitInsn(opcode);
}
}
}
@@ -247,6 +247,18 @@ public enum GuiType {
return new GuiFluidPatternWireless(player.inventory, inv);
}
}),
WIRELESS_INTERFACE_TERMINAL(new ItemGuiFactory<IWirelessTerminal>(IWirelessTerminal.class) {
@Override
protected Object createServerGui(EntityPlayer player, IWirelessTerminal inv) {
return new ContainerInterfaceWireless(player.inventory, inv);
}
@Override
protected Object createClientGui(EntityPlayer player, IWirelessTerminal inv) {
return new GuiInterfaceTerminalWireless(player.inventory, inv);
}
}),
WIRELESS_CRAFTING_TERMINAL(new ItemGuiFactory<IWirelessTerminal>(IWirelessTerminal.class) {
@@ -0,0 +1,4 @@
package com.glodblock.github.inventory.item;
public interface IWirelessInterfaceTerminal extends IWirelessTerminal {
}
@@ -0,0 +1,111 @@
package com.glodblock.github.inventory.item;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.config.*;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.api.networking.IGridNode;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.AECableType;
import appeng.api.util.IConfigManager;
import appeng.items.tools.powered.ToolWirelessTerminal;
import appeng.tile.inventory.InvOperation;
import appeng.util.ConfigManager;
import appeng.util.Platform;
public class WirelessInterfaceTerminalInventory implements IWirelessInterfaceTerminal {
private final ItemStack target;
private final IAEItemPowerStorage ips;
private final int inventorySlot;
private final IGridNode grid;
public WirelessInterfaceTerminalInventory(ItemStack is, int slot, IGridNode gridNode, EntityPlayer player) {
this.ips = (ToolWirelessTerminal) is.getItem();
this.grid = gridNode;
this.target = is;
this.inventorySlot = slot;
}
@Override
public IGridNode getActionableNode() {
return this.grid;
}
@Override
public IGridNode getGridNode(ForgeDirection dir) {
return this.grid;
}
@Override
public AECableType getCableConnectionType(ForgeDirection dir) {
return AECableType.NONE;
}
@Override
public void securityBreak() {
this.getGridNode(ForgeDirection.UNKNOWN).getMachine().securityBreak();
}
@Override
public ItemStack getItemStack() {
return this.target;
}
@Override
public IInventory getViewCellStorage() {
return null;
}
@Override
public double extractAEPower(double amt, Actionable mode, PowerMultiplier usePowerMultiplier) {
amt = usePowerMultiplier.multiply(amt);
if (mode == Actionable.SIMULATE) {
return usePowerMultiplier.divide(Math.min(amt, this.ips.getAECurrentPower(this.target)));
}
return usePowerMultiplier.divide(this.ips.extractAEPower(this.target, amt));
}
@Override
public IMEMonitor<IAEItemStack> getItemInventory() {
return null;
}
@Override
public IMEMonitor<IAEFluidStack> getFluidInventory() {
return null;
}
@Override
public IConfigManager getConfigManager() {
final ConfigManager out = new ConfigManager((manager, settingName, newValue) -> {
final NBTTagCompound data = Platform.openNbtData(this.target);
manager.writeToNBT(data);
});
out.registerSetting(Settings.TERMINAL_STYLE, TerminalStyle.SMALL);
out.readFromNBT((NBTTagCompound) Platform.openNbtData(this.target).copy());
return out;
}
@Override
public int getInventorySlot() {
return this.inventorySlot;
}
@Override
public void saveChanges() {
}
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack,
ItemStack newStack) {
}
}
@@ -35,6 +35,8 @@ public class ItemAndBlockHolder {
public static ItemWirelessFluidTerminal WIRELESS_FLUID_TERM = new ItemWirelessFluidTerminal().register();
public static ItemWirelessUltraTerminal WIRELESS_ULTRA_TERM = new ItemWirelessUltraTerminal().register();
public static ItemWirelessPatternTerminal WIRELESS_PATTERN_TERM = new ItemWirelessPatternTerminal().register();
public static ItemWirelessInterfaceTerminal WIRELESS_INTERFACE_TERM = new ItemWirelessInterfaceTerminal()
.register();
public static ItemFluidPacket PACKET = new ItemFluidPacket().register();
public static ItemBasicFluidStorageCell CELL1K = new ItemBasicFluidStorageCell(CellType.Cell1kPart, 1).register();
public static ItemBasicFluidStorageCell CELL4K = new ItemBasicFluidStorageCell(CellType.Cell4kPart, 4).register();
@@ -142,6 +142,7 @@ public class RecipeLoader implements Runnable {
GameRegistry.addShapelessRecipe(INTERFACE.stack(), FLUID_INTERFACE.stack());
GameRegistry.addShapelessRecipe(WIRELESS_FLUID_TERM.stack(), AE2_WIRELESS_TERMINAL, BUCKET);
GameRegistry.addShapelessRecipe(WIRELESS_PATTERN_TERM.stack(), WIRELESS_FLUID_TERM, FLUID_TERMINAL);
GameRegistry.addShapelessRecipe(WIRELESS_INTERFACE_TERM.stack(), AE2_WIRELESS_TERMINAL, AE2_INTERFACE);
GameRegistry
.addRecipe(new ShapedOreRecipe(CERTUS_QUARTZ_TANK.stack(), "GGG", "G G", "GGG", 'G', AE2_QUARTZ_GLASS));
GameRegistry.addShapelessRecipe(FLUID_AUTO_FILLER.stack(), FLUID_TERMINAL, ENCODER);
@@ -462,10 +463,11 @@ public class RecipeLoader implements Runnable {
GameRegistry.addRecipe(new WirelessTerminalRecipe(WIRELESS_PATTERN_TERM.stack()));
GameRegistry.addRecipe(new WirelessTerminalRecipe(WIRELESS_FLUID_TERM.stack()));
GameRegistry.addRecipe(new WirelessTerminalRecipe(WIRELESS_ULTRA_TERM.stack()));
GameRegistry.addRecipe(new WirelessTerminalRecipe(WIRELESS_INTERFACE_TERM.stack()));
}
ItemStack[] term = { AE2_WIRELESS_TERMINAL, WIRELESS_FLUID_TERM.stack(), WIRELESS_PATTERN_TERM.stack(),
THE_WIRELESS_TERM, WCT_WIRELESS_TERM };
WIRELESS_INTERFACE_TERM.stack(), THE_WIRELESS_TERM, WCT_WIRELESS_TERM };
GameRegistry.addShapelessRecipe(
WIRELESS_ULTRA_TERM.stack(),
Arrays.stream(term).filter(Objects::nonNull).toArray());
@@ -37,6 +37,7 @@ public class NameConst {
public static final String ITEM_FLUID_STORAGE = "fluid_storage";
public static final String ITEM_FLUID_PORTABLE_CELL = "portable_fluid_cell";
public static final String ITEM_WIRELESS_FLUID_TERMINAL = "wireless_fluid_terminal";
public static final String ITEM_WIRELESS_INTERFACE_TERMINAL = "wireless_interface_terminal";
public static final String ITEM_WIRELESS_ULTRA_TERMINAL = "wireless_ultra_terminal";
public static final String ITEM_WIRELESS_FLUID_PATTERN_TERMINAL = "wireless_fluid_pattern_terminal";
public static final String ITEM_FLUID_PART = "fluid_part";