Add Wireless Terminal Network Manager (#1268)

Co-authored-by: lordIcocain <[email protected]>
Co-authored-by: Maya <[email protected]>
Co-authored-by: Martin Robertz <[email protected]>
Co-authored-by: NeOzay <[email protected]>
Co-authored-by: Ethryan <[email protected]>
Co-authored-by: NeOzay <[email protected]>
Co-authored-by: PLASMAchicken <[email protected]>
Co-authored-by: Kogepan229 <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
12 files changed
+342 -22

No files matched your search

@@ -41,6 +41,7 @@ import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StringUtils;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent;
import net.minecraftforge.common.MinecraftForge;
import org.jetbrains.annotations.NotNull;
@@ -1184,4 +1185,12 @@ public abstract class AEBaseGui extends GuiContainer implements IGuiTooltipHandl
if (this.equals(this.mc.currentScreen)) MinecraftForge.EVENT_BUS
.post(new GuiScreenEvent.ActionPerformedEvent.Post(this, event.button, this.buttonList));
}
protected void reinitalize() {
if (!MinecraftForge.EVENT_BUS.post(new InitGuiEvent.Pre(this, this.buttonList))) {
this.buttonList.clear();
this.initGui();
}
MinecraftForge.EVENT_BUS.post(new InitGuiEvent.Post(this, this.buttonList));
}
}
@@ -32,8 +32,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent;
import net.minecraftforge.common.MinecraftForge;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.input.Keyboard;
@@ -343,13 +341,10 @@ public class GuiMEMonitorable extends AEBaseGui
}
}
private void reinitalize() {
@Override
protected void reinitalize() {
memoryText = this.searchField.getText();
if (!MinecraftForge.EVENT_BUS.post(new InitGuiEvent.Pre(this, this.buttonList))) {
this.buttonList.clear();
this.initGui();
}
MinecraftForge.EVENT_BUS.post(new InitGuiEvent.Post(this, this.buttonList));
super.reinitalize();
}
private boolean checkTypeFilter(IAEStackType<?> type) {
@@ -0,0 +1,124 @@
package appeng.client.gui.implementations;
import java.util.ArrayList;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.util.AEColor;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiColorButton;
import appeng.client.gui.widgets.MEGuiTextField;
import appeng.container.implementations.ContainerWirelessNetworkManager;
import appeng.core.localization.GuiText;
import appeng.server.ServerHelper;
import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public class GuiWirelessNetworkManager extends AEBaseGui {
private final ArrayList<GuiColorButton> colorButtons = new ArrayList<>();
private final ContainerWirelessNetworkManager containerWirelessNetworkManager;
private final MEGuiTextField renameField = new MEGuiTextField(96, 12);
private GuiColorButton buttonOnRename = null;
boolean needReInitialize = false;
public GuiWirelessNetworkManager(final InventoryPlayer inventoryPlayer, final IGuiItemObject item) {
super(new ContainerWirelessNetworkManager(inventoryPlayer, item));
this.containerWirelessNetworkManager = (ContainerWirelessNetworkManager) inventorySlots;
this.xSize = 106;
this.ySize = 232;
}
@Override
public void initGui() {
super.initGui();
this.addButtons();
this.renameField.setFocused(false);
this.renameField.setVisible(false);
this.renameField.setMaxStringLength(96);
}
private void addButtons() {
final Int2ObjectOpenHashMap<Pair<Boolean, String>> keysStatus = this.containerWirelessNetworkManager.getKeys();
for (int y = 0; y < 16; y++) {
final Pair<Boolean, String> keyStatus = keysStatus.getOrDefault(y, Pair.of(false, ""));
final GuiColorButton btn = new GuiColorButton(
y,
this.guiLeft + 5,
this.guiTop + 5 + (14 * y),
96,
12,
AEColor.values()[y],
keyStatus.value(),
GuiText.WirelessManagerToolTips.getLocal());
btn.visible = keyStatus.key();
this.colorButtons.add(btn);
this.buttonList.add(btn);
}
}
@Override
protected void actionPerformed(GuiButton button) {
for (final GuiColorButton btn : this.colorButtons) {
if (button == btn) {
if (this.isExtraAction()) {
this.renameField.x = btn.xPosition - this.guiLeft;
this.renameField.y = btn.yPosition - this.guiTop;
this.renameField.setText(btn.displayString);
this.renameField.setVisible(true);
this.renameField.setFocused(true);
this.renameField.setCursorPositionEnd();
buttonOnRename = btn;
btn.drawDisplayString = false;
} else if (isShiftKeyDown()) {
this.containerWirelessNetworkManager.removeNetwork((byte) btn.id);
this.needReInitialize = true;
} else {
this.containerWirelessNetworkManager.switch2Action((byte) btn.id);
this.needReInitialize = true;
}
this.flushPendingSync();
}
}
}
public boolean isExtraAction() {
int keyCode = ServerHelper.WIRELESS_EXTRA_ACTION.getKeyCode();
if (keyCode < 0) {
// In vanilla code, mouse buttons are registered as keyCodes with their values offset by -100.
return Mouse.isButtonDown(keyCode + 100);
} else {
return Keyboard.isKeyDown(keyCode);
}
}
@Override
protected void keyTyped(char typedChar, int keyCode) {
if ((keyCode == Keyboard.KEY_RETURN || keyCode == Keyboard.KEY_NUMPADENTER) && this.renameField.isFocused()) {
final String newName = this.renameField.getText();
this.containerWirelessNetworkManager.renameNetwork(this.buttonOnRename.getColor(), newName);
this.needReInitialize = true;
} else if (this.renameField.textboxKeyTyped(typedChar, keyCode)) {} else super.keyTyped(typedChar, keyCode);
}
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
this.renameField.drawTextBox();
if (this.needReInitialize) {
this.needReInitialize = false;
this.reinitalize();
}
}
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
this.bindTexture("guis/wireless_network_manager.png");
this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize);
}
}
@@ -1,5 +1,7 @@
package appeng.client.gui.widgets;
import java.util.Objects;
import net.minecraft.client.Minecraft;
import appeng.api.util.AEColor;
@@ -8,10 +10,16 @@ import appeng.core.localization.GuiColors;
public class GuiColorButton extends GuiAeButton {
private final AEColor color;
public boolean drawDisplayString = true;
public GuiColorButton(int id, int xPosition, int yPosition, int width, int height, AEColor color,
String tootipString) {
super(id, xPosition, yPosition, width, height, "", tootipString);
this(id, xPosition, yPosition, width, height, color, "", tootipString);
}
public GuiColorButton(int id, int xPosition, int yPosition, int width, int height, AEColor color,
String displayString, String tootipString) {
super(id, xPosition, yPosition, width, height, displayString, tootipString);
this.color = color;
}
@@ -50,6 +58,15 @@ public class GuiColorButton extends GuiAeButton {
this.yPosition + this.height - 1,
GuiColors.ColorButtonOutline.getColor());
if (this.drawDisplayString && !Objects.equals(this.displayString, "")) {
this.drawCenteredString(
mc.fontRenderer,
this.displayString,
this.xPosition + this.width / 2,
this.yPosition + (this.height - 8) / 2,
Integer.MAX_VALUE);
}
this.mouseDragged(mc, mouseX, mouseY);
}
}
@@ -303,6 +303,10 @@ public class MEGuiTextField implements ITooltip {
return field.getVisible();
}
public void setVisible(boolean visible) {
this.field.setVisible(visible);
}
public void setSelectionPos(int pos) {
field.setSelectionPos(pos);
}
@@ -1140,7 +1140,7 @@ public abstract class AEBaseContainer extends Container {
this.powerMultiplier = powerMultiplier;
}
private void portableSourceTick() {
protected void portableSourceTick() {
final Object obj = this.getTarget();
if (obj instanceof WirelessTerminalGuiObject wtgo) {
if (!wtgo.rangeCheck()) {
@@ -1154,6 +1154,19 @@ public abstract class AEBaseContainer extends Container {
}
}
this.checkItem(obj);
if (obj instanceof IEnergySource ies) {
// drain 1 ae t
this.ticks++;
if (this.ticks > 10) {
ies.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG);
this.ticks = 0;
}
}
}
protected void checkItem(final Object obj) {
if (obj instanceof IPortableCell ipc) {
final int slotIndex = ipc.getInventorySlot();
final ItemStack currentItem = getItemFromPlayerInventoryBySlotIndex(
@@ -1172,15 +1185,6 @@ public abstract class AEBaseContainer extends Container {
}
}
}
if (obj instanceof IEnergySource ies) {
// drain 1 ae t
this.ticks++;
if (this.ticks > 10) {
ies.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG);
this.ticks = 0;
}
}
}
// need for universal terminal, because getMode(ItemStack terminal) always have outdated mode
@@ -0,0 +1,136 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import org.jetbrains.annotations.NotNull;
import com.gtnewhorizon.gtnhlib.item.ItemStackNBT;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.util.AEColor;
import appeng.container.AEBaseContainer;
import appeng.container.sync.ActionHandler;
import appeng.container.sync.StreamCodecs;
import appeng.container.sync.SyncRegistrar;
import appeng.util.Platform;
import cpw.mods.fml.common.network.ByteBufUtils;
import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public class ContainerWirelessNetworkManager extends AEBaseContainer {
private final ItemStack terminal;
private final @NotNull ActionHandler<Byte> switchAction;
private final @NotNull ActionHandler<Byte> removeAction;
private final @NotNull ActionHandler<NewName> renameAction;
private final static class NewName {
public final AEColor color;
public final String name;
public NewName(AEColor color, String name) {
this.color = color;
this.name = name;
}
public NewName(ByteBuf buf) {
this.color = AEColor.fromOrdinal(buf.readInt());
this.name = ByteBufUtils.readUTF8String(buf);
}
public static void writeToPacket(ByteBuf buf, NewName value) {
buf.writeInt(value.color.ordinal());
ByteBufUtils.writeUTF8String(buf, value.name);
}
}
public ContainerWirelessNetworkManager(InventoryPlayer ip, Object anchor) {
super(ip, anchor);
this.terminal = ((IGuiItemObject) anchor).getItemStack();
final SyncRegistrar sync = this.syncRegistrar();
this.switchAction = sync.actionC2S("switch", StreamCodecs.byteValue()).onServerAction(this::setCurrent);
this.removeAction = sync.actionC2S("remove", StreamCodecs.byteValue()).onServerAction(this::remove);
this.renameAction = sync
.actionC2S("rename", StreamCodecs.of(NewName.class.getName(), NewName::writeToPacket, NewName::new))
.onServerAction(this::rename);
if (Platform.isServer()) {
final NBTTagCompound data = ItemStackNBT.get(this.terminal);
if (!data.hasKey("encryptionKeys") && data.hasKey("encryptionKey")) {
final NBTTagCompound keys = new NBTTagCompound();
final String key = data.getString("encryptionKey");
final String colorKey = AEColor.values()[0].name();
final String colorName = AEColor.values()[0].toString();
keys.setString(colorKey, key);
keys.setString(colorKey + "Name", colorName);
data.setTag("encryptionKeys", keys);
}
}
}
public Int2ObjectOpenHashMap<Pair<Boolean, String>> getKeys() {
final Int2ObjectOpenHashMap<Pair<Boolean, String>> keysStatus = new Int2ObjectOpenHashMap<>();
final NBTTagCompound data = ItemStackNBT.get(this.terminal);
if (data.hasKey("encryptionKeys")) {
final NBTTagCompound keys = data.getCompoundTag("encryptionKeys");
for (int i = 0; i < 16; i++) {
final String key = AEColor.values()[i].name();
final String name = keys.hasKey(key + "Name") ? keys.getString(key + "Name")
: AEColor.values()[i].toString();
keysStatus.put(i, Pair.of(keys.hasKey(key), name));
}
}
return keysStatus;
}
@Override
protected void portableSourceTick() {}
public void switch2Action(final byte color) {
this.switchAction.send(color);
}
private void setCurrent(final byte color) {
final NBTTagCompound data = ItemStackNBT.get(this.terminal);
final NBTTagCompound keys = data.getCompoundTag("encryptionKeys");
ItemStackNBT.of(this.terminal).setString("encryptionKey", keys.getString(AEColor.values()[color].name()));
this.checkItem(this.getTarget());
this.getInventoryPlayer().player.closeScreen();
}
public void removeNetwork(final byte color) {
this.removeAction.send(color);
this.remove(color);
}
private void remove(final byte color) {
final NBTTagCompound data = ItemStackNBT.get(this.terminal);
final NBTTagCompound keys = data.getCompoundTag("encryptionKeys");
keys.removeTag(AEColor.values()[color].name());
keys.removeTag(AEColor.values()[color].name() + "Name");
if (Platform.isServer()) this.checkItem(this.getTarget());
}
public void renameNetwork(final AEColor color, final String newName) {
final NewName n = new NewName(color, newName);
this.renameAction.send(n);
this.rename(n);
}
private void rename(final NewName newName) {
final NBTTagCompound data = ItemStackNBT.get(this.terminal);
final NBTTagCompound keys = data.getCompoundTag("encryptionKeys");
keys.setString(newName.color.name() + "Name", newName.name);
if (Platform.isServer()) this.checkItem(this.getTarget());
}
}
@@ -392,7 +392,9 @@ public enum GuiText implements Localization {
GuiDimensionalCoordShortNoDim,
itemMEStackPacketDesc1,
itemMEStackPacketDesc2;
itemMEStackPacketDesc2,
WirelessManagerToolTips;
private final String root;
@@ -104,6 +104,7 @@ import appeng.container.implementations.ContainerStorageReshuffle;
import appeng.container.implementations.ContainerVibrationChamber;
import appeng.container.implementations.ContainerWireless;
import appeng.container.implementations.ContainerWirelessKit;
import appeng.container.implementations.ContainerWirelessNetworkManager;
import appeng.core.stats.Achievements;
import appeng.helpers.ICellRestriction;
import appeng.helpers.ICustomNameObject;
@@ -253,7 +254,9 @@ public enum GuiBridge implements IGuiHandler {
GUI_CRYSTAL_GROWTH_CHAMBER(ContainerCrystalGrowthChamber.class, TileCrystalGrowthChamber.class, GuiHostType.WORLD,
null),
GUI_SUPER_WIRELESS_KIT(ContainerWirelessKit.class, IGuiItemObject.class, GuiHostType.ITEM, null);
GUI_SUPER_WIRELESS_KIT(ContainerWirelessKit.class, IGuiItemObject.class, GuiHostType.ITEM, null),
GUI_WIRELESS_NETWORK_MANAGER(ContainerWirelessNetworkManager.class, IGuiItemObject.class, GuiHostType.ITEM, null);
private final Class tileClass;
private final Class containerClass;
@@ -30,6 +30,7 @@ import appeng.api.config.SortDir;
import appeng.api.config.SortOrder;
import appeng.api.config.ViewItems;
import appeng.api.features.IWirelessTermHandler;
import appeng.api.util.AEColor;
import appeng.api.util.IConfigManager;
import appeng.core.AEConfig;
import appeng.core.AppEng;
@@ -37,6 +38,7 @@ import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText;
import appeng.core.sync.GuiBridge;
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
import appeng.server.ServerHelper;
import appeng.util.ConfigManager;
import appeng.util.Platform;
import baubles.api.BaubleType;
@@ -62,7 +64,9 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless
@Override
public ItemStack onItemRightClick(final ItemStack item, final World w, final EntityPlayer player) {
if (ForgeEventFactory.onItemUseStart(player, item, 1) > 0)
if (ServerHelper.WIRELESS_MODE_SWITCH.isKeyDown(player))
Platform.openGUI(player, null, null, GuiBridge.GUI_WIRELESS_NETWORK_MANAGER);
else if (ForgeEventFactory.onItemUseStart(player, item, 1) > 0)
AEApi.instance().registries().wireless().openWirelessTerminalGui(item, w, player);
return item;
}
@@ -125,6 +129,26 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless
@Override
public void setEncryptionKey(final ItemStack item, final String encKey, final String name) {
final NBTTagCompound data = ItemStackNBT.get(item);
final NBTTagCompound keys = data.getCompoundTag("encryptionKeys");
if (!keys.hasKey(AEColor.values()[0].name()) && data.hasKey("encryptionKey")) {
keys.setString(AEColor.values()[0].name(), data.getString("encryptionKey"));
}
String freeKey = "";
for (int i = 0; i < 16; i++) {
final String key = AEColor.values()[i].name();
if (keys.hasKey(key)) {
if (keys.getString(key).equals(encKey)) return;
} else {
freeKey = key;
break;
}
}
if (freeKey.isEmpty()) return;
keys.setString(freeKey, encKey);
data.setTag("encryptionKeys", keys);
ItemStackNBT.of(item).setString("encryptionKey", encKey).setString("name", name);
}
@@ -502,6 +502,8 @@ gui.appliedenergistics2.GuiDimensionalCoordShortNoDim=§c%s§r, §a%s§r, §9%s
gui.appliedenergistics2.itemMEStackPacketDesc1=Leftover after inject in system operation
gui.appliedenergistics2.itemMEStackPacketDesc2=Make sure you have free space and then put this item in ME Terminal
gui.appliedenergistics2.WirelessManagerToolTips=Network\n§6LClick§7 - Select\n §6+ WirelessExtraAction§7 - Rename\n §6+ Sneak§7 - Remove
# GUI Colors - ARGB
gui.color.appliedenergistics2.SearchboxFocused=6E000000
gui.color.appliedenergistics2.SearchboxUnfocused=00000000
Binary file not shown.

After

Width:  |  Height:  |  Size: 592 B