From 55a56ad79da51981e4d3c9051184db5aae48207a Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Wed, 19 Oct 2022 16:56:22 -0300 Subject: [PATCH 01/35] Start implementing wireless terminals. --- .../java/appeng/api/definitions/IItems.java | 9 +- .../api/features/IWirelessTermHandler.java | 66 ++++---- .../GuiWirelessCraftingTerminal.java | 89 ++++++++++ .../GuiWirelessFluidTerminal.java | 36 +++++ .../GuiWirelessPatternTerminal.java | 36 +++++ .../ContainerMEMonitorable.java | 9 +- .../ContainerMEPortableCell.java | 18 ++- .../ContainerWirelessCraftingTerminal.java | 152 ++++++++++++++++++ .../ContainerWirelessFluidTerminal.java | 52 ++++++ .../ContainerWirelessPatternTerminal.java | 52 ++++++ src/main/java/appeng/core/Registration.java | 4 + .../appeng/core/api/definitions/ApiItems.java | 22 +++ .../java/appeng/core/features/AEFeature.java | 4 + .../features/registries/WirelessRegistry.java | 2 +- src/main/java/appeng/core/sync/GuiBridge.java | 4 + .../helpers/WirelessTerminalGuiObject.java | 50 +++++- .../powered/ToolWirelessCraftingTerminal.java | 144 +++++++++++++++++ .../powered/ToolWirelessFluidTerminal.java | 144 +++++++++++++++++ .../powered/ToolWirelessPatternTerminal.java | 144 +++++++++++++++++ .../tools/powered/ToolWirelessTerminal.java | 7 + .../appeng/util/inv/IAEAppEngInventory.java | 4 + 21 files changed, 1005 insertions(+), 43 deletions(-) create mode 100644 src/main/java/appeng/client/gui/implementations/GuiWirelessCraftingTerminal.java create mode 100644 src/main/java/appeng/client/gui/implementations/GuiWirelessFluidTerminal.java create mode 100644 src/main/java/appeng/client/gui/implementations/GuiWirelessPatternTerminal.java create mode 100644 src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java create mode 100644 src/main/java/appeng/container/implementations/ContainerWirelessFluidTerminal.java create mode 100644 src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java create mode 100644 src/main/java/appeng/items/tools/powered/ToolWirelessCraftingTerminal.java create mode 100644 src/main/java/appeng/items/tools/powered/ToolWirelessFluidTerminal.java create mode 100644 src/main/java/appeng/items/tools/powered/ToolWirelessPatternTerminal.java diff --git a/src/api/java/appeng/api/definitions/IItems.java b/src/api/java/appeng/api/definitions/IItems.java index e7acf2686..6695c294f 100644 --- a/src/api/java/appeng/api/definitions/IItems.java +++ b/src/api/java/appeng/api/definitions/IItems.java @@ -30,8 +30,7 @@ import appeng.api.util.AEColoredItemDefinition; /** * A list of all items in AE */ -public interface IItems -{ +public interface IItems { IItemDefinition certusQuartzAxe(); IItemDefinition certusQuartzHoe(); @@ -64,6 +63,12 @@ public interface IItems IItemDefinition wirelessTerminal(); + IItemDefinition wirelessCraftingTerminal(); + + IItemDefinition wirelessPatternTerminal(); + + IItemDefinition wirelessFluidTerminal(); + IItemDefinition biometricCard(); IItemDefinition chargedStaff(); diff --git a/src/api/java/appeng/api/features/IWirelessTermHandler.java b/src/api/java/appeng/api/features/IWirelessTermHandler.java index 2d26716a4..5c865a80f 100644 --- a/src/api/java/appeng/api/features/IWirelessTermHandler.java +++ b/src/api/java/appeng/api/features/IWirelessTermHandler.java @@ -28,47 +28,45 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import appeng.api.util.IConfigManager; +import net.minecraftforge.fml.common.network.IGuiHandler; /** * A handler for a wireless terminal. */ -public interface IWirelessTermHandler extends INetworkEncodable -{ +public interface IWirelessTermHandler extends INetworkEncodable { - /** - * @param is wireless terminal - * - * @return true, if usePower, hasPower, etc... can be called for the provided item - */ - boolean canHandle( ItemStack is ); + /** + * @param is wireless terminal + * @return true, if usePower, hasPower, etc... can be called for the provided item + */ + boolean canHandle(ItemStack is); - /** - * use an amount of power, in AE units - * - * @param amount is in AE units ( 5 per MJ ), if you return false, the item should be dead and return false for - * hasPower - * @param is wireless terminal - * - * @return true if wireless terminal uses power - */ - boolean usePower( EntityPlayer player, double amount, ItemStack is ); + /** + * use an amount of power, in AE units + * + * @param amount is in AE units ( 5 per MJ ), if you return false, the item should be dead and return false for + * hasPower + * @param is wireless terminal + * @return true if wireless terminal uses power + */ + boolean usePower(EntityPlayer player, double amount, ItemStack is); - /** - * gets the power status of the item. - * - * @param is wireless terminal - * - * @return returns true if there is any power left. - */ - boolean hasPower( EntityPlayer player, double amount, ItemStack is ); + /** + * gets the power status of the item. + * + * @param is wireless terminal + * @return returns true if there is any power left. + */ + boolean hasPower(EntityPlayer player, double amount, ItemStack is); - /** - * Return the config manager for the wireless terminal. - * - * @param is wireless terminal - * - * @return config manager of wireless terminal - */ - IConfigManager getConfigManager( ItemStack is ); + /** + * Return the config manager for the wireless terminal. + * + * @param is wireless terminal + * @return config manager of wireless terminal + */ + IConfigManager getConfigManager(ItemStack is); + + IGuiHandler getGuiHandler(ItemStack is); } \ No newline at end of file diff --git a/src/main/java/appeng/client/gui/implementations/GuiWirelessCraftingTerminal.java b/src/main/java/appeng/client/gui/implementations/GuiWirelessCraftingTerminal.java new file mode 100644 index 000000000..f40a4b08d --- /dev/null +++ b/src/main/java/appeng/client/gui/implementations/GuiWirelessCraftingTerminal.java @@ -0,0 +1,89 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.client.gui.implementations; + + +import appeng.api.config.ActionItems; +import appeng.api.config.Settings; +import appeng.client.gui.widgets.GuiImgButton; +import appeng.client.me.ItemRepo; +import appeng.container.implementations.ContainerWirelessCraftingTerminal; +import appeng.container.slot.SlotCraftingMatrix; +import appeng.core.localization.GuiText; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketInventoryAction; +import appeng.helpers.InventoryAction; +import appeng.helpers.WirelessTerminalGuiObject; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; + + +public class GuiWirelessCraftingTerminal extends GuiMEMonitorable { + + private GuiImgButton clearBtn; + + public GuiWirelessCraftingTerminal(final InventoryPlayer inventoryPlayer, final WirelessTerminalGuiObject te) { + super(inventoryPlayer, te, new ContainerWirelessCraftingTerminal(inventoryPlayer, te)); + this.setReservedSpace(73); + } + + @Override + protected void actionPerformed(final GuiButton btn) { + super.actionPerformed(btn); + + if (this.clearBtn == btn) { + Slot s = null; + final Container c = this.inventorySlots; + for (final Object j : c.inventorySlots) { + if (j instanceof SlotCraftingMatrix) { + s = (Slot) j; + } + } + + if (s != null) { + final PacketInventoryAction p = new PacketInventoryAction(InventoryAction.MOVE_REGION, s.slotNumber, 0); + NetworkHandler.instance().sendToServer(p); + } + } + } + + @Override + public void initGui() { + super.initGui(); + this.buttonList.add(this.clearBtn = new GuiImgButton(this.guiLeft + 92, this.guiTop + this.ySize - 156, Settings.ACTIONS, ActionItems.STASH)); + this.clearBtn.setHalfSize(true); + } + + @Override + public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { + super.drawFG(offsetX, offsetY, mouseX, mouseY); + this.fontRenderer.drawString(GuiText.CraftingTerminal.getLocal(), 8, this.ySize - 96 + 1 - this.getReservedSpace(), 4210752); + } + + @Override + protected String getBackground() { + return "guis/crafting.png"; + } + + public ItemRepo getRepo() { + return this.repo; + } +} diff --git a/src/main/java/appeng/client/gui/implementations/GuiWirelessFluidTerminal.java b/src/main/java/appeng/client/gui/implementations/GuiWirelessFluidTerminal.java new file mode 100644 index 000000000..2c2641eec --- /dev/null +++ b/src/main/java/appeng/client/gui/implementations/GuiWirelessFluidTerminal.java @@ -0,0 +1,36 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.client.gui.implementations; + + +import appeng.api.implementations.guiobjects.IPortableCell; +import net.minecraft.entity.player.InventoryPlayer; + + +public class GuiWirelessFluidTerminal extends GuiMEPortableCell { + + public GuiWirelessFluidTerminal(final InventoryPlayer inventoryPlayer, final IPortableCell te) { + super(inventoryPlayer, te); + } + + @Override + int getMaxRows() { + return this.defaultGetMaxRows(); + } +} diff --git a/src/main/java/appeng/client/gui/implementations/GuiWirelessPatternTerminal.java b/src/main/java/appeng/client/gui/implementations/GuiWirelessPatternTerminal.java new file mode 100644 index 000000000..ea7bb55e4 --- /dev/null +++ b/src/main/java/appeng/client/gui/implementations/GuiWirelessPatternTerminal.java @@ -0,0 +1,36 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.client.gui.implementations; + + +import appeng.api.implementations.guiobjects.IPortableCell; +import net.minecraft.entity.player.InventoryPlayer; + + +public class GuiWirelessPatternTerminal extends GuiMEPortableCell { + + public GuiWirelessPatternTerminal(final InventoryPlayer inventoryPlayer, final IPortableCell te) { + super(inventoryPlayer, te); + } + + @Override + int getMaxRows() { + return this.defaultGetMaxRows(); + } +} diff --git a/src/main/java/appeng/container/implementations/ContainerMEMonitorable.java b/src/main/java/appeng/container/implementations/ContainerMEMonitorable.java index 7bf98bcb6..ebabec598 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEMonitorable.java +++ b/src/main/java/appeng/container/implementations/ContainerMEMonitorable.java @@ -21,6 +21,7 @@ package appeng.container.implementations; import appeng.api.AEApi; import appeng.api.config.*; +import appeng.api.implementations.guiobjects.IGuiItemObject; import appeng.api.implementations.guiobjects.IPortableCell; import appeng.api.implementations.tiles.IMEChest; import appeng.api.implementations.tiles.IViewCellStorage; @@ -70,7 +71,7 @@ import java.util.List; public class ContainerMEMonitorable extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver { - private final SlotRestrictedInput[] cellView = new SlotRestrictedInput[5]; + protected final SlotRestrictedInput[] cellView = new SlotRestrictedInput[5]; private final IMEMonitor monitor; public final IItemList items = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); private final IConfigManager clientCM; @@ -90,7 +91,11 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa } protected ContainerMEMonitorable(final InventoryPlayer ip, final ITerminalHost monitorable, final boolean bindInventory) { - super(ip, monitorable instanceof TileEntity ? (TileEntity) monitorable : null, monitorable instanceof IPart ? (IPart) monitorable : null); + this(ip, monitorable, null, bindInventory); + } + + protected ContainerMEMonitorable(final InventoryPlayer ip, final ITerminalHost monitorable, final IGuiItemObject iGuiItemObject, final boolean bindInventory) { + super(ip, monitorable instanceof TileEntity ? (TileEntity) monitorable : null, monitorable instanceof IPart ? (IPart) monitorable : null, iGuiItemObject); this.host = monitorable; this.clientCM = new ConfigManager(this); diff --git a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java index c1a2d43fe..25a28ea50 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java +++ b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java @@ -21,8 +21,10 @@ package appeng.container.implementations; import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; +import appeng.api.implementations.guiobjects.IGuiItemObject; import appeng.api.implementations.guiobjects.IPortableCell; import appeng.container.interfaces.IInventorySlotAware; +import appeng.helpers.WirelessTerminalGuiObject; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; @@ -31,12 +33,20 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable { private double powerMultiplier = 0.5; - private final IPortableCell civ; + protected final IPortableCell civ; private int ticks = 0; private final int slot; public ContainerMEPortableCell(final InventoryPlayer ip, final IPortableCell monitorable) { - super(ip, monitorable, false); + this(ip, monitorable, null, true); + } + + public ContainerMEPortableCell(final InventoryPlayer ip, final IPortableCell monitorable, IGuiItemObject iGuiItemObject) { + this(ip, monitorable, iGuiItemObject, true); + } + + public ContainerMEPortableCell(InventoryPlayer ip, IPortableCell monitorable, IGuiItemObject iGuiItemObject, boolean bindInventory) { + super(ip, monitorable, iGuiItemObject, bindInventory); if (monitorable instanceof IInventorySlotAware) { final int slotIndex = ((IInventorySlotAware) monitorable).getInventorySlot(); this.lockPlayerInventorySlot(slotIndex); @@ -46,7 +56,9 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable { this.lockPlayerInventorySlot(ip.currentItem); } this.civ = monitorable; - this.bindPlayerInventory(ip, 0, 0); + if (bindInventory) { + this.bindPlayerInventory(ip, 0, 0); + } } @Override diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java new file mode 100644 index 000000000..c4e5495e9 --- /dev/null +++ b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java @@ -0,0 +1,152 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.container.implementations; + + +import appeng.api.config.SecurityPermissions; +import appeng.api.implementations.tiles.IViewCellStorage; +import appeng.container.ContainerNull; +import appeng.container.slot.SlotCraftingMatrix; +import appeng.container.slot.SlotCraftingTerm; +import appeng.core.AEConfig; +import appeng.core.localization.PlayerMessages; +import appeng.helpers.IContainerCraftingPacket; +import appeng.helpers.WirelessTerminalGuiObject; +import appeng.tile.inventory.AppEngInternalInventory; +import appeng.util.Platform; +import appeng.util.inv.IAEAppEngInventory; +import appeng.util.inv.InvOperation; +import appeng.util.inv.WrapperInvItemHandler; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.wrapper.PlayerInvWrapper; + + +public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell implements IAEAppEngInventory, IContainerCraftingPacket { + + private final WirelessTerminalGuiObject wirelessTerminalGUIObject; + + private final AppEngInternalInventory output = new AppEngInternalInventory(this, 1); + private final SlotCraftingMatrix[] craftingSlots = new SlotCraftingMatrix[9]; + private final SlotCraftingTerm outputSlot; + + private final AppEngInternalInventory craftingGrid = new AppEngInternalInventory(this, 9); + + private IRecipe currentRecipe; + + public ContainerWirelessCraftingTerminal(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) { + super(ip, gui, gui, false); + this.wirelessTerminalGUIObject = gui; + + final IItemHandler crafting = this.craftingGrid; + + for (int y = 0; y < 3; y++) { + for (int x = 0; x < 3; x++) { + this.addSlotToContainer(this.craftingSlots[x + y * 3] = new SlotCraftingMatrix(this, crafting, x + y * 3, 37 + x * 18, -72 + y * 18)); + } + } + + this.addSlotToContainer(this.outputSlot = new SlotCraftingTerm(this.getPlayerInv().player, this.getActionSource(), this + .getPowerSource(), this.civ, crafting, crafting, this.output, 131, -72 + 18, this)); + + this.bindPlayerInventory(ip, 0, 0); + this.loadFromNBT(); + + this.onCraftMatrixChanged(new WrapperInvItemHandler(crafting)); + } + + @Override + public void detectAndSendChanges() { + super.detectAndSendChanges(); + + if (!this.wirelessTerminalGUIObject.rangeCheck()) { + if (Platform.isServer() && this.isValidContainer()) { + this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + } + + this.setValidContainer(false); + } else { + this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); + } + } + + @Override + public void onCraftMatrixChanged(IInventory inventory) { + final ContainerNull cn = new ContainerNull(); + final InventoryCrafting ic = new InventoryCrafting(cn, 3, 3); + + for (int x = 0; x < 9; x++) { + ic.setInventorySlotContents(x, this.craftingSlots[x].getStack()); + } + + if (this.currentRecipe == null || !this.currentRecipe.matches(ic, this.getPlayerInv().player.world)) { + this.currentRecipe = CraftingManager.findMatchingRecipe(ic, this.getPlayerInv().player.world); + } + + if (this.currentRecipe == null) { + this.outputSlot.putStack(ItemStack.EMPTY); + } else { + final ItemStack craftingResult = this.currentRecipe.getCraftingResult(ic); + + this.outputSlot.putStack(craftingResult); + } + } + + @Override + public void saveChanges() { + if (Platform.isServer()) { + NBTTagCompound tag = new NBTTagCompound(); + this.craftingGrid.writeToNBT(tag, "craftingGrid"); + this.wirelessTerminalGUIObject.saveChanges(tag); + } + } + + private void loadFromNBT() { + NBTTagCompound data = wirelessTerminalGUIObject.getItemStack().getTagCompound(); + if (data != null) { + this.craftingGrid.readFromNBT(data, "craftingGrid"); + } + } + + @Override + public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) { + if (inv == craftingGrid) { + saveChanges(); + } + } + + @Override + public IItemHandler getInventoryByName(final String name) { + if (name.equals("player")) { + return new PlayerInvWrapper(this.getInventoryPlayer()); + } + return null; + } + + @Override + public boolean useRealItems() { + return true; + } +} diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessFluidTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessFluidTerminal.java new file mode 100644 index 000000000..96acd8d42 --- /dev/null +++ b/src/main/java/appeng/container/implementations/ContainerWirelessFluidTerminal.java @@ -0,0 +1,52 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.container.implementations; + + +import appeng.core.AEConfig; +import appeng.core.localization.PlayerMessages; +import appeng.helpers.WirelessTerminalGuiObject; +import appeng.util.Platform; +import net.minecraft.entity.player.InventoryPlayer; + + +public class ContainerWirelessFluidTerminal extends ContainerMEPortableCell { + + private final WirelessTerminalGuiObject wirelessTerminalGUIObject; + + public ContainerWirelessFluidTerminal(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) { + super(ip, gui); + this.wirelessTerminalGUIObject = gui; + } + + @Override + public void detectAndSendChanges() { + super.detectAndSendChanges(); + + if (!this.wirelessTerminalGUIObject.rangeCheck()) { + if (Platform.isServer() && this.isValidContainer()) { + this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + } + + this.setValidContainer(false); + } else { + this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); + } + } +} diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java new file mode 100644 index 000000000..b2bdfc1e5 --- /dev/null +++ b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java @@ -0,0 +1,52 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.container.implementations; + + +import appeng.core.AEConfig; +import appeng.core.localization.PlayerMessages; +import appeng.helpers.WirelessTerminalGuiObject; +import appeng.util.Platform; +import net.minecraft.entity.player.InventoryPlayer; + + +public class ContainerWirelessPatternTerminal extends ContainerMEPortableCell { + + private final WirelessTerminalGuiObject wirelessTerminalGUIObject; + + public ContainerWirelessPatternTerminal(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) { + super(ip, gui); + this.wirelessTerminalGUIObject = gui; + } + + @Override + public void detectAndSendChanges() { + super.detectAndSendChanges(); + + if (!this.wirelessTerminalGUIObject.rangeCheck()) { + if (Platform.isServer() && this.isValidContainer()) { + this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + } + + this.setValidContainer(false); + } else { + this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); + } + } +} diff --git a/src/main/java/appeng/core/Registration.java b/src/main/java/appeng/core/Registration.java index c26497d82..9e021ba41 100644 --- a/src/main/java/appeng/core/Registration.java +++ b/src/main/java/appeng/core/Registration.java @@ -404,6 +404,10 @@ final class Registration { // Wireless Terminal Handler items.wirelessTerminal().maybeItem().ifPresent(terminal -> registries.wireless().registerWirelessHandler((IWirelessTermHandler) terminal)); + items.wirelessCraftingTerminal().maybeItem().ifPresent(terminal -> registries.wireless().registerWirelessHandler((IWirelessTermHandler) terminal)); + items.wirelessPatternTerminal().maybeItem().ifPresent(terminal -> registries.wireless().registerWirelessHandler((IWirelessTermHandler) terminal)); + items.wirelessFluidTerminal().maybeItem().ifPresent(terminal -> registries.wireless().registerWirelessHandler((IWirelessTermHandler) terminal)); + // Charge Rates items.chargedStaff().maybeItem().ifPresent(chargedStaff -> registries.charger().addChargeRate(chargedStaff, 320d)); diff --git a/src/main/java/appeng/core/api/definitions/ApiItems.java b/src/main/java/appeng/core/api/definitions/ApiItems.java index 103806e7e..2dbd0953f 100644 --- a/src/main/java/appeng/core/api/definitions/ApiItems.java +++ b/src/main/java/appeng/core/api/definitions/ApiItems.java @@ -78,6 +78,9 @@ public final class ApiItems implements IItems { private final IItemDefinition entropyManipulator; private final IItemDefinition wirelessTerminal; + private final IItemDefinition wirelessCraftingTerminal; + private final IItemDefinition wirelessPatternTerminal; + private final IItemDefinition wirelessFluidTerminal; private final IItemDefinition biometricCard; private final IItemDefinition chargedStaff; private final IItemDefinition massCannon; @@ -178,6 +181,10 @@ public final class ApiItems implements IItems { .dispenserBehavior(DispenserBlockTool::new) .build(); this.wirelessTerminal = powerTools.item("wireless_terminal", ToolWirelessTerminal::new).addFeatures(AEFeature.WIRELESS_ACCESS_TERMINAL).build(); + this.wirelessCraftingTerminal = powerTools.item("wireless_crafting_terminal", ToolWirelessCraftingTerminal::new).addFeatures(AEFeature.WIRELESS_CRAFTING_TERMINAL).build(); + this.wirelessPatternTerminal = powerTools.item("wireless_pattern_terminal", ToolWirelessPatternTerminal::new).addFeatures(AEFeature.WIRELESS_PATTERN_TERMINAL).build(); + this.wirelessFluidTerminal = powerTools.item("wireless_fluid_terminal", ToolWirelessFluidTerminal::new).addFeatures(AEFeature.WIRELESS_FLUID_TERMINAL).build(); + this.chargedStaff = powerTools.item("charged_staff", ToolChargedStaff::new).addFeatures(AEFeature.CHARGED_STAFF).build(); this.massCannon = powerTools.item("matter_cannon", ToolMatterCannon::new) .addFeatures(AEFeature.MATTER_CANNON) @@ -343,6 +350,21 @@ public final class ApiItems implements IItems { return this.wirelessTerminal; } + @Override + public IItemDefinition wirelessCraftingTerminal() { + return wirelessCraftingTerminal; + } + + @Override + public IItemDefinition wirelessFluidTerminal() { + return wirelessFluidTerminal; + } + + @Override + public IItemDefinition wirelessPatternTerminal() { + return wirelessPatternTerminal; + } + @Override public IItemDefinition biometricCard() { return this.biometricCard; diff --git a/src/main/java/appeng/core/features/AEFeature.java b/src/main/java/appeng/core/features/AEFeature.java index be47fd423..067654301 100644 --- a/src/main/java/appeng/core/features/AEFeature.java +++ b/src/main/java/appeng/core/features/AEFeature.java @@ -64,6 +64,10 @@ public enum AEFeature { ENTROPY_MANIPULATOR("EntropyManipulator", Constants.CATEGORY_TOOLS), MATTER_CANNON("MatterCannon", Constants.CATEGORY_TOOLS), WIRELESS_ACCESS_TERMINAL("WirelessAccessTerminal", Constants.CATEGORY_TOOLS), + WIRELESS_CRAFTING_TERMINAL("WirelessCraftingTerminal", Constants.CATEGORY_TOOLS), + WIRELESS_PATTERN_TERMINAL("WirelessPatternTerminal", Constants.CATEGORY_TOOLS), + WIRELESS_FLUID_TERMINAL("WirelessFluidTerminal", Constants.CATEGORY_TOOLS), + COLOR_APPLICATOR("ColorApplicator", Constants.CATEGORY_TOOLS), METEORITE_COMPASS("MeteoriteCompass", Constants.CATEGORY_TOOLS), diff --git a/src/main/java/appeng/core/features/registries/WirelessRegistry.java b/src/main/java/appeng/core/features/registries/WirelessRegistry.java index 35690001d..be546948b 100644 --- a/src/main/java/appeng/core/features/registries/WirelessRegistry.java +++ b/src/main/java/appeng/core/features/registries/WirelessRegistry.java @@ -94,7 +94,7 @@ public final class WirelessRegistry implements IWirelessTermRegistry { } if (handler.hasPower(player, 0.5, item)) { - Platform.openGUI(player, null, null, GuiBridge.GUI_WIRELESS_TERM); + Platform.openGUI(player, null, null, (GuiBridge) handler.getGuiHandler(item)); } else { player.sendMessage(PlayerMessages.DeviceNotPowered.get()); } diff --git a/src/main/java/appeng/core/sync/GuiBridge.java b/src/main/java/appeng/core/sync/GuiBridge.java index 48fd3bdad..1a519cc0c 100644 --- a/src/main/java/appeng/core/sync/GuiBridge.java +++ b/src/main/java/appeng/core/sync/GuiBridge.java @@ -101,6 +101,10 @@ public enum GuiBridge implements IGuiHandler { GUI_PORTABLE_CELL(ContainerMEPortableCell.class, IPortableCell.class, GuiHostType.ITEM, null), GUI_WIRELESS_TERM(ContainerWirelessTerm.class, WirelessTerminalGuiObject.class, GuiHostType.ITEM, null), + GUI_WIRELESS_CRAFTING_TERMINAL(ContainerWirelessCraftingTerminal.class, WirelessTerminalGuiObject.class, GuiHostType.ITEM, null), + GUI_WIRELESS_PATTERN_TERMINAL(ContainerWirelessPatternTerminal.class, WirelessTerminalGuiObject.class, GuiHostType.ITEM, null), + GUI_WIRELESS_FLUID_TERMINAL(ContainerWirelessFluidTerminal.class, WirelessTerminalGuiObject.class, GuiHostType.ITEM, null), + GUI_NETWORK_STATUS(ContainerNetworkStatus.class, INetworkTool.class, GuiHostType.ITEM, null), diff --git a/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java index ece89e8ec..9c9193c64 100644 --- a/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java +++ b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java @@ -26,6 +26,7 @@ import appeng.api.config.PowerMultiplier; import appeng.api.features.ILocatable; import appeng.api.features.IWirelessTermHandler; import appeng.api.implementations.guiobjects.IPortableCell; +import appeng.api.implementations.tiles.IViewCellStorage; import appeng.api.implementations.tiles.IWirelessAccessPoint; import appeng.api.networking.IGrid; import appeng.api.networking.IGridNode; @@ -43,13 +44,18 @@ import appeng.api.storage.data.IItemList; import appeng.api.util.DimensionalCoord; import appeng.api.util.IConfigManager; import appeng.container.interfaces.IInventorySlotAware; +import appeng.tile.inventory.AppEngInternalInventory; import appeng.tile.networking.TileWireless; +import appeng.util.inv.IAEAppEngInventory; +import appeng.util.inv.InvOperation; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; +import net.minecraftforge.items.IItemHandler; -public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, IInventorySlotAware { +public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, IInventorySlotAware, IViewCellStorage, IAEAppEngInventory { private final ItemStack effectiveItem; private final IWirelessTermHandler wth; @@ -63,6 +69,8 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II private double myRange = Double.MAX_VALUE; private final int inventorySlot; + private final AppEngInternalInventory viewCell = new AppEngInternalInventory(this, 5); + public WirelessTerminalGuiObject(final IWirelessTermHandler wh, final ItemStack is, final EntityPlayer ep, final World w, final int x, final int y, final int z) { this.encryptionKey = wh.getEncryptionKey(is); this.effectiveItem = is; @@ -91,6 +99,8 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II } } } + + this.loadFromNBT(); } public double getRange() { @@ -286,4 +296,42 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II return this.inventorySlot; } + @Override + public IItemHandler getViewCellStorage() { + NBTTagCompound data = effectiveItem.getTagCompound(); + if (data != null) { + viewCell.readFromNBT(data, "viewCell"); + } + return this.viewCell; + } + + @Override + public void saveChanges() { + NBTTagCompound data = effectiveItem.getTagCompound(); + if (data == null) { + data = new NBTTagCompound(); + } + viewCell.writeToNBT(data, "viewCell"); + } + + @Override + public void saveChanges(NBTTagCompound data) { + if (effectiveItem.getTagCompound() != null) { + effectiveItem.getTagCompound().merge(data); + } else { + effectiveItem.setTagCompound(data); + } + } + + private void loadFromNBT() { + NBTTagCompound data = effectiveItem.getTagCompound(); + if (data != null) { + viewCell.readFromNBT(data); + } + } + + @Override + public void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) { + + } } diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessCraftingTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessCraftingTerminal.java new file mode 100644 index 000000000..f77bf90cd --- /dev/null +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessCraftingTerminal.java @@ -0,0 +1,144 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.items.tools.powered; + + +import appeng.api.AEApi; +import appeng.api.config.Actionable; +import appeng.api.config.Settings; +import appeng.api.config.SortDir; +import appeng.api.config.SortOrder; +import appeng.api.config.ViewItems; +import appeng.api.features.IWirelessTermHandler; +import appeng.api.util.IConfigManager; +import appeng.core.AEConfig; +import appeng.core.localization.GuiText; +import appeng.core.sync.GuiBridge; +import appeng.items.tools.powered.powersink.AEBasePoweredItem; +import appeng.util.ConfigManager; +import appeng.util.Platform; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.text.translation.I18n; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.network.IGuiHandler; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import java.util.List; + + +public class ToolWirelessCraftingTerminal extends AEBasePoweredItem implements IWirelessTermHandler { + + public ToolWirelessCraftingTerminal() { + super(AEConfig.instance().getWirelessTerminalBattery()); + } + + @Override + public ActionResult onItemRightClick(final World w, final EntityPlayer player, final EnumHand hand) { + AEApi.instance().registries().wireless().openWirelessTerminalGui(player.getHeldItem(hand), w, player); + return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand)); + } + + @SideOnly(Side.CLIENT) + @Override + public boolean isFull3D() { + return false; + } + + @Override + @SideOnly(Side.CLIENT) + public void addCheckedInformation(final ItemStack stack, final World world, final List lines, final ITooltipFlag advancedTooltips) { + super.addCheckedInformation(stack, world, lines, advancedTooltips); + + if (stack.hasTagCompound()) { + final NBTTagCompound tag = Platform.openNbtData(stack); + if (tag != null) { + final String encKey = tag.getString("encryptionKey"); + + if (encKey == null || encKey.isEmpty()) { + lines.add(GuiText.Unlinked.getLocal()); + } else { + lines.add(GuiText.Linked.getLocal()); + } + } + } else { + lines.add(I18n.translateToLocal("AppEng.GuiITooltip.Unlinked")); + } + } + + @Override + public boolean canHandle(final ItemStack is) { + return AEApi.instance().definitions().items().wirelessCraftingTerminal().isSameAs(is); + } + + @Override + public boolean usePower(final EntityPlayer player, final double amount, final ItemStack is) { + return this.extractAEPower(is, amount, Actionable.MODULATE) >= amount - 0.5; + } + + @Override + public boolean hasPower(final EntityPlayer player, final double amt, final ItemStack is) { + return this.getAECurrentPower(is) >= amt; + } + + @Override + public IConfigManager getConfigManager(final ItemStack target) { + final ConfigManager out = new ConfigManager((manager, settingName, newValue) -> + { + final NBTTagCompound data = Platform.openNbtData(target); + manager.writeToNBT(data); + }); + + out.registerSetting(Settings.SORT_BY, SortOrder.NAME); + out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); + out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING); + + out.readFromNBT(Platform.openNbtData(target).copy()); + return out; + } + + @Override + public String getEncryptionKey(final ItemStack item) { + final NBTTagCompound tag = Platform.openNbtData(item); + return tag.getString("encryptionKey"); + } + + @Override + public void setEncryptionKey(final ItemStack item, final String encKey, final String name) { + final NBTTagCompound tag = Platform.openNbtData(item); + tag.setString("encryptionKey", encKey); + tag.setString("name", name); + } + + @Override + public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) { + return slotChanged; + } + + @Override + public IGuiHandler getGuiHandler(ItemStack is) { + return GuiBridge.GUI_WIRELESS_CRAFTING_TERMINAL; + } +} diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessFluidTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessFluidTerminal.java new file mode 100644 index 000000000..3465fd721 --- /dev/null +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessFluidTerminal.java @@ -0,0 +1,144 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.items.tools.powered; + + +import appeng.api.AEApi; +import appeng.api.config.Actionable; +import appeng.api.config.Settings; +import appeng.api.config.SortDir; +import appeng.api.config.SortOrder; +import appeng.api.config.ViewItems; +import appeng.api.features.IWirelessTermHandler; +import appeng.api.util.IConfigManager; +import appeng.core.AEConfig; +import appeng.core.localization.GuiText; +import appeng.core.sync.GuiBridge; +import appeng.items.tools.powered.powersink.AEBasePoweredItem; +import appeng.util.ConfigManager; +import appeng.util.Platform; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.text.translation.I18n; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.network.IGuiHandler; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import java.util.List; + + +public class ToolWirelessFluidTerminal extends AEBasePoweredItem implements IWirelessTermHandler { + + public ToolWirelessFluidTerminal() { + super(AEConfig.instance().getWirelessTerminalBattery()); + } + + @Override + public ActionResult onItemRightClick(final World w, final EntityPlayer player, final EnumHand hand) { + AEApi.instance().registries().wireless().openWirelessTerminalGui(player.getHeldItem(hand), w, player); + return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand)); + } + + @SideOnly(Side.CLIENT) + @Override + public boolean isFull3D() { + return false; + } + + @Override + @SideOnly(Side.CLIENT) + public void addCheckedInformation(final ItemStack stack, final World world, final List lines, final ITooltipFlag advancedTooltips) { + super.addCheckedInformation(stack, world, lines, advancedTooltips); + + if (stack.hasTagCompound()) { + final NBTTagCompound tag = Platform.openNbtData(stack); + if (tag != null) { + final String encKey = tag.getString("encryptionKey"); + + if (encKey == null || encKey.isEmpty()) { + lines.add(GuiText.Unlinked.getLocal()); + } else { + lines.add(GuiText.Linked.getLocal()); + } + } + } else { + lines.add(I18n.translateToLocal("AppEng.GuiITooltip.Unlinked")); + } + } + + @Override + public boolean canHandle(final ItemStack is) { + return AEApi.instance().definitions().items().wirelessFluidTerminal().isSameAs(is); + } + + @Override + public boolean usePower(final EntityPlayer player, final double amount, final ItemStack is) { + return this.extractAEPower(is, amount, Actionable.MODULATE) >= amount - 0.5; + } + + @Override + public boolean hasPower(final EntityPlayer player, final double amt, final ItemStack is) { + return this.getAECurrentPower(is) >= amt; + } + + @Override + public IConfigManager getConfigManager(final ItemStack target) { + final ConfigManager out = new ConfigManager((manager, settingName, newValue) -> + { + final NBTTagCompound data = Platform.openNbtData(target); + manager.writeToNBT(data); + }); + + out.registerSetting(Settings.SORT_BY, SortOrder.NAME); + out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); + out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING); + + out.readFromNBT(Platform.openNbtData(target).copy()); + return out; + } + + @Override + public String getEncryptionKey(final ItemStack item) { + final NBTTagCompound tag = Platform.openNbtData(item); + return tag.getString("encryptionKey"); + } + + @Override + public void setEncryptionKey(final ItemStack item, final String encKey, final String name) { + final NBTTagCompound tag = Platform.openNbtData(item); + tag.setString("encryptionKey", encKey); + tag.setString("name", name); + } + + @Override + public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) { + return slotChanged; + } + + @Override + public IGuiHandler getGuiHandler(ItemStack is) { + return GuiBridge.GUI_WIRELESS_FLUID_TERMINAL; + } +} diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessPatternTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessPatternTerminal.java new file mode 100644 index 000000000..1859a6878 --- /dev/null +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessPatternTerminal.java @@ -0,0 +1,144 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.items.tools.powered; + + +import appeng.api.AEApi; +import appeng.api.config.Actionable; +import appeng.api.config.Settings; +import appeng.api.config.SortDir; +import appeng.api.config.SortOrder; +import appeng.api.config.ViewItems; +import appeng.api.features.IWirelessTermHandler; +import appeng.api.util.IConfigManager; +import appeng.core.AEConfig; +import appeng.core.localization.GuiText; +import appeng.core.sync.GuiBridge; +import appeng.items.tools.powered.powersink.AEBasePoweredItem; +import appeng.util.ConfigManager; +import appeng.util.Platform; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.text.translation.I18n; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.network.IGuiHandler; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import java.util.List; + + +public class ToolWirelessPatternTerminal extends AEBasePoweredItem implements IWirelessTermHandler { + + public ToolWirelessPatternTerminal() { + super(AEConfig.instance().getWirelessTerminalBattery()); + } + + @Override + public ActionResult onItemRightClick(final World w, final EntityPlayer player, final EnumHand hand) { + AEApi.instance().registries().wireless().openWirelessTerminalGui(player.getHeldItem(hand), w, player); + return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand)); + } + + @SideOnly(Side.CLIENT) + @Override + public boolean isFull3D() { + return false; + } + + @Override + @SideOnly(Side.CLIENT) + public void addCheckedInformation(final ItemStack stack, final World world, final List lines, final ITooltipFlag advancedTooltips) { + super.addCheckedInformation(stack, world, lines, advancedTooltips); + + if (stack.hasTagCompound()) { + final NBTTagCompound tag = Platform.openNbtData(stack); + if (tag != null) { + final String encKey = tag.getString("encryptionKey"); + + if (encKey == null || encKey.isEmpty()) { + lines.add(GuiText.Unlinked.getLocal()); + } else { + lines.add(GuiText.Linked.getLocal()); + } + } + } else { + lines.add(I18n.translateToLocal("AppEng.GuiITooltip.Unlinked")); + } + } + + @Override + public boolean canHandle(final ItemStack is) { + return AEApi.instance().definitions().items().wirelessFluidTerminal().isSameAs(is); + } + + @Override + public boolean usePower(final EntityPlayer player, final double amount, final ItemStack is) { + return this.extractAEPower(is, amount, Actionable.MODULATE) >= amount - 0.5; + } + + @Override + public boolean hasPower(final EntityPlayer player, final double amt, final ItemStack is) { + return this.getAECurrentPower(is) >= amt; + } + + @Override + public IConfigManager getConfigManager(final ItemStack target) { + final ConfigManager out = new ConfigManager((manager, settingName, newValue) -> + { + final NBTTagCompound data = Platform.openNbtData(target); + manager.writeToNBT(data); + }); + + out.registerSetting(Settings.SORT_BY, SortOrder.NAME); + out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); + out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING); + + out.readFromNBT(Platform.openNbtData(target).copy()); + return out; + } + + @Override + public String getEncryptionKey(final ItemStack item) { + final NBTTagCompound tag = Platform.openNbtData(item); + return tag.getString("encryptionKey"); + } + + @Override + public void setEncryptionKey(final ItemStack item, final String encKey, final String name) { + final NBTTagCompound tag = Platform.openNbtData(item); + tag.setString("encryptionKey", encKey); + tag.setString("name", name); + } + + @Override + public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) { + return slotChanged; + } + + @Override + public IGuiHandler getGuiHandler(ItemStack is) { + return GuiBridge.GUI_WIRELESS_PATTERN_TERMINAL; + } +} diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java index d341dbc63..a096e5081 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java @@ -25,6 +25,7 @@ import appeng.api.features.IWirelessTermHandler; import appeng.api.util.IConfigManager; import appeng.core.AEConfig; import appeng.core.localization.GuiText; +import appeng.core.sync.GuiBridge; import appeng.items.tools.powered.powersink.AEBasePoweredItem; import appeng.util.ConfigManager; import appeng.util.Platform; @@ -37,6 +38,7 @@ import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.util.text.translation.I18n; import net.minecraft.world.World; +import net.minecraftforge.fml.common.network.IGuiHandler; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -130,4 +132,9 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) { return slotChanged; } + + @Override + public IGuiHandler getGuiHandler(ItemStack is) { + return GuiBridge.GUI_WIRELESS_TERM; + } } diff --git a/src/main/java/appeng/util/inv/IAEAppEngInventory.java b/src/main/java/appeng/util/inv/IAEAppEngInventory.java index 3e7a29e4b..687ec93ae 100644 --- a/src/main/java/appeng/util/inv/IAEAppEngInventory.java +++ b/src/main/java/appeng/util/inv/IAEAppEngInventory.java @@ -20,11 +20,15 @@ package appeng.util.inv; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.items.IItemHandler; public interface IAEAppEngInventory { void saveChanges(); + default void saveChanges(NBTTagCompound data) { + } + void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack); } From cb1011295ce82e6d03f8231e8612571e1d622090 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Wed, 19 Oct 2022 17:48:18 -0300 Subject: [PATCH 02/35] wip --- .../gui/implementations/GuiPatternTerm.java | 11 +- .../GuiWirelessPatternTerminal.java | 16 +- .../ContainerPatternEncoder.java | 66 ++++++++- .../ContainerWirelessCraftingTerminal.java | 2 - .../ContainerWirelessPatternTerminal.java | 139 +++++++++++++++++- .../powered/ToolWirelessPatternTerminal.java | 2 +- 6 files changed, 214 insertions(+), 22 deletions(-) diff --git a/src/main/java/appeng/client/gui/implementations/GuiPatternTerm.java b/src/main/java/appeng/client/gui/implementations/GuiPatternTerm.java index f7d8cd248..456dcca52 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiPatternTerm.java +++ b/src/main/java/appeng/client/gui/implementations/GuiPatternTerm.java @@ -25,7 +25,9 @@ import appeng.api.config.Settings; import appeng.api.storage.ITerminalHost; import appeng.client.gui.widgets.GuiImgButton; import appeng.client.gui.widgets.GuiTabButton; +import appeng.container.implementations.ContainerPatternEncoder; import appeng.container.implementations.ContainerPatternTerm; +import appeng.container.implementations.ContainerWirelessPatternTerminal; import appeng.container.interfaces.IJEIGhostIngredients; import appeng.container.slot.AppEngSlot; import appeng.container.slot.SlotFake; @@ -35,6 +37,7 @@ import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketInventoryAction; import appeng.core.sync.packets.PacketValueConfig; import appeng.helpers.InventoryAction; +import appeng.helpers.WirelessTerminalGuiObject; import appeng.util.item.AEItemStack; import mezz.jei.api.gui.IGhostIngredientHandler.Target; import net.minecraft.client.gui.GuiButton; @@ -60,7 +63,7 @@ public class GuiPatternTerm extends GuiMEMonitorable implements IJEIGhostIngredi private static final String CRAFTMODE_CRFTING = "1"; private static final String CRAFTMODE_PROCESSING = "0"; - private final ContainerPatternTerm container; + private final ContainerPatternEncoder container; private GuiTabButton tabCraftButton; private GuiTabButton tabProcessButton; @@ -83,6 +86,12 @@ public class GuiPatternTerm extends GuiMEMonitorable implements IJEIGhostIngredi this.setReservedSpace(81); } + public GuiPatternTerm(final InventoryPlayer inventoryPlayer, WirelessTerminalGuiObject te, final ContainerWirelessPatternTerminal wpt) { + super(inventoryPlayer, te, wpt); + this.container = (ContainerWirelessPatternTerminal) this.inventorySlots; + this.setReservedSpace(81); + } + @Override protected void actionPerformed(final GuiButton btn) { super.actionPerformed(btn); diff --git a/src/main/java/appeng/client/gui/implementations/GuiWirelessPatternTerminal.java b/src/main/java/appeng/client/gui/implementations/GuiWirelessPatternTerminal.java index ea7bb55e4..b85e313b4 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiWirelessPatternTerminal.java +++ b/src/main/java/appeng/client/gui/implementations/GuiWirelessPatternTerminal.java @@ -19,18 +19,18 @@ package appeng.client.gui.implementations; +import appeng.api.implementations.guiobjects.IGuiItemObject; import appeng.api.implementations.guiobjects.IPortableCell; +import appeng.container.implementations.ContainerWirelessCraftingTerminal; +import appeng.container.implementations.ContainerWirelessPatternTerminal; +import appeng.helpers.WirelessTerminalGuiObject; import net.minecraft.entity.player.InventoryPlayer; -public class GuiWirelessPatternTerminal extends GuiMEPortableCell { +public class GuiWirelessPatternTerminal extends GuiPatternTerm { - public GuiWirelessPatternTerminal(final InventoryPlayer inventoryPlayer, final IPortableCell te) { - super(inventoryPlayer, te); - } - - @Override - int getMaxRows() { - return this.defaultGetMaxRows(); + public GuiWirelessPatternTerminal(final InventoryPlayer inventoryPlayer, final WirelessTerminalGuiObject te) { + super(inventoryPlayer, te, new ContainerWirelessPatternTerminal(inventoryPlayer, te)); + this.setReservedSpace(81); } } diff --git a/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java b/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java index 399d80229..9e7644f01 100644 --- a/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java +++ b/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java @@ -2,6 +2,7 @@ package appeng.container.implementations; import appeng.api.AEApi; import appeng.api.definitions.IDefinitions; +import appeng.api.implementations.guiobjects.IGuiItemObject; import appeng.api.storage.ITerminalHost; import appeng.container.guisync.GuiSync; import appeng.container.slot.AppEngSlot; @@ -42,7 +43,9 @@ import static appeng.helpers.ItemStackHelper.stackWriteToNBT; public abstract class ContainerPatternEncoder extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket { - private final AbstractPartEncoder patternTerminal; + protected AbstractPartEncoder patternTerminal = null; + + protected IGuiItemObject iGuiItemObject = null; final AppEngInternalInventory cOut = new AppEngInternalInventory(null, 1); @@ -70,6 +73,14 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp patternTerminal = (AbstractPartEncoder) monitorable; } + protected ContainerPatternEncoder(InventoryPlayer ip, ITerminalHost monitorable, IGuiItemObject iGuiItemObject, boolean bindInventory) { + super(ip, monitorable, iGuiItemObject, bindInventory); + if (monitorable instanceof AbstractPartEncoder) { + patternTerminal = (AbstractPartEncoder) monitorable; + } + this.iGuiItemObject = iGuiItemObject; + } + @Override public ItemStack transferStackInSlot(final EntityPlayer p, final int idx) { if (Platform.isClient()) { @@ -99,7 +110,10 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp if (name.equals("player")) { return new PlayerInvWrapper(this.getInventoryPlayer()); } - return this.getPart().getInventoryByName(name); + if (this.getPart() != null) { + return this.getPart().getInventoryByName(name); + } + return null; } @Override @@ -492,12 +506,50 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp public void detectAndSendChanges() { super.detectAndSendChanges(); if (Platform.isServer()) { - if (this.isCraftingMode() != this.getPart().isCraftingRecipe()) { - this.setCraftingMode(this.getPart().isCraftingRecipe()); - this.updateOrderOfOutputSlots(); + if (getPart() != null) { + if (this.isCraftingMode() != this.getPart().isCraftingRecipe()) { + this.setCraftingMode(this.getPart().isCraftingRecipe()); + this.updateOrderOfOutputSlots(); + } + } + if (iGuiItemObject != null) { + NBTTagCompound nbtTagCompound = iGuiItemObject.getItemStack().getTagCompound(); + if (nbtTagCompound != null) { + if (nbtTagCompound.hasKey("isCraftingMode")) { + boolean crafting = nbtTagCompound.getBoolean("isCraftingMode"); + if (this.isCraftingMode() != crafting) { + this.setCraftingMode(crafting); + this.updateOrderOfOutputSlots(); + } + } else { + nbtTagCompound.setBoolean("isCraftingMode", false); + } + } else { + nbtTagCompound = new NBTTagCompound(); + nbtTagCompound.setBoolean("isCraftingMode", false); + iGuiItemObject.getItemStack().setTagCompound(nbtTagCompound); + } + } + if (getPart() != null) { + this.substitute = this.getPart().isSubstitution(); + } else if (iGuiItemObject != null) { + NBTTagCompound nbtTagCompound = iGuiItemObject.getItemStack().getTagCompound(); + if (nbtTagCompound != null) { + if (nbtTagCompound.hasKey("isSubstitute")) { + boolean crafting = nbtTagCompound.getBoolean("isSubstitute"); + if (this.isCraftingMode() != crafting) { + this.setCraftingMode(crafting); + this.updateOrderOfOutputSlots(); + } + } else { + nbtTagCompound.setBoolean("isSubstitute", false); + } + } else { + nbtTagCompound = new NBTTagCompound(); + nbtTagCompound.setBoolean("isSubstitute", false); + iGuiItemObject.getItemStack().setTagCompound(nbtTagCompound); + } } - - this.substitute = this.getPart().isSubstitution(); } } diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java index c4e5495e9..f459c7f37 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java @@ -19,8 +19,6 @@ package appeng.container.implementations; -import appeng.api.config.SecurityPermissions; -import appeng.api.implementations.tiles.IViewCellStorage; import appeng.container.ContainerNull; import appeng.container.slot.SlotCraftingMatrix; import appeng.container.slot.SlotCraftingTerm; diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java index b2bdfc1e5..974bc4155 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java @@ -19,25 +19,109 @@ package appeng.container.implementations; +import appeng.api.config.Actionable; +import appeng.api.config.PowerMultiplier; +import appeng.api.implementations.guiobjects.IPortableCell; +import appeng.container.interfaces.IInventorySlotAware; +import appeng.container.slot.OptionalSlotFake; +import appeng.container.slot.SlotFakeCraftingMatrix; +import appeng.container.slot.SlotPatternOutputs; +import appeng.container.slot.SlotPatternTerm; +import appeng.container.slot.SlotRestrictedInput; import appeng.core.AEConfig; import appeng.core.localization.PlayerMessages; import appeng.helpers.WirelessTerminalGuiObject; +import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.Platform; +import appeng.util.inv.InvOperation; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.items.IItemHandler; -public class ContainerWirelessPatternTerminal extends ContainerMEPortableCell { +public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder { private final WirelessTerminalGuiObject wirelessTerminalGUIObject; + private double powerMultiplier = 0.5; + protected final IPortableCell civ; + private int ticks = 0; + private final int slot; + private final AppEngInternalInventory craftingGrid = new AppEngInternalInventory(this, 9); + + protected AppEngInternalInventory output; + protected AppEngInternalInventory pattern; + public ContainerWirelessPatternTerminal(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) { - super(ip, gui); + super(ip, gui, gui, false); + + this.craftingSlots = new SlotFakeCraftingMatrix[9]; + this.outputSlots = new OptionalSlotFake[3]; + + if (gui != null) { + final int slotIndex = gui.getInventorySlot(); + this.lockPlayerInventorySlot(slotIndex); + this.slot = slotIndex; + } else { + this.slot = -1; + this.lockPlayerInventorySlot(ip.currentItem); + } + this.civ = gui; + + for (int y = 0; y < 3; y++) { + for (int x = 0; x < 3; x++) { + this.addSlotToContainer(this.craftingSlots[x + y * 3] = new SlotFakeCraftingMatrix(this.crafting, x + y * 3, 18 + x * 18, -76 + y * 18)); + } + } + + this.addSlotToContainer(this.craftSlot = new SlotPatternTerm(ip.player, this.getActionSource(), this + .getPowerSource(), gui, this.crafting, patternInv, this.cOut, 110, -76 + 18, this, 2, this)); + this.craftSlot.setIIcon(-1); + + for (int y = 0; y < this.outputSlots.length; y++) { + this.addSlotToContainer(this.outputSlots[y] = new SlotPatternOutputs(output, this, y, 110, -76 + y * 18, 0, 0, 1)); + this.outputSlots[y].setRenderDisabled(false); + this.outputSlots[y].setIIcon(-1); + } + + this.addSlotToContainer( + this.patternSlotIN = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.BLANK_PATTERN, patternInv, 0, 147, -72 - 9, this + .getInventoryPlayer())); + this.addSlotToContainer( + this.patternSlotOUT = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN, patternInv, 1, 147, -72 + 34, this + .getInventoryPlayer())); + + this.patternSlotOUT.setStackLimit(1); + + this.bindPlayerInventory(ip, 0, 0); + this.updateOrderOfOutputSlots(); + + this.bindPlayerInventory(ip, 0, 0); this.wirelessTerminalGUIObject = gui; + this.loadFromNBT(); } @Override public void detectAndSendChanges() { - super.detectAndSendChanges(); + final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); + + if (this.civ == null || currentItem.isEmpty()) { + this.setValidContainer(false); + } else if (this.civ != null && !this.civ.getItemStack().isEmpty() && currentItem != this.civ.getItemStack()) { + if (ItemStack.areItemsEqual(this.civ.getItemStack(), currentItem)) { + this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.civ.getItemStack()); + } else { + this.setValidContainer(false); + } + } + + // drain 1 ae t + this.ticks++; + if (this.ticks > 10) { + this.civ.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); + this.ticks = 0; + } if (!this.wirelessTerminalGUIObject.rangeCheck()) { if (Platform.isServer() && this.isValidContainer()) { @@ -48,5 +132,54 @@ public class ContainerWirelessPatternTerminal extends ContainerMEPortableCell { } else { this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); } + + super.detectAndSendChanges(); + } + + private double getPowerMultiplier() { + return this.powerMultiplier; + } + + void setPowerMultiplier(final double powerMultiplier) { + this.powerMultiplier = powerMultiplier; + } + + @Override + public boolean isSlotEnabled(final int idx) { + if (idx == 1) { + return Platform.isServer() ? !this.getPart().isCraftingRecipe() : !this.isCraftingMode(); + } else if (idx == 2) { + return Platform.isServer() ? this.getPart().isCraftingRecipe() : this.isCraftingMode(); + } else { + return false; + } + } + + @Override + public void saveChanges() { + if (Platform.isServer()) { + NBTTagCompound tag = new NBTTagCompound(); + this.craftingGrid.writeToNBT(tag, "craftingGrid"); + this.wirelessTerminalGUIObject.saveChanges(tag); + } + } + + private void loadFromNBT() { + NBTTagCompound data = wirelessTerminalGUIObject.getItemStack().getTagCompound(); + if (data != null) { + this.craftingGrid.readFromNBT(data, "craftingGrid"); + } + } + + @Override + public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) { + if (inv == craftingGrid) { + saveChanges(); + } + } + + @Override + public boolean useRealItems() { + return false; } } diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessPatternTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessPatternTerminal.java index 1859a6878..f55bc1d86 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessPatternTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessPatternTerminal.java @@ -90,7 +90,7 @@ public class ToolWirelessPatternTerminal extends AEBasePoweredItem implements IW @Override public boolean canHandle(final ItemStack is) { - return AEApi.instance().definitions().items().wirelessFluidTerminal().isSameAs(is); + return AEApi.instance().definitions().items().wirelessPatternTerminal().isSameAs(is); } @Override From f407a26a8f3e2f0a32fd196e324d8effdaeadfdc Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Wed, 19 Oct 2022 20:53:05 -0300 Subject: [PATCH 03/35] work on wireless pattern terminal --- .../ContainerPatternEncoder.java | 25 +++++++-- .../implementations/ContainerPatternTerm.java | 9 +--- .../ContainerWirelessPatternTerminal.java | 51 +++++++++++++------ .../core/sync/packets/PacketValueConfig.java | 31 ++--------- 4 files changed, 60 insertions(+), 56 deletions(-) diff --git a/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java b/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java index 9e7644f01..d24b83c73 100644 --- a/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java +++ b/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java @@ -53,7 +53,7 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp protected SlotPatternTerm craftSlot; protected SlotRestrictedInput patternSlotIN; protected SlotRestrictedInput patternSlotOUT; - private IRecipe currentRecipe; + protected IRecipe currentRecipe; protected SlotFakeCraftingMatrix[] craftingSlots; protected OptionalSlotFake[] outputSlots; @@ -128,7 +128,20 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp @Override public void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) { + if (inv == this.crafting) { + this.fixCraftingRecipes(); + } + } + private void fixCraftingRecipes() { + if (this.isCraftingMode()) { + for (int x = 0; x < this.crafting.getSlots(); x++) { + final ItemStack is = this.crafting.getStackInSlot(x); + if (!is.isEmpty()) { + is.setCount(1); + } + } + } } @Override @@ -215,7 +228,6 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp Optional maybePattern = AEApi.instance().definitions().items().encodedPattern().maybeStack(1); if (maybePattern.isPresent()) { output = maybePattern.get(); - this.patternSlotOUT.putStack(output); } } @@ -239,6 +251,8 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp encodedValue.setBoolean("substitute", this.isSubstitute()); output.setTagCompound(encodedValue); + + patternSlotOUT.putStack(output); } public void multiply(int multiple) { @@ -489,8 +503,9 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp return this.craftingMode; } - void setCraftingMode(final boolean craftingMode) { + public void setCraftingMode(final boolean craftingMode) { this.craftingMode = craftingMode; + this.fixCraftingRecipes(); } @@ -518,7 +533,7 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp if (nbtTagCompound.hasKey("isCraftingMode")) { boolean crafting = nbtTagCompound.getBoolean("isCraftingMode"); if (this.isCraftingMode() != crafting) { - this.setCraftingMode(crafting); + this.setCraftingMode(isCraftingMode()); this.updateOrderOfOutputSlots(); } } else { @@ -538,7 +553,7 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp if (nbtTagCompound.hasKey("isSubstitute")) { boolean crafting = nbtTagCompound.getBoolean("isSubstitute"); if (this.isCraftingMode() != crafting) { - this.setCraftingMode(crafting); + this.setCraftingMode(!crafting); this.updateOrderOfOutputSlots(); } } else { diff --git a/src/main/java/appeng/container/implementations/ContainerPatternTerm.java b/src/main/java/appeng/container/implementations/ContainerPatternTerm.java index ba597944d..3fb2dd9cb 100644 --- a/src/main/java/appeng/container/implementations/ContainerPatternTerm.java +++ b/src/main/java/appeng/container/implementations/ContainerPatternTerm.java @@ -27,15 +27,10 @@ import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; import appeng.container.ContainerNull; -import appeng.container.guisync.GuiSync; -import appeng.container.slot.AppEngSlot; -import appeng.container.slot.IOptionalSlotHost; import appeng.container.slot.OptionalSlotFake; import appeng.container.slot.SlotFakeCraftingMatrix; import appeng.container.slot.SlotPatternOutputs; import appeng.container.slot.SlotPatternTerm; -import appeng.container.slot.SlotPlayerHotBar; -import appeng.container.slot.SlotPlayerInv; import appeng.container.slot.SlotRestrictedInput; import appeng.core.sync.packets.PacketPatternSlot; import appeng.items.storage.ItemViewCell; @@ -48,10 +43,8 @@ import appeng.util.item.AEItemStack; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IContainerListener; import net.minecraft.inventory.InventoryCraftResult; import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.inventory.Slot; import net.minecraft.inventory.SlotCrafting; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; @@ -60,7 +53,7 @@ import net.minecraftforge.items.IItemHandler; public class ContainerPatternTerm extends ContainerPatternEncoder { - + public ContainerPatternTerm(final InventoryPlayer ip, final ITerminalHost monitorable) { super(ip, monitorable, false); diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java index 974bc4155..b169a12bc 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java @@ -35,20 +35,25 @@ import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.Platform; import appeng.util.inv.InvOperation; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTUtil; +import net.minecraftforge.common.util.Constants; import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.ItemStackHandler; + +import static appeng.helpers.PatternHelper.CRAFTING_GRID_DIMENSION; public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder { private final WirelessTerminalGuiObject wirelessTerminalGUIObject; - private double powerMultiplier = 0.5; protected final IPortableCell civ; private int ticks = 0; private final int slot; - private final AppEngInternalInventory craftingGrid = new AppEngInternalInventory(this, 9); protected AppEngInternalInventory output; protected AppEngInternalInventory pattern; @@ -56,6 +61,10 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder { public ContainerWirelessPatternTerminal(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) { super(ip, gui, gui, false); + this.crafting = new AppEngInternalInventory(this, CRAFTING_GRID_DIMENSION * CRAFTING_GRID_DIMENSION); + this.output = new AppEngInternalInventory(this, 3); + this.pattern = new AppEngInternalInventory(this, 2); + this.craftingSlots = new SlotFakeCraftingMatrix[9]; this.outputSlots = new OptionalSlotFake[3]; @@ -68,6 +77,9 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder { this.lockPlayerInventorySlot(ip.currentItem); } this.civ = gui; + this.wirelessTerminalGUIObject = gui; + + this.loadFromNBT(); for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { @@ -76,7 +88,7 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder { } this.addSlotToContainer(this.craftSlot = new SlotPatternTerm(ip.player, this.getActionSource(), this - .getPowerSource(), gui, this.crafting, patternInv, this.cOut, 110, -76 + 18, this, 2, this)); + .getPowerSource(), gui, this.crafting, pattern, this.cOut, 110, -76 + 18, this, 2, this)); this.craftSlot.setIIcon(-1); for (int y = 0; y < this.outputSlots.length; y++) { @@ -86,20 +98,17 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder { } this.addSlotToContainer( - this.patternSlotIN = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.BLANK_PATTERN, patternInv, 0, 147, -72 - 9, this + this.patternSlotIN = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.BLANK_PATTERN, pattern, 0, 147, -72 - 9, this .getInventoryPlayer())); this.addSlotToContainer( - this.patternSlotOUT = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN, patternInv, 1, 147, -72 + 34, this + this.patternSlotOUT = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN, pattern, 1, 147, -72 + 34, this .getInventoryPlayer())); this.patternSlotOUT.setStackLimit(1); - this.bindPlayerInventory(ip, 0, 0); this.updateOrderOfOutputSlots(); this.bindPlayerInventory(ip, 0, 0); - this.wirelessTerminalGUIObject = gui; - this.loadFromNBT(); } @Override @@ -146,10 +155,19 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder { @Override public boolean isSlotEnabled(final int idx) { + boolean crafting = false; + if (Platform.isServer()) { + NBTTagCompound nbtTagCompound = iGuiItemObject.getItemStack().getTagCompound(); + if (nbtTagCompound != null) { + if (nbtTagCompound.hasKey("isCraftingMode")) { + crafting = nbtTagCompound.getBoolean("isCraftingMode"); + } + } + } if (idx == 1) { - return Platform.isServer() ? !this.getPart().isCraftingRecipe() : !this.isCraftingMode(); + return Platform.isServer() ? !crafting : !this.isCraftingMode(); } else if (idx == 2) { - return Platform.isServer() ? this.getPart().isCraftingRecipe() : this.isCraftingMode(); + return Platform.isServer() ? crafting : this.isCraftingMode(); } else { return false; } @@ -159,7 +177,10 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder { public void saveChanges() { if (Platform.isServer()) { NBTTagCompound tag = new NBTTagCompound(); - this.craftingGrid.writeToNBT(tag, "craftingGrid"); + ((AppEngInternalInventory) crafting).writeToNBT(tag, "craftingGrid"); + + this.output.writeToNBT(tag, "output"); + this.pattern.writeToNBT(tag, "patterns"); this.wirelessTerminalGUIObject.saveChanges(tag); } } @@ -167,15 +188,15 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder { private void loadFromNBT() { NBTTagCompound data = wirelessTerminalGUIObject.getItemStack().getTagCompound(); if (data != null) { - this.craftingGrid.readFromNBT(data, "craftingGrid"); + ((AppEngInternalInventory) crafting).readFromNBT(data, "craftingGrid"); + this.output.readFromNBT(data, "output"); + this.pattern.readFromNBT(data, "patterns"); } } @Override public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) { - if (inv == craftingGrid) { - saveChanges(); - } + super.onChangeInventory(inv, slot, mc, removedStack, newStack); } @Override diff --git a/src/main/java/appeng/core/sync/packets/PacketValueConfig.java b/src/main/java/appeng/core/sync/packets/PacketValueConfig.java index 2f94a69c1..ef9156931 100644 --- a/src/main/java/appeng/core/sync/packets/PacketValueConfig.java +++ b/src/main/java/appeng/core/sync/packets/PacketValueConfig.java @@ -130,10 +130,10 @@ public class PacketValueConfig extends AppEngPacket { final ContainerFluidLevelEmitter lvc = (ContainerFluidLevelEmitter) c; lvc.setLevel(Long.parseLong(this.Value), player); } else if (this.Name.startsWith("PatternTerminal.")) { - if (c instanceof ContainerPatternTerm) { - final ContainerPatternTerm cpt = (ContainerPatternTerm) c; + if (c instanceof ContainerPatternEncoder) { + final ContainerPatternEncoder cpt = (ContainerPatternEncoder) c; if (this.Name.equals("PatternTerminal.CraftMode")) { - cpt.getPart().setCraftingRecipe(this.Value.equals("1")); + cpt.setCraftingMode(this.Value.equals("1")); } else if (this.Name.equals("PatternTerminal.Encode")) { if (this.Value.equals("2")) { cpt.encodeAndMoveToInventory(); @@ -159,31 +159,6 @@ public class PacketValueConfig extends AppEngPacket { } else if (this.Name.equals("PatternTerminal.Substitute")) { cpt.getPart().setSubstitution(this.Value.equals("1")); } - } else if (c instanceof ContainerExpandedProcessingPatternTerm) { - final ContainerExpandedProcessingPatternTerm cept = (ContainerExpandedProcessingPatternTerm) c; - if (this.Name.equals("PatternTerminal.Encode")) { - if (this.Value.equals("2")) { - cept.encodeAndMoveToInventory(); - } else { - cept.encode(); - } - } else if (this.Name.equals("PatternTerminal.Clear")) { - cept.clear(); - } else if (this.Name.equals("PatternTerminal.MultiplyByTwo")) { - cept.multiply(2); - } else if (this.Name.equals("PatternTerminal.MultiplyByThree")) { - cept.multiply(3); - } else if (this.Name.equals("PatternTerminal.DivideByTwo")) { - cept.divide(2); - } else if (this.Name.equals("PatternTerminal.DivideByThree")) { - cept.divide(3); - } else if (this.Name.equals("PatternTerminal.IncreaseByOne")) { - cept.increase(1); - } else if (this.Name.equals("PatternTerminal.DecreaseByOne")) { - cept.decrease(1); - } else if (this.Name.equals("PatternTerminal.MaximizeCount")) { - cept.maximizeCount(); - } } } else if (this.Name.startsWith("StorageBus.")) { if (this.Name.equals("StorageBus.Action")) { From 36197a5dc6642d9463113ae84c0aaa9379b895bd Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Sat, 28 Jan 2023 19:18:38 -0300 Subject: [PATCH 04/35] refresh status if a encoded pattern is put in the output slot --- .../ContainerPatternEncoder.java | 33 +++++++++++-------- .../ContainerWirelessPatternTerminal.java | 26 +++++++++++++++ 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java b/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java index d24b83c73..d3aa12e1e 100644 --- a/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java +++ b/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java @@ -133,7 +133,7 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp } } - private void fixCraftingRecipes() { + void fixCraftingRecipes() { if (this.isCraftingMode()) { for (int x = 0; x < this.crafting.getSlots(); x++) { final ItemStack is = this.crafting.getStackInSlot(x); @@ -505,7 +505,18 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp public void setCraftingMode(final boolean craftingMode) { this.craftingMode = craftingMode; - this.fixCraftingRecipes(); + if (getPart() != null) { + getPart().setCraftingRecipe(craftingMode); + } else if (iGuiItemObject != null) { + NBTTagCompound nbtTagCompound = iGuiItemObject.getItemStack().getTagCompound(); + if (nbtTagCompound != null) { + nbtTagCompound.setBoolean("isCraftingMode", craftingMode); + this.updateOrderOfOutputSlots(); + } + } + if (craftingMode) { + this.fixCraftingRecipes(); + } } @@ -526,14 +537,15 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp this.setCraftingMode(this.getPart().isCraftingRecipe()); this.updateOrderOfOutputSlots(); } + this.substitute = this.getPart().isSubstitution(); } - if (iGuiItemObject != null) { + else if (iGuiItemObject != null) { NBTTagCompound nbtTagCompound = iGuiItemObject.getItemStack().getTagCompound(); if (nbtTagCompound != null) { if (nbtTagCompound.hasKey("isCraftingMode")) { boolean crafting = nbtTagCompound.getBoolean("isCraftingMode"); if (this.isCraftingMode() != crafting) { - this.setCraftingMode(isCraftingMode()); + this.setCraftingMode(crafting); this.updateOrderOfOutputSlots(); } } else { @@ -544,17 +556,12 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp nbtTagCompound.setBoolean("isCraftingMode", false); iGuiItemObject.getItemStack().setTagCompound(nbtTagCompound); } - } - if (getPart() != null) { - this.substitute = this.getPart().isSubstitution(); - } else if (iGuiItemObject != null) { - NBTTagCompound nbtTagCompound = iGuiItemObject.getItemStack().getTagCompound(); + nbtTagCompound = iGuiItemObject.getItemStack().getTagCompound(); if (nbtTagCompound != null) { if (nbtTagCompound.hasKey("isSubstitute")) { - boolean crafting = nbtTagCompound.getBoolean("isSubstitute"); - if (this.isCraftingMode() != crafting) { - this.setCraftingMode(!crafting); - this.updateOrderOfOutputSlots(); + boolean substitute = nbtTagCompound.getBoolean("isSubstitute"); + if (this.isSubstitute() != substitute) { + this.setSubstitute(substitute); } } else { nbtTagCompound.setBoolean("isSubstitute", false); diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java index b169a12bc..68181ba8e 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java @@ -21,7 +21,10 @@ package appeng.container.implementations; import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; +import appeng.api.implementations.ICraftingPatternItem; import appeng.api.implementations.guiobjects.IPortableCell; +import appeng.api.networking.crafting.ICraftingPatternDetails; +import appeng.api.storage.data.IAEItemStack; import appeng.container.interfaces.IInventorySlotAware; import appeng.container.slot.OptionalSlotFake; import appeng.container.slot.SlotFakeCraftingMatrix; @@ -30,9 +33,11 @@ import appeng.container.slot.SlotPatternTerm; import appeng.container.slot.SlotRestrictedInput; import appeng.core.AEConfig; import appeng.core.localization.PlayerMessages; +import appeng.helpers.ItemStackHelper; import appeng.helpers.WirelessTerminalGuiObject; import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.Platform; +import appeng.util.helpers.ItemHandlerUtil; import appeng.util.inv.InvOperation; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; @@ -196,6 +201,27 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder { @Override public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) { + if (inv == this.pattern && slot == 1) { + final ItemStack is = this.pattern.getStackInSlot(1); + if (!is.isEmpty() && is.getItem() instanceof ICraftingPatternItem) { + final ICraftingPatternItem pattern = (ICraftingPatternItem) is.getItem(); + final ICraftingPatternDetails details = pattern.getPatternForItem(is, this.getPlayerInv().player.world); + if (details != null) { + this.setCraftingMode(details.isCraftable()); + this.setSubstitute(details.canSubstitute()); + + for (int x = 0; x < this.crafting.getSlots() && x < details.getInputs().length; x++) { + final IAEItemStack item = details.getInputs()[x]; + ItemHandlerUtil.setStackInSlot(this.crafting, x, item == null ? ItemStack.EMPTY : item.createItemStack()); + } + + for (int x = 0; x < this.output.getSlots() && x < details.getOutputs().length; x++) { + final IAEItemStack item = details.getOutputs()[x]; + this.output.setStackInSlot(x, item == null ? ItemStack.EMPTY : item.createItemStack()); + } + } + } + } super.onChangeInventory(inv, slot, mc, removedStack, newStack); } From 03ed421331e5438f9349c5f7f308fc8fa3aad5ca Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Sat, 28 Jan 2023 20:28:10 -0300 Subject: [PATCH 05/35] more fixes --- .../ContainerMEMonitorable.java | 4 + .../ContainerPatternEncoder.java | 112 +++++++++++++++++- .../implementations/ContainerPatternTerm.java | 109 ----------------- .../ContainerWirelessCraftingTerminal.java | 2 + .../ContainerWirelessPatternTerminal.java | 8 ++ .../core/sync/packets/PacketJEIRecipe.java | 3 +- .../core/sync/packets/PacketPatternSlot.java | 7 +- .../integration/modules/jei/JEIPlugin.java | 6 +- .../modules/jei/RecipeTransferHandler.java | 5 +- 9 files changed, 135 insertions(+), 121 deletions(-) diff --git a/src/main/java/appeng/container/implementations/ContainerMEMonitorable.java b/src/main/java/appeng/container/implementations/ContainerMEMonitorable.java index ebabec598..409f0e6f8 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEMonitorable.java +++ b/src/main/java/appeng/container/implementations/ContainerMEMonitorable.java @@ -51,6 +51,7 @@ import appeng.core.AELog; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketMEInventoryUpdate; import appeng.core.sync.packets.PacketValueConfig; +import appeng.helpers.WirelessTerminalGuiObject; import appeng.me.helpers.ChannelPowerSrc; import appeng.util.ConfigManager; import appeng.util.IConfigManagerHost; @@ -115,6 +116,9 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa if (monitorable instanceof IPortableCell) { this.setPowerSource((IEnergySource) monitorable); + if ( monitorable instanceof WirelessTerminalGuiObject) { + this.networkNode = ((WirelessTerminalGuiObject) monitorable).getActionableNode(); + } } else if (monitorable instanceof IMEChest) { this.setPowerSource((IEnergySource) monitorable); } else if (monitorable instanceof IGridHost || monitorable instanceof IActionHost) { diff --git a/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java b/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java index d3aa12e1e..e50082a16 100644 --- a/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java +++ b/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java @@ -1,9 +1,16 @@ package appeng.container.implementations; import appeng.api.AEApi; +import appeng.api.config.Actionable; import appeng.api.definitions.IDefinitions; import appeng.api.implementations.guiobjects.IGuiItemObject; +import appeng.api.networking.security.IActionHost; +import appeng.api.storage.IMEMonitor; import appeng.api.storage.ITerminalHost; +import appeng.api.storage.channels.IItemStorageChannel; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IItemList; +import appeng.container.ContainerNull; import appeng.container.guisync.GuiSync; import appeng.container.slot.AppEngSlot; import appeng.container.slot.IOptionalSlotHost; @@ -13,18 +20,23 @@ import appeng.container.slot.SlotPatternTerm; import appeng.container.slot.SlotPlayerHotBar; import appeng.container.slot.SlotPlayerInv; import appeng.container.slot.SlotRestrictedInput; +import appeng.core.sync.packets.PacketPatternSlot; import appeng.helpers.IContainerCraftingPacket; +import appeng.items.storage.ItemViewCell; +import appeng.me.helpers.MachineSource; import appeng.parts.reporting.AbstractPartEncoder; import appeng.tile.inventory.AppEngInternalInventory; +import appeng.util.InventoryAdaptor; import appeng.util.Platform; +import appeng.util.inv.AdaptorItemHandler; import appeng.util.inv.IAEAppEngInventory; import appeng.util.inv.InvOperation; +import appeng.util.inv.WrapperCursorItemHandler; +import appeng.util.item.AEItemStack; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IContainerListener; -import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.inventory.Slot; +import net.minecraft.inventory.*; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; @@ -620,4 +632,98 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp this.detectAndSendChanges(); this.getAndUpdateOutput(); } + + public void craftOrGetItem(final PacketPatternSlot packetPatternSlot) { + if (packetPatternSlot.slotItem != null && this.getCellInventory() != null) { + final IAEItemStack out = packetPatternSlot.slotItem.copy(); + InventoryAdaptor inv = new AdaptorItemHandler(new WrapperCursorItemHandler(this.getPlayerInv().player.inventory)); + final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor(this.getPlayerInv().player); + + if (packetPatternSlot.shift) { + inv = playerInv; + } + + if (!inv.simulateAdd(out.createItemStack()).isEmpty()) { + return; + } + + final IAEItemStack extracted = Platform.poweredExtraction(this.getPowerSource(), this.getCellInventory(), out, this.getActionSource()); + final EntityPlayer p = this.getPlayerInv().player; + + if (extracted != null) { + inv.addItems(extracted.createItemStack()); + if (p instanceof EntityPlayerMP) { + this.updateHeld((EntityPlayerMP) p); + } + this.detectAndSendChanges(); + return; + } + + final InventoryCrafting ic = new InventoryCrafting(new ContainerNull(), 3, 3); + final InventoryCrafting real = new InventoryCrafting(new ContainerNull(), 3, 3); + + for (int x = 0; x < 9; x++) { + ic.setInventorySlotContents(x, packetPatternSlot.pattern[x] == null ? ItemStack.EMPTY : packetPatternSlot.pattern[x].createItemStack()); + } + + final IRecipe r = CraftingManager.findMatchingRecipe(ic, p.world); + + if (r == null) { + return; + } + + IMEMonitor storage = null; + if (getPart() != null) { + storage = this.getPart() + .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + } else if (iGuiItemObject != null) { + storage = ((ITerminalHost)iGuiItemObject).getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + } + + final IItemList all = storage.getStorageList(); + + final ItemStack is = r.getCraftingResult(ic); + + for (int x = 0; x < ic.getSizeInventory(); x++) { + if (!ic.getStackInSlot(x).isEmpty()) { + final ItemStack pulled = Platform.extractItemsByRecipe(this.getPowerSource(), this.getActionSource(), storage, p.world, r, is, ic, + ic.getStackInSlot(x), x, all, Actionable.MODULATE, ItemViewCell.createFilter(this.getViewCells())); + real.setInventorySlotContents(x, pulled); + } + } + + final IRecipe rr = CraftingManager.findMatchingRecipe(real, p.world); + + if (rr == r && Platform.itemComparisons().isSameItem(rr.getCraftingResult(real), is)) { + final InventoryCraftResult craftingResult = new InventoryCraftResult(); + craftingResult.setRecipeUsed(rr); + + final SlotCrafting sc = new SlotCrafting(p, real, craftingResult, 0, 0, 0); + sc.onTake(p, is); + + for (int x = 0; x < real.getSizeInventory(); x++) { + final ItemStack failed = playerInv.addItems(real.getStackInSlot(x)); + + if (!failed.isEmpty()) { + p.dropItem(failed, false); + } + } + + inv.addItems(is); + if (p instanceof EntityPlayerMP) { + this.updateHeld((EntityPlayerMP) p); + } + this.detectAndSendChanges(); + } else { + for (int x = 0; x < real.getSizeInventory(); x++) { + final ItemStack failed = real.getStackInSlot(x); + if (!failed.isEmpty()) { + this.getCellInventory() + .injectItems(AEItemStack.fromItemStack(failed), Actionable.MODULATE, + new MachineSource(this.getPart() != null? this.getPart() : (IActionHost) iGuiItemObject)); + } + } + } + } + } } diff --git a/src/main/java/appeng/container/implementations/ContainerPatternTerm.java b/src/main/java/appeng/container/implementations/ContainerPatternTerm.java index 3fb2dd9cb..fae7e211e 100644 --- a/src/main/java/appeng/container/implementations/ContainerPatternTerm.java +++ b/src/main/java/appeng/container/implementations/ContainerPatternTerm.java @@ -19,36 +19,14 @@ package appeng.container.implementations; -import appeng.api.AEApi; -import appeng.api.config.Actionable; -import appeng.api.storage.IMEMonitor; import appeng.api.storage.ITerminalHost; -import appeng.api.storage.channels.IItemStorageChannel; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; -import appeng.container.ContainerNull; import appeng.container.slot.OptionalSlotFake; import appeng.container.slot.SlotFakeCraftingMatrix; import appeng.container.slot.SlotPatternOutputs; import appeng.container.slot.SlotPatternTerm; import appeng.container.slot.SlotRestrictedInput; -import appeng.core.sync.packets.PacketPatternSlot; -import appeng.items.storage.ItemViewCell; -import appeng.me.helpers.MachineSource; -import appeng.util.InventoryAdaptor; import appeng.util.Platform; -import appeng.util.inv.AdaptorItemHandler; -import appeng.util.inv.WrapperCursorItemHandler; -import appeng.util.item.AEItemStack; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.InventoryCraftResult; -import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.inventory.SlotCrafting; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.CraftingManager; -import net.minecraft.item.crafting.IRecipe; import net.minecraftforge.items.IItemHandler; @@ -107,91 +85,4 @@ public class ContainerPatternTerm extends ContainerPatternEncoder { } } - public void craftOrGetItem(final PacketPatternSlot packetPatternSlot) { - if (packetPatternSlot.slotItem != null && this.getCellInventory() != null) { - final IAEItemStack out = packetPatternSlot.slotItem.copy(); - InventoryAdaptor inv = new AdaptorItemHandler(new WrapperCursorItemHandler(this.getPlayerInv().player.inventory)); - final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor(this.getPlayerInv().player); - - if (packetPatternSlot.shift) { - inv = playerInv; - } - - if (!inv.simulateAdd(out.createItemStack()).isEmpty()) { - return; - } - - final IAEItemStack extracted = Platform.poweredExtraction(this.getPowerSource(), this.getCellInventory(), out, this.getActionSource()); - final EntityPlayer p = this.getPlayerInv().player; - - if (extracted != null) { - inv.addItems(extracted.createItemStack()); - if (p instanceof EntityPlayerMP) { - this.updateHeld((EntityPlayerMP) p); - } - this.detectAndSendChanges(); - return; - } - - final InventoryCrafting ic = new InventoryCrafting(new ContainerNull(), 3, 3); - final InventoryCrafting real = new InventoryCrafting(new ContainerNull(), 3, 3); - - for (int x = 0; x < 9; x++) { - ic.setInventorySlotContents(x, packetPatternSlot.pattern[x] == null ? ItemStack.EMPTY : packetPatternSlot.pattern[x].createItemStack()); - } - - final IRecipe r = CraftingManager.findMatchingRecipe(ic, p.world); - - if (r == null) { - return; - } - - final IMEMonitor storage = this.getPart() - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); - final IItemList all = storage.getStorageList(); - - final ItemStack is = r.getCraftingResult(ic); - - for (int x = 0; x < ic.getSizeInventory(); x++) { - if (!ic.getStackInSlot(x).isEmpty()) { - final ItemStack pulled = Platform.extractItemsByRecipe(this.getPowerSource(), this.getActionSource(), storage, p.world, r, is, ic, - ic.getStackInSlot(x), x, all, Actionable.MODULATE, ItemViewCell.createFilter(this.getViewCells())); - real.setInventorySlotContents(x, pulled); - } - } - - final IRecipe rr = CraftingManager.findMatchingRecipe(real, p.world); - - if (rr == r && Platform.itemComparisons().isSameItem(rr.getCraftingResult(real), is)) { - final InventoryCraftResult craftingResult = new InventoryCraftResult(); - craftingResult.setRecipeUsed(rr); - - final SlotCrafting sc = new SlotCrafting(p, real, craftingResult, 0, 0, 0); - sc.onTake(p, is); - - for (int x = 0; x < real.getSizeInventory(); x++) { - final ItemStack failed = playerInv.addItems(real.getStackInSlot(x)); - - if (!failed.isEmpty()) { - p.dropItem(failed, false); - } - } - - inv.addItems(is); - if (p instanceof EntityPlayerMP) { - this.updateHeld((EntityPlayerMP) p); - } - this.detectAndSendChanges(); - } else { - for (int x = 0; x < real.getSizeInventory(); x++) { - final ItemStack failed = real.getStackInSlot(x); - if (!failed.isEmpty()) { - this.getCellInventory() - .injectItems(AEItemStack.fromItemStack(failed), Actionable.MODULATE, - new MachineSource(this.getPart())); - } - } - } - } - } } diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java index f459c7f37..4842e5aa8 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java @@ -139,6 +139,8 @@ public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell i public IItemHandler getInventoryByName(final String name) { if (name.equals("player")) { return new PlayerInvWrapper(this.getInventoryPlayer()); + } else if (name.equals("crafting")) { + return this.craftingGrid; } return null; } diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java index 68181ba8e..95b44e7e2 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java @@ -225,6 +225,14 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder { super.onChangeInventory(inv, slot, mc, removedStack, newStack); } + @Override + public IItemHandler getInventoryByName(String name) { + if (name.equals("crafting")) { + return this.crafting; + } + return super.getInventoryByName(name); + } + @Override public boolean useRealItems() { return false; diff --git a/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java b/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java index ed989f819..bdfab5900 100644 --- a/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java +++ b/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java @@ -33,6 +33,7 @@ import appeng.api.storage.IMEMonitor; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.container.implementations.ContainerExpandedProcessingPatternTerm; +import appeng.container.implementations.ContainerPatternEncoder; import appeng.container.implementations.ContainerPatternTerm; import appeng.core.sync.AppEngPacket; import appeng.core.sync.network.INetworkInfo; @@ -252,7 +253,7 @@ public class PacketJEIRecipe extends AppEngPacket { con.onCraftMatrixChanged(new WrapperInvItemHandler(craftMatrix)); - if (this.output != null && ((con instanceof ContainerPatternTerm && !((ContainerPatternTerm) con).isCraftingMode()) || con instanceof ContainerExpandedProcessingPatternTerm)) { + if (this.output != null && ((con instanceof ContainerPatternEncoder && !((ContainerPatternEncoder) con).isCraftingMode()))) { IItemHandler outputSlots = cct.getInventoryByName("output"); for (int i = 0; i < outputSlots.getSlots(); ++i) { ItemHandlerUtil.setStackInSlot(outputSlots, i, ItemStack.EMPTY); diff --git a/src/main/java/appeng/core/sync/packets/PacketPatternSlot.java b/src/main/java/appeng/core/sync/packets/PacketPatternSlot.java index 4a22380e1..678bb3f57 100644 --- a/src/main/java/appeng/core/sync/packets/PacketPatternSlot.java +++ b/src/main/java/appeng/core/sync/packets/PacketPatternSlot.java @@ -22,6 +22,7 @@ package appeng.core.sync.packets; import appeng.api.AEApi; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; +import appeng.container.implementations.ContainerPatternEncoder; import appeng.container.implementations.ContainerPatternTerm; import appeng.core.sync.AppEngPacket; import appeng.core.sync.network.INetworkInfo; @@ -98,9 +99,9 @@ public class PacketPatternSlot extends AppEngPacket { @Override public void serverPacketData(final INetworkInfo manager, final AppEngPacket packet, final EntityPlayer player) { final EntityPlayerMP sender = (EntityPlayerMP) player; - if (sender.openContainer instanceof ContainerPatternTerm) { - final ContainerPatternTerm patternTerminal = (ContainerPatternTerm) sender.openContainer; - patternTerminal.craftOrGetItem(this); + if (sender.openContainer instanceof ContainerPatternEncoder) { + final ContainerPatternEncoder patternEncoder = (ContainerPatternEncoder) sender.openContainer; + patternEncoder.craftOrGetItem(this); } } } diff --git a/src/main/java/appeng/integration/modules/jei/JEIPlugin.java b/src/main/java/appeng/integration/modules/jei/JEIPlugin.java index fa70a2188..589ad2d7c 100644 --- a/src/main/java/appeng/integration/modules/jei/JEIPlugin.java +++ b/src/main/java/appeng/integration/modules/jei/JEIPlugin.java @@ -27,9 +27,7 @@ import appeng.api.definitions.IMaterials; import appeng.api.features.IGrinderRecipe; import appeng.api.features.IInscriberRecipe; import appeng.client.gui.AEGuiHandler; -import appeng.container.implementations.ContainerCraftingTerm; -import appeng.container.implementations.ContainerExpandedProcessingPatternTerm; -import appeng.container.implementations.ContainerPatternTerm; +import appeng.container.implementations.*; import appeng.core.AEConfig; import appeng.core.features.AEFeature; import appeng.core.localization.GuiText; @@ -86,8 +84,10 @@ public class JEIPlugin implements IModPlugin { // Allow recipe transfer from JEI to crafting and pattern terminal registry.getRecipeTransferRegistry().addRecipeTransferHandler(new RecipeTransferHandler<>(ContainerCraftingTerm.class), VanillaRecipeCategoryUid.CRAFTING); + registry.getRecipeTransferRegistry().addRecipeTransferHandler(new RecipeTransferHandler<>(ContainerWirelessCraftingTerminal.class), VanillaRecipeCategoryUid.CRAFTING); registry.getRecipeTransferRegistry().addRecipeTransferHandler(new RecipeTransferHandler<>(ContainerPatternTerm.class), Constants.UNIVERSAL_RECIPE_TRANSFER_UID); registry.getRecipeTransferRegistry().addRecipeTransferHandler(new RecipeTransferHandler<>(ContainerExpandedProcessingPatternTerm.class), Constants.UNIVERSAL_RECIPE_TRANSFER_UID); + registry.getRecipeTransferRegistry().addRecipeTransferHandler(new RecipeTransferHandler<>(ContainerWirelessPatternTerminal.class), Constants.UNIVERSAL_RECIPE_TRANSFER_UID); aeGuiHandler = new AEGuiHandler(); registry.addAdvancedGuiHandlers(aeGuiHandler); diff --git a/src/main/java/appeng/integration/modules/jei/RecipeTransferHandler.java b/src/main/java/appeng/integration/modules/jei/RecipeTransferHandler.java index 2546bc157..5bfa3ba85 100644 --- a/src/main/java/appeng/integration/modules/jei/RecipeTransferHandler.java +++ b/src/main/java/appeng/integration/modules/jei/RecipeTransferHandler.java @@ -20,6 +20,7 @@ package appeng.integration.modules.jei; import appeng.container.implementations.ContainerCraftingTerm; +import appeng.container.implementations.ContainerPatternEncoder; import appeng.container.implementations.ContainerPatternTerm; import appeng.container.slot.SlotCraftingMatrix; import appeng.container.slot.SlotFakeCraftingMatrix; @@ -82,9 +83,9 @@ class RecipeTransferHandler implements IRecipeTransferHandl return null; } - if (container instanceof ContainerPatternTerm) { + if (container instanceof ContainerPatternEncoder) { try { - if (!((ContainerPatternTerm) container).isCraftingMode()) { + if (!((ContainerPatternEncoder) container).isCraftingMode()) { if (recipeType.equals(VanillaRecipeCategoryUid.CRAFTING)) { NetworkHandler.instance().sendToServer(new PacketValueConfig("PatternTerminal.CraftMode", "1")); } From 7c4e5679a30015742cceef9799dc4c7256cfb061 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Sat, 28 Jan 2023 22:59:40 -0300 Subject: [PATCH 06/35] fluid terminal --- .../gui/implementations/GuiMEMonitorable.java | 2 +- .../implementations/GuiMEPortableCell.java | 2 +- .../gui/implementations/GuiWirelessTerm.java | 2 +- .../packets/PacketMEFluidInventoryUpdate.java | 3 + .../sync/packets/PacketTargetFluidStack.java | 3 + .../client/gui/GuiMEPortableFluidCell.java | 311 +++++++++++ .../client/gui}/GuiWirelessFluidTerminal.java | 15 +- .../ContainerMEPortableFluidCell.java | 518 ++++++++++++++++++ .../ContainerWirelessFluidTerminal.java | 5 +- 9 files changed, 847 insertions(+), 14 deletions(-) create mode 100644 src/main/java/appeng/fluids/client/gui/GuiMEPortableFluidCell.java rename src/main/java/appeng/{client/gui/implementations => fluids/client/gui}/GuiWirelessFluidTerminal.java (73%) create mode 100644 src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java rename src/main/java/appeng/{container/implementations => fluids/container}/ContainerWirelessFluidTerminal.java (94%) diff --git a/src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java b/src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java index 2567cac39..92483b728 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java +++ b/src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java @@ -442,7 +442,7 @@ public class GuiMEMonitorable 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; } diff --git a/src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java b/src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java index 697a7e80b..14346c274 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java +++ b/src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java @@ -35,7 +35,7 @@ public class GuiMEPortableCell extends GuiMEMonitorable { } @Override - int getMaxRows() { + protected int getMaxRows() { return 3; } } diff --git a/src/main/java/appeng/client/gui/implementations/GuiWirelessTerm.java b/src/main/java/appeng/client/gui/implementations/GuiWirelessTerm.java index c9a9b968b..a0bd8813c 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiWirelessTerm.java +++ b/src/main/java/appeng/client/gui/implementations/GuiWirelessTerm.java @@ -30,7 +30,7 @@ public class GuiWirelessTerm extends GuiMEPortableCell { } @Override - int getMaxRows() { + protected int getMaxRows() { return this.defaultGetMaxRows(); } } diff --git a/src/main/java/appeng/core/sync/packets/PacketMEFluidInventoryUpdate.java b/src/main/java/appeng/core/sync/packets/PacketMEFluidInventoryUpdate.java index 8b2110fff..330935658 100644 --- a/src/main/java/appeng/core/sync/packets/PacketMEFluidInventoryUpdate.java +++ b/src/main/java/appeng/core/sync/packets/PacketMEFluidInventoryUpdate.java @@ -24,6 +24,7 @@ import appeng.core.AELog; import appeng.core.sync.AppEngPacket; import appeng.core.sync.network.INetworkInfo; import appeng.fluids.client.gui.GuiFluidTerminal; +import appeng.fluids.client.gui.GuiWirelessFluidTerminal; import appeng.fluids.util.AEFluidStack; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -138,6 +139,8 @@ public class PacketMEFluidInventoryUpdate extends AppEngPacket { if (gs instanceof GuiFluidTerminal) { ((GuiFluidTerminal) gs).postUpdate(this.list); + } else if (gs instanceof GuiWirelessFluidTerminal) { + ((GuiWirelessFluidTerminal)gs).postUpdate(this.list); } } diff --git a/src/main/java/appeng/core/sync/packets/PacketTargetFluidStack.java b/src/main/java/appeng/core/sync/packets/PacketTargetFluidStack.java index 35d888226..94b7476ef 100644 --- a/src/main/java/appeng/core/sync/packets/PacketTargetFluidStack.java +++ b/src/main/java/appeng/core/sync/packets/PacketTargetFluidStack.java @@ -25,6 +25,7 @@ import appeng.core.sync.AppEngPacket; import appeng.core.sync.network.INetworkInfo; import appeng.fluids.container.ContainerFluidInterface; import appeng.fluids.container.ContainerFluidTerminal; +import appeng.fluids.container.ContainerWirelessFluidTerminal; import appeng.fluids.util.AEFluidStack; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -74,6 +75,8 @@ public class PacketTargetFluidStack extends AppEngPacket { public void serverPacketData(final INetworkInfo manager, final AppEngPacket packet, final EntityPlayer player) { if (player.openContainer instanceof ContainerFluidTerminal) { ((ContainerFluidTerminal) player.openContainer).setTargetStack(this.stack); + } else if (player.openContainer instanceof ContainerWirelessFluidTerminal) { + ((ContainerWirelessFluidTerminal) player.openContainer).setTargetStack(this.stack); } else if (player.openContainer instanceof ContainerFluidInterface) { ((ContainerFluidInterface) player.openContainer).setTargetStack(this.stack); } else if (player.openContainer instanceof ContainerFluidInterfaceConfigurationTerminal) { diff --git a/src/main/java/appeng/fluids/client/gui/GuiMEPortableFluidCell.java b/src/main/java/appeng/fluids/client/gui/GuiMEPortableFluidCell.java new file mode 100644 index 000000000..3660f1f42 --- /dev/null +++ b/src/main/java/appeng/fluids/client/gui/GuiMEPortableFluidCell.java @@ -0,0 +1,311 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.fluids.client.gui; + + +import appeng.api.config.Settings; +import appeng.api.storage.ITerminalHost; +import appeng.api.storage.data.IAEFluidStack; +import appeng.api.util.IConfigManager; +import appeng.api.util.IConfigurableObject; +import appeng.client.gui.AEBaseMEGui; +import appeng.client.gui.widgets.GuiImgButton; +import appeng.client.gui.widgets.GuiScrollbar; +import appeng.client.gui.widgets.ISortSource; +import appeng.client.gui.widgets.MEGuiTextField; +import appeng.client.me.FluidRepo; +import appeng.client.me.InternalFluidSlotME; +import appeng.client.me.SlotFluidME; +import appeng.core.AELog; +import appeng.core.localization.GuiText; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketInventoryAction; +import appeng.core.sync.packets.PacketValueConfig; +import appeng.fluids.container.ContainerMEPortableFluidCell; +import appeng.fluids.container.ContainerWirelessFluidTerminal; +import appeng.fluids.container.slots.IMEFluidSlot; +import appeng.helpers.InventoryAction; +import appeng.helpers.WirelessTerminalGuiObject; +import appeng.util.IConfigManagerHost; +import appeng.util.Platform; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ClickType; +import net.minecraft.inventory.Slot; +import net.minecraft.util.text.TextFormatting; +import net.minecraftforge.fml.common.Loader; +import org.lwjgl.input.Mouse; + +import javax.annotation.Nonnull; +import java.io.IOException; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; + + +public class GuiMEPortableFluidCell extends AEBaseMEGui implements ISortSource, IConfigManagerHost { + private final List meFluidSlots = new LinkedList<>(); + private final FluidRepo repo; + private final IConfigManager configSrc; + private final ContainerMEPortableFluidCell container; + private final int offsetX = 9; + private final int rows = 6; + private final int perRow = 9; + + protected ITerminalHost terminal; + + private MEGuiTextField searchField; + private GuiImgButton sortByBox; + private GuiImgButton sortDirBox; + + public GuiMEPortableFluidCell(InventoryPlayer inventoryPlayer, final WirelessTerminalGuiObject te, final ContainerWirelessFluidTerminal c) { + super(c); + this.terminal = te; + this.xSize = 185; + this.ySize = 222; + final GuiScrollbar scrollbar = new GuiScrollbar(); + this.setScrollBar(scrollbar); + this.repo = new FluidRepo(scrollbar, this); + this.configSrc = ((IConfigurableObject) this.inventorySlots).getConfigManager(); + (this.container = (ContainerMEPortableFluidCell) this.inventorySlots).setGui(this); + } + + @Override + public void initGui() { + this.mc.player.openContainer = this.inventorySlots; + this.guiLeft = (this.width - this.xSize) / 2; + this.guiTop = (this.height - this.ySize) / 2; + + this.searchField = new MEGuiTextField(this.fontRenderer, 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.setSelectionColor(0xFF99FF99); + this.searchField.setVisible(true); + + int offset = this.guiTop; + + 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.sortDirBox = new GuiImgButton(this.guiLeft - 18, offset, Settings.SORT_DIRECTION, this.configSrc + .getSetting(Settings.SORT_DIRECTION))); + + for (int y = 0; y < this.rows; y++) { + for (int x = 0; x < this.perRow; x++) { + SlotFluidME slot = new SlotFluidME(new InternalFluidSlotME(this.repo, x + y * this.perRow, this.offsetX + x * 18, 18 + y * 18)); + this.getMeFluidSlots().add(slot); + this.inventorySlots.inventorySlots.add(slot); + } + } + this.setScrollBar(); + } + + @Override + public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) { + this.fontRenderer.drawString(this.getGuiDisplayName("Fluid Terminal"), 8, 6, 4210752); + this.fontRenderer.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752); + } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) { + this.bindTexture(this.getBackground()); + final int x_width = 197; + this.drawTexturedModalRect(offsetX, offsetY, 0, 0, x_width, 18); + + for (int x = 0; x < 6; x++) { + this.drawTexturedModalRect(offsetX, offsetY + 18 + x * 18, 0, 18, x_width, 18); + } + + this.drawTexturedModalRect(offsetX, offsetY + 16 + 6 * 18, 0, 106 - 18 - 18, x_width, 99 + 77); + + if (this.searchField != null) { + this.searchField.drawTextBox(); + } + } + + @Override + public void updateScreen() { + this.repo.setPower(this.container.isPowered()); + super.updateScreen(); + } + + @Override + protected void renderHoveredToolTip(int mouseX, int mouseY) { + final Slot slot = this.getSlot(mouseX, mouseY); + + if (slot != null && slot instanceof IMEFluidSlot && slot.isEnabled()) { + final IMEFluidSlot fluidSlot = (IMEFluidSlot) slot; + + if (fluidSlot.getAEFluidStack() != null && fluidSlot.shouldRenderAsFluid()) { + final IAEFluidStack fluidStack = fluidSlot.getAEFluidStack(); + final String formattedAmount = NumberFormat.getNumberInstance(Locale.US).format(fluidStack.getStackSize() / 1000.0) + " B"; + + final String modName = "" + TextFormatting.BLUE + TextFormatting.ITALIC + Loader.instance() + .getIndexedModList() + .get(Platform.getModId(fluidStack)) + .getName(); + + final List list = new ArrayList<>(); + + list.add(fluidStack.getFluidStack().getLocalizedName()); + list.add(formattedAmount); + list.add(modName); + + this.drawHoveringText(list, mouseX, mouseY); + + return; + } + } + super.renderHoveredToolTip(mouseX, mouseY); + } + + @Override + protected void actionPerformed(GuiButton btn) throws IOException { + 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()); + + try { + NetworkHandler.instance().sendToServer(new PacketValueConfig(iBtn.getSetting().name(), next.name())); + } catch (final IOException e) { + AELog.debug(e); + } + + iBtn.set(next); + } + } + } + + @Override + protected void handleMouseClick(Slot slot, int slotIdx, int mouseButton, ClickType clickType) { + if (slot instanceof SlotFluidME) { + final SlotFluidME meSlot = (SlotFluidME) slot; + + if (clickType == ClickType.PICKUP) { + // TODO: Allow more options + if (mouseButton == 0 && meSlot.getHasStack()) { + this.container.setTargetStack(meSlot.getAEFluidStack()); + AELog.debug("mouse0 GUI STACK SIZE %s", meSlot.getAEFluidStack().getStackSize()); + NetworkHandler.instance().sendToServer(new PacketInventoryAction(InventoryAction.FILL_ITEM, slot.slotNumber, 0)); + } else { + this.container.setTargetStack(meSlot.getAEFluidStack()); + if (meSlot.getAEFluidStack() != null) { + AELog.debug("mouse1 GUI STACK SIZE %s", meSlot.getAEFluidStack().getStackSize()); + } + NetworkHandler.instance().sendToServer(new PacketInventoryAction(InventoryAction.EMPTY_ITEM, slot.slotNumber, 0)); + } + } + return; + } + super.handleMouseClick(slot, slotIdx, mouseButton, clickType); + } + + @Override + protected void keyTyped(final char character, final int key) throws IOException { + 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 + protected void mouseClicked(final int xCoord, final int yCoord, final int btn) throws IOException { + this.searchField.mouseClicked(xCoord, yCoord, btn); + + if (btn == 1 && this.searchField.isMouseIn(xCoord, yCoord)) { + this.searchField.setText(""); + this.repo.setSearchString(""); + this.repo.updateView(); + this.setScrollBar(); + } + + super.mouseClicked(xCoord, yCoord, btn); + } + + public void postUpdate(final List list) { + for (final IAEFluidStack is : list) { + this.repo.postUpdate(is); + } + + 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 + 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(IConfigManager manager, Enum settingName, 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)); + } + + this.repo.updateView(); + } + + protected List getMeFluidSlots() { + return this.meFluidSlots; + } + + @Override + protected boolean isPowered() { + return this.repo.hasPower(); + } + + protected String getBackground() { + return "guis/terminal.png"; + } +} diff --git a/src/main/java/appeng/client/gui/implementations/GuiWirelessFluidTerminal.java b/src/main/java/appeng/fluids/client/gui/GuiWirelessFluidTerminal.java similarity index 73% rename from src/main/java/appeng/client/gui/implementations/GuiWirelessFluidTerminal.java rename to src/main/java/appeng/fluids/client/gui/GuiWirelessFluidTerminal.java index 2c2641eec..bd3dc0882 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiWirelessFluidTerminal.java +++ b/src/main/java/appeng/fluids/client/gui/GuiWirelessFluidTerminal.java @@ -16,21 +16,18 @@ * along with Applied Energistics 2. If not, see . */ -package appeng.client.gui.implementations; +package appeng.fluids.client.gui; import appeng.api.implementations.guiobjects.IPortableCell; +import appeng.fluids.container.ContainerWirelessFluidTerminal; +import appeng.helpers.WirelessTerminalGuiObject; import net.minecraft.entity.player.InventoryPlayer; -public class GuiWirelessFluidTerminal extends GuiMEPortableCell { +public class GuiWirelessFluidTerminal extends GuiMEPortableFluidCell { - public GuiWirelessFluidTerminal(final InventoryPlayer inventoryPlayer, final IPortableCell te) { - super(inventoryPlayer, te); - } - - @Override - int getMaxRows() { - return this.defaultGetMaxRows(); + public GuiWirelessFluidTerminal(final InventoryPlayer inventoryPlayer, final WirelessTerminalGuiObject te) { + super(inventoryPlayer, te, new ContainerWirelessFluidTerminal(inventoryPlayer, te)); } } diff --git a/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java new file mode 100644 index 000000000..840ff03a1 --- /dev/null +++ b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java @@ -0,0 +1,518 @@ +package appeng.fluids.container; + +import appeng.api.AEApi; +import appeng.api.config.*; +import appeng.api.implementations.guiobjects.IPortableCell; +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.networking.energy.IEnergySource; +import appeng.api.networking.security.IActionHost; +import appeng.api.networking.security.IActionSource; +import appeng.api.networking.storage.IBaseMonitor; +import appeng.api.storage.IMEMonitor; +import appeng.api.storage.IMEMonitorHandlerReceiver; +import appeng.api.storage.ITerminalHost; +import appeng.api.storage.channels.IFluidStorageChannel; +import appeng.api.storage.data.IAEFluidStack; +import appeng.api.storage.data.IItemList; +import appeng.api.util.AEPartLocation; +import appeng.api.util.IConfigManager; +import appeng.api.util.IConfigurableObject; +import appeng.container.AEBaseContainer; +import appeng.container.guisync.GuiSync; +import appeng.container.interfaces.IInventorySlotAware; +import appeng.container.slot.AppEngSlot; +import appeng.container.slot.SlotPlayerHotBar; +import appeng.container.slot.SlotPlayerInv; +import appeng.core.AEConfig; +import appeng.core.AELog; +import appeng.core.localization.PlayerMessages; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketMEFluidInventoryUpdate; +import appeng.core.sync.packets.PacketTargetFluidStack; +import appeng.core.sync.packets.PacketValueConfig; +import appeng.fluids.util.AEFluidStack; +import appeng.helpers.InventoryAction; +import appeng.helpers.WirelessTerminalGuiObject; +import appeng.util.ConfigManager; +import appeng.util.IConfigManagerHost; +import appeng.util.Platform; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.IContainerListener; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidUtil; +import net.minecraftforge.fluids.capability.IFluidHandlerItem; + +import javax.annotation.Nonnull; +import java.io.IOException; +import java.nio.BufferOverflowException; + +public class ContainerMEPortableFluidCell extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver { + + private final WirelessTerminalGuiObject wirelessTerminalGUIObject; + + private final IConfigManager clientCM; + private final IMEMonitor monitor; + private final IItemList fluids = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class).createList(); + @GuiSync(99) + public boolean hasPower = false; + private final ITerminalHost terminal; + private IConfigManager serverCM; + private IConfigManagerHost gui; + private IGridNode networkNode; + // Holds the fluid the client wishes to extract, or null for insert + private IAEFluidStack clientRequestedTargetFluid = null; + private double powerMultiplier = 0.5; + + protected final IPortableCell civ; + private int ticks = 0; + private final int slot; + + public ContainerMEPortableFluidCell(final InventoryPlayer ip, final IPortableCell monitorable) { + this(ip, monitorable, null, true); + } + + public ContainerMEPortableFluidCell(final InventoryPlayer ip, final IPortableCell monitorable, WirelessTerminalGuiObject iGuiItemObject) { + this(ip, monitorable, iGuiItemObject, true); + } + + public ContainerMEPortableFluidCell(InventoryPlayer ip, IPortableCell monitorable, WirelessTerminalGuiObject iGuiItemObject, boolean bindInventory) { + super(ip, monitorable); + + this.terminal = monitorable; + this.wirelessTerminalGUIObject = (WirelessTerminalGuiObject) monitorable; + + this.clientCM = new ConfigManager(this); + + this.clientCM.registerSetting(Settings.SORT_BY, SortOrder.NAME); + this.clientCM.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING); + this.clientCM.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); + if (Platform.isServer()) { + this.serverCM = terminal.getConfigManager(); + this.monitor = terminal.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)); + + if (this.monitor != null) { + this.monitor.addListener(this, null); + + this.setPowerSource((IEnergySource) terminal); + if (terminal instanceof IGridHost || terminal instanceof IActionHost) { + final IGridNode node; + if (terminal instanceof IGridHost) { + node = ((IGridHost) terminal).getGridNode(AEPartLocation.INTERNAL); + } else { + node = ((IActionHost) terminal).getActionableNode(); + } + + if (node != null) { + this.networkNode = node; + } + } + } + } else { + this.monitor = null; + } + + if (monitorable instanceof IInventorySlotAware) { + final int slotIndex = ((IInventorySlotAware) monitorable).getInventorySlot(); + this.lockPlayerInventorySlot(slotIndex); + this.slot = slotIndex; + } else { + this.slot = -1; + this.lockPlayerInventorySlot(ip.currentItem); + } + this.civ = monitorable; + if (bindInventory) { + this.bindPlayerInventory(ip, 0, 140); + } + hasPower = this.civ.extractAEPower(this.getPowerMultiplier(), Actionable.SIMULATE, PowerMultiplier.CONFIG) > 0.001; + + } + + @Override + public void detectAndSendChanges() { + final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); + + if (this.civ == null || currentItem.isEmpty()) { + this.setValidContainer(false); + } else if (this.civ != null && !this.civ.getItemStack().isEmpty() && currentItem != this.civ.getItemStack()) { + if (ItemStack.areItemsEqual(this.civ.getItemStack(), currentItem)) { + this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.civ.getItemStack()); + } else { + this.setValidContainer(false); + } + } + + // drain 1 ae t + this.ticks++; + if (this.ticks > 10) { + double power = this.civ.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); + this.ticks = 0; + this.hasPower = power > 0.001; + } + + if (!this.wirelessTerminalGUIObject.rangeCheck()) { + if (Platform.isServer() && this.isValidContainer()) { + this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + } + + this.setValidContainer(false); + } else { + this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); + } + if (Platform.isServer()) { + if (this.monitor != this.terminal.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class))) { + this.setValidContainer(false); + } + + 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 IContainerListener crafter : this.listeners) { + if (crafter instanceof EntityPlayerMP) { + try { + NetworkHandler.instance().sendTo(new PacketValueConfig(set.name(), sideLocal.name()), (EntityPlayerMP) crafter); + } catch (final IOException e) { + AELog.debug(e); + } + } + } + } + } + + if (!this.fluids.isEmpty()) { + try { + final IItemList monitorCache = this.monitor.getStorageList(); + + final PacketMEFluidInventoryUpdate piu = new PacketMEFluidInventoryUpdate(); + + for (final IAEFluidStack is : this.fluids) { + final IAEFluidStack send = monitorCache.findPrecise(is); + if (send == null) { + is.setStackSize(0); + piu.appendFluid(is); + } else { + piu.appendFluid(send); + } + } + + if (!piu.isEmpty()) { + this.fluids.resetStatus(); + + for (final Object c : this.listeners) { + if (c instanceof EntityPlayer) { + NetworkHandler.instance().sendTo(piu, (EntityPlayerMP) c); + } + } + } + } catch (final IOException e) { + AELog.debug(e); + } + } + //this.updatePowerStatus(); + + } + super.detectAndSendChanges(); + } + + @Override + public ItemStack transferStackInSlot(final EntityPlayer p, final int idx) { + if (Platform.isClient()) { + return ItemStack.EMPTY; + } + EntityPlayerMP player = (EntityPlayerMP) p; + if (this.inventorySlots.get(idx) instanceof SlotPlayerInv || this.inventorySlots.get(idx) instanceof SlotPlayerHotBar) { + final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get(idx); // require AE SLots! + ItemStack itemStack = clickSlot.getStack(); + + ItemStack copy = itemStack.copy(); + copy.setCount(1); + IFluidHandlerItem fh = FluidUtil.getFluidHandler(copy); + if (fh == null) { + // only fluid handlers items + return ItemStack.EMPTY; + } + + int heldAmount = itemStack.getCount(); + for (int i = 0; i < heldAmount; i++) { + copy = itemStack.copy(); + copy.setCount(1); + fh = FluidUtil.getFluidHandler(copy); + + final FluidStack extract = fh.drain(Integer.MAX_VALUE, false); + if (extract == null || extract.amount < 1) { + return ItemStack.EMPTY; + } + + // Check if we can push into the system + final IAEFluidStack notStorable = Platform.poweredInsert(this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack(extract), this.getActionSource(), Actionable.SIMULATE); + + if (notStorable != null && notStorable.getStackSize() > 0) { + final int toStore = (int) (extract.amount - notStorable.getStackSize()); + final FluidStack storable = fh.drain(toStore, false); + + if (storable == null || storable.amount == 0) { + return ItemStack.EMPTY; + } else { + extract.amount = storable.amount; + } + } + + // Actually drain + final FluidStack drained = fh.drain(extract, true); + extract.amount = drained.amount; + + final IAEFluidStack notInserted = Platform.poweredInsert(this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack(extract), this.getActionSource()); + + if (notInserted != null && notInserted.getStackSize() > 0) { + IAEFluidStack spill = this.monitor.injectItems(notInserted, Actionable.MODULATE, this.getActionSource()); + if (spill != null && spill.getStackSize() > 0) { + fh.fill(spill.getFluidStack(), true); + } + } + + if (notInserted == null || notInserted.getStackSize() == 0) { + if (!player.inventory.addItemStackToInventory(fh.getContainer())) { + player.dropItem(fh.getContainer(), false); + } + clickSlot.decrStackSize(1); + } + } + this.detectAndSendChanges(); + return ItemStack.EMPTY; + } + return super.transferStackInSlot(p, idx); + } + + @Override + public void doAction(EntityPlayerMP player, InventoryAction action, int slot, long id) { + if (action != InventoryAction.FILL_ITEM && action != InventoryAction.EMPTY_ITEM) { + super.doAction(player, action, slot, id); + return; + } + + final ItemStack held = player.inventory.getItemStack(); + ItemStack heldCopy = held.copy(); + heldCopy.setCount(1); + IFluidHandlerItem fh = FluidUtil.getFluidHandler(heldCopy); + if (fh == null) { + // only fluid handlers items + return; + } + + if (action == InventoryAction.FILL_ITEM && this.clientRequestedTargetFluid != null) { + final IAEFluidStack stack = this.clientRequestedTargetFluid.copy(); + + // Check how much we can store in the item + stack.setStackSize(Integer.MAX_VALUE); + int amountAllowed = fh.fill(stack.getFluidStack(), false); + int heldAmount = held.getCount(); + for (int i = 0; i < heldAmount; i++) { + ItemStack copiedFluidContainer = held.copy(); + copiedFluidContainer.setCount(1); + fh = FluidUtil.getFluidHandler(copiedFluidContainer); + + // Check if we can pull out of the system + final IAEFluidStack canPull = Platform.poweredExtraction(this.getPowerSource(), this.monitor, stack.setStackSize(amountAllowed), this.getActionSource(), Actionable.SIMULATE); + if (canPull == null || canPull.getStackSize() < 1) { + return; + } + + // How much could fit into the container + final int canFill = fh.fill(canPull.getFluidStack(), false); + if (canFill == 0) { + return; + } + + // Now actually pull out of the system + final IAEFluidStack pulled = Platform.poweredExtraction(this.getPowerSource(), this.monitor, stack.setStackSize(canFill), this.getActionSource()); + if (pulled == null || pulled.getStackSize() < 1) { + // Something went wrong + AELog.error("Unable to pull fluid out of the ME system even though the simulation said yes "); + return; + } + + // Actually fill + final int used = fh.fill(pulled.getFluidStack(), true); + + if (used != canFill) { + AELog.error("Fluid item [%s] reported a different possible amount than it actually accepted.", held.getDisplayName()); + } + + if (held.getCount() == 1) { + player.inventory.setItemStack(fh.getContainer()); + } else { + player.inventory.getItemStack().shrink(1); + if (!player.inventory.addItemStackToInventory(fh.getContainer())) { + player.dropItem(fh.getContainer(), false); + } + } + } + this.updateHeld(player); + + } else if (action == InventoryAction.EMPTY_ITEM) { + int heldAmount = held.getCount(); + for (int i = 0; i < heldAmount; i++) { + ItemStack copiedFluidContainer = held.copy(); + copiedFluidContainer.setCount(1); + fh = FluidUtil.getFluidHandler(copiedFluidContainer); + + // See how much we can drain from the item + final FluidStack extract = fh.drain(Integer.MAX_VALUE, false); + if (extract == null || extract.amount < 1) { + return; + } + + // Check if we can push into the system + final IAEFluidStack notStorable = Platform.poweredInsert(this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack(extract), this.getActionSource(), Actionable.SIMULATE); + + if (notStorable != null && notStorable.getStackSize() > 0) { + final int toStore = (int) (extract.amount - notStorable.getStackSize()); + final FluidStack storable = fh.drain(toStore, false); + + if (storable == null || storable.amount == 0) { + return; + } else { + extract.amount = storable.amount; + } + } + + // Actually drain + final FluidStack drained = fh.drain(extract, true); + extract.amount = drained.amount; + + final IAEFluidStack notInserted = Platform.poweredInsert(this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack(extract), this.getActionSource()); + + if (notInserted != null && notInserted.getStackSize() > 0) { + IAEFluidStack spill = this.monitor.injectItems(notInserted, Actionable.MODULATE, this.getActionSource()); + if (spill != null && spill.getStackSize() > 0) { + fh.fill(spill.getFluidStack(), true); + } + } + + if (held.getCount() == 1) { + player.inventory.setItemStack(fh.getContainer()); + } else { + player.inventory.getItemStack().shrink(1); + if (!player.inventory.addItemStackToInventory(fh.getContainer())) { + player.dropItem(fh.getContainer(), false); + } + } + } + this.updateHeld(player); + } + } + + private double getPowerMultiplier() { + return this.powerMultiplier; + } + + void setPowerMultiplier(final double powerMultiplier) { + this.powerMultiplier = powerMultiplier; + } + + public boolean isValid(Object verificationToken) { + return true; + } + + + @Override + public void postChange(IBaseMonitor monitor, Iterable change, IActionSource actionSource) { + for (final IAEFluidStack is : change) { + this.fluids.add(is); + } + } + + @Override + public void onListUpdate() { + for (final IContainerListener c : this.listeners) { + this.queueInventory(c); + } + } + + @Override + public void addListener(IContainerListener listener) { + super.addListener(listener); + + this.queueInventory(listener); + } + + @Override + public void onContainerClosed(final EntityPlayer player) { + super.onContainerClosed(player); + if (this.monitor != null) { + this.monitor.removeListener(this); + } + } + + private void queueInventory(final IContainerListener c) { + if (Platform.isServer() && c instanceof EntityPlayer && this.monitor != null) { + try { + PacketMEFluidInventoryUpdate piu = new PacketMEFluidInventoryUpdate(); + final IItemList monitorCache = this.monitor.getStorageList(); + + for (final IAEFluidStack send : monitorCache) { + try { + piu.appendFluid(send); + } catch (final BufferOverflowException boe) { + NetworkHandler.instance().sendTo(piu, (EntityPlayerMP) c); + + piu = new PacketMEFluidInventoryUpdate(); + piu.appendFluid(send); + } + } + + NetworkHandler.instance().sendTo(piu, (EntityPlayerMP) c); + } catch (final IOException e) { + AELog.debug(e); + } + } + } + + @Override + public IConfigManager getConfigManager() { + if (Platform.isServer()) { + return this.serverCM; + } + return this.clientCM; + } + + @Override + public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue) { + if (this.getGui() != null) { + this.getGui().updateSetting(manager, settingName, newValue); + } + } + + public void setTargetStack(final IAEFluidStack stack) { + if (Platform.isClient()) { + if (stack == null && this.clientRequestedTargetFluid == null) { + return; + } + if (stack != null && this.clientRequestedTargetFluid != null && stack.getFluidStack() + .isFluidEqual(this.clientRequestedTargetFluid.getFluidStack())) { + return; + } + NetworkHandler.instance().sendToServer(new PacketTargetFluidStack((AEFluidStack) stack)); + } + + this.clientRequestedTargetFluid = stack == null ? null : stack.copy(); + } + + private IConfigManagerHost getGui() { + return this.gui; + } + + public boolean isPowered() { + return this.hasPower; + } + + public void setGui(@Nonnull final IConfigManagerHost gui) { + this.gui = gui; + } +} diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessFluidTerminal.java b/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java similarity index 94% rename from src/main/java/appeng/container/implementations/ContainerWirelessFluidTerminal.java rename to src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java index 96acd8d42..26f5497fb 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessFluidTerminal.java +++ b/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java @@ -16,9 +16,10 @@ * along with Applied Energistics 2. If not, see . */ -package appeng.container.implementations; +package appeng.fluids.container; +import appeng.container.implementations.ContainerMEPortableCell; import appeng.core.AEConfig; import appeng.core.localization.PlayerMessages; import appeng.helpers.WirelessTerminalGuiObject; @@ -26,7 +27,7 @@ import appeng.util.Platform; import net.minecraft.entity.player.InventoryPlayer; -public class ContainerWirelessFluidTerminal extends ContainerMEPortableCell { +public class ContainerWirelessFluidTerminal extends ContainerMEPortableFluidCell { private final WirelessTerminalGuiObject wirelessTerminalGUIObject; From 13c30670682ccfb43c513e4624b8210f11e40750 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Mon, 30 Jan 2023 14:58:55 -0300 Subject: [PATCH 07/35] add upgrade slots --- .../IUpgradeableCellContainer.java | 7 ++ .../implementations/IUpgradeableCellHost.java | 41 +++++++++++ .../implementations/GuiMEPortableCell.java | 3 +- .../GuiWirelessPatternTerminal.java | 3 - .../ContainerMEPortableCell.java | 71 +++++++++++++------ .../ContainerPatternEncoder.java | 12 +--- .../ContainerWirelessCraftingTerminal.java | 19 +---- .../ContainerWirelessPatternTerminal.java | 47 +++++++----- .../ContainerWirelessTerm.java | 2 +- .../features/registries/WirelessRegistry.java | 11 +++ .../ContainerMEPortableFluidCell.java | 60 ++++++++++------ .../ContainerWirelessFluidTerminal.java | 1 - .../helpers/WirelessTerminalGuiObject.java | 18 ++++- 13 files changed, 198 insertions(+), 97 deletions(-) create mode 100644 src/api/java/appeng/api/implementations/IUpgradeableCellContainer.java create mode 100644 src/api/java/appeng/api/implementations/IUpgradeableCellHost.java diff --git a/src/api/java/appeng/api/implementations/IUpgradeableCellContainer.java b/src/api/java/appeng/api/implementations/IUpgradeableCellContainer.java new file mode 100644 index 000000000..1f1283a80 --- /dev/null +++ b/src/api/java/appeng/api/implementations/IUpgradeableCellContainer.java @@ -0,0 +1,7 @@ +package appeng.api.implementations; + +public interface IUpgradeableCellContainer { + int availableUpgrades(); + + void setupUpgrades(); +} diff --git a/src/api/java/appeng/api/implementations/IUpgradeableCellHost.java b/src/api/java/appeng/api/implementations/IUpgradeableCellHost.java new file mode 100644 index 000000000..b454316a8 --- /dev/null +++ b/src/api/java/appeng/api/implementations/IUpgradeableCellHost.java @@ -0,0 +1,41 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2013 AlgorithmX2 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package appeng.api.implementations; + + +import appeng.api.config.Upgrades; +import appeng.api.implementations.tiles.ISegmentedInventory; +import appeng.api.util.IConfigurableObject; + + +public interface IUpgradeableCellHost extends IConfigurableObject, ISegmentedInventory { + + /** + * determine how many of an upgrade are installed. + */ + default int getInstalledUpgrades(Upgrades u) { + return 0; + } + +} diff --git a/src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java b/src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java index 14346c274..89dc0dcdc 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java +++ b/src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java @@ -20,14 +20,13 @@ package appeng.client.gui.implementations; import appeng.api.implementations.guiobjects.IPortableCell; -import appeng.container.implementations.ContainerMEPortableCell; import net.minecraft.entity.player.InventoryPlayer; public class GuiMEPortableCell extends GuiMEMonitorable { public GuiMEPortableCell(final InventoryPlayer inventoryPlayer, final IPortableCell te) { - super(inventoryPlayer, te, new ContainerMEPortableCell(inventoryPlayer, te)); + super(inventoryPlayer, te); } int defaultGetMaxRows() { diff --git a/src/main/java/appeng/client/gui/implementations/GuiWirelessPatternTerminal.java b/src/main/java/appeng/client/gui/implementations/GuiWirelessPatternTerminal.java index b85e313b4..b326d895c 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiWirelessPatternTerminal.java +++ b/src/main/java/appeng/client/gui/implementations/GuiWirelessPatternTerminal.java @@ -19,9 +19,6 @@ package appeng.client.gui.implementations; -import appeng.api.implementations.guiobjects.IGuiItemObject; -import appeng.api.implementations.guiobjects.IPortableCell; -import appeng.container.implementations.ContainerWirelessCraftingTerminal; import appeng.container.implementations.ContainerWirelessPatternTerminal; import appeng.helpers.WirelessTerminalGuiObject; import net.minecraft.entity.player.InventoryPlayer; diff --git a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java index 25a28ea50..458dbbc81 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java +++ b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java @@ -21,33 +21,29 @@ package appeng.container.implementations; import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; -import appeng.api.implementations.guiobjects.IGuiItemObject; -import appeng.api.implementations.guiobjects.IPortableCell; +import appeng.api.implementations.IUpgradeableCellContainer; import appeng.container.interfaces.IInventorySlotAware; +import appeng.container.slot.SlotRestrictedInput; +import appeng.core.AEConfig; +import appeng.core.localization.PlayerMessages; import appeng.helpers.WirelessTerminalGuiObject; +import appeng.util.Platform; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; -public class ContainerMEPortableCell extends ContainerMEMonitorable { +public class ContainerMEPortableCell extends ContainerMEMonitorable implements IUpgradeableCellContainer { - private double powerMultiplier = 0.5; - - protected final IPortableCell civ; - private int ticks = 0; + protected final WirelessTerminalGuiObject wirelessTerminalGUIObject; private final int slot; + private double powerMultiplier = 0.5; + private int ticks = 0; - public ContainerMEPortableCell(final InventoryPlayer ip, final IPortableCell monitorable) { - this(ip, monitorable, null, true); - } - public ContainerMEPortableCell(final InventoryPlayer ip, final IPortableCell monitorable, IGuiItemObject iGuiItemObject) { - this(ip, monitorable, iGuiItemObject, true); - } - - public ContainerMEPortableCell(InventoryPlayer ip, IPortableCell monitorable, IGuiItemObject iGuiItemObject, boolean bindInventory) { - super(ip, monitorable, iGuiItemObject, bindInventory); - if (monitorable instanceof IInventorySlotAware) { + public ContainerMEPortableCell(InventoryPlayer ip, WirelessTerminalGuiObject monitorable, boolean bindInventory) { + super(ip, monitorable, bindInventory); + if (monitorable != null) { final int slotIndex = ((IInventorySlotAware) monitorable).getInventorySlot(); this.lockPlayerInventorySlot(slotIndex); this.slot = slotIndex; @@ -55,21 +51,22 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable { this.slot = -1; this.lockPlayerInventorySlot(ip.currentItem); } - this.civ = monitorable; + this.wirelessTerminalGUIObject = monitorable; if (bindInventory) { this.bindPlayerInventory(ip, 0, 0); } + this.setupUpgrades(); } @Override public void detectAndSendChanges() { final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); - if (this.civ == null || currentItem.isEmpty()) { + if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { this.setValidContainer(false); - } else if (this.civ != null && !this.civ.getItemStack().isEmpty() && currentItem != this.civ.getItemStack()) { - if (ItemStack.areItemsEqual(this.civ.getItemStack(), currentItem)) { - this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.civ.getItemStack()); + } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { + if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { + this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack()); } else { this.setValidContainer(false); } @@ -78,9 +75,20 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable { // drain 1 ae t this.ticks++; if (this.ticks > 10) { - this.civ.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); + this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); this.ticks = 0; } + + if (!this.wirelessTerminalGUIObject.rangeCheck()) { + if (Platform.isServer() && this.isValidContainer()) { + this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + } + + this.setValidContainer(false); + } else { + this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); + } + super.detectAndSendChanges(); } @@ -91,4 +99,21 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable { void setPowerMultiplier(final double powerMultiplier) { this.powerMultiplier = powerMultiplier; } + + public int availableUpgrades() { + return 2; + } + + @Override + public void setupUpgrades() { + if (wirelessTerminalGUIObject != null) { + final IItemHandler upgrades = wirelessTerminalGUIObject.getInventoryByName("upgrades"); + for (int a = 0; a < availableUpgrades(); a++) { + this.addSlotToContainer( + (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, a * 18, this.getInventoryPlayer())) + .setNotDraggable()); + } + } + } + } diff --git a/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java b/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java index e50082a16..0a8017778 100644 --- a/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java +++ b/src/main/java/appeng/container/implementations/ContainerPatternEncoder.java @@ -75,11 +75,6 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp @GuiSync(96) public boolean substitute = false; - public ContainerPatternEncoder(InventoryPlayer ip, ITerminalHost monitorable) { - super(ip, monitorable); - patternTerminal = (AbstractPartEncoder) monitorable; - } - protected ContainerPatternEncoder(InventoryPlayer ip, ITerminalHost monitorable, boolean bindInventory) { super(ip, monitorable, bindInventory); patternTerminal = (AbstractPartEncoder) monitorable; @@ -550,8 +545,7 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp this.updateOrderOfOutputSlots(); } this.substitute = this.getPart().isSubstitution(); - } - else if (iGuiItemObject != null) { + } else if (iGuiItemObject != null) { NBTTagCompound nbtTagCompound = iGuiItemObject.getItemStack().getTagCompound(); if (nbtTagCompound != null) { if (nbtTagCompound.hasKey("isCraftingMode")) { @@ -677,7 +671,7 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp storage = this.getPart() .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); } else if (iGuiItemObject != null) { - storage = ((ITerminalHost)iGuiItemObject).getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + storage = ((ITerminalHost) iGuiItemObject).getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); } final IItemList all = storage.getStorageList(); @@ -720,7 +714,7 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp if (!failed.isEmpty()) { this.getCellInventory() .injectItems(AEItemStack.fromItemStack(failed), Actionable.MODULATE, - new MachineSource(this.getPart() != null? this.getPart() : (IActionHost) iGuiItemObject)); + new MachineSource(this.getPart() != null ? this.getPart() : (IActionHost) iGuiItemObject)); } } } diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java index 4842e5aa8..82b5b9aea 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java @@ -55,7 +55,7 @@ public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell i private IRecipe currentRecipe; public ContainerWirelessCraftingTerminal(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) { - super(ip, gui, gui, false); + super(ip, gui, false); this.wirelessTerminalGUIObject = gui; final IItemHandler crafting = this.craftingGrid; @@ -67,7 +67,7 @@ public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell i } this.addSlotToContainer(this.outputSlot = new SlotCraftingTerm(this.getPlayerInv().player, this.getActionSource(), this - .getPowerSource(), this.civ, crafting, crafting, this.output, 131, -72 + 18, this)); + .getPowerSource(), this.wirelessTerminalGUIObject, crafting, crafting, this.output, 131, -72 + 18, this)); this.bindPlayerInventory(ip, 0, 0); this.loadFromNBT(); @@ -75,21 +75,6 @@ public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell i this.onCraftMatrixChanged(new WrapperInvItemHandler(crafting)); } - @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - - if (!this.wirelessTerminalGUIObject.rangeCheck()) { - if (Platform.isServer() && this.isValidContainer()) { - this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); - } - - this.setValidContainer(false); - } else { - this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); - } - } - @Override public void onCraftMatrixChanged(IInventory inventory) { final ContainerNull cn = new ContainerNull(); diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java index 95b44e7e2..64ff826a9 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java @@ -22,10 +22,9 @@ package appeng.container.implementations; import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; import appeng.api.implementations.ICraftingPatternItem; -import appeng.api.implementations.guiobjects.IPortableCell; +import appeng.api.implementations.IUpgradeableCellContainer; import appeng.api.networking.crafting.ICraftingPatternDetails; import appeng.api.storage.data.IAEItemStack; -import appeng.container.interfaces.IInventorySlotAware; import appeng.container.slot.OptionalSlotFake; import appeng.container.slot.SlotFakeCraftingMatrix; import appeng.container.slot.SlotPatternOutputs; @@ -33,35 +32,27 @@ import appeng.container.slot.SlotPatternTerm; import appeng.container.slot.SlotRestrictedInput; import appeng.core.AEConfig; import appeng.core.localization.PlayerMessages; -import appeng.helpers.ItemStackHelper; import appeng.helpers.WirelessTerminalGuiObject; import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.Platform; import appeng.util.helpers.ItemHandlerUtil; import appeng.util.inv.InvOperation; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTUtil; -import net.minecraftforge.common.util.Constants; import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.ItemStackHandler; import static appeng.helpers.PatternHelper.CRAFTING_GRID_DIMENSION; -public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder { +public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder implements IUpgradeableCellContainer { private final WirelessTerminalGuiObject wirelessTerminalGUIObject; - private double powerMultiplier = 0.5; - protected final IPortableCell civ; - private int ticks = 0; private final int slot; - protected AppEngInternalInventory output; protected AppEngInternalInventory pattern; + private double powerMultiplier = 0.5; + private int ticks = 0; public ContainerWirelessPatternTerminal(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) { super(ip, gui, gui, false); @@ -81,7 +72,6 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder { this.slot = -1; this.lockPlayerInventorySlot(ip.currentItem); } - this.civ = gui; this.wirelessTerminalGUIObject = gui; this.loadFromNBT(); @@ -114,17 +104,19 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder { this.updateOrderOfOutputSlots(); this.bindPlayerInventory(ip, 0, 0); + + this.setupUpgrades(); } @Override public void detectAndSendChanges() { final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); - if (this.civ == null || currentItem.isEmpty()) { + if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { this.setValidContainer(false); - } else if (this.civ != null && !this.civ.getItemStack().isEmpty() && currentItem != this.civ.getItemStack()) { - if (ItemStack.areItemsEqual(this.civ.getItemStack(), currentItem)) { - this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.civ.getItemStack()); + } else if (this.wirelessTerminalGUIObject != null && !this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { + if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { + this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack()); } else { this.setValidContainer(false); } @@ -133,7 +125,7 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder { // drain 1 ae t this.ticks++; if (this.ticks > 10) { - this.civ.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); + this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); this.ticks = 0; } @@ -237,4 +229,21 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder { public boolean useRealItems() { return false; } + + @Override + public int availableUpgrades() { + return 2; + } + + @Override + public void setupUpgrades() { + if (wirelessTerminalGUIObject != null) { + final IItemHandler upgrades = wirelessTerminalGUIObject.getInventoryByName("upgrades"); + for (int a = 0; a < availableUpgrades(); a++) { + this.addSlotToContainer( + (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, -2 + a * 18, this.getInventoryPlayer())) + .setNotDraggable()); + } + } + } } diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessTerm.java b/src/main/java/appeng/container/implementations/ContainerWirelessTerm.java index 0eac8fdbc..3a2ba0a4d 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessTerm.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessTerm.java @@ -31,7 +31,7 @@ public class ContainerWirelessTerm extends ContainerMEPortableCell { private final WirelessTerminalGuiObject wirelessTerminalGUIObject; public ContainerWirelessTerm(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) { - super(ip, gui); + super(ip, gui, true); this.wirelessTerminalGUIObject = gui; } diff --git a/src/main/java/appeng/core/features/registries/WirelessRegistry.java b/src/main/java/appeng/core/features/registries/WirelessRegistry.java index be546948b..a7eaeaf8a 100644 --- a/src/main/java/appeng/core/features/registries/WirelessRegistry.java +++ b/src/main/java/appeng/core/features/registries/WirelessRegistry.java @@ -25,10 +25,13 @@ import appeng.api.features.IWirelessTermHandler; import appeng.api.features.IWirelessTermRegistry; import appeng.core.localization.PlayerMessages; import appeng.core.sync.GuiBridge; +import appeng.helpers.WirelessTerminalGuiObject; import appeng.util.Platform; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.util.text.TextComponentString; import net.minecraft.world.World; +import net.minecraftforge.items.IItemHandler; import java.util.ArrayList; import java.util.List; @@ -80,6 +83,14 @@ public final class WirelessRegistry implements IWirelessTermRegistry { } final IWirelessTermHandler handler = this.getWirelessTerminalHandler(item); + + WirelessTerminalGuiObject wtgo = new WirelessTerminalGuiObject(handler, item, player, w, (int) player.posX, (int) player.posY, (int) player.posZ); + IItemHandler upgrades = wtgo.getInventoryByName("upgrades"); + if (upgrades.getSlots() > 0) { + player.sendMessage(new TextComponentString("ahhaah eheheh ihihih")); + } + + final String unparsedKey = handler.getEncryptionKey(item); if (unparsedKey.isEmpty()) { player.sendMessage(PlayerMessages.DeviceNotLinked.get()); diff --git a/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java index 840ff03a1..16662112b 100644 --- a/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java +++ b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java @@ -2,6 +2,7 @@ package appeng.fluids.container; import appeng.api.AEApi; import appeng.api.config.*; +import appeng.api.implementations.IUpgradeableCellContainer; import appeng.api.implementations.guiobjects.IPortableCell; import appeng.api.networking.IGridHost; import appeng.api.networking.IGridNode; @@ -24,6 +25,7 @@ import appeng.container.interfaces.IInventorySlotAware; import appeng.container.slot.AppEngSlot; import appeng.container.slot.SlotPlayerHotBar; import appeng.container.slot.SlotPlayerInv; +import appeng.container.slot.SlotRestrictedInput; import appeng.core.AEConfig; import appeng.core.AELog; import appeng.core.localization.PlayerMessages; @@ -45,12 +47,13 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.fluids.capability.IFluidHandlerItem; +import net.minecraftforge.items.IItemHandler; import javax.annotation.Nonnull; import java.io.IOException; import java.nio.BufferOverflowException; -public class ContainerMEPortableFluidCell extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver { +public class ContainerMEPortableFluidCell extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver, IUpgradeableCellContainer { private final WirelessTerminalGuiObject wirelessTerminalGUIObject; @@ -66,8 +69,6 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements ICo // Holds the fluid the client wishes to extract, or null for insert private IAEFluidStack clientRequestedTargetFluid = null; private double powerMultiplier = 0.5; - - protected final IPortableCell civ; private int ticks = 0; private final int slot; @@ -98,24 +99,22 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements ICo this.monitor.addListener(this, null); this.setPowerSource((IEnergySource) terminal); - if (terminal instanceof IGridHost || terminal instanceof IActionHost) { - final IGridNode node; - if (terminal instanceof IGridHost) { - node = ((IGridHost) terminal).getGridNode(AEPartLocation.INTERNAL); - } else { - node = ((IActionHost) terminal).getActionableNode(); - } + final IGridNode node; + if (terminal instanceof IGridHost) { + node = ((IGridHost) terminal).getGridNode(AEPartLocation.INTERNAL); + } else { + node = ((IActionHost) terminal).getActionableNode(); + } - if (node != null) { - this.networkNode = node; - } + if (node != null) { + this.networkNode = node; } } } else { this.monitor = null; } - if (monitorable instanceof IInventorySlotAware) { + if (monitorable != null) { final int slotIndex = ((IInventorySlotAware) monitorable).getInventorySlot(); this.lockPlayerInventorySlot(slotIndex); this.slot = slotIndex; @@ -123,11 +122,13 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements ICo this.slot = -1; this.lockPlayerInventorySlot(ip.currentItem); } - this.civ = monitorable; + if (bindInventory) { this.bindPlayerInventory(ip, 0, 140); } - hasPower = this.civ.extractAEPower(this.getPowerMultiplier(), Actionable.SIMULATE, PowerMultiplier.CONFIG) > 0.001; + hasPower = this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier(), Actionable.SIMULATE, PowerMultiplier.CONFIG) > 0.001; + + this.setupUpgrades(); } @@ -135,11 +136,11 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements ICo public void detectAndSendChanges() { final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); - if (this.civ == null || currentItem.isEmpty()) { + if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { this.setValidContainer(false); - } else if (this.civ != null && !this.civ.getItemStack().isEmpty() && currentItem != this.civ.getItemStack()) { - if (ItemStack.areItemsEqual(this.civ.getItemStack(), currentItem)) { - this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.civ.getItemStack()); + } else if (this.wirelessTerminalGUIObject != null && !this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { + if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { + this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack()); } else { this.setValidContainer(false); } @@ -148,7 +149,7 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements ICo // drain 1 ae t this.ticks++; if (this.ticks > 10) { - double power = this.civ.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); + double power = this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); this.ticks = 0; this.hasPower = power > 0.001; } @@ -515,4 +516,21 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements ICo public void setGui(@Nonnull final IConfigManagerHost gui) { this.gui = gui; } + + @Override + public int availableUpgrades() { + return 2; + } + + @Override + public void setupUpgrades() { + if (wirelessTerminalGUIObject instanceof WirelessTerminalGuiObject) { + final IItemHandler upgrades = ((WirelessTerminalGuiObject) wirelessTerminalGUIObject).getInventoryByName("upgrades"); + for (int a = 0; a < availableUpgrades(); a++) { + this.addSlotToContainer( + (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 139 + a * 18, this.getInventoryPlayer())) + .setNotDraggable()); + } + } + } } diff --git a/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java b/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java index 26f5497fb..214e55a15 100644 --- a/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java +++ b/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java @@ -19,7 +19,6 @@ package appeng.fluids.container; -import appeng.container.implementations.ContainerMEPortableCell; import appeng.core.AEConfig; import appeng.core.localization.PlayerMessages; import appeng.helpers.WirelessTerminalGuiObject; diff --git a/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java index 9c9193c64..0721c1c31 100644 --- a/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java +++ b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java @@ -25,6 +25,7 @@ import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; import appeng.api.features.ILocatable; import appeng.api.features.IWirelessTermHandler; +import appeng.api.implementations.IUpgradeableCellHost; import appeng.api.implementations.guiobjects.IPortableCell; import appeng.api.implementations.tiles.IViewCellStorage; import appeng.api.implementations.tiles.IWirelessAccessPoint; @@ -44,6 +45,8 @@ import appeng.api.storage.data.IItemList; import appeng.api.util.DimensionalCoord; import appeng.api.util.IConfigManager; import appeng.container.interfaces.IInventorySlotAware; +import appeng.parts.automation.StackUpgradeInventory; +import appeng.parts.automation.UpgradeInventory; import appeng.tile.inventory.AppEngInternalInventory; import appeng.tile.networking.TileWireless; import appeng.util.inv.IAEAppEngInventory; @@ -55,7 +58,7 @@ import net.minecraft.world.World; import net.minecraftforge.items.IItemHandler; -public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, IInventorySlotAware, IViewCellStorage, IAEAppEngInventory { +public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, IInventorySlotAware, IViewCellStorage, IAEAppEngInventory, IUpgradeableCellHost { private final ItemStack effectiveItem; private final IWirelessTermHandler wth; @@ -70,6 +73,8 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II private final int inventorySlot; private final AppEngInternalInventory viewCell = new AppEngInternalInventory(this, 5); + private final UpgradeInventory upgrades; + public WirelessTerminalGuiObject(final IWirelessTermHandler wh, final ItemStack is, final EntityPlayer ep, final World w, final int x, final int y, final int z) { this.encryptionKey = wh.getEncryptionKey(is); @@ -100,6 +105,8 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II } } + upgrades = new StackUpgradeInventory(effectiveItem, this, 4); + this.loadFromNBT(); } @@ -327,6 +334,7 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II NBTTagCompound data = effectiveItem.getTagCompound(); if (data != null) { viewCell.readFromNBT(data); + upgrades.readFromNBT(data); } } @@ -334,4 +342,12 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II public void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) { } + + @Override + public IItemHandler getInventoryByName(String name) { + if (name.equals("upgrades")) { + return upgrades; + } + return null; + } } From 9dee7f6c0e6b3a56ce20fe2f0eb488216df41371 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Mon, 30 Jan 2023 16:50:47 -0300 Subject: [PATCH 08/35] cards --- src/api/java/appeng/api/config/Upgrades.java | 105 +++++++-------- .../appeng/api/definitions/IMaterials.java | 123 +++++++++--------- .../ContainerMEPortableCell.java | 4 +- .../ContainerWirelessPatternTerminal.java | 6 +- src/main/java/appeng/core/Registration.java | 21 ++- .../core/api/definitions/ApiMaterials.java | 14 ++ .../ContainerMEPortableFluidCell.java | 25 +++- .../helpers/WirelessTerminalGuiObject.java | 5 +- .../appeng/items/materials/ItemMaterial.java | 4 + .../appeng/items/materials/MaterialType.java | 4 +- .../parts/automation/UpgradeInventory.java | 15 ++- 11 files changed, 192 insertions(+), 134 deletions(-) diff --git a/src/api/java/appeng/api/config/Upgrades.java b/src/api/java/appeng/api/config/Upgrades.java index 606ab700e..cef2babfd 100644 --- a/src/api/java/appeng/api/config/Upgrades.java +++ b/src/api/java/appeng/api/config/Upgrades.java @@ -32,66 +32,61 @@ import net.minecraft.item.ItemStack; import appeng.api.definitions.IItemDefinition; -public enum Upgrades -{ - /** - * Gold Tier Upgrades. - */ - CAPACITY( 0 ), - REDSTONE( 0 ), - CRAFTING( 0 ), +public enum Upgrades { + /** + * Gold Tier Upgrades. + */ + CAPACITY(0), + REDSTONE(0), + CRAFTING(0), + MAGNET(0), - /** - * Diamond Tier Upgrades. - */ - FUZZY( 1 ), - SPEED( 1 ), - INVERTER( 1 ), - PATTERN_EXPANSION(1); + /** + * Diamond Tier Upgrades. + */ + FUZZY(1), + SPEED(1), + INVERTER(1), + PATTERN_EXPANSION(1), + QUANTUM_LINK(1); - private final int tier; - private final Map supportedMax = new HashMap<>(); + private final int tier; + private final Map supportedMax = new HashMap<>(); - Upgrades( final int tier ) - { - this.tier = tier; - } + Upgrades(final int tier) { + this.tier = tier; + } - /** - * @return list of Items/Blocks that support this upgrade, and how many it supports. - */ - public Map getSupported() - { - return this.supportedMax; - } + /** + * @return list of Items/Blocks that support this upgrade, and how many it supports. + */ + public Map getSupported() { + return this.supportedMax; + } - /** - * Registers a specific amount of this upgrade into a specific machine - * - * @param item machine in which this upgrade can be installed - * @param maxSupported amount how many upgrades can be installed - */ - public void registerItem( final IItemDefinition item, final int maxSupported ) - { - item.maybeStack( 1 ).ifPresent( is -> this.registerItem( is, maxSupported ) ); - } + /** + * Registers a specific amount of this upgrade into a specific machine + * + * @param item machine in which this upgrade can be installed + * @param maxSupported amount how many upgrades can be installed + */ + public void registerItem(final IItemDefinition item, final int maxSupported) { + item.maybeStack(1).ifPresent(is -> this.registerItem(is, maxSupported)); + } - /** - * Registers a specific amount of this upgrade into a specific machine - * - * @param stack machine in which this upgrade can be installed - * @param maxSupported amount how many upgrades can be installed - */ - public void registerItem( final ItemStack stack, final int maxSupported ) - { - if( stack != null ) - { - this.supportedMax.put( stack, maxSupported ); - } - } + /** + * Registers a specific amount of this upgrade into a specific machine + * + * @param stack machine in which this upgrade can be installed + * @param maxSupported amount how many upgrades can be installed + */ + public void registerItem(final ItemStack stack, final int maxSupported) { + if (stack != null) { + this.supportedMax.put(stack, maxSupported); + } + } - public int getTier() - { - return this.tier; - } + public int getTier() { + return this.tier; + } } diff --git a/src/api/java/appeng/api/definitions/IMaterials.java b/src/api/java/appeng/api/definitions/IMaterials.java index dc62679de..09d03120f 100644 --- a/src/api/java/appeng/api/definitions/IMaterials.java +++ b/src/api/java/appeng/api/definitions/IMaterials.java @@ -27,121 +27,124 @@ package appeng.api.definitions; /** * A list of all materials in AE */ -public interface IMaterials -{ - IItemDefinition cell2SpatialPart(); +public interface IMaterials { + IItemDefinition cell2SpatialPart(); - IItemDefinition cell16SpatialPart(); + IItemDefinition cell16SpatialPart(); - IItemDefinition cell128SpatialPart(); + IItemDefinition cell128SpatialPart(); - IItemDefinition silicon(); + IItemDefinition silicon(); - IItemDefinition skyDust(); + IItemDefinition skyDust(); - IItemDefinition calcProcessorPress(); + IItemDefinition calcProcessorPress(); - IItemDefinition engProcessorPress(); + IItemDefinition engProcessorPress(); - IItemDefinition logicProcessorPress(); + IItemDefinition logicProcessorPress(); - IItemDefinition calcProcessorPrint(); + IItemDefinition calcProcessorPrint(); - IItemDefinition engProcessorPrint(); + IItemDefinition engProcessorPrint(); - IItemDefinition logicProcessorPrint(); + IItemDefinition logicProcessorPrint(); - IItemDefinition siliconPress(); + IItemDefinition siliconPress(); - IItemDefinition siliconPrint(); + IItemDefinition siliconPrint(); - IItemDefinition namePress(); + IItemDefinition namePress(); - IItemDefinition logicProcessor(); + IItemDefinition logicProcessor(); - IItemDefinition calcProcessor(); + IItemDefinition calcProcessor(); - IItemDefinition engProcessor(); + IItemDefinition engProcessor(); - IItemDefinition basicCard(); + IItemDefinition basicCard(); - IItemDefinition advCard(); + IItemDefinition advCard(); - IItemDefinition purifiedCertusQuartzCrystal(); + IItemDefinition purifiedCertusQuartzCrystal(); - IItemDefinition purifiedNetherQuartzCrystal(); + IItemDefinition purifiedNetherQuartzCrystal(); - IItemDefinition purifiedFluixCrystal(); + IItemDefinition purifiedFluixCrystal(); - IItemDefinition cell1kPart(); + IItemDefinition cell1kPart(); - IItemDefinition cell4kPart(); + IItemDefinition cell4kPart(); - IItemDefinition cell16kPart(); + IItemDefinition cell16kPart(); - IItemDefinition cell64kPart(); + IItemDefinition cell64kPart(); - IItemDefinition emptyStorageCell(); + IItemDefinition emptyStorageCell(); - IItemDefinition cardRedstone(); + IItemDefinition cardRedstone(); - IItemDefinition cardSpeed(); + IItemDefinition cardSpeed(); - IItemDefinition cardCapacity(); + IItemDefinition cardCapacity(); - IItemDefinition cardPatternExpansion(); + IItemDefinition cardPatternExpansion(); - IItemDefinition cardFuzzy(); + public IItemDefinition cardQuantumLink(); - IItemDefinition cardInverter(); + public IItemDefinition cardMagnet(); - IItemDefinition cardCrafting(); + IItemDefinition cardFuzzy(); - IItemDefinition enderDust(); + IItemDefinition cardInverter(); - IItemDefinition flour(); + IItemDefinition cardCrafting(); - IItemDefinition goldDust(); + IItemDefinition enderDust(); - IItemDefinition ironDust(); + IItemDefinition flour(); - IItemDefinition fluixDust(); + IItemDefinition goldDust(); - IItemDefinition certusQuartzDust(); + IItemDefinition ironDust(); - IItemDefinition netherQuartzDust(); + IItemDefinition fluixDust(); - IItemDefinition matterBall(); + IItemDefinition certusQuartzDust(); - IItemDefinition certusQuartzCrystal(); + IItemDefinition netherQuartzDust(); - IItemDefinition certusQuartzCrystalCharged(); + IItemDefinition matterBall(); - IItemDefinition fluixCrystal(); + IItemDefinition certusQuartzCrystal(); - IItemDefinition fluixPearl(); + IItemDefinition certusQuartzCrystalCharged(); - IItemDefinition woodenGear(); + IItemDefinition fluixCrystal(); - IItemDefinition wirelessReceiver(); + IItemDefinition fluixPearl(); - IItemDefinition wirelessBooster(); + IItemDefinition woodenGear(); - IItemDefinition annihilationCore(); + IItemDefinition wirelessReceiver(); - IItemDefinition formationCore(); + IItemDefinition wirelessBooster(); - IItemDefinition singularity(); + IItemDefinition annihilationCore(); - IItemDefinition qESingularity(); + IItemDefinition formationCore(); - IItemDefinition blankPattern(); + IItemDefinition singularity(); - IItemDefinition fluidCell1kPart(); + IItemDefinition qESingularity(); - IItemDefinition fluidCell4kPart(); + IItemDefinition blankPattern(); - IItemDefinition fluidCell16kPart(); + IItemDefinition fluidCell1kPart(); - IItemDefinition fluidCell64kPart(); + IItemDefinition fluidCell4kPart(); + + IItemDefinition fluidCell16kPart(); + + IItemDefinition fluidCell64kPart(); } diff --git a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java index 458dbbc81..22fa2ba33 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java +++ b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java @@ -108,9 +108,9 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I public void setupUpgrades() { if (wirelessTerminalGUIObject != null) { final IItemHandler upgrades = wirelessTerminalGUIObject.getInventoryByName("upgrades"); - for (int a = 0; a < availableUpgrades(); a++) { + for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) { this.addSlotToContainer( - (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, a * 18, this.getInventoryPlayer())) + (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 187, upgradeSlot * 18, this.getInventoryPlayer())) .setNotDraggable()); } } diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java index 64ff826a9..5c6761b05 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java @@ -114,7 +114,7 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { this.setValidContainer(false); - } else if (this.wirelessTerminalGUIObject != null && !this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { + } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack()); } else { @@ -239,9 +239,9 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im public void setupUpgrades() { if (wirelessTerminalGUIObject != null) { final IItemHandler upgrades = wirelessTerminalGUIObject.getInventoryByName("upgrades"); - for (int a = 0; a < availableUpgrades(); a++) { + for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) { this.addSlotToContainer( - (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, -2 + a * 18, this.getInventoryPlayer())) + (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 187, upgradeSlot * 18 - 2, this.getInventoryPlayer())) .setNotDraggable()); } } diff --git a/src/main/java/appeng/core/Registration.java b/src/main/java/appeng/core/Registration.java index 9e021ba41..7087934a0 100644 --- a/src/main/java/appeng/core/Registration.java +++ b/src/main/java/appeng/core/Registration.java @@ -21,6 +21,7 @@ package appeng.core; import appeng.api.config.Upgrades; import appeng.api.definitions.IBlocks; +import appeng.api.definitions.IItemDefinition; import appeng.api.definitions.IItems; import appeng.api.definitions.IParts; import appeng.api.features.IRecipeHandlerRegistry; @@ -105,7 +106,9 @@ import javax.annotation.Nonnull; import java.io.File; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; @@ -403,11 +406,19 @@ final class Registration { Upgrades.SPEED.registerItem(blocks.inscriber(), 3); // Wireless Terminal Handler - items.wirelessTerminal().maybeItem().ifPresent(terminal -> registries.wireless().registerWirelessHandler((IWirelessTermHandler) terminal)); - items.wirelessCraftingTerminal().maybeItem().ifPresent(terminal -> registries.wireless().registerWirelessHandler((IWirelessTermHandler) terminal)); - items.wirelessPatternTerminal().maybeItem().ifPresent(terminal -> registries.wireless().registerWirelessHandler((IWirelessTermHandler) terminal)); - items.wirelessFluidTerminal().maybeItem().ifPresent(terminal -> registries.wireless().registerWirelessHandler((IWirelessTermHandler) terminal)); - + ArrayList iids = new ArrayList<>(); + iids.add(items.wirelessTerminal()); + iids.add(items.wirelessCraftingTerminal()); + iids.add(items.wirelessPatternTerminal()); + iids.add(items.wirelessFluidTerminal()); + + for (IItemDefinition id : iids) { + id.maybeItem().ifPresent(terminal -> { + registries.wireless().registerWirelessHandler((IWirelessTermHandler) terminal); + Upgrades.QUANTUM_LINK.registerItem(id, 1); + Upgrades.MAGNET.registerItem(id, 1); + }); + } // Charge Rates items.chargedStaff().maybeItem().ifPresent(chargedStaff -> registries.charger().addChargeRate(chargedStaff, 320d)); diff --git a/src/main/java/appeng/core/api/definitions/ApiMaterials.java b/src/main/java/appeng/core/api/definitions/ApiMaterials.java index d2f55074e..4a86f8fce 100644 --- a/src/main/java/appeng/core/api/definitions/ApiMaterials.java +++ b/src/main/java/appeng/core/api/definitions/ApiMaterials.java @@ -85,6 +85,8 @@ public final class ApiMaterials implements IMaterials { private final IItemDefinition cardSpeed; private final IItemDefinition cardCapacity; private final IItemDefinition cardPatternExpansion; + private final IItemDefinition cardQuantumLink; + private final IItemDefinition cardMagnet; private final IItemDefinition cardFuzzy; private final IItemDefinition cardInverter; private final IItemDefinition cardCrafting; @@ -201,6 +203,8 @@ public final class ApiMaterials implements IMaterials { this.cardSpeed = new DamagedItemDefinition("material.card.acceleration", materials.createMaterial(MaterialType.CARD_SPEED)); this.cardCapacity = new DamagedItemDefinition("material.card.capacity", materials.createMaterial(MaterialType.CARD_CAPACITY)); this.cardPatternExpansion = new DamagedItemDefinition("material.card.pattern.expansion", materials.createMaterial(MaterialType.CARD_PATTERN_EXPANSION)); + this.cardQuantumLink = new DamagedItemDefinition("material.card.quantum.link", materials.createMaterial(MaterialType.CARD_QUANTUM_LINK)); + this.cardMagnet = new DamagedItemDefinition("material.card.magnet", materials.createMaterial(MaterialType.CARD_MAGNET)); this.cardFuzzy = new DamagedItemDefinition("material.card.fuzzy", materials.createMaterial(MaterialType.CARD_FUZZY)); this.cardInverter = new DamagedItemDefinition("material.card.inverter", materials.createMaterial(MaterialType.CARD_INVERTER)); this.cardCrafting = new DamagedItemDefinition("material.card.crafting", materials.createMaterial(MaterialType.CARD_CRAFTING)); @@ -396,6 +400,16 @@ public final class ApiMaterials implements IMaterials { return this.cardPatternExpansion; } + @Override + public IItemDefinition cardQuantumLink() { + return this.cardQuantumLink; + } + + @Override + public IItemDefinition cardMagnet() { + return this.cardMagnet; + } + @Override public IItemDefinition cardFuzzy() { return this.cardFuzzy; diff --git a/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java index 16662112b..bb730ca6e 100644 --- a/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java +++ b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java @@ -39,6 +39,8 @@ import appeng.helpers.WirelessTerminalGuiObject; import appeng.util.ConfigManager; import appeng.util.IConfigManagerHost; import appeng.util.Platform; +import appeng.util.inv.IAEAppEngInventory; +import appeng.util.inv.InvOperation; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; @@ -53,7 +55,7 @@ import javax.annotation.Nonnull; import java.io.IOException; import java.nio.BufferOverflowException; -public class ContainerMEPortableFluidCell extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver, IUpgradeableCellContainer { +public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAEAppEngInventory, IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver, IUpgradeableCellContainer { private final WirelessTerminalGuiObject wirelessTerminalGUIObject; @@ -138,7 +140,7 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements ICo if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { this.setValidContainer(false); - } else if (this.wirelessTerminalGUIObject != null && !this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { + } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack()); } else { @@ -524,13 +526,24 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements ICo @Override public void setupUpgrades() { - if (wirelessTerminalGUIObject instanceof WirelessTerminalGuiObject) { - final IItemHandler upgrades = ((WirelessTerminalGuiObject) wirelessTerminalGUIObject).getInventoryByName("upgrades"); - for (int a = 0; a < availableUpgrades(); a++) { + if (wirelessTerminalGUIObject != null) { + final IItemHandler upgrades = wirelessTerminalGUIObject.getInventoryByName("upgrades"); + for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) { this.addSlotToContainer( - (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 139 + a * 18, this.getInventoryPlayer())) + (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 187, 139 + upgradeSlot * 18, this.getInventoryPlayer())) .setNotDraggable()); } } } + + + @Override + public void saveChanges() { + + } + + @Override + public void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) { + + } } diff --git a/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java index 0721c1c31..8d4ebcc29 100644 --- a/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java +++ b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java @@ -105,7 +105,7 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II } } - upgrades = new StackUpgradeInventory(effectiveItem, this, 4); + upgrades = new StackUpgradeInventory(effectiveItem, this, 2); this.loadFromNBT(); } @@ -319,6 +319,7 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II data = new NBTTagCompound(); } viewCell.writeToNBT(data, "viewCell"); + upgrades.writeToNBT(data, "upgrades"); } @Override @@ -347,6 +348,8 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II public IItemHandler getInventoryByName(String name) { if (name.equals("upgrades")) { return upgrades; + } else if (name.equals("viewCell")) { + return viewCell; } return null; } diff --git a/src/main/java/appeng/items/materials/ItemMaterial.java b/src/main/java/appeng/items/materials/ItemMaterial.java index ed752dc5b..25013958e 100644 --- a/src/main/java/appeng/items/materials/ItemMaterial.java +++ b/src/main/java/appeng/items/materials/ItemMaterial.java @@ -144,6 +144,10 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent, return Upgrades.CRAFTING; case CARD_PATTERN_EXPANSION: return Upgrades.PATTERN_EXPANSION; + case CARD_MAGNET: + return Upgrades.MAGNET; + case CARD_QUANTUM_LINK: + return Upgrades.QUANTUM_LINK; default: return null; } diff --git a/src/main/java/appeng/items/materials/MaterialType.java b/src/main/java/appeng/items/materials/MaterialType.java index 1c0de3f9f..f1f0b9ad6 100644 --- a/src/main/java/appeng/items/materials/MaterialType.java +++ b/src/main/java/appeng/items/materials/MaterialType.java @@ -118,7 +118,9 @@ public enum MaterialType { FLUID_CELL16K_PART(56, "material_fluid_cell16k_part", EnumSet.of(AEFeature.STORAGE_CELLS)), FLUID_CELL64K_PART(57, "material_fluid_cell64k_part", EnumSet.of(AEFeature.STORAGE_CELLS)), - CARD_PATTERN_EXPANSION(58, "material_card_pattern_expansion", EnumSet.of(AEFeature.ADVANCED_CARDS)); + CARD_PATTERN_EXPANSION(58, "material_card_pattern_expansion", EnumSet.of(AEFeature.ADVANCED_CARDS)), + CARD_QUANTUM_LINK(59, "material_card_quantum_link", EnumSet.of(AEFeature.ADVANCED_CARDS)), + CARD_MAGNET(60, "material_card_quantum_link", EnumSet.of(AEFeature.BASIC_CARDS)); private final Set features; diff --git a/src/main/java/appeng/parts/automation/UpgradeInventory.java b/src/main/java/appeng/parts/automation/UpgradeInventory.java index 27d579546..87799513a 100644 --- a/src/main/java/appeng/parts/automation/UpgradeInventory.java +++ b/src/main/java/appeng/parts/automation/UpgradeInventory.java @@ -46,6 +46,8 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement private int inverterUpgrades = 0; private int craftingUpgrades = 0; private int patternExpansionUpgrades = 0; + private int magnetUpgrades = 0; + private int quantumUpgrades = 0; public UpgradeInventory(final IAEAppEngInventory parent, final int s) { super(null, s, 1); @@ -79,6 +81,10 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement return this.craftingUpgrades; case PATTERN_EXPANSION: return this.patternExpansionUpgrades; + case MAGNET: + return this.magnetUpgrades; + case QUANTUM_LINK: + return this.quantumUpgrades; default: return 0; } @@ -88,7 +94,7 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement private void updateUpgradeInfo() { this.cached = true; - this.patternExpansionUpgrades = this.inverterUpgrades = this.capacityUpgrades = this.redstoneUpgrades = this.speedUpgrades = this.fuzzyUpgrades = this.craftingUpgrades = 0; + this.patternExpansionUpgrades = this.inverterUpgrades = this.capacityUpgrades = this.redstoneUpgrades = this.speedUpgrades = this.fuzzyUpgrades = this.craftingUpgrades = magnetUpgrades = quantumUpgrades = 0; for (final ItemStack is : this) { if (is == null || is.getItem() == Items.AIR || !(is.getItem() instanceof IUpgradeModule)) { @@ -118,6 +124,11 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement case PATTERN_EXPANSION: this.patternExpansionUpgrades++; break; + case MAGNET: + this.magnetUpgrades++; + break; + case QUANTUM_LINK: + this.quantumUpgrades++; default: break; } @@ -130,6 +141,8 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement this.inverterUpgrades = Math.min(this.inverterUpgrades, this.getMaxInstalled(Upgrades.INVERTER)); this.craftingUpgrades = Math.min(this.craftingUpgrades, this.getMaxInstalled(Upgrades.CRAFTING)); this.patternExpansionUpgrades = Math.min(this.patternExpansionUpgrades, this.getMaxInstalled(Upgrades.PATTERN_EXPANSION)); + this.magnetUpgrades = Math.min(this.magnetUpgrades, this.getMaxInstalled(Upgrades.MAGNET)); + this.quantumUpgrades = Math.min(this.quantumUpgrades, this.getMaxInstalled(Upgrades.QUANTUM_LINK)); } @Override From d7e1554e418629c2f0ac10a781c713fcc502c54b Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Mon, 30 Jan 2023 20:40:16 -0300 Subject: [PATCH 09/35] save upgrades --- .../ContainerMEPortableCell.java | 93 ++++++++++++------ .../ContainerWirelessCraftingTerminal.java | 10 +- .../ContainerWirelessPatternTerminal.java | 61 +++++++----- .../ContainerMEPortableFluidCell.java | 97 ++++++++++++------- .../ContainerWirelessFluidTerminal.java | 18 ++-- .../helpers/WirelessTerminalGuiObject.java | 2 +- 6 files changed, 179 insertions(+), 102 deletions(-) diff --git a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java index 22fa2ba33..7f90f1278 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java +++ b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java @@ -27,19 +27,26 @@ import appeng.container.slot.SlotRestrictedInput; import appeng.core.AEConfig; import appeng.core.localization.PlayerMessages; import appeng.helpers.WirelessTerminalGuiObject; +import appeng.parts.automation.StackUpgradeInventory; +import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.Platform; +import appeng.util.inv.IAEAppEngInventory; +import appeng.util.inv.InvOperation; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.items.IItemHandler; -public class ContainerMEPortableCell extends ContainerMEMonitorable implements IUpgradeableCellContainer { +public class ContainerMEPortableCell extends ContainerMEMonitorable implements IUpgradeableCellContainer, IAEAppEngInventory { protected final WirelessTerminalGuiObject wirelessTerminalGUIObject; private final int slot; private double powerMultiplier = 0.5; private int ticks = 0; + protected AppEngInternalInventory upgrades; public ContainerMEPortableCell(InventoryPlayer ip, WirelessTerminalGuiObject monitorable, boolean bindInventory) { super(ip, monitorable, bindInventory); @@ -52,44 +59,51 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I this.lockPlayerInventorySlot(ip.currentItem); } this.wirelessTerminalGUIObject = monitorable; + this.upgrades = new StackUpgradeInventory(wirelessTerminalGUIObject.getItemStack(), this, 2); + this.loadFromNBT(); + if (bindInventory) { this.bindPlayerInventory(ip, 0, 0); } this.setupUpgrades(); } + @Override public void detectAndSendChanges() { - final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); + if (Platform.isServer()) { - if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { - this.setValidContainer(false); - } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { - if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { - this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack()); - } else { + final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); + + if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { this.setValidContainer(false); - } - } - - // drain 1 ae t - this.ticks++; - if (this.ticks > 10) { - this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); - this.ticks = 0; - } - - if (!this.wirelessTerminalGUIObject.rangeCheck()) { - if (Platform.isServer() && this.isValidContainer()) { - this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { + if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { + this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack()); + } else { + this.setValidContainer(false); + } } - this.setValidContainer(false); - } else { - this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); - } + // drain 1 ae t + this.ticks++; + if (this.ticks > 10) { + this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); + this.ticks = 0; + } - super.detectAndSendChanges(); + if (!this.wirelessTerminalGUIObject.rangeCheck()) { + if (Platform.isServer() && this.isValidContainer()) { + this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + } + + this.setValidContainer(false); + } else { + this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); + } + + super.detectAndSendChanges(); + } } private double getPowerMultiplier() { @@ -107,7 +121,6 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I @Override public void setupUpgrades() { if (wirelessTerminalGUIObject != null) { - final IItemHandler upgrades = wirelessTerminalGUIObject.getInventoryByName("upgrades"); for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) { this.addSlotToContainer( (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 187, upgradeSlot * 18, this.getInventoryPlayer())) @@ -116,4 +129,30 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I } } + @Override + public void onSlotChange(Slot s) { + super.detectAndSendChanges(); + } + + @Override + public void saveChanges() { + if (Platform.isServer()) { + NBTTagCompound tag = new NBTTagCompound(); + this.upgrades.writeToNBT(tag, "upgrades"); + + this.wirelessTerminalGUIObject.saveChanges(tag); + } + } + + private void loadFromNBT() { + NBTTagCompound data = wirelessTerminalGUIObject.getItemStack().getTagCompound(); + if (data != null) { + upgrades.readFromNBT(wirelessTerminalGUIObject.getItemStack().getTagCompound().getCompoundTag("upgrades")); + } + } + + @Override + public void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) { + + } } diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java index 82b5b9aea..0fc9fecdf 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java @@ -22,8 +22,6 @@ package appeng.container.implementations; import appeng.container.ContainerNull; import appeng.container.slot.SlotCraftingMatrix; import appeng.container.slot.SlotCraftingTerm; -import appeng.core.AEConfig; -import appeng.core.localization.PlayerMessages; import appeng.helpers.IContainerCraftingPacket; import appeng.helpers.WirelessTerminalGuiObject; import appeng.tile.inventory.AppEngInternalInventory; @@ -58,6 +56,8 @@ public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell i super(ip, gui, false); this.wirelessTerminalGUIObject = gui; + this.loadFromNBT(); + final IItemHandler crafting = this.craftingGrid; for (int y = 0; y < 3; y++) { @@ -70,7 +70,6 @@ public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell i .getPowerSource(), this.wirelessTerminalGUIObject, crafting, crafting, this.output, 131, -72 + 18, this)); this.bindPlayerInventory(ip, 0, 0); - this.loadFromNBT(); this.onCraftMatrixChanged(new WrapperInvItemHandler(crafting)); } @@ -102,14 +101,17 @@ public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell i if (Platform.isServer()) { NBTTagCompound tag = new NBTTagCompound(); this.craftingGrid.writeToNBT(tag, "craftingGrid"); + this.upgrades.writeToNBT(tag, "upgrades"); + this.wirelessTerminalGUIObject.saveChanges(tag); } } - private void loadFromNBT() { + protected void loadFromNBT() { NBTTagCompound data = wirelessTerminalGUIObject.getItemStack().getTagCompound(); if (data != null) { this.craftingGrid.readFromNBT(data, "craftingGrid"); + upgrades.readFromNBT(wirelessTerminalGUIObject.getItemStack().getTagCompound().getCompoundTag("upgrades")); } } diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java index 5c6761b05..289d62a82 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java @@ -33,6 +33,7 @@ import appeng.container.slot.SlotRestrictedInput; import appeng.core.AEConfig; import appeng.core.localization.PlayerMessages; import appeng.helpers.WirelessTerminalGuiObject; +import appeng.parts.automation.StackUpgradeInventory; import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.Platform; import appeng.util.helpers.ItemHandlerUtil; @@ -51,6 +52,8 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im private final int slot; protected AppEngInternalInventory output; protected AppEngInternalInventory pattern; + protected AppEngInternalInventory upgrades; + private double powerMultiplier = 0.5; private int ticks = 0; @@ -73,6 +76,7 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im this.lockPlayerInventorySlot(ip.currentItem); } this.wirelessTerminalGUIObject = gui; + upgrades = new StackUpgradeInventory(wirelessTerminalGUIObject.getItemStack(), this, 2); this.loadFromNBT(); @@ -110,36 +114,39 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im @Override public void detectAndSendChanges() { - final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); + if (Platform.isServer()) { - if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { - this.setValidContainer(false); - } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { - if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { - this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack()); - } else { + final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); + + if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { this.setValidContainer(false); - } - } - - // drain 1 ae t - this.ticks++; - if (this.ticks > 10) { - this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); - this.ticks = 0; - } - - if (!this.wirelessTerminalGUIObject.rangeCheck()) { - if (Platform.isServer() && this.isValidContainer()) { - this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { + if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { + this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack()); + } else { + this.setValidContainer(false); + } } - this.setValidContainer(false); - } else { - this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); - } + // drain 1 ae t + this.ticks++; + if (this.ticks > 10) { + this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); + this.ticks = 0; + } - super.detectAndSendChanges(); + if (!this.wirelessTerminalGUIObject.rangeCheck()) { + if (Platform.isServer() && this.isValidContainer()) { + this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + } + + this.setValidContainer(false); + } else { + this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); + } + + super.detectAndSendChanges(); + } } private double getPowerMultiplier() { @@ -178,6 +185,8 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im this.output.writeToNBT(tag, "output"); this.pattern.writeToNBT(tag, "patterns"); + this.upgrades.writeToNBT(tag, "upgrades"); + this.wirelessTerminalGUIObject.saveChanges(tag); } } @@ -188,6 +197,7 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im ((AppEngInternalInventory) crafting).readFromNBT(data, "craftingGrid"); this.output.readFromNBT(data, "output"); this.pattern.readFromNBT(data, "patterns"); + upgrades.readFromNBT(wirelessTerminalGUIObject.getItemStack().getTagCompound().getCompoundTag("upgrades")); } } @@ -238,7 +248,6 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im @Override public void setupUpgrades() { if (wirelessTerminalGUIObject != null) { - final IItemHandler upgrades = wirelessTerminalGUIObject.getInventoryByName("upgrades"); for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) { this.addSlotToContainer( (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 187, upgradeSlot * 18 - 2, this.getInventoryPlayer())) diff --git a/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java index bb730ca6e..0f7574b97 100644 --- a/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java +++ b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java @@ -1,7 +1,12 @@ package appeng.fluids.container; import appeng.api.AEApi; -import appeng.api.config.*; +import appeng.api.config.Actionable; +import appeng.api.config.PowerMultiplier; +import appeng.api.config.Settings; +import appeng.api.config.SortDir; +import appeng.api.config.SortOrder; +import appeng.api.config.ViewItems; import appeng.api.implementations.IUpgradeableCellContainer; import appeng.api.implementations.guiobjects.IPortableCell; import appeng.api.networking.IGridHost; @@ -36,6 +41,8 @@ import appeng.core.sync.packets.PacketValueConfig; import appeng.fluids.util.AEFluidStack; import appeng.helpers.InventoryAction; import appeng.helpers.WirelessTerminalGuiObject; +import appeng.parts.automation.StackUpgradeInventory; +import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.ConfigManager; import appeng.util.IConfigManagerHost; import appeng.util.Platform; @@ -45,7 +52,9 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IContainerListener; +import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.fluids.capability.IFluidHandlerItem; @@ -74,6 +83,8 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE private int ticks = 0; private final int slot; + protected AppEngInternalInventory upgrades; + public ContainerMEPortableFluidCell(final InventoryPlayer ip, final IPortableCell monitorable) { this(ip, monitorable, null, true); } @@ -129,43 +140,45 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE this.bindPlayerInventory(ip, 0, 140); } hasPower = this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier(), Actionable.SIMULATE, PowerMultiplier.CONFIG) > 0.001; + upgrades = new StackUpgradeInventory(wirelessTerminalGUIObject.getItemStack(), this, 2); + this.loadFromNBT(); this.setupUpgrades(); - } @Override public void detectAndSendChanges() { - final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); - - if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { - this.setValidContainer(false); - } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { - if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { - this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack()); - } else { - this.setValidContainer(false); - } - } - - // drain 1 ae t - this.ticks++; - if (this.ticks > 10) { - double power = this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); - this.ticks = 0; - this.hasPower = power > 0.001; - } - - if (!this.wirelessTerminalGUIObject.rangeCheck()) { - if (Platform.isServer() && this.isValidContainer()) { - this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); - } - - this.setValidContainer(false); - } else { - this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); - } if (Platform.isServer()) { + final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); + + if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { + this.setValidContainer(false); + } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { + if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { + this.getPlayerInv().setInventorySlotContents(this.getPlayerInv().currentItem, this.wirelessTerminalGUIObject.getItemStack()); + } else { + this.setValidContainer(false); + } + } + + // drain 1 ae t + this.ticks++; + if (this.ticks > 10) { + double power = this.wirelessTerminalGUIObject.extractAEPower(this.getPowerMultiplier() * this.ticks, Actionable.MODULATE, PowerMultiplier.CONFIG); + this.ticks = 0; + this.hasPower = power > 0.001; + } + + if (!this.wirelessTerminalGUIObject.rangeCheck()) { + if (Platform.isServer() && this.isValidContainer()) { + this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + } + + this.setValidContainer(false); + } else { + this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); + } + if (this.monitor != this.terminal.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class))) { this.setValidContainer(false); } @@ -218,9 +231,7 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE } } //this.updatePowerStatus(); - } - super.detectAndSendChanges(); } @Override @@ -453,6 +464,11 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE } } + @Override + public void onSlotChange(Slot s) { + detectAndSendChanges(); + } + private void queueInventory(final IContainerListener c) { if (Platform.isServer() && c instanceof EntityPlayer && this.monitor != null) { try { @@ -527,7 +543,6 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE @Override public void setupUpgrades() { if (wirelessTerminalGUIObject != null) { - final IItemHandler upgrades = wirelessTerminalGUIObject.getInventoryByName("upgrades"); for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) { this.addSlotToContainer( (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 187, 139 + upgradeSlot * 18, this.getInventoryPlayer())) @@ -536,14 +551,24 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE } } - @Override public void saveChanges() { + if (Platform.isServer()) { + NBTTagCompound tag = new NBTTagCompound(); + this.upgrades.writeToNBT(tag, "upgrades"); + this.wirelessTerminalGUIObject.saveChanges(tag); + } + } + + private void loadFromNBT() { + NBTTagCompound data = wirelessTerminalGUIObject.getItemStack().getTagCompound(); + if (data != null) { + upgrades.readFromNBT(wirelessTerminalGUIObject.getItemStack().getTagCompound().getCompoundTag("upgrades")); + } } @Override public void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) { - } } diff --git a/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java b/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java index 214e55a15..c2ce18046 100644 --- a/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java +++ b/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java @@ -37,16 +37,18 @@ public class ContainerWirelessFluidTerminal extends ContainerMEPortableFluidCell @Override public void detectAndSendChanges() { - super.detectAndSendChanges(); + if (Platform.isServer()) { + super.detectAndSendChanges(); - if (!this.wirelessTerminalGUIObject.rangeCheck()) { - if (Platform.isServer() && this.isValidContainer()) { - this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + if (!this.wirelessTerminalGUIObject.rangeCheck()) { + if (Platform.isServer() && this.isValidContainer()) { + this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); + } + + this.setValidContainer(false); + } else { + this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); } - - this.setValidContainer(false); - } else { - this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); } } } diff --git a/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java index 8d4ebcc29..72504cc4b 100644 --- a/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java +++ b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java @@ -331,7 +331,7 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II } } - private void loadFromNBT() { + public void loadFromNBT() { NBTTagCompound data = effectiveItem.getTagCompound(); if (data != null) { viewCell.readFromNBT(data); From d76eec2145697da5c9b595fccc5c8a3041dcd493 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Mon, 30 Jan 2023 21:50:26 -0300 Subject: [PATCH 10/35] wip --- .../implementations/ContainerMEPortableCell.java | 10 +++++++++- .../ContainerWirelessCraftingTerminal.java | 1 - 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java index 7f90f1278..215281f79 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java +++ b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java @@ -21,7 +21,10 @@ package appeng.container.implementations; import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; +import appeng.api.config.SecurityPermissions; import appeng.api.implementations.IUpgradeableCellContainer; +import appeng.api.implementations.tiles.IViewCellStorage; +import appeng.api.networking.security.IActionHost; import appeng.container.interfaces.IInventorySlotAware; import appeng.container.slot.SlotRestrictedInput; import appeng.core.AEConfig; @@ -32,6 +35,7 @@ import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.Platform; import appeng.util.inv.IAEAppEngInventory; import appeng.util.inv.InvOperation; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; @@ -68,7 +72,6 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I this.setupUpgrades(); } - @Override public void detectAndSendChanges() { if (Platform.isServer()) { @@ -106,6 +109,11 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I } } + @Override + protected IActionHost getActionHost() { + return this.wirelessTerminalGUIObject; + } + private double getPowerMultiplier() { return this.powerMultiplier; } diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java index 0fc9fecdf..bdab4d39b 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java @@ -102,7 +102,6 @@ public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell i NBTTagCompound tag = new NBTTagCompound(); this.craftingGrid.writeToNBT(tag, "craftingGrid"); this.upgrades.writeToNBT(tag, "upgrades"); - this.wirelessTerminalGUIObject.saveChanges(tag); } } From ae0d02e7d53d08645959751fd4c6ba4b4c8d0b63 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Mon, 30 Jan 2023 23:41:13 -0300 Subject: [PATCH 11/35] linking kinda works --- .../implementations/ContainerQNB.java | 15 ++++++++-- .../container/slot/SlotRestrictedInput.java | 8 ++++++ .../helpers/WirelessTerminalGuiObject.java | 28 +++++++++++++++++-- .../appeng/tile/qnb/TileQuantumBridge.java | 2 +- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/main/java/appeng/container/implementations/ContainerQNB.java b/src/main/java/appeng/container/implementations/ContainerQNB.java index c34ab38a7..78213bac6 100644 --- a/src/main/java/appeng/container/implementations/ContainerQNB.java +++ b/src/main/java/appeng/container/implementations/ContainerQNB.java @@ -23,16 +23,27 @@ import appeng.container.AEBaseContainer; import appeng.container.slot.SlotRestrictedInput; import appeng.tile.qnb.TileQuantumBridge; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; public class ContainerQNB extends AEBaseContainer { + SlotRestrictedInput SINGULARITY; + SlotRestrictedInput QUANTUM_CARD; + public ContainerQNB(final InventoryPlayer ip, final TileQuantumBridge quantumBridge) { super(ip, quantumBridge, null); - this.addSlotToContainer((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.QE_SINGULARITY, quantumBridge - .getInternalInventory(), 0, 80, 37, this.getInventoryPlayer())).setStackLimit(1)); + SINGULARITY = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.QE_SINGULARITY, quantumBridge + .getInternalInventory(), 0, 80, 37, this.getInventoryPlayer()); + this.addSlotToContainer(SINGULARITY.setStackLimit(1)); + + QUANTUM_CARD = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.CARD_QUANTUM, quantumBridge + .getInternalInventory(), 1, 80, 55, this.getInventoryPlayer()); + this.addSlotToContainer((QUANTUM_CARD).setStackLimit(1)); this.bindPlayerInventory(ip, 0, 166 - /* height of player inventory */82); } + + } diff --git a/src/main/java/appeng/container/slot/SlotRestrictedInput.java b/src/main/java/appeng/container/slot/SlotRestrictedInput.java index 8b0350d85..7327bcf14 100644 --- a/src/main/java/appeng/container/slot/SlotRestrictedInput.java +++ b/src/main/java/appeng/container/slot/SlotRestrictedInput.java @@ -20,6 +20,7 @@ package appeng.container.slot; import appeng.api.AEApi; +import appeng.api.config.Upgrades; import appeng.api.definitions.IDefinitions; import appeng.api.definitions.IItems; import appeng.api.definitions.IMaterials; @@ -200,6 +201,11 @@ public class SlotRestrictedInput extends AppEngSlot { return i.getItem() instanceof IBiometricCard; case UPGRADES: return i.getItem() instanceof IUpgradeModule && ((IUpgradeModule) i.getItem()).getType(i) != null; + case CARD_QUANTUM: + if (AEApi.instance().definitions().materials().cardQuantumLink().maybeItem().isPresent()) { + return AEApi.instance().definitions().materials().cardQuantumLink().maybeItem().get() == i.getItem(); + } + return false; default: break; } @@ -269,6 +275,8 @@ public class SlotRestrictedInput extends AppEngSlot { RANGE_BOOSTER(6 * 16 + 15), QE_SINGULARITY(10 * 16 + 15), + + CARD_QUANTUM(0), SPATIAL_STORAGE_CELLS(11 * 16 + 15), FUEL(12 * 16 + 15), diff --git a/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java index 72504cc4b..f797315e9 100644 --- a/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java +++ b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java @@ -45,10 +45,13 @@ import appeng.api.storage.data.IItemList; import appeng.api.util.DimensionalCoord; import appeng.api.util.IConfigManager; import appeng.container.interfaces.IInventorySlotAware; +import appeng.me.cluster.IAECluster; +import appeng.me.cluster.implementations.QuantumCluster; import appeng.parts.automation.StackUpgradeInventory; import appeng.parts.automation.UpgradeInventory; import appeng.tile.inventory.AppEngInternalInventory; import appeng.tile.networking.TileWireless; +import appeng.tile.qnb.TileQuantumBridge; import appeng.util.inv.IAEAppEngInventory; import appeng.util.inv.InvOperation; import net.minecraft.entity.player.EntityPlayer; @@ -74,6 +77,7 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II private final AppEngInternalInventory viewCell = new AppEngInternalInventory(this, 5); private final UpgradeInventory upgrades; + private QuantumCluster myQC; public WirelessTerminalGuiObject(final IWirelessTermHandler wh, final ItemStack is, final EntityPlayer ep, final World w, final int x, final int y, final int z) { @@ -244,6 +248,8 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II this.rangeCheck(); if (this.myWap != null) { return this.myWap.getActionableNode(); + } else if (this.myQC != null && this.myQC.getCenter().isPowered()) { + return this.myQC.getCenter().getActionableNode(); } return null; } @@ -259,9 +265,10 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II return false; } - final IMachineSet tw = this.targetGrid.getMachines(TileWireless.class); + IMachineSet tw = this.targetGrid.getMachines(TileWireless.class); this.myWap = null; + this.myQC = null; for (final IGridNode n : tw) { final IWirelessAccessPoint wap = (IWirelessAccessPoint) n.getMachine(); @@ -270,7 +277,24 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II } } - return this.myWap != null; + if (myWap != null) return true; + + tw = this.targetGrid.getMachines(TileQuantumBridge.class); + for (final IGridNode n : tw) { + TileQuantumBridge tqb = (TileQuantumBridge) n.getMachine(); + if (tqb.getCluster() != null) { + TileQuantumBridge center = ((QuantumCluster) tqb.getCluster()).getCenter(); + if (center != null) { + if (center.getInternalInventory().getStackInSlot(1).isItemEqual(AEApi.instance().definitions().materials().cardQuantumLink().maybeStack(1).get())) { + myQC = (QuantumCluster) tqb.getCluster(); + myRange = 1; + return true; + } + } + } + } + + return this.myWap != null || this.myQC != null; } return false; } diff --git a/src/main/java/appeng/tile/qnb/TileQuantumBridge.java b/src/main/java/appeng/tile/qnb/TileQuantumBridge.java index 24e308371..d0ef6a64e 100644 --- a/src/main/java/appeng/tile/qnb/TileQuantumBridge.java +++ b/src/main/java/appeng/tile/qnb/TileQuantumBridge.java @@ -53,7 +53,7 @@ import java.util.Optional; public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock, ITickable { private final byte corner = 16; - private final AppEngInternalInventory internalInventory = new AppEngInternalInventory(this, 1, 1); + private final AppEngInternalInventory internalInventory = new AppEngInternalInventory(this, 2, 1); private final byte hasSingularity = 32; private final byte powered = 64; From 1759bd898e6aeb047bebba5733cde8514b082541 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Tue, 31 Jan 2023 12:40:41 -0300 Subject: [PATCH 12/35] magnetize magnet --- .../powered/ToolWirelessCraftingTerminal.java | 88 ++----------------- .../powered/ToolWirelessFluidTerminal.java | 81 +---------------- .../powered/ToolWirelessPatternTerminal.java | 81 +---------------- .../tools/powered/ToolWirelessTerminal.java | 34 +++++++ 4 files changed, 47 insertions(+), 237 deletions(-) diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessCraftingTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessCraftingTerminal.java index f77bf90cd..3c457aae1 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessCraftingTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessCraftingTerminal.java @@ -31,61 +31,35 @@ import appeng.core.AEConfig; import appeng.core.localization.GuiText; import appeng.core.sync.GuiBridge; import appeng.items.tools.powered.powersink.AEBasePoweredItem; +import appeng.parts.automation.StackUpgradeInventory; import appeng.util.ConfigManager; import appeng.util.Platform; import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.translation.I18n; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.IGuiHandler; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.items.ItemStackHandler; import java.util.List; -public class ToolWirelessCraftingTerminal extends AEBasePoweredItem implements IWirelessTermHandler { +public class ToolWirelessCraftingTerminal extends ToolWirelessTerminal implements IWirelessTermHandler { public ToolWirelessCraftingTerminal() { - super(AEConfig.instance().getWirelessTerminalBattery()); - } - - @Override - public ActionResult onItemRightClick(final World w, final EntityPlayer player, final EnumHand hand) { - AEApi.instance().registries().wireless().openWirelessTerminalGui(player.getHeldItem(hand), w, player); - return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand)); - } - - @SideOnly(Side.CLIENT) - @Override - public boolean isFull3D() { - return false; - } - - @Override - @SideOnly(Side.CLIENT) - public void addCheckedInformation(final ItemStack stack, final World world, final List lines, final ITooltipFlag advancedTooltips) { - super.addCheckedInformation(stack, world, lines, advancedTooltips); - - if (stack.hasTagCompound()) { - final NBTTagCompound tag = Platform.openNbtData(stack); - if (tag != null) { - final String encKey = tag.getString("encryptionKey"); - - if (encKey == null || encKey.isEmpty()) { - lines.add(GuiText.Unlinked.getLocal()); - } else { - lines.add(GuiText.Linked.getLocal()); - } - } - } else { - lines.add(I18n.translateToLocal("AppEng.GuiITooltip.Unlinked")); - } + super(); } @Override @@ -93,50 +67,6 @@ public class ToolWirelessCraftingTerminal extends AEBasePoweredItem implements I return AEApi.instance().definitions().items().wirelessCraftingTerminal().isSameAs(is); } - @Override - public boolean usePower(final EntityPlayer player, final double amount, final ItemStack is) { - return this.extractAEPower(is, amount, Actionable.MODULATE) >= amount - 0.5; - } - - @Override - public boolean hasPower(final EntityPlayer player, final double amt, final ItemStack is) { - return this.getAECurrentPower(is) >= amt; - } - - @Override - public IConfigManager getConfigManager(final ItemStack target) { - final ConfigManager out = new ConfigManager((manager, settingName, newValue) -> - { - final NBTTagCompound data = Platform.openNbtData(target); - manager.writeToNBT(data); - }); - - out.registerSetting(Settings.SORT_BY, SortOrder.NAME); - out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); - out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING); - - out.readFromNBT(Platform.openNbtData(target).copy()); - return out; - } - - @Override - public String getEncryptionKey(final ItemStack item) { - final NBTTagCompound tag = Platform.openNbtData(item); - return tag.getString("encryptionKey"); - } - - @Override - public void setEncryptionKey(final ItemStack item, final String encKey, final String name) { - final NBTTagCompound tag = Platform.openNbtData(item); - tag.setString("encryptionKey", encKey); - tag.setString("name", name); - } - - @Override - public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) { - return slotChanged; - } - @Override public IGuiHandler getGuiHandler(ItemStack is) { return GuiBridge.GUI_WIRELESS_CRAFTING_TERMINAL; diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessFluidTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessFluidTerminal.java index 3465fd721..0bc9bd4f3 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessFluidTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessFluidTerminal.java @@ -49,43 +49,10 @@ import net.minecraftforge.fml.relauncher.SideOnly; import java.util.List; -public class ToolWirelessFluidTerminal extends AEBasePoweredItem implements IWirelessTermHandler { +public class ToolWirelessFluidTerminal extends ToolWirelessTerminal implements IWirelessTermHandler { public ToolWirelessFluidTerminal() { - super(AEConfig.instance().getWirelessTerminalBattery()); - } - - @Override - public ActionResult onItemRightClick(final World w, final EntityPlayer player, final EnumHand hand) { - AEApi.instance().registries().wireless().openWirelessTerminalGui(player.getHeldItem(hand), w, player); - return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand)); - } - - @SideOnly(Side.CLIENT) - @Override - public boolean isFull3D() { - return false; - } - - @Override - @SideOnly(Side.CLIENT) - public void addCheckedInformation(final ItemStack stack, final World world, final List lines, final ITooltipFlag advancedTooltips) { - super.addCheckedInformation(stack, world, lines, advancedTooltips); - - if (stack.hasTagCompound()) { - final NBTTagCompound tag = Platform.openNbtData(stack); - if (tag != null) { - final String encKey = tag.getString("encryptionKey"); - - if (encKey == null || encKey.isEmpty()) { - lines.add(GuiText.Unlinked.getLocal()); - } else { - lines.add(GuiText.Linked.getLocal()); - } - } - } else { - lines.add(I18n.translateToLocal("AppEng.GuiITooltip.Unlinked")); - } + super(); } @Override @@ -93,50 +60,6 @@ public class ToolWirelessFluidTerminal extends AEBasePoweredItem implements IWir return AEApi.instance().definitions().items().wirelessFluidTerminal().isSameAs(is); } - @Override - public boolean usePower(final EntityPlayer player, final double amount, final ItemStack is) { - return this.extractAEPower(is, amount, Actionable.MODULATE) >= amount - 0.5; - } - - @Override - public boolean hasPower(final EntityPlayer player, final double amt, final ItemStack is) { - return this.getAECurrentPower(is) >= amt; - } - - @Override - public IConfigManager getConfigManager(final ItemStack target) { - final ConfigManager out = new ConfigManager((manager, settingName, newValue) -> - { - final NBTTagCompound data = Platform.openNbtData(target); - manager.writeToNBT(data); - }); - - out.registerSetting(Settings.SORT_BY, SortOrder.NAME); - out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); - out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING); - - out.readFromNBT(Platform.openNbtData(target).copy()); - return out; - } - - @Override - public String getEncryptionKey(final ItemStack item) { - final NBTTagCompound tag = Platform.openNbtData(item); - return tag.getString("encryptionKey"); - } - - @Override - public void setEncryptionKey(final ItemStack item, final String encKey, final String name) { - final NBTTagCompound tag = Platform.openNbtData(item); - tag.setString("encryptionKey", encKey); - tag.setString("name", name); - } - - @Override - public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) { - return slotChanged; - } - @Override public IGuiHandler getGuiHandler(ItemStack is) { return GuiBridge.GUI_WIRELESS_FLUID_TERMINAL; diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessPatternTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessPatternTerminal.java index f55bc1d86..d061bb5a2 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessPatternTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessPatternTerminal.java @@ -49,43 +49,10 @@ import net.minecraftforge.fml.relauncher.SideOnly; import java.util.List; -public class ToolWirelessPatternTerminal extends AEBasePoweredItem implements IWirelessTermHandler { +public class ToolWirelessPatternTerminal extends ToolWirelessTerminal implements IWirelessTermHandler { public ToolWirelessPatternTerminal() { - super(AEConfig.instance().getWirelessTerminalBattery()); - } - - @Override - public ActionResult onItemRightClick(final World w, final EntityPlayer player, final EnumHand hand) { - AEApi.instance().registries().wireless().openWirelessTerminalGui(player.getHeldItem(hand), w, player); - return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand)); - } - - @SideOnly(Side.CLIENT) - @Override - public boolean isFull3D() { - return false; - } - - @Override - @SideOnly(Side.CLIENT) - public void addCheckedInformation(final ItemStack stack, final World world, final List lines, final ITooltipFlag advancedTooltips) { - super.addCheckedInformation(stack, world, lines, advancedTooltips); - - if (stack.hasTagCompound()) { - final NBTTagCompound tag = Platform.openNbtData(stack); - if (tag != null) { - final String encKey = tag.getString("encryptionKey"); - - if (encKey == null || encKey.isEmpty()) { - lines.add(GuiText.Unlinked.getLocal()); - } else { - lines.add(GuiText.Linked.getLocal()); - } - } - } else { - lines.add(I18n.translateToLocal("AppEng.GuiITooltip.Unlinked")); - } + super(); } @Override @@ -93,50 +60,6 @@ public class ToolWirelessPatternTerminal extends AEBasePoweredItem implements IW return AEApi.instance().definitions().items().wirelessPatternTerminal().isSameAs(is); } - @Override - public boolean usePower(final EntityPlayer player, final double amount, final ItemStack is) { - return this.extractAEPower(is, amount, Actionable.MODULATE) >= amount - 0.5; - } - - @Override - public boolean hasPower(final EntityPlayer player, final double amt, final ItemStack is) { - return this.getAECurrentPower(is) >= amt; - } - - @Override - public IConfigManager getConfigManager(final ItemStack target) { - final ConfigManager out = new ConfigManager((manager, settingName, newValue) -> - { - final NBTTagCompound data = Platform.openNbtData(target); - manager.writeToNBT(data); - }); - - out.registerSetting(Settings.SORT_BY, SortOrder.NAME); - out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); - out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING); - - out.readFromNBT(Platform.openNbtData(target).copy()); - return out; - } - - @Override - public String getEncryptionKey(final ItemStack item) { - final NBTTagCompound tag = Platform.openNbtData(item); - return tag.getString("encryptionKey"); - } - - @Override - public void setEncryptionKey(final ItemStack item, final String encKey, final String name) { - final NBTTagCompound tag = Platform.openNbtData(item); - tag.setString("encryptionKey", encKey); - tag.setString("name", name); - } - - @Override - public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) { - return slotChanged; - } - @Override public IGuiHandler getGuiHandler(ItemStack is) { return GuiBridge.GUI_WIRELESS_PATTERN_TERMINAL; diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java index a096e5081..8311ebc0d 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java @@ -30,23 +30,30 @@ import appeng.items.tools.powered.powersink.AEBasePoweredItem; import appeng.util.ConfigManager; import appeng.util.Platform; import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.translation.I18n; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.IGuiHandler; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.items.ItemStackHandler; import java.util.List; public class ToolWirelessTerminal extends AEBasePoweredItem implements IWirelessTermHandler { + int magnetTick; + public ToolWirelessTerminal() { super(AEConfig.instance().getWirelessTerminalBattery()); } @@ -133,6 +140,33 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless return slotChanged; } + @Override + public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); + if (entityIn instanceof EntityPlayer) { + this.magnetTick++; + if (magnetTick % 5 != 0) { + return; + } + magnetTick = 0; + if (!entityIn.isSneaking()) { + NBTTagCompound upgradeNBT = Platform.openNbtData(stack).getCompoundTag("upgrades"); + ItemStackHandler siu = new ItemStackHandler(0); + siu.deserializeNBT(upgradeNBT); + for (int s = 0; s < siu.getSlots(); s++) { + if (siu.getStackInSlot(s).isItemEqual(AEApi.instance().definitions().materials().cardMagnet().maybeStack(1).get())) { + List ei = worldIn.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB( + new Vec3d(entityIn.posX + 5, entityIn.posY + 5, entityIn.posZ + 5), + new Vec3d(entityIn.posX - 5, entityIn.posY - 5, entityIn.posZ - 5))); + for (EntityItem i : ei) { + i.setPosition(entityIn.posX, entityIn.posY, entityIn.posZ); + } + } + } + } + } + } + @Override public IGuiHandler getGuiHandler(ItemStack is) { return GuiBridge.GUI_WIRELESS_TERM; From 9785e38e3f07e3a2c9d98d04cc655476042599c9 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Tue, 31 Jan 2023 15:29:43 -0300 Subject: [PATCH 13/35] magnet filtering --- src/main/java/appeng/core/Registration.java | 4 ++ .../appeng/items/materials/ItemMaterial.java | 37 +++++++++++++++- .../tools/powered/ToolWirelessTerminal.java | 43 ++++++++++++++++++- 3 files changed, 81 insertions(+), 3 deletions(-) diff --git a/src/main/java/appeng/core/Registration.java b/src/main/java/appeng/core/Registration.java index 7087934a0..25ef37615 100644 --- a/src/main/java/appeng/core/Registration.java +++ b/src/main/java/appeng/core/Registration.java @@ -19,6 +19,7 @@ package appeng.core; +import appeng.api.AEApi; import appeng.api.config.Upgrades; import appeng.api.definitions.IBlocks; import appeng.api.definitions.IItemDefinition; @@ -380,6 +381,9 @@ final class Registration { Upgrades.FUZZY.registerItem(items.viewCell(), 1); Upgrades.INVERTER.registerItem(items.viewCell(), 1); + Upgrades.FUZZY.registerItem(AEApi.instance().definitions().materials().cardMagnet(), 1); + Upgrades.INVERTER.registerItem(AEApi.instance().definitions().materials().cardMagnet(), 1); + // Storage Bus Upgrades.FUZZY.registerItem(parts.storageBus(), 1); Upgrades.INVERTER.registerItem(parts.storageBus(), 1); diff --git a/src/main/java/appeng/items/materials/ItemMaterial.java b/src/main/java/appeng/items/materials/ItemMaterial.java index 25013958e..17250b6c6 100644 --- a/src/main/java/appeng/items/materials/ItemMaterial.java +++ b/src/main/java/appeng/items/materials/ItemMaterial.java @@ -19,6 +19,8 @@ package appeng.items.materials; +import appeng.api.AEApi; +import appeng.api.config.FuzzyMode; import appeng.api.config.Upgrades; import appeng.api.implementations.IUpgradeableHost; import appeng.api.implementations.items.IItemGroup; @@ -27,11 +29,14 @@ import appeng.api.implementations.items.IUpgradeModule; import appeng.api.implementations.tiles.ISegmentedInventory; import appeng.api.parts.IPartHost; import appeng.api.parts.SelectedPart; +import appeng.api.storage.ICellWorkbenchItem; import appeng.core.AEConfig; import appeng.core.features.AEFeature; import appeng.core.features.IStackSrc; import appeng.core.features.MaterialStackSrc; import appeng.items.AEBaseItem; +import appeng.items.contents.CellConfig; +import appeng.items.contents.CellUpgrades; import appeng.util.InventoryAdaptor; import appeng.util.Platform; import appeng.util.inv.AdaptorItemHandler; @@ -63,7 +68,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public final class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule { +public final class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule, ICellWorkbenchItem { public static ItemMaterial instance; private static final int KILO_SCALAR = 1024; @@ -313,6 +318,36 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent, return false; } + @Override + public boolean isEditable(ItemStack is) { + return is.isItemEqual(AEApi.instance().definitions().materials().cardMagnet().maybeStack(1).get()); + } + + @Override + public IItemHandler getUpgradesInventory(final ItemStack is) { + return new CellUpgrades(is, 2); + } + + @Override + public IItemHandler getConfigInventory(final ItemStack is) { + return new CellConfig(is); + } + + @Override + public FuzzyMode getFuzzyMode(final ItemStack is) { + final String fz = Platform.openNbtData(is).getString("FuzzyMode"); + try { + return FuzzyMode.valueOf(fz); + } catch (final Throwable t) { + return FuzzyMode.IGNORE_ALL; + } + } + + @Override + public void setFuzzyMode(final ItemStack is, final FuzzyMode fzMode) { + Platform.openNbtData(is).setString("FuzzyMode", fzMode.name()); + } + private static class SlightlyBetterSort implements Comparator { private final Pattern pattern; diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java index 8311ebc0d..eafdf6895 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java @@ -26,6 +26,9 @@ import appeng.api.util.IConfigManager; import appeng.core.AEConfig; import appeng.core.localization.GuiText; import appeng.core.sync.GuiBridge; +import appeng.items.contents.CellConfig; +import appeng.items.contents.CellUpgrades; +import appeng.items.materials.ItemMaterial; import appeng.items.tools.powered.powersink.AEBasePoweredItem; import appeng.util.ConfigManager; import appeng.util.Platform; @@ -154,12 +157,48 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless ItemStackHandler siu = new ItemStackHandler(0); siu.deserializeNBT(upgradeNBT); for (int s = 0; s < siu.getSlots(); s++) { - if (siu.getStackInSlot(s).isItemEqual(AEApi.instance().definitions().materials().cardMagnet().maybeStack(1).get())) { + ItemStack is = siu.getStackInSlot(s); + if (is.isItemEqual(AEApi.instance().definitions().materials().cardMagnet().maybeStack(1).get())) { + ItemMaterial im = (ItemMaterial) is.getItem(); + CellConfig c = (CellConfig) im.getConfigInventory(is); + CellUpgrades u = (CellUpgrades) im.getUpgradesInventory(is); + FuzzyMode fz = null; + boolean isFuzzy = u.getInstalledUpgrades(Upgrades.FUZZY) == 1; + if (isFuzzy) { + fz = im.getFuzzyMode(is); + } + boolean inverted = u.getInstalledUpgrades(Upgrades.INVERTER) == 1; + List ei = worldIn.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB( new Vec3d(entityIn.posX + 5, entityIn.posY + 5, entityIn.posZ + 5), new Vec3d(entityIn.posX - 5, entityIn.posY - 5, entityIn.posZ - 5))); + boolean emptyFilter = true; for (EntityItem i : ei) { - i.setPosition(entityIn.posX, entityIn.posY, entityIn.posZ); + boolean matched = false; + for (int ss = 0; ss < c.getSlots(); ss++) { + ItemStack filter = c.getStackInSlot(ss); + if (filter.isEmpty()) continue; + emptyFilter = false; + if (isFuzzy) { + if (Platform.itemComparisons().isFuzzyEqualItem(filter, i.getItem(), fz)) { + matched = true; + break; + } + } else { + if (Platform.itemComparisons().isSameItem(filter, i.getItem())) { + matched = true; + break; + } + } + } + if (emptyFilter) { + i.setPosition(entityIn.posX, entityIn.posY, entityIn.posZ); + } + if (matched && !inverted) { + i.setPosition(entityIn.posX, entityIn.posY, entityIn.posZ); + } else if (!matched && inverted) { + i.setPosition(entityIn.posX, entityIn.posY, entityIn.posZ); + } } } } From d6f2ed30e5f61aec259bbdfc706241377e2abfed Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Tue, 31 Jan 2023 16:52:00 -0300 Subject: [PATCH 14/35] make them bauble trinkets --- gradle/scripts/dependencies.gradle | 5 +-- .../tools/powered/ToolWirelessTerminal.java | 37 ++++++++++++++++--- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/gradle/scripts/dependencies.gradle b/gradle/scripts/dependencies.gradle index a68a2c5ed..ed201c44f 100644 --- a/gradle/scripts/dependencies.gradle +++ b/gradle/scripts/dependencies.gradle @@ -23,12 +23,10 @@ repositories { url "https://cursemaven.com" } - /* maven { name = "CurseForge" url = "https://minecraft.curseforge.com/api/maven/" } - */ maven { name "Mobius" @@ -87,11 +85,12 @@ dependencies { compileOnly "curse.maven:chisel-235279:2915375" + deobfCompile "baubles:Baubles:1.12:1.5.2" //mods "mcp.mobius.waila:Hwyla:${hwyla_version}" mods "curse.maven:hwyla-253449:2568751" mods "net.industrial-craft:industrialcraft-2:${ic2_version}:dev" mods "mcjty.theoneprobe:TheOneProbe-${minecraft_version}:${top_version}" - + // compile against provided APIs compileOnly "mezz.jei:jei_${minecraft_version}:${jei_version}:api" //compileOnly "mcp.mobius.waila:Hwyla:${hwyla_version}" diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java index eafdf6895..48430ac6d 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java @@ -32,8 +32,11 @@ import appeng.items.materials.ItemMaterial; import appeng.items.tools.powered.powersink.AEBasePoweredItem; import appeng.util.ConfigManager; import appeng.util.Platform; +import baubles.api.BaubleType; +import baubles.api.IBauble; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -45,6 +48,7 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.translation.I18n; import net.minecraft.world.World; +import net.minecraftforge.fml.common.Optional; import net.minecraftforge.fml.common.network.IGuiHandler; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -52,8 +56,9 @@ import net.minecraftforge.items.ItemStackHandler; import java.util.List; +@Optional.Interface(iface = "baubles.api.IBauble", modid = "baubles") -public class ToolWirelessTerminal extends AEBasePoweredItem implements IWirelessTermHandler { +public class ToolWirelessTerminal extends AEBasePoweredItem implements IWirelessTermHandler, IBauble { int magnetTick; @@ -146,6 +151,31 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless @Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); + if (Platform.isServer()) { + magnetLogic(stack, worldIn, entityIn); + } + } + + @Override + public IGuiHandler getGuiHandler(ItemStack is) { + return GuiBridge.GUI_WIRELESS_TERM; + } + + @Optional.Method(modid = "baubles") + @Override + public BaubleType getBaubleType(ItemStack itemStack) { + return BaubleType.TRINKET; + } + + @Optional.Method(modid = "baubles") + @Override + public void onWornTick(ItemStack itemstack, EntityLivingBase player) { + if (Platform.isServer()) { + magnetLogic(itemstack, player.world, player); + } + } + + public void magnetLogic(ItemStack stack, World worldIn, Entity entityIn) { if (entityIn instanceof EntityPlayer) { this.magnetTick++; if (magnetTick % 5 != 0) { @@ -205,9 +235,4 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless } } } - - @Override - public IGuiHandler getGuiHandler(ItemStack is) { - return GuiBridge.GUI_WIRELESS_TERM; - } } From a0ec9ceb517be2aed9e1a492a146ead5bb5edbb8 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Tue, 31 Jan 2023 23:24:27 -0300 Subject: [PATCH 15/35] keybinds work --- src/main/java/appeng/client/ClientHelper.java | 40 +++++++++- src/main/java/appeng/client/KeyBindings.java | 28 +++++++ .../ContainerMEPortableCell.java | 14 +++- .../ContainerWirelessPatternTerminal.java | 15 +++- .../ContainerWirelessTerm.java | 3 - .../interfaces/IInventorySlotAware.java | 74 ++++++++++--------- src/main/java/appeng/core/Registration.java | 7 +- .../core/sync/AppEngPacketHandlerBase.java | 4 +- src/main/java/appeng/core/sync/GuiBridge.java | 25 +++++-- .../core/sync/packets/PacketTerminalUse.java | 53 +++++++++++++ .../ContainerMEPortableFluidCell.java | 17 +++-- .../ContainerWirelessFluidTerminal.java | 22 ------ .../helpers/WirelessTerminalGuiObject.java | 7 ++ .../appeng/items/tools/powered/Terminal.java | 28 +++++++ .../tools/powered/ToolWirelessTerminal.java | 9 +++ src/main/java/appeng/util/Platform.java | 12 +++ 16 files changed, 275 insertions(+), 83 deletions(-) create mode 100644 src/main/java/appeng/client/KeyBindings.java create mode 100644 src/main/java/appeng/core/sync/packets/PacketTerminalUse.java create mode 100644 src/main/java/appeng/items/tools/powered/Terminal.java diff --git a/src/main/java/appeng/client/ClientHelper.java b/src/main/java/appeng/client/ClientHelper.java index 91af9bd96..a09e1a270 100644 --- a/src/main/java/appeng/client/ClientHelper.java +++ b/src/main/java/appeng/client/ClientHelper.java @@ -35,6 +35,7 @@ import appeng.core.Api; import appeng.core.AppEng; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketAssemblerAnimation; +import appeng.core.sync.packets.PacketTerminalUse; import appeng.core.sync.packets.PacketValueConfig; import appeng.entity.EntityFloatingItem; import appeng.entity.EntityTinyTNTPrimed; @@ -44,6 +45,8 @@ import appeng.helpers.HighlighterHandler; import appeng.helpers.IMouseWheelItem; import appeng.hooks.TickHandler; import appeng.hooks.TickHandler.PlayerColor; +import appeng.items.tools.powered.Terminal; +import appeng.items.tools.powered.ToolWirelessTerminal; import appeng.server.ServerHelper; import appeng.util.Platform; import net.minecraft.client.Minecraft; @@ -59,12 +62,19 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.client.event.*; import net.minecraftforge.client.model.ModelLoaderRegistry; +import net.minecraftforge.client.settings.KeyConflictContext; +import net.minecraftforge.client.settings.KeyModifier; import net.minecraftforge.common.ForgeModContainer; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.FMLClientHandler; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.client.registry.RenderingRegistry; +import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.InputEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import java.io.IOException; @@ -73,11 +83,17 @@ import java.util.EnumMap; import java.util.List; import java.util.Random; +import static appeng.client.KeyBindings.WCT; +import static appeng.client.KeyBindings.WFT; +import static appeng.client.KeyBindings.WPT; +import static appeng.client.KeyBindings.WT; + public class ClientHelper extends ServerHelper { - private final static String KEY_CATEGORY = "key.appliedenergistics2.category"; + public final static String KEY_CATEGORY = "key.appliedenergistics2.category"; private final EnumMap bindings = new EnumMap<>(ActionKey.class); + private final List keyBindings = new ArrayList<>(); @Override public void preinit() { @@ -99,6 +115,11 @@ public class ClientHelper extends ServerHelper { this.bindings.put(key, binding); } + for (KeyBindings k : KeyBindings.values()) { + ClientRegistry.registerKeyBinding(k.getKeyBinding()); + this.keyBindings.add(k.getKeyBinding()); + } + Api.INSTANCE.definitions().items().encodedPattern().maybeItem().ifPresent(pattern -> Minecraft.getMinecraft().getItemColors().registerItemColorHandler(ItemEncodedPatternBakedModel.PATTERN_ITEM_COLOR_HANDLER, pattern)); } @@ -319,6 +340,23 @@ public class ClientHelper extends ServerHelper { } } + @SubscribeEvent(priority = EventPriority.HIGHEST) + public void onInputEvent(final InputEvent.KeyInputEvent event) { + for (KeyBinding k : keyBindings) { + if (k.isPressed()) { + if (k == WT.getKeyBinding()) { + NetworkHandler.instance().sendToServer(new PacketTerminalUse(Terminal.WIRELESS_TERMINAL)); + } else if (k == WCT.getKeyBinding()) { + NetworkHandler.instance().sendToServer(new PacketTerminalUse(Terminal.WIRELESS_CRAFTING_TERMINAL)); + } else if (k == WPT.getKeyBinding()) { + NetworkHandler.instance().sendToServer(new PacketTerminalUse(Terminal.WIRELESS_PATTERN_TERMINAL)); + } else if (k == WFT.getKeyBinding()) { + NetworkHandler.instance().sendToServer(new PacketTerminalUse(Terminal.WIRELESS_FLUID_TERMINAL)); + } + } + } + } + @SubscribeEvent public void onTextureStitch(final TextureStitchEvent.Pre event) { ParticleTextures.registerSprite(event); diff --git a/src/main/java/appeng/client/KeyBindings.java b/src/main/java/appeng/client/KeyBindings.java new file mode 100644 index 000000000..6dd711313 --- /dev/null +++ b/src/main/java/appeng/client/KeyBindings.java @@ -0,0 +1,28 @@ +package appeng.client; + +import net.minecraft.client.settings.KeyBinding; +import net.minecraftforge.client.settings.KeyConflictContext; +import net.minecraftforge.client.settings.KeyModifier; +import org.lwjgl.input.Keyboard; + +import static appeng.client.ClientHelper.KEY_CATEGORY; + + +public enum KeyBindings { + WT(new KeyBinding("open_wireless_terminal", KeyConflictContext.UNIVERSAL, KeyModifier.SHIFT, Keyboard.KEY_T, KEY_CATEGORY)), + WCT(new KeyBinding("open_wireless_crafting_terminal", KeyConflictContext.UNIVERSAL, KeyModifier.SHIFT, Keyboard.KEY_E, KEY_CATEGORY)), + WPT(new KeyBinding("open_wireless_pattern_terminal", KeyConflictContext.UNIVERSAL, KeyModifier.SHIFT, Keyboard.KEY_R, KEY_CATEGORY)), + WFT(new KeyBinding("open_wireless_fluid_terminal", KeyConflictContext.UNIVERSAL, KeyModifier.SHIFT, Keyboard.KEY_F, KEY_CATEGORY)); + + private KeyBinding keyBinding; + + KeyBindings(KeyBinding keyBinding) { + this.keyBinding = keyBinding; + } + + ; + + public KeyBinding getKeyBinding() { + return keyBinding; + } +} diff --git a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java index 215281f79..525db0fe3 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java +++ b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java @@ -35,6 +35,7 @@ import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.Platform; import appeng.util.inv.IAEAppEngInventory; import appeng.util.inv.InvOperation; +import baubles.api.BaublesApi; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; @@ -56,7 +57,9 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I super(ip, monitorable, bindInventory); if (monitorable != null) { final int slotIndex = ((IInventorySlotAware) monitorable).getInventorySlot(); - this.lockPlayerInventorySlot(slotIndex); + if (!((IInventorySlotAware) monitorable).isBaubleSlot()) { + this.lockPlayerInventorySlot(slotIndex); + } this.slot = slotIndex; } else { this.slot = -1; @@ -76,9 +79,14 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I public void detectAndSendChanges() { if (Platform.isServer()) { - final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); + final ItemStack currentItem; + if (wirelessTerminalGUIObject.isBaubleSlot()) { + currentItem = BaublesApi.getBaublesHandler(this.getPlayerInv().player).getStackInSlot(this.slot); + } else { + currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); + } - if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { + if (currentItem.isEmpty()) { this.setValidContainer(false); } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java index 289d62a82..23753b534 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java @@ -25,6 +25,7 @@ import appeng.api.implementations.ICraftingPatternItem; import appeng.api.implementations.IUpgradeableCellContainer; import appeng.api.networking.crafting.ICraftingPatternDetails; import appeng.api.storage.data.IAEItemStack; +import appeng.container.interfaces.IInventorySlotAware; import appeng.container.slot.OptionalSlotFake; import appeng.container.slot.SlotFakeCraftingMatrix; import appeng.container.slot.SlotPatternOutputs; @@ -38,6 +39,7 @@ import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.Platform; import appeng.util.helpers.ItemHandlerUtil; import appeng.util.inv.InvOperation; +import baubles.api.BaublesApi; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -69,7 +71,9 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im if (gui != null) { final int slotIndex = gui.getInventorySlot(); - this.lockPlayerInventorySlot(slotIndex); + if (!((IInventorySlotAware) gui).isBaubleSlot()) { + this.lockPlayerInventorySlot(slotIndex); + } this.slot = slotIndex; } else { this.slot = -1; @@ -116,9 +120,14 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im public void detectAndSendChanges() { if (Platform.isServer()) { - final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); + final ItemStack currentItem; + if (wirelessTerminalGUIObject.isBaubleSlot()) { + currentItem = BaublesApi.getBaublesHandler(this.getPlayerInv().player).getStackInSlot(this.slot); + } else { + currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); + } - if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { + if (currentItem.isEmpty()) { this.setValidContainer(false); } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessTerm.java b/src/main/java/appeng/container/implementations/ContainerWirelessTerm.java index 3a2ba0a4d..cd9eae785 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessTerm.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessTerm.java @@ -28,11 +28,8 @@ import net.minecraft.entity.player.InventoryPlayer; public class ContainerWirelessTerm extends ContainerMEPortableCell { - private final WirelessTerminalGuiObject wirelessTerminalGUIObject; - public ContainerWirelessTerm(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) { super(ip, gui, true); - this.wirelessTerminalGUIObject = gui; } @Override diff --git a/src/main/java/appeng/container/interfaces/IInventorySlotAware.java b/src/main/java/appeng/container/interfaces/IInventorySlotAware.java index 1af2a7be7..1471e9118 100644 --- a/src/main/java/appeng/container/interfaces/IInventorySlotAware.java +++ b/src/main/java/appeng/container/interfaces/IInventorySlotAware.java @@ -1,35 +1,39 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. - * - * Applied Energistics 2 is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Applied Energistics 2 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Applied Energistics 2. If not, see . - */ - -package appeng.container.interfaces; - - -/** - * Any item providing a GUI and depending on an exact inventory slot. - *

- * This interface is likely a volatile one until a general GUI refactoring occurred. - * Use it with care and expect changes. - */ -public interface IInventorySlotAware { - /** - * This is needed to select the correct slot index. - * - * @return the inventory index of this portable cell. - */ - int getInventorySlot(); -} +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.container.interfaces; + + +/** + * Any item providing a GUI and depending on an exact inventory slot. + *

+ * This interface is likely a volatile one until a general GUI refactoring occurred. + * Use it with care and expect changes. + */ +public interface IInventorySlotAware { + /** + * This is needed to select the correct slot index. + * + * @return the inventory index of this portable cell. + */ + int getInventorySlot(); + + default boolean isBaubleSlot() { + return false; + } +} diff --git a/src/main/java/appeng/core/Registration.java b/src/main/java/appeng/core/Registration.java index 25ef37615..2297041d6 100644 --- a/src/main/java/appeng/core/Registration.java +++ b/src/main/java/appeng/core/Registration.java @@ -414,8 +414,7 @@ final class Registration { iids.add(items.wirelessTerminal()); iids.add(items.wirelessCraftingTerminal()); iids.add(items.wirelessPatternTerminal()); - iids.add(items.wirelessFluidTerminal()); - + for (IItemDefinition id : iids) { id.maybeItem().ifPresent(terminal -> { registries.wireless().registerWirelessHandler((IWirelessTermHandler) terminal); @@ -423,6 +422,10 @@ final class Registration { Upgrades.MAGNET.registerItem(id, 1); }); } + items.wirelessFluidTerminal().maybeItem().ifPresent(terminal -> { + registries.wireless().registerWirelessHandler((IWirelessTermHandler) terminal); + Upgrades.QUANTUM_LINK.registerItem(items.wirelessFluidTerminal(), 1); + }); // Charge Rates items.chargedStaff().maybeItem().ifPresent(chargedStaff -> registries.charger().addChargeRate(chargedStaff, 320d)); diff --git a/src/main/java/appeng/core/sync/AppEngPacketHandlerBase.java b/src/main/java/appeng/core/sync/AppEngPacketHandlerBase.java index 5738fb18c..6e7065161 100644 --- a/src/main/java/appeng/core/sync/AppEngPacketHandlerBase.java +++ b/src/main/java/appeng/core/sync/AppEngPacketHandlerBase.java @@ -84,7 +84,9 @@ public class AppEngPacketHandlerBase { PACKET_INFORM_PLAYER(PacketInformPlayer.class), - PACKET_CRAFTING_CPUS_UPDATE(PacketCraftingCPUsUpdate.class); + PACKET_CRAFTING_CPUS_UPDATE(PacketCraftingCPUsUpdate.class), + + PACKET_TERMINAL_KEYBIND(PacketTerminalUse.class); private final Class packetClass; diff --git a/src/main/java/appeng/core/sync/GuiBridge.java b/src/main/java/appeng/core/sync/GuiBridge.java index 1a519cc0c..748f27532 100644 --- a/src/main/java/appeng/core/sync/GuiBridge.java +++ b/src/main/java/appeng/core/sync/GuiBridge.java @@ -71,6 +71,7 @@ import appeng.tile.storage.TileDrive; import appeng.tile.storage.TileIOPort; import appeng.tile.storage.TileSkyChest; import appeng.util.Platform; +import baubles.api.BaublesApi; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; @@ -233,10 +234,14 @@ public enum GuiBridge implements IGuiHandler { final boolean stem = ((ordinal >> 3) & 1) == 1; if (ID.type.isItem()) { ItemStack it = ItemStack.EMPTY; - if (stem) { - it = player.inventory.getCurrentItem(); - } else if (x >= 0 && x < player.inventory.mainInventory.size()) { - it = player.inventory.getStackInSlot(x); + if (y == 0) { + if (stem) { + it = player.inventory.getCurrentItem(); + } else if (x >= 0 && x < player.inventory.mainInventory.size()) { + it = player.inventory.getStackInSlot(x); + } + } else { + it = BaublesApi.getBaublesHandler(player).getStackInSlot(x); } final Object myItem = this.getGuiObject(it, player, w, x, y, z); if (myItem != null && ID.CorrectTileOrPart(myItem)) { @@ -344,10 +349,14 @@ public enum GuiBridge implements IGuiHandler { final boolean stem = ((ordinal >> 3) & 1) == 1; if (ID.type.isItem()) { ItemStack it = ItemStack.EMPTY; - if (stem) { - it = player.inventory.getCurrentItem(); - } else if (x >= 0 && x < player.inventory.mainInventory.size()) { - it = player.inventory.getStackInSlot(x); + if (y == 0) { + if (stem) { + it = player.inventory.getCurrentItem(); + } else if (x >= 0 && x < player.inventory.mainInventory.size()) { + it = player.inventory.getStackInSlot(x); + } + } else { + it = BaublesApi.getBaublesHandler(player).getStackInSlot(x); } final Object myItem = this.getGuiObject(it, player, w, x, y, z); if (myItem != null && ID.CorrectTileOrPart(myItem)) { diff --git a/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java b/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java new file mode 100644 index 000000000..2a932a423 --- /dev/null +++ b/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java @@ -0,0 +1,53 @@ +package appeng.core.sync.packets; + +import appeng.core.sync.AppEngPacket; +import appeng.core.sync.network.INetworkInfo; +import appeng.items.tools.powered.Terminal; +import appeng.util.Platform; +import baubles.api.BaublesApi; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; + +public class PacketTerminalUse extends AppEngPacket { + Terminal terminal; + + public PacketTerminalUse(final ByteBuf stream) { + this.terminal = Terminal.values()[stream.readInt()]; + } + + public PacketTerminalUse(Enum terminal) { + + final ByteBuf data = Unpooled.buffer(); + + data.writeInt(this.getPacketID()); + data.writeInt(terminal.ordinal()); + + this.configureWrite(data); + } + + @Override + public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player) { + NonNullList mainInventory = player.inventory.mainInventory; + for (int i = 0; i < mainInventory.size(); i++) { + ItemStack is = mainInventory.get(i); + if (is.isItemEqual(terminal.getItemDefinition().maybeStack(1).get())) { + Platform.openGUI(player, i, terminal.getBridge(), false); + return; + } + } + for (int i = 0; i < BaublesApi.getBaublesHandler(player).getSlots(); i++) { + ItemStack is = BaublesApi.getBaublesHandler(player).getStackInSlot(i); + if (is.isItemEqual(terminal.getItemDefinition().maybeStack(1).get())) { + Platform.openGUI(player, i, terminal.getBridge(), true); + break; + } + } + } + + enum a { + + } +} diff --git a/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java index 0f7574b97..785db70e8 100644 --- a/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java +++ b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java @@ -48,6 +48,7 @@ import appeng.util.IConfigManagerHost; import appeng.util.Platform; import appeng.util.inv.IAEAppEngInventory; import appeng.util.inv.InvOperation; +import baubles.api.BaublesApi; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; @@ -66,7 +67,7 @@ import java.nio.BufferOverflowException; public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAEAppEngInventory, IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver, IUpgradeableCellContainer { - private final WirelessTerminalGuiObject wirelessTerminalGUIObject; + protected final WirelessTerminalGuiObject wirelessTerminalGUIObject; private final IConfigManager clientCM; private final IMEMonitor monitor; @@ -129,7 +130,9 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE if (monitorable != null) { final int slotIndex = ((IInventorySlotAware) monitorable).getInventorySlot(); - this.lockPlayerInventorySlot(slotIndex); + if (!((IInventorySlotAware) monitorable).isBaubleSlot()) { + this.lockPlayerInventorySlot(slotIndex); + } this.slot = slotIndex; } else { this.slot = -1; @@ -149,9 +152,13 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE @Override public void detectAndSendChanges() { if (Platform.isServer()) { - final ItemStack currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); - - if (this.wirelessTerminalGUIObject == null || currentItem.isEmpty()) { + final ItemStack currentItem; + if (wirelessTerminalGUIObject.isBaubleSlot()) { + currentItem = BaublesApi.getBaublesHandler(this.getPlayerInv().player).getStackInSlot(this.slot); + } else { + currentItem = this.slot < 0 ? this.getPlayerInv().getCurrentItem() : this.getPlayerInv().getStackInSlot(this.slot); + } + if (currentItem.isEmpty()) { this.setValidContainer(false); } else if (!this.wirelessTerminalGUIObject.getItemStack().isEmpty() && currentItem != this.wirelessTerminalGUIObject.getItemStack()) { if (ItemStack.areItemsEqual(this.wirelessTerminalGUIObject.getItemStack(), currentItem)) { diff --git a/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java b/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java index c2ce18046..8f903aa67 100644 --- a/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java +++ b/src/main/java/appeng/fluids/container/ContainerWirelessFluidTerminal.java @@ -19,36 +19,14 @@ package appeng.fluids.container; -import appeng.core.AEConfig; -import appeng.core.localization.PlayerMessages; import appeng.helpers.WirelessTerminalGuiObject; -import appeng.util.Platform; import net.minecraft.entity.player.InventoryPlayer; public class ContainerWirelessFluidTerminal extends ContainerMEPortableFluidCell { - private final WirelessTerminalGuiObject wirelessTerminalGUIObject; public ContainerWirelessFluidTerminal(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) { super(ip, gui); - this.wirelessTerminalGUIObject = gui; - } - - @Override - public void detectAndSendChanges() { - if (Platform.isServer()) { - super.detectAndSendChanges(); - - if (!this.wirelessTerminalGUIObject.rangeCheck()) { - if (Platform.isServer() && this.isValidContainer()) { - this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); - } - - this.setValidContainer(false); - } else { - this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); - } - } } } diff --git a/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java index f797315e9..60e7ea433 100644 --- a/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java +++ b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java @@ -67,6 +67,7 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II private final IWirelessTermHandler wth; private final String encryptionKey; private final EntityPlayer myPlayer; + private final boolean isBaubleSlot; private IGrid targetGrid; private IStorageGrid sg; private IMEMonitor itemStorage; @@ -86,6 +87,7 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II this.myPlayer = ep; this.wth = wh; this.inventorySlot = x; + this.isBaubleSlot = y == 1; ILocatable obj = null; @@ -327,6 +329,11 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II return this.inventorySlot; } + @Override + public boolean isBaubleSlot() { + return isBaubleSlot; + } + @Override public IItemHandler getViewCellStorage() { NBTTagCompound data = effectiveItem.getTagCompound(); diff --git a/src/main/java/appeng/items/tools/powered/Terminal.java b/src/main/java/appeng/items/tools/powered/Terminal.java new file mode 100644 index 000000000..0b94857c9 --- /dev/null +++ b/src/main/java/appeng/items/tools/powered/Terminal.java @@ -0,0 +1,28 @@ +package appeng.items.tools.powered; + +import appeng.api.AEApi; +import appeng.api.definitions.IItemDefinition; +import appeng.core.sync.GuiBridge; + +public enum Terminal { + WIRELESS_TERMINAL(AEApi.instance().definitions().items().wirelessTerminal(), GuiBridge.GUI_WIRELESS_TERM), + WIRELESS_CRAFTING_TERMINAL(AEApi.instance().definitions().items().wirelessCraftingTerminal(), GuiBridge.GUI_WIRELESS_CRAFTING_TERMINAL), + WIRELESS_PATTERN_TERMINAL(AEApi.instance().definitions().items().wirelessPatternTerminal(), GuiBridge.GUI_WIRELESS_PATTERN_TERMINAL), + WIRELESS_FLUID_TERMINAL(AEApi.instance().definitions().items().wirelessFluidTerminal(), GuiBridge.GUI_WIRELESS_FLUID_TERMINAL); + + final GuiBridge bridge; + final IItemDefinition itemDefinition; + + Terminal(IItemDefinition itemDefinition, GuiBridge guiBridge) { + this.itemDefinition = itemDefinition; + this.bridge = guiBridge; + } + + public GuiBridge getBridge() { + return bridge; + } + + public IItemDefinition getItemDefinition() { + return itemDefinition; + } +} diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java index 48430ac6d..4e7235831 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java @@ -26,6 +26,9 @@ import appeng.api.util.IConfigManager; import appeng.core.AEConfig; import appeng.core.localization.GuiText; import appeng.core.sync.GuiBridge; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketCraftRequest; +import appeng.core.sync.packets.PacketTerminalUse; import appeng.items.contents.CellConfig; import appeng.items.contents.CellUpgrades; import appeng.items.materials.ItemMaterial; @@ -34,6 +37,7 @@ import appeng.util.ConfigManager; import appeng.util.Platform; import baubles.api.BaubleType; import baubles.api.IBauble; +import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; @@ -48,11 +52,16 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.translation.I18n; import net.minecraft.world.World; +import net.minecraftforge.client.event.MouseEvent; import net.minecraftforge.fml.common.Optional; +import net.minecraftforge.fml.common.eventhandler.EventPriority; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.InputEvent; import net.minecraftforge.fml.common.network.IGuiHandler; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.items.ItemStackHandler; +import org.lwjgl.input.Keyboard; import java.util.List; diff --git a/src/main/java/appeng/util/Platform.java b/src/main/java/appeng/util/Platform.java index f81f132b0..7992bb4ba 100644 --- a/src/main/java/appeng/util/Platform.java +++ b/src/main/java/appeng/util/Platform.java @@ -342,6 +342,18 @@ public class Platform { } } + public static void openGUI(@Nonnull final EntityPlayer p, int i, @Nonnull final GuiBridge type, boolean isBauble) { + if (isClient()) { + return; + } + + if (type.getType().isItem()) { + if (type.getType() == GuiHostType.ITEM) { + p.openGui(AppEng.instance(), type.ordinal() << 4, p.getEntityWorld(), i, isBauble ? 1 : 0, 0); + } + } + } + /* * returns true if the code is on the client. */ From acd77ff3f268f6a19694139182f42674746a697d Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Wed, 1 Feb 2023 21:10:41 -0300 Subject: [PATCH 16/35] lock quantumbridge inventory to 1 card or singularity --- .../implementations/ContainerQNB.java | 28 ++++++++++++++----- .../helpers/WirelessTerminalGuiObject.java | 3 +- .../tools/powered/ToolWirelessTerminal.java | 9 ------ .../appeng/tile/qnb/TileQuantumBridge.java | 23 +++++++++++++++ .../appeng/util/inv/IAEAppEngInventory.java | 4 --- 5 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/main/java/appeng/container/implementations/ContainerQNB.java b/src/main/java/appeng/container/implementations/ContainerQNB.java index 78213bac6..cf745505b 100644 --- a/src/main/java/appeng/container/implementations/ContainerQNB.java +++ b/src/main/java/appeng/container/implementations/ContainerQNB.java @@ -20,30 +20,44 @@ package appeng.container.implementations; import appeng.container.AEBaseContainer; +import appeng.container.slot.IOptionalSlotHost; +import appeng.container.slot.OptionalSlotRestrictedInput; import appeng.container.slot.SlotRestrictedInput; import appeng.tile.qnb.TileQuantumBridge; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; -public class ContainerQNB extends AEBaseContainer { +public class ContainerQNB extends AEBaseContainer implements IOptionalSlotHost { - SlotRestrictedInput SINGULARITY; - SlotRestrictedInput QUANTUM_CARD; + OptionalSlotRestrictedInput SINGULARITY; + OptionalSlotRestrictedInput QUANTUM_CARD; public ContainerQNB(final InventoryPlayer ip, final TileQuantumBridge quantumBridge) { super(ip, quantumBridge, null); - SINGULARITY = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.QE_SINGULARITY, quantumBridge - .getInternalInventory(), 0, 80, 37, this.getInventoryPlayer()); + SINGULARITY = new OptionalSlotRestrictedInput(SlotRestrictedInput.PlacableItemType.QE_SINGULARITY, quantumBridge + .getInternalInventory(), this, 0, 80, 37, 0, this.getInventoryPlayer()); this.addSlotToContainer(SINGULARITY.setStackLimit(1)); - QUANTUM_CARD = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.CARD_QUANTUM, quantumBridge - .getInternalInventory(), 1, 80, 55, this.getInventoryPlayer()); + QUANTUM_CARD = new OptionalSlotRestrictedInput(SlotRestrictedInput.PlacableItemType.CARD_QUANTUM, quantumBridge + .getInternalInventory(), this, 1, 80, 55, 1, this.getInventoryPlayer()); this.addSlotToContainer((QUANTUM_CARD).setStackLimit(1)); this.bindPlayerInventory(ip, 0, 166 - /* height of player inventory */82); } + @Override + public boolean isSlotEnabled(int idx) { + if (QUANTUM_CARD.getItemHandler().getStackInSlot(QUANTUM_CARD.slotNumber).isEmpty() && + SINGULARITY.getItemHandler().getStackInSlot(SINGULARITY.slotNumber).isEmpty()) { + return true; + } else if (idx == 0) { + return QUANTUM_CARD.getItemHandler().getStackInSlot(QUANTUM_CARD.slotNumber).isEmpty(); + } else if (idx == 1) { + return SINGULARITY.getItemHandler().getStackInSlot(SINGULARITY.slotNumber).isEmpty(); + } + return false; + } } diff --git a/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java index 60e7ea433..95c0fd841 100644 --- a/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java +++ b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java @@ -352,8 +352,7 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II viewCell.writeToNBT(data, "viewCell"); upgrades.writeToNBT(data, "upgrades"); } - - @Override + public void saveChanges(NBTTagCompound data) { if (effectiveItem.getTagCompound() != null) { effectiveItem.getTagCompound().merge(data); diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java index 4e7235831..48430ac6d 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java @@ -26,9 +26,6 @@ import appeng.api.util.IConfigManager; import appeng.core.AEConfig; import appeng.core.localization.GuiText; import appeng.core.sync.GuiBridge; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketCraftRequest; -import appeng.core.sync.packets.PacketTerminalUse; import appeng.items.contents.CellConfig; import appeng.items.contents.CellUpgrades; import appeng.items.materials.ItemMaterial; @@ -37,7 +34,6 @@ import appeng.util.ConfigManager; import appeng.util.Platform; import baubles.api.BaubleType; import baubles.api.IBauble; -import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; @@ -52,16 +48,11 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.translation.I18n; import net.minecraft.world.World; -import net.minecraftforge.client.event.MouseEvent; import net.minecraftforge.fml.common.Optional; -import net.minecraftforge.fml.common.eventhandler.EventPriority; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.InputEvent; import net.minecraftforge.fml.common.network.IGuiHandler; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.items.ItemStackHandler; -import org.lwjgl.input.Keyboard; import java.util.List; diff --git a/src/main/java/appeng/tile/qnb/TileQuantumBridge.java b/src/main/java/appeng/tile/qnb/TileQuantumBridge.java index d0ef6a64e..48f24e4f7 100644 --- a/src/main/java/appeng/tile/qnb/TileQuantumBridge.java +++ b/src/main/java/appeng/tile/qnb/TileQuantumBridge.java @@ -36,6 +36,8 @@ import appeng.tile.grid.AENetworkInvTile; import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.Platform; import appeng.util.inv.InvOperation; +import appeng.util.inv.filter.AEItemDefinitionFilter; +import appeng.util.inv.filter.IAEItemFilter; import io.netty.buffer.ByteBuf; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; @@ -66,6 +68,7 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock this.getProxy().setValidSides(EnumSet.noneOf(EnumFacing.class)); this.getProxy().setFlags(GridFlags.DENSE_CAPACITY); this.getProxy().setIdlePowerUsage(22); + this.internalInventory.setFilter(new QuantumBridgeInventoryFilter()); } @Override @@ -292,4 +295,24 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock public byte getCorner() { return this.corner; } + + private class QuantumBridgeInventoryFilter implements IAEItemFilter { + + + @Override + public boolean allowExtract(IItemHandler inv, int slot, int amount) { + return true; + } + + @Override + public boolean allowInsert(IItemHandler inv, int slot, ItemStack stack) { + if (inv.getStackInSlot(0).isEmpty() && inv.getStackInSlot(1).isEmpty() ) { + if (slot == 0 && stack.isItemEqual(AEApi.instance().definitions().materials().qESingularity().maybeStack(1).get())) { + return true; + } else return slot == 1 && stack.isItemEqual(AEApi.instance().definitions().materials().cardQuantumLink().maybeStack(1).get()); + } else if (slot == 0 && inv.getStackInSlot(1).isEmpty()) { + return true; + }else return slot == 1 && inv.getStackInSlot(0).isEmpty(); + } + } } diff --git a/src/main/java/appeng/util/inv/IAEAppEngInventory.java b/src/main/java/appeng/util/inv/IAEAppEngInventory.java index 687ec93ae..3e7a29e4b 100644 --- a/src/main/java/appeng/util/inv/IAEAppEngInventory.java +++ b/src/main/java/appeng/util/inv/IAEAppEngInventory.java @@ -20,15 +20,11 @@ package appeng.util.inv; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.items.IItemHandler; public interface IAEAppEngInventory { void saveChanges(); - default void saveChanges(NBTTagCompound data) { - } - void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack); } From 405f14bd133d870eb50753d5fea78c24b49ae186 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Wed, 1 Feb 2023 21:19:09 -0300 Subject: [PATCH 17/35] safer comparisons --- src/main/java/appeng/core/sync/packets/PacketTerminalUse.java | 4 ++-- .../java/appeng/items/tools/powered/ToolWirelessTerminal.java | 2 +- src/main/java/appeng/tile/qnb/TileQuantumBridge.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java b/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java index 2a932a423..63007dad9 100644 --- a/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java +++ b/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java @@ -33,14 +33,14 @@ public class PacketTerminalUse extends AppEngPacket { NonNullList mainInventory = player.inventory.mainInventory; for (int i = 0; i < mainInventory.size(); i++) { ItemStack is = mainInventory.get(i); - if (is.isItemEqual(terminal.getItemDefinition().maybeStack(1).get())) { + if (terminal.getItemDefinition().isSameAs(is)) { Platform.openGUI(player, i, terminal.getBridge(), false); return; } } for (int i = 0; i < BaublesApi.getBaublesHandler(player).getSlots(); i++) { ItemStack is = BaublesApi.getBaublesHandler(player).getStackInSlot(i); - if (is.isItemEqual(terminal.getItemDefinition().maybeStack(1).get())) { + if (terminal.getItemDefinition().isSameAs(is)) { Platform.openGUI(player, i, terminal.getBridge(), true); break; } diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java index 48430ac6d..669638f6d 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java @@ -188,7 +188,7 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless siu.deserializeNBT(upgradeNBT); for (int s = 0; s < siu.getSlots(); s++) { ItemStack is = siu.getStackInSlot(s); - if (is.isItemEqual(AEApi.instance().definitions().materials().cardMagnet().maybeStack(1).get())) { + if (AEApi.instance().definitions().materials().cardMagnet().isSameAs(is)) { ItemMaterial im = (ItemMaterial) is.getItem(); CellConfig c = (CellConfig) im.getConfigInventory(is); CellUpgrades u = (CellUpgrades) im.getUpgradesInventory(is); diff --git a/src/main/java/appeng/tile/qnb/TileQuantumBridge.java b/src/main/java/appeng/tile/qnb/TileQuantumBridge.java index 48f24e4f7..6058e449d 100644 --- a/src/main/java/appeng/tile/qnb/TileQuantumBridge.java +++ b/src/main/java/appeng/tile/qnb/TileQuantumBridge.java @@ -307,9 +307,9 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock @Override public boolean allowInsert(IItemHandler inv, int slot, ItemStack stack) { if (inv.getStackInSlot(0).isEmpty() && inv.getStackInSlot(1).isEmpty() ) { - if (slot == 0 && stack.isItemEqual(AEApi.instance().definitions().materials().qESingularity().maybeStack(1).get())) { + if (slot == 0 && AEApi.instance().definitions().materials().qESingularity().isSameAs(stack)) { return true; - } else return slot == 1 && stack.isItemEqual(AEApi.instance().definitions().materials().cardQuantumLink().maybeStack(1).get()); + } else return slot == 1 && AEApi.instance().definitions().materials().cardQuantumLink().isSameAs(stack); } else if (slot == 0 && inv.getStackInSlot(1).isEmpty()) { return true; }else return slot == 1 && inv.getStackInSlot(0).isEmpty(); From 149e7d251aac1d9027277c36c429b74c1dea221f Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Wed, 1 Feb 2023 21:25:12 -0300 Subject: [PATCH 18/35] clean up --- .../features/registries/WirelessRegistry.java | 7 ----- .../core/sync/packets/PacketTerminalUse.java | 4 --- .../powered/ToolWirelessCraftingTerminal.java | 30 ------------------- .../powered/ToolWirelessFluidTerminal.java | 23 -------------- .../powered/ToolWirelessPatternTerminal.java | 23 -------------- 5 files changed, 87 deletions(-) diff --git a/src/main/java/appeng/core/features/registries/WirelessRegistry.java b/src/main/java/appeng/core/features/registries/WirelessRegistry.java index a7eaeaf8a..6d7599ad4 100644 --- a/src/main/java/appeng/core/features/registries/WirelessRegistry.java +++ b/src/main/java/appeng/core/features/registries/WirelessRegistry.java @@ -84,13 +84,6 @@ public final class WirelessRegistry implements IWirelessTermRegistry { final IWirelessTermHandler handler = this.getWirelessTerminalHandler(item); - WirelessTerminalGuiObject wtgo = new WirelessTerminalGuiObject(handler, item, player, w, (int) player.posX, (int) player.posY, (int) player.posZ); - IItemHandler upgrades = wtgo.getInventoryByName("upgrades"); - if (upgrades.getSlots() > 0) { - player.sendMessage(new TextComponentString("ahhaah eheheh ihihih")); - } - - final String unparsedKey = handler.getEncryptionKey(item); if (unparsedKey.isEmpty()) { player.sendMessage(PlayerMessages.DeviceNotLinked.get()); diff --git a/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java b/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java index 63007dad9..5e4d90eab 100644 --- a/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java +++ b/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java @@ -46,8 +46,4 @@ public class PacketTerminalUse extends AppEngPacket { } } } - - enum a { - - } } diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessCraftingTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessCraftingTerminal.java index 3c457aae1..31dded327 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessCraftingTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessCraftingTerminal.java @@ -20,40 +20,10 @@ package appeng.items.tools.powered; import appeng.api.AEApi; -import appeng.api.config.Actionable; -import appeng.api.config.Settings; -import appeng.api.config.SortDir; -import appeng.api.config.SortOrder; -import appeng.api.config.ViewItems; import appeng.api.features.IWirelessTermHandler; -import appeng.api.util.IConfigManager; -import appeng.core.AEConfig; -import appeng.core.localization.GuiText; import appeng.core.sync.GuiBridge; -import appeng.items.tools.powered.powersink.AEBasePoweredItem; -import appeng.parts.automation.StackUpgradeInventory; -import appeng.util.ConfigManager; -import appeng.util.Platform; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ActionResult; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumHand; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.text.translation.I18n; -import net.minecraft.world.World; import net.minecraftforge.fml.common.network.IGuiHandler; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import net.minecraftforge.items.ItemStackHandler; - -import java.util.List; public class ToolWirelessCraftingTerminal extends ToolWirelessTerminal implements IWirelessTermHandler { diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessFluidTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessFluidTerminal.java index 0bc9bd4f3..5a591ee88 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessFluidTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessFluidTerminal.java @@ -20,33 +20,10 @@ package appeng.items.tools.powered; import appeng.api.AEApi; -import appeng.api.config.Actionable; -import appeng.api.config.Settings; -import appeng.api.config.SortDir; -import appeng.api.config.SortOrder; -import appeng.api.config.ViewItems; import appeng.api.features.IWirelessTermHandler; -import appeng.api.util.IConfigManager; -import appeng.core.AEConfig; -import appeng.core.localization.GuiText; import appeng.core.sync.GuiBridge; -import appeng.items.tools.powered.powersink.AEBasePoweredItem; -import appeng.util.ConfigManager; -import appeng.util.Platform; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ActionResult; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumHand; -import net.minecraft.util.text.translation.I18n; -import net.minecraft.world.World; import net.minecraftforge.fml.common.network.IGuiHandler; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -import java.util.List; public class ToolWirelessFluidTerminal extends ToolWirelessTerminal implements IWirelessTermHandler { diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessPatternTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessPatternTerminal.java index d061bb5a2..f6ff1f70c 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessPatternTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessPatternTerminal.java @@ -20,33 +20,10 @@ package appeng.items.tools.powered; import appeng.api.AEApi; -import appeng.api.config.Actionable; -import appeng.api.config.Settings; -import appeng.api.config.SortDir; -import appeng.api.config.SortOrder; -import appeng.api.config.ViewItems; import appeng.api.features.IWirelessTermHandler; -import appeng.api.util.IConfigManager; -import appeng.core.AEConfig; -import appeng.core.localization.GuiText; import appeng.core.sync.GuiBridge; -import appeng.items.tools.powered.powersink.AEBasePoweredItem; -import appeng.util.ConfigManager; -import appeng.util.Platform; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ActionResult; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumHand; -import net.minecraft.util.text.translation.I18n; -import net.minecraft.world.World; import net.minecraftforge.fml.common.network.IGuiHandler; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -import java.util.List; public class ToolWirelessPatternTerminal extends ToolWirelessTerminal implements IWirelessTermHandler { From e230440cba4fb6d1e2c1e21e1ab23f1c28796a94 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Wed, 1 Feb 2023 22:20:26 -0300 Subject: [PATCH 19/35] add some textures --- .../appeng/client/gui/implementations/GuiQNB.java | 2 +- .../container/implementations/ContainerQNB.java | 1 - .../container/slot/SlotRestrictedInput.java | 2 +- .../java/appeng/items/materials/MaterialType.java | 2 +- .../models/item/material_card_quantum_link.json | 6 ++++++ .../appliedenergistics2/textures/guis/qbgui.png | Bin 0 -> 802 bytes .../textures/items/material_card_quantum_link.png | Bin 0 -> 270 bytes 7 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/assets/appliedenergistics2/models/item/material_card_quantum_link.json create mode 100644 src/main/resources/assets/appliedenergistics2/textures/guis/qbgui.png create mode 100644 src/main/resources/assets/appliedenergistics2/textures/items/material_card_quantum_link.png diff --git a/src/main/java/appeng/client/gui/implementations/GuiQNB.java b/src/main/java/appeng/client/gui/implementations/GuiQNB.java index fe2fdb40a..67003e0ec 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiQNB.java +++ b/src/main/java/appeng/client/gui/implementations/GuiQNB.java @@ -41,7 +41,7 @@ public class GuiQNB extends AEBaseGui { @Override public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - this.bindTexture("guis/chest.png"); + this.bindTexture("guis/qbgui.png"); this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize); } } diff --git a/src/main/java/appeng/container/implementations/ContainerQNB.java b/src/main/java/appeng/container/implementations/ContainerQNB.java index cf745505b..fab42aa06 100644 --- a/src/main/java/appeng/container/implementations/ContainerQNB.java +++ b/src/main/java/appeng/container/implementations/ContainerQNB.java @@ -25,7 +25,6 @@ import appeng.container.slot.OptionalSlotRestrictedInput; import appeng.container.slot.SlotRestrictedInput; import appeng.tile.qnb.TileQuantumBridge; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; public class ContainerQNB extends AEBaseContainer implements IOptionalSlotHost { diff --git a/src/main/java/appeng/container/slot/SlotRestrictedInput.java b/src/main/java/appeng/container/slot/SlotRestrictedInput.java index 7327bcf14..59ea5e0f1 100644 --- a/src/main/java/appeng/container/slot/SlotRestrictedInput.java +++ b/src/main/java/appeng/container/slot/SlotRestrictedInput.java @@ -276,7 +276,7 @@ public class SlotRestrictedInput extends AppEngSlot { RANGE_BOOSTER(6 * 16 + 15), QE_SINGULARITY(10 * 16 + 15), - CARD_QUANTUM(0), + CARD_QUANTUM(13 * 16 + 15), SPATIAL_STORAGE_CELLS(11 * 16 + 15), FUEL(12 * 16 + 15), diff --git a/src/main/java/appeng/items/materials/MaterialType.java b/src/main/java/appeng/items/materials/MaterialType.java index f1f0b9ad6..848fc0cd8 100644 --- a/src/main/java/appeng/items/materials/MaterialType.java +++ b/src/main/java/appeng/items/materials/MaterialType.java @@ -120,7 +120,7 @@ public enum MaterialType { CARD_PATTERN_EXPANSION(58, "material_card_pattern_expansion", EnumSet.of(AEFeature.ADVANCED_CARDS)), CARD_QUANTUM_LINK(59, "material_card_quantum_link", EnumSet.of(AEFeature.ADVANCED_CARDS)), - CARD_MAGNET(60, "material_card_quantum_link", EnumSet.of(AEFeature.BASIC_CARDS)); + CARD_MAGNET(60, "material_card_magnet", EnumSet.of(AEFeature.BASIC_CARDS)); private final Set features; diff --git a/src/main/resources/assets/appliedenergistics2/models/item/material_card_quantum_link.json b/src/main/resources/assets/appliedenergistics2/models/item/material_card_quantum_link.json new file mode 100644 index 000000000..0d6b3a656 --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/item/material_card_quantum_link.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "appliedenergistics2:items/material_card_quantum_link" + } +} diff --git a/src/main/resources/assets/appliedenergistics2/textures/guis/qbgui.png b/src/main/resources/assets/appliedenergistics2/textures/guis/qbgui.png new file mode 100644 index 0000000000000000000000000000000000000000..47efde21aa2e1df771a83af257d0c9bc80ee133f GIT binary patch literal 802 zcmeAS@N?(olHy`uVBq!ia0y~yU}OMc4rT@hhU_&FAs}9Hkh>GZx^prw85kH?(j9#r z85lP9bN@+XWnf?s4e$wZWnf_V|NsB7W5+^6L(R?2ySuv?7#LDFPnTw3U|=r^@(cbC z1`JZ(%x(+}44efXk;M!QLSW3;qqLKqfq|*n)5S5QBJS<&i&?iFBw7MhSAPB1e`nXs zsH1y1pT*BgJy&k5&>SHz;v`x%=lMqe=QYPG_q@H#)R?^d{r_)v`X8hp)K0gvJI4Bs zVdrl)Mg|6j=W^T(3=9lK-+7rB7#z;oih+1f-bu4CFf`1m)&cQO+%@N5U|_KP9s%M_ z*xmo-@y=*FiA?r}+rf*=*^#v=GoJWf$D$zL1J|C$m^c6b_NVJV9rUoaVLV@{JcZv4 z#U^Z8Uft(d%ZqGfz5oNmX@*bB&#aFA_R2m!l6OM=9^0zldEp=zfiTo@AST2Ae}SKO z$42r@_^ubuegAFB`h6v-rVjJAxO2-tyS@&r1mxp)8(~a_YkN=5+_gzU;eG5nv3<8s z#?`(&mDOOA*)L{yW_>IuszEBB+)0Kp8P-%!HZDyyJRk=N!q@x`_x8r=*6g3X_t&MV zR~dfhe$IHPzXg|NXXozPB$3e1!0>|YM+9Sm-1pykmzf$qpV(WT@#pt_#=5@}IhUU= zRF5t=y_adiT3&~3W(+rPF{ETO4>(7g-QxUwz1UTgIhOA^0tysQS3j3^P6QUyn+TPOLCkD4yoZ>6X^YxkmJDs}|GoM5f~}Z$Gbd-E+~C)#J&^2rC8#1_n=8 KKbLh*2~7aTl3#`Z literal 0 HcmV?d00001 From 11a47838818d1fe2fb1ac99a47a1afe4be13dc12 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Thu, 2 Feb 2023 11:23:51 -0300 Subject: [PATCH 20/35] more textures --- .../tools/powered/ToolWirelessTerminal.java | 27 ++++++++++++++---- .../appliedenergistics2/lang/en_us.lang | 5 ++++ .../models/item/material_card_magnet.json | 6 ++++ .../item/wireless_crafting_terminal.json | 6 ++++ .../models/item/wireless_fluid_terminal.json | 6 ++++ .../item/wireless_pattern_terminal.json | 6 ++++ .../textures/items/material_card_magnet.png | Bin 0 -> 277 bytes .../items/wireless_crafting_terminal.png | Bin 0 -> 242 bytes .../items/wireless_fluid_terminal.png | Bin 0 -> 260 bytes .../items/wireless_pattern_terminal.png | Bin 0 -> 256 bytes 10 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/assets/appliedenergistics2/models/item/material_card_magnet.json create mode 100644 src/main/resources/assets/appliedenergistics2/models/item/wireless_crafting_terminal.json create mode 100644 src/main/resources/assets/appliedenergistics2/models/item/wireless_fluid_terminal.json create mode 100644 src/main/resources/assets/appliedenergistics2/models/item/wireless_pattern_terminal.json create mode 100644 src/main/resources/assets/appliedenergistics2/textures/items/material_card_magnet.png create mode 100644 src/main/resources/assets/appliedenergistics2/textures/items/wireless_crafting_terminal.png create mode 100644 src/main/resources/assets/appliedenergistics2/textures/items/wireless_fluid_terminal.png create mode 100644 src/main/resources/assets/appliedenergistics2/textures/items/wireless_pattern_terminal.png diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java index 669638f6d..8d12c604e 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java @@ -204,6 +204,19 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless new Vec3d(entityIn.posX - 5, entityIn.posY - 5, entityIn.posZ - 5))); boolean emptyFilter = true; for (EntityItem i : ei) { + if (i.isDead) { + continue; + } + + NBTTagCompound itemTag = i.getEntityData(); + if (itemTag.hasKey("PreventRemoteMovement")) { + continue; + } + + if (i.getThrower().equals(entityIn.getName()) && i.cannotPickup()) { + continue; + } + boolean matched = false; for (int ss = 0; ss < c.getSlots(); ss++) { ItemStack filter = c.getStackInSlot(ss); @@ -222,12 +235,11 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless } } if (emptyFilter) { - i.setPosition(entityIn.posX, entityIn.posY, entityIn.posZ); - } - if (matched && !inverted) { - i.setPosition(entityIn.posX, entityIn.posY, entityIn.posZ); + teleportItem(i,entityIn); + } else if (matched && !inverted) { + teleportItem(i,entityIn); } else if (!matched && inverted) { - i.setPosition(entityIn.posX, entityIn.posY, entityIn.posZ); + teleportItem(i,entityIn); } } } @@ -235,4 +247,9 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless } } } + + private void teleportItem(EntityItem i, Entity entityIn){ + i.motionX = i.motionY = i.motionZ = 0; + i.setPosition(entityIn.posX, entityIn.posY, entityIn.posZ); + } } diff --git a/src/main/resources/assets/appliedenergistics2/lang/en_us.lang b/src/main/resources/assets/appliedenergistics2/lang/en_us.lang index ebebd4590..bd2527ddd 100644 --- a/src/main/resources/assets/appliedenergistics2/lang/en_us.lang +++ b/src/main/resources/assets/appliedenergistics2/lang/en_us.lang @@ -462,6 +462,8 @@ item.appliedenergistics2.material.blank_pattern.name=Blank Pattern item.appliedenergistics2.material.calculation_processor.name=Calculation Processor item.appliedenergistics2.material.card_capacity.name=Capacity Card item.appliedenergistics2.material.card_pattern_expansion.name=Pattern Expansion Card +item.appliedenergistics2.material.card_magnet.name=Magnet Card +item.appliedenergistics2.material.card_quantum_link.name=Quantum Link Card item.appliedenergistics2.material.card_fuzzy.name=Fuzzy Card item.appliedenergistics2.material.card_inverter.name=Inverter Card item.appliedenergistics2.material.card_redstone.name=Redstone Card @@ -586,6 +588,9 @@ item.appliedenergistics2.matter_cannon.name=Matter Cannon item.appliedenergistics2.memory_card.name=Memory Card item.appliedenergistics2.color_applicator.name=Color Applicator item.appliedenergistics2.wireless_terminal.name=Wireless Terminal +item.appliedenergistics2.wireless_crafting_terminal.name=Wireless Crafting Terminal +item.appliedenergistics2.wireless_pattern_terminal.name=Wireless Pattern Terminal +item.appliedenergistics2.wireless_fluid_terminal.name=Wireless Fluid Terminal item.appliedenergistics2.biometric_card.name=Biometric Card item.appliedenergistics2.debug_card.name=Dev.DebugCard diff --git a/src/main/resources/assets/appliedenergistics2/models/item/material_card_magnet.json b/src/main/resources/assets/appliedenergistics2/models/item/material_card_magnet.json new file mode 100644 index 000000000..cdc1d4b62 --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/item/material_card_magnet.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "appliedenergistics2:items/material_card_magnet" + } +} diff --git a/src/main/resources/assets/appliedenergistics2/models/item/wireless_crafting_terminal.json b/src/main/resources/assets/appliedenergistics2/models/item/wireless_crafting_terminal.json new file mode 100644 index 000000000..ebae5a8a6 --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/item/wireless_crafting_terminal.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "appliedenergistics2:items/wireless_crafting_terminal" + } +} diff --git a/src/main/resources/assets/appliedenergistics2/models/item/wireless_fluid_terminal.json b/src/main/resources/assets/appliedenergistics2/models/item/wireless_fluid_terminal.json new file mode 100644 index 000000000..d252e1501 --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/item/wireless_fluid_terminal.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "appliedenergistics2:items/wireless_fluid_terminal" + } +} diff --git a/src/main/resources/assets/appliedenergistics2/models/item/wireless_pattern_terminal.json b/src/main/resources/assets/appliedenergistics2/models/item/wireless_pattern_terminal.json new file mode 100644 index 000000000..2e2f2da2d --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/item/wireless_pattern_terminal.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "appliedenergistics2:items/wireless_pattern_terminal" + } +} diff --git a/src/main/resources/assets/appliedenergistics2/textures/items/material_card_magnet.png b/src/main/resources/assets/appliedenergistics2/textures/items/material_card_magnet.png new file mode 100644 index 0000000000000000000000000000000000000000..ad95ae0158b349e3fce5a74aa4bf4c463442dfad GIT binary patch literal 277 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4rT@h1`S>QU zNAoo(@UU#xcYOHo`P6BvT;{g)`an}INNS`Np9|#nbi^X zdfspA!W-rrJ7#9+-kTh8BtEI;c9TG)PMUb6t=NZG^~ZI;)Gk44ofy`glX=O&z`&C3 z=2h=8TI_S9@Dx9q6l{n0x zXm{ea$W8_kz66J@1`1D7O6)iSp0HX-Jd9&lo@$)XCFFdH`+sAQ56^$ef5uLqMFJR> p{JLN7#+J5X_QzB!AqHkQU|AsWG@{qB4R z95{|hcs%{j&zC!0j+neJv_uB;QWzdUY5&Rc*V=V&%1B0ilpUXO@geCxI1yt<- literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/appliedenergistics2/textures/items/wireless_pattern_terminal.png b/src/main/resources/assets/appliedenergistics2/textures/items/wireless_pattern_terminal.png new file mode 100644 index 0000000000000000000000000000000000000000..82719e0755961b9b3a1397edf18fcfa1b151049a GIT binary patch literal 256 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4rT@h1`S>QUS9Amy12}?&Ey;%6>$M2(u u1i}{IC~N6!=$x(ogz3uj-0eCm>I|$|#GKFYFJWL{VDNPHb6Mw<&;$VaU{c`# literal 0 HcmV?d00001 From 329e613c99f8defd892adb6bb84a10243d121003 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Thu, 2 Feb 2023 11:39:16 -0300 Subject: [PATCH 21/35] recipes --- .../network/wireless_crafting_terminal.json | 47 +++++++++++++++++++ .../network/wireless_fluid_terminal.json | 47 +++++++++++++++++++ .../network/wireless_pattern_terminal.json | 47 +++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 src/main/resources/assets/appliedenergistics2/recipes/network/wireless_crafting_terminal.json create mode 100644 src/main/resources/assets/appliedenergistics2/recipes/network/wireless_fluid_terminal.json create mode 100644 src/main/resources/assets/appliedenergistics2/recipes/network/wireless_pattern_terminal.json diff --git a/src/main/resources/assets/appliedenergistics2/recipes/network/wireless_crafting_terminal.json b/src/main/resources/assets/appliedenergistics2/recipes/network/wireless_crafting_terminal.json new file mode 100644 index 000000000..a0e5dff94 --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/recipes/network/wireless_crafting_terminal.json @@ -0,0 +1,47 @@ +{ + "conditions": [ + { + "type": "forge:and", + "values": [ + { + "type": "minecraft:item_exists", + "item": "appliedenergistics2:wireless_crafting_terminal" + }, + { + "type": "minecraft:item_exists", + "item": "appliedenergistics2:dense_energy_cell" + }, + { + "type": "appliedenergistics2:part_exists", + "part": "part.crafting_terminal" + }, + { + "type": "appliedenergistics2:material_exists", + "material": "material.wireless" + } + ] + } + ], + "result": { + "item": "appliedenergistics2:wireless_crafting_terminal" + }, + "type": "forge:ore_shaped", + "pattern": [ + "a", + "b", + "c" + ], + "key": { + "b": { + "type": "appliedenergistics2:part", + "part": "part.crafting_terminal" + }, + "c": { + "item": "appliedenergistics2:dense_energy_cell" + }, + "a": { + "type": "appliedenergistics2:part", + "part": "material.wireless" + } + } +} diff --git a/src/main/resources/assets/appliedenergistics2/recipes/network/wireless_fluid_terminal.json b/src/main/resources/assets/appliedenergistics2/recipes/network/wireless_fluid_terminal.json new file mode 100644 index 000000000..5b70708a2 --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/recipes/network/wireless_fluid_terminal.json @@ -0,0 +1,47 @@ +{ + "conditions": [ + { + "type": "forge:and", + "values": [ + { + "type": "minecraft:item_exists", + "item": "appliedenergistics2:wireless_fluid_terminal" + }, + { + "type": "minecraft:item_exists", + "item": "appliedenergistics2:dense_energy_cell" + }, + { + "type": "appliedenergistics2:part_exists", + "part": "part.fluid_terminal" + }, + { + "type": "appliedenergistics2:material_exists", + "material": "material.wireless" + } + ] + } + ], + "result": { + "item": "appliedenergistics2:wireless_fluid_terminal" + }, + "type": "forge:ore_shaped", + "pattern": [ + "a", + "b", + "c" + ], + "key": { + "b": { + "type": "appliedenergistics2:part", + "part": "part.fluid_terminal" + }, + "c": { + "item": "appliedenergistics2:dense_energy_cell" + }, + "a": { + "type": "appliedenergistics2:part", + "part": "material.wireless" + } + } +} diff --git a/src/main/resources/assets/appliedenergistics2/recipes/network/wireless_pattern_terminal.json b/src/main/resources/assets/appliedenergistics2/recipes/network/wireless_pattern_terminal.json new file mode 100644 index 000000000..78b1604d4 --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/recipes/network/wireless_pattern_terminal.json @@ -0,0 +1,47 @@ +{ + "conditions": [ + { + "type": "forge:and", + "values": [ + { + "type": "minecraft:item_exists", + "item": "appliedenergistics2:wireless_pattern_terminal" + }, + { + "type": "minecraft:item_exists", + "item": "appliedenergistics2:dense_energy_cell" + }, + { + "type": "appliedenergistics2:part_exists", + "part": "part.pattern_terminal" + }, + { + "type": "appliedenergistics2:material_exists", + "material": "material.wireless" + } + ] + } + ], + "result": { + "item": "appliedenergistics2:wireless_pattern_terminal" + }, + "type": "forge:ore_shaped", + "pattern": [ + "a", + "b", + "c" + ], + "key": { + "b": { + "type": "appliedenergistics2:part", + "part": "part.pattern_terminal" + }, + "c": { + "item": "appliedenergistics2:dense_energy_cell" + }, + "a": { + "type": "appliedenergistics2:part", + "part": "material.wireless" + } + } +} From 58a6dabb2038b45dd10f9cfd6cf1cda2b8829d41 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Thu, 2 Feb 2023 14:50:23 -0300 Subject: [PATCH 22/35] wip --- .../implementations/ContainerMEPortableCell.java | 3 ++- .../ContainerWirelessPatternTerminal.java | 2 +- .../client/gui/GuiMEPortableFluidCell.java | 2 +- .../tools/powered/ToolWirelessTerminal.java | 2 +- .../textures/guis/wirelessupgrades.png | Bin 0 -> 2791 bytes 5 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/assets/appliedenergistics2/textures/guis/wirelessupgrades.png diff --git a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java index 525db0fe3..b546c6065 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java +++ b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java @@ -130,8 +130,9 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I this.powerMultiplier = powerMultiplier; } + @Override public int availableUpgrades() { - return 2; + return 1; } @Override diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java index 23753b534..e6aefca4e 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java @@ -251,7 +251,7 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im @Override public int availableUpgrades() { - return 2; + return 1; } @Override diff --git a/src/main/java/appeng/fluids/client/gui/GuiMEPortableFluidCell.java b/src/main/java/appeng/fluids/client/gui/GuiMEPortableFluidCell.java index 3660f1f42..9b6aa48be 100644 --- a/src/main/java/appeng/fluids/client/gui/GuiMEPortableFluidCell.java +++ b/src/main/java/appeng/fluids/client/gui/GuiMEPortableFluidCell.java @@ -121,7 +121,7 @@ public class GuiMEPortableFluidCell extends AEBaseMEGui implements ISortSource, @Override public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) { - this.fontRenderer.drawString(this.getGuiDisplayName("Fluid Terminal"), 8, 6, 4210752); + this.fontRenderer.drawString(this.getGuiDisplayName(GuiText.WirelessTerminal.getLocal()), 8, 6, 4210752); this.fontRenderer.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752); } diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java index 8d12c604e..68daf4dad 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java @@ -213,7 +213,7 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless continue; } - if (i.getThrower().equals(entityIn.getName()) && i.cannotPickup()) { + if (i.getThrower() != null && i.getThrower().equals(entityIn.getName()) && i.cannotPickup()) { continue; } diff --git a/src/main/resources/assets/appliedenergistics2/textures/guis/wirelessupgrades.png b/src/main/resources/assets/appliedenergistics2/textures/guis/wirelessupgrades.png new file mode 100644 index 0000000000000000000000000000000000000000..ed7b89c109c8c63edd106c9b9ca3cd22f563c17c GIT binary patch literal 2791 zcmeAS@N?(olHy`uVBq!ia0y~yU{C;I4rT@h2A3sW#~2tG8#A4q13aCb6#|O#(=u~X z85lIqPo3zi;SwlwwBEQwZE}*B&{wgDnL?9PojrSJv88VKa8KI!%AWM9{FLOCIa6Ev zd)K%2nnrU+FP+jqY3WqajT7hnuU(uLwD``hyYbKO74P~U!y)&?=k(flY^U`sPF|d0 zHh0#=tofXRY*Lw*ea-EscpO=2VVB3b;;Y)KO+W5)EEkUvW}5Y3!OU{5L!S@*UER9p zk?g~cohz2N`nT?u*}34u-b=ko`!&w}k_nk9m~LdLBO`ciQ)!TXPX z3qLYCvb9CCPjK4C3$^yI`0L7Fr&U#Vd44rqQTb`lcD@yNo7VfD|84VS&wAw*RW01R zpTyfWG?rg9_m28)XR_w-%~Vh0Z4YahXUTuswfJ|?)H4Zc%|WiX!q+=)xSUY+?U^&FDF~n`XpYIfq{WRG{7gsm4Sib|NsBT zjvWgP4K+76@9yqqU|>kyJYAZBfq}gw$S?Rm7%)hAGrKV`FmM)lL>4nJ@a+d-Mhn(p z6$S>5lFX2Zk_cZPtK|G#y~LFKq*T3%+yaml3^w)^1&PVosU-?Ysp*+{wo31J?^jaD zOtDo8H}y5}EpSfF$n>ZxN)4{^3rViZPPR-@vbW>qvZ=7D$SufCElE_U$j!+swyLmI z0vl|VS8N3m)>l#hD=EpgRf_NpP;kyKN>wn?Gto29b*;!OGg7kSIbD3=a&{Gr@EG<=9MVJEK5m->n$iP$^rW#C0Rc;Cp9-U zucTPtP|pxNCxbDnB^6@1#t6FRKolT zQdr>YYvq!kTnciJr;Du;$Wp76{N&6OD+trr+{837)k4=e&DcoSB-JuS*V51^Q8(Ej zDb3K>$kf;}*#c&cXI^nhVqS78$efDY0=>-46sr^y%QOq4)HL0sBuf)rljKAr-9*de zL|r3ua|=sLQRm#jwOi$G>$V*pJ0EMiTV}Pfvl98SP zlpBzfSdx}slxwTxlbKgq0Tm6&%uNk0NdyI)p_!SfnUR5+iJ7^Xskx;gR7F^7QE_H| z9>^#|13hCSB?VBpTlp7drskC-f)bsrk|EebR?bDKi6!|(A^G_^wn`v3C>ZG(8bIWH zQ%e$45=#*k2`L3EK5yMf(j;QB<7{3rr0X! z!$dN%#I#XLiiMf6Ws{iLH`*W^MsEa1=Dav7rf5SDujy3Tgu*BV9uST|>hVBO@ylGb>YbSn%l6#xEvD zhUTfs7RI`1DMm)RCPqfax)$aZsk(_4h9-tdsY$5@#uhL)lJ6H|D+5z2LsJ_2#mvAY zDbXm=RM*nL#6Z`?+{{QfF(uhp*E}`Z$lNp~&Ct{|jVgYzv@$lLv0n@ljSN%M5)*YT z5={(sO-zkVbS=}8Ep!ttO-+;1(#(=gjS{Kh7eiw!16unf)yN>#)ZEZgH#sfQRM*5P z*-SUdz|2@T)xs<-$uuoBH7U)2Lcd@ZC&>B5Mjuo?B9{j?`q+vNh&rTd6`bcFqCqZh zpjLoBxQ++a_aGj;DUq6&Vyjf7WN)|g$o3)z28IYv7sn6_|F@G3g&GVvSk5ba|F3@f zs0bf(Sky~1gAL}HOdekhwjH@<{CKs# Date: Thu, 2 Feb 2023 16:19:56 -0300 Subject: [PATCH 23/35] wip --- .../gui/implementations/GuiCraftConfirm.java | 4 ++-- .../implementations/ContainerMEPortableCell.java | 16 +++++++++++----- .../ContainerWirelessCraftingTerminal.java | 2 -- src/main/java/appeng/core/sync/GuiBridge.java | 9 ++++++++- .../container/ContainerMEPortableFluidCell.java | 2 +- src/main/java/appeng/util/Platform.java | 12 ++++++++++-- 6 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/main/java/appeng/client/gui/implementations/GuiCraftConfirm.java b/src/main/java/appeng/client/gui/implementations/GuiCraftConfirm.java index d60bbf623..cf8b716cb 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiCraftConfirm.java +++ b/src/main/java/appeng/client/gui/implementations/GuiCraftConfirm.java @@ -83,8 +83,8 @@ public class GuiCraftConfirm extends AEBaseGui { this.ccc = (ContainerCraftConfirm) this.inventorySlots; this.ccc.setGui(this); - if (te instanceof WirelessTerminalGuiObject) { - this.OriginalGui = GuiBridge.GUI_WIRELESS_TERM; + if (te instanceof IWirelessTermHandler) { + this.OriginalGui = (GuiBridge) ((IWirelessTermHandler)te).getGuiHandler(((WirelessTerminalGuiObject)te).getItemStack())); } if (te instanceof PartTerminal) { diff --git a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java index b546c6065..26d3dae19 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java +++ b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java @@ -44,7 +44,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.items.IItemHandler; -public class ContainerMEPortableCell extends ContainerMEMonitorable implements IUpgradeableCellContainer, IAEAppEngInventory { +public class ContainerMEPortableCell extends ContainerMEMonitorable implements IUpgradeableCellContainer, IAEAppEngInventory, IInventorySlotAware { protected final WirelessTerminalGuiObject wirelessTerminalGUIObject; private final int slot; @@ -68,10 +68,6 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I this.wirelessTerminalGUIObject = monitorable; this.upgrades = new StackUpgradeInventory(wirelessTerminalGUIObject.getItemStack(), this, 2); this.loadFromNBT(); - - if (bindInventory) { - this.bindPlayerInventory(ip, 0, 0); - } this.setupUpgrades(); } @@ -172,4 +168,14 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I public void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) { } + + @Override + public int getInventorySlot() { + return wirelessTerminalGUIObject.getInventorySlot(); + } + + @Override + public boolean isBaubleSlot() { + return wirelessTerminalGUIObject.isBaubleSlot(); + } } diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java index bdab4d39b..3c3ee8feb 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java @@ -69,8 +69,6 @@ public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell i this.addSlotToContainer(this.outputSlot = new SlotCraftingTerm(this.getPlayerInv().player, this.getActionSource(), this .getPowerSource(), this.wirelessTerminalGUIObject, crafting, crafting, this.output, 131, -72 + 18, this)); - this.bindPlayerInventory(ip, 0, 0); - this.onCraftMatrixChanged(new WrapperInvItemHandler(crafting)); } diff --git a/src/main/java/appeng/core/sync/GuiBridge.java b/src/main/java/appeng/core/sync/GuiBridge.java index 748f27532..4b3d5d4ca 100644 --- a/src/main/java/appeng/core/sync/GuiBridge.java +++ b/src/main/java/appeng/core/sync/GuiBridge.java @@ -241,7 +241,14 @@ public enum GuiBridge implements IGuiHandler { it = player.inventory.getStackInSlot(x); } } else { - it = BaublesApi.getBaublesHandler(player).getStackInSlot(x); + if (stem) { + if (player.openContainer instanceof IInventorySlotAware) { + int slot = ((IInventorySlotAware)player.openContainer).getInventorySlot(); + it = BaublesApi.getBaublesHandler(player).getStackInSlot(slot); + } + }else { + it = BaublesApi.getBaublesHandler(player).getStackInSlot(x); + } } final Object myItem = this.getGuiObject(it, player, w, x, y, z); if (myItem != null && ID.CorrectTileOrPart(myItem)) { diff --git a/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java index 785db70e8..b13824efa 100644 --- a/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java +++ b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java @@ -544,7 +544,7 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE @Override public int availableUpgrades() { - return 2; + return 1; } @Override diff --git a/src/main/java/appeng/util/Platform.java b/src/main/java/appeng/util/Platform.java index 7992bb4ba..186174f1e 100644 --- a/src/main/java/appeng/util/Platform.java +++ b/src/main/java/appeng/util/Platform.java @@ -45,6 +45,7 @@ import appeng.api.storage.data.IItemList; import appeng.api.util.AEColor; import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalCoord; +import appeng.container.interfaces.IInventorySlotAware; import appeng.core.AEConfig; import appeng.core.AELog; import appeng.core.AppEng; @@ -322,18 +323,25 @@ public class Platform { return; } - int x = (int) p.posX; + int x; int y = (int) p.posY; int z = (int) p.posZ; if (tile != null) { x = tile.getPos().getX(); y = tile.getPos().getY(); z = tile.getPos().getZ(); + } else { + if (p.openContainer instanceof IInventorySlotAware) { + x = ((IInventorySlotAware) p.openContainer).getInventorySlot(); + y = ((IInventorySlotAware)p.openContainer).isBaubleSlot() ? 1 : 0; + } else { + x = p.inventory.currentItem; + } } if ((type.getType().isItem() && tile == null) || type.hasPermissions(tile, x, y, z, side, p)) { if (tile == null && type.getType() == GuiHostType.ITEM) { - p.openGui(AppEng.instance(), type.ordinal() << 4, p.getEntityWorld(), p.inventory.currentItem, 0, 0); + p.openGui(AppEng.instance(), type.ordinal() << 4, p.getEntityWorld(), x, 0, 0); } else if (tile == null || type.getType() == GuiHostType.ITEM) { p.openGui(AppEng.instance(), type.ordinal() << 4 | (1 << 3), p.getEntityWorld(), x, y, z); } else { From 0e797b2120ffaec1fa680ff361d066258e75ef65 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Thu, 2 Feb 2023 18:22:20 -0300 Subject: [PATCH 24/35] GUI/Container fixes Ugh --- .../gui/implementations/GuiCraftAmount.java | 6 ++--- .../gui/implementations/GuiCraftConfirm.java | 6 +++-- .../implementations/GuiCraftingStatus.java | 7 +++--- .../implementations/GuiMEPortableCell.java | 6 +---- .../GuiWirelessCraftingTerminal.java | 8 +++++++ .../GuiWirelessPatternTerminal.java | 8 +++++++ .../gui/implementations/GuiWirelessTerm.java | 15 ++++++++----- .../ContainerMEPortableCell.java | 4 ++-- .../ContainerWirelessCraftingTerminal.java | 15 +++++-------- .../ContainerWirelessPatternTerminal.java | 14 ++++++++++-- src/main/java/appeng/core/sync/GuiBridge.java | 14 +++++++++--- .../client/gui/GuiWirelessFluidTerminal.java | 22 +++++++++++++++++++ .../ContainerMEPortableFluidCell.java | 14 ++++++++++-- 13 files changed, 103 insertions(+), 36 deletions(-) diff --git a/src/main/java/appeng/client/gui/implementations/GuiCraftAmount.java b/src/main/java/appeng/client/gui/implementations/GuiCraftAmount.java index f1d3a001c..02e07e2a8 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiCraftAmount.java +++ b/src/main/java/appeng/client/gui/implementations/GuiCraftAmount.java @@ -22,6 +22,7 @@ package appeng.client.gui.implementations; import appeng.api.AEApi; import appeng.api.definitions.IDefinitions; import appeng.api.definitions.IParts; +import appeng.api.features.IWirelessTermHandler; import appeng.api.storage.ITerminalHost; import appeng.client.gui.AEBaseGui; import appeng.client.gui.widgets.GuiNumberBox; @@ -97,9 +98,8 @@ public class GuiCraftAmount extends AEBaseGui { final IParts parts = definitions.parts(); if (target instanceof WirelessTerminalGuiObject) { - myIcon = definitions.items().wirelessTerminal().maybeStack(1).orElse(myIcon); - - this.originalGui = GuiBridge.GUI_WIRELESS_TERM; + myIcon = ((WirelessTerminalGuiObject) target).getItemStack(); + this.originalGui = (GuiBridge) AEApi.instance().registries().wireless().getWirelessTerminalHandler(myIcon).getGuiHandler(myIcon); } if (target instanceof PartTerminal) { diff --git a/src/main/java/appeng/client/gui/implementations/GuiCraftConfirm.java b/src/main/java/appeng/client/gui/implementations/GuiCraftConfirm.java index cf8b716cb..043b57835 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiCraftConfirm.java +++ b/src/main/java/appeng/client/gui/implementations/GuiCraftConfirm.java @@ -20,6 +20,7 @@ package appeng.client.gui.implementations; import appeng.api.AEApi; +import appeng.api.features.IWirelessTermHandler; import appeng.api.storage.ITerminalHost; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; @@ -83,8 +84,9 @@ public class GuiCraftConfirm extends AEBaseGui { this.ccc = (ContainerCraftConfirm) this.inventorySlots; this.ccc.setGui(this); - if (te instanceof IWirelessTermHandler) { - this.OriginalGui = (GuiBridge) ((IWirelessTermHandler)te).getGuiHandler(((WirelessTerminalGuiObject)te).getItemStack())); + if (te instanceof WirelessTerminalGuiObject) { + ItemStack itemStack = ((WirelessTerminalGuiObject) te).getItemStack(); + this.OriginalGui = (GuiBridge) AEApi.instance().registries().wireless().getWirelessTerminalHandler(itemStack).getGuiHandler(itemStack); } if (te instanceof PartTerminal) { diff --git a/src/main/java/appeng/client/gui/implementations/GuiCraftingStatus.java b/src/main/java/appeng/client/gui/implementations/GuiCraftingStatus.java index 6e9efecd4..556e34af7 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiCraftingStatus.java +++ b/src/main/java/appeng/client/gui/implementations/GuiCraftingStatus.java @@ -26,6 +26,7 @@ package appeng.client.gui.implementations; import appeng.api.AEApi; import appeng.api.definitions.IDefinitions; import appeng.api.definitions.IParts; +import appeng.api.features.IWirelessTermHandler; import appeng.api.storage.ITerminalHost; import appeng.api.storage.data.IAEItemStack; import appeng.client.gui.widgets.GuiScrollbar; @@ -33,6 +34,7 @@ import appeng.client.gui.widgets.GuiTabButton; import appeng.container.implementations.ContainerCraftingStatus; import appeng.container.implementations.CraftingCPUStatus; import appeng.core.AELog; +import appeng.core.features.registries.WirelessRegistry; import appeng.core.localization.GuiText; import appeng.core.sync.GuiBridge; import appeng.core.sync.network.NetworkHandler; @@ -84,9 +86,8 @@ public class GuiCraftingStatus extends GuiCraftingCPU { final IParts parts = definitions.parts(); if (target instanceof WirelessTerminalGuiObject) { - this.myIcon = definitions.items().wirelessTerminal().maybeStack(1).orElse(ItemStack.EMPTY); - - this.originalGui = GuiBridge.GUI_WIRELESS_TERM; + myIcon = ((WirelessTerminalGuiObject) target).getItemStack(); + this.originalGui = (GuiBridge) AEApi.instance().registries().wireless().getWirelessTerminalHandler(myIcon).getGuiHandler(myIcon); } if (target instanceof PartTerminal) { diff --git a/src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java b/src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java index 89dc0dcdc..2cb29d3ce 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java +++ b/src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java @@ -28,11 +28,7 @@ public class GuiMEPortableCell extends GuiMEMonitorable { public GuiMEPortableCell(final InventoryPlayer inventoryPlayer, final IPortableCell te) { super(inventoryPlayer, te); } - - int defaultGetMaxRows() { - return super.getMaxRows(); - } - + @Override protected int getMaxRows() { return 3; diff --git a/src/main/java/appeng/client/gui/implementations/GuiWirelessCraftingTerminal.java b/src/main/java/appeng/client/gui/implementations/GuiWirelessCraftingTerminal.java index f40a4b08d..fa4b4a821 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiWirelessCraftingTerminal.java +++ b/src/main/java/appeng/client/gui/implementations/GuiWirelessCraftingTerminal.java @@ -30,6 +30,7 @@ import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketInventoryAction; import appeng.helpers.InventoryAction; import appeng.helpers.WirelessTerminalGuiObject; +import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; @@ -78,6 +79,13 @@ public class GuiWirelessCraftingTerminal extends GuiMEMonitorable { this.fontRenderer.drawString(GuiText.CraftingTerminal.getLocal(), 8, this.ySize - 96 + 1 - this.getReservedSpace(), 4210752); } + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) { + this.bindTexture("guis/wirelessupgrades.png"); + Gui.drawModalRectWithCustomSizedTexture(offsetX + 198, offsetY + 127, 0, 0, 32, 32, 32, 32); + super.drawBG(offsetX, offsetY, mouseX, mouseY); + } + @Override protected String getBackground() { return "guis/crafting.png"; diff --git a/src/main/java/appeng/client/gui/implementations/GuiWirelessPatternTerminal.java b/src/main/java/appeng/client/gui/implementations/GuiWirelessPatternTerminal.java index b326d895c..433501815 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiWirelessPatternTerminal.java +++ b/src/main/java/appeng/client/gui/implementations/GuiWirelessPatternTerminal.java @@ -21,6 +21,7 @@ package appeng.client.gui.implementations; import appeng.container.implementations.ContainerWirelessPatternTerminal; import appeng.helpers.WirelessTerminalGuiObject; +import net.minecraft.client.gui.Gui; import net.minecraft.entity.player.InventoryPlayer; @@ -30,4 +31,11 @@ public class GuiWirelessPatternTerminal extends GuiPatternTerm { super(inventoryPlayer, te, new ContainerWirelessPatternTerminal(inventoryPlayer, te)); this.setReservedSpace(81); } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) { + this.bindTexture("guis/wirelessupgrades.png"); + Gui.drawModalRectWithCustomSizedTexture(offsetX + 198, offsetY + 127, 0, 0, 32, 32, 32, 32); + super.drawBG(offsetX, offsetY, mouseX, mouseY); + } } diff --git a/src/main/java/appeng/client/gui/implementations/GuiWirelessTerm.java b/src/main/java/appeng/client/gui/implementations/GuiWirelessTerm.java index a0bd8813c..25b9eff27 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiWirelessTerm.java +++ b/src/main/java/appeng/client/gui/implementations/GuiWirelessTerm.java @@ -20,17 +20,22 @@ package appeng.client.gui.implementations; import appeng.api.implementations.guiobjects.IPortableCell; +import appeng.container.implementations.ContainerWirelessTerm; +import appeng.helpers.WirelessTerminalGuiObject; +import net.minecraft.client.gui.Gui; import net.minecraft.entity.player.InventoryPlayer; -public class GuiWirelessTerm extends GuiMEPortableCell { +public class GuiWirelessTerm extends GuiMEMonitorable { - public GuiWirelessTerm(final InventoryPlayer inventoryPlayer, final IPortableCell te) { - super(inventoryPlayer, te); + public GuiWirelessTerm(final InventoryPlayer inventoryPlayer, final WirelessTerminalGuiObject te) { + super(inventoryPlayer, te, new ContainerWirelessTerm(inventoryPlayer, te)); } @Override - protected int getMaxRows() { - return this.defaultGetMaxRows(); + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) { + this.bindTexture("guis/wirelessupgrades.png"); + Gui.drawModalRectWithCustomSizedTexture(offsetX + 198, offsetY + 127, 0, 0, 32, 32, 32, 32); + super.drawBG(offsetX, offsetY, mouseX, mouseY); } } diff --git a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java index 26d3dae19..b5a8c3ef5 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java +++ b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java @@ -136,7 +136,7 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I if (wirelessTerminalGUIObject != null) { for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) { this.addSlotToContainer( - (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 187, upgradeSlot * 18, this.getInventoryPlayer())) + (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 206, 135 + upgradeSlot * 18, this.getInventoryPlayer())) .setNotDraggable()); } } @@ -157,7 +157,7 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I } } - private void loadFromNBT() { + protected void loadFromNBT() { NBTTagCompound data = wirelessTerminalGUIObject.getItemStack().getTagCompound(); if (data != null) { upgrades.readFromNBT(wirelessTerminalGUIObject.getItemStack().getTagCompound().getCompoundTag("upgrades")); diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java index 3c3ee8feb..78435661d 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java @@ -40,23 +40,18 @@ import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.wrapper.PlayerInvWrapper; -public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell implements IAEAppEngInventory, IContainerCraftingPacket { - - private final WirelessTerminalGuiObject wirelessTerminalGUIObject; +public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell implements IContainerCraftingPacket { private final AppEngInternalInventory output = new AppEngInternalInventory(this, 1); private final SlotCraftingMatrix[] craftingSlots = new SlotCraftingMatrix[9]; private final SlotCraftingTerm outputSlot; - private final AppEngInternalInventory craftingGrid = new AppEngInternalInventory(this, 9); + private AppEngInternalInventory craftingGrid; private IRecipe currentRecipe; public ContainerWirelessCraftingTerminal(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) { - super(ip, gui, false); - this.wirelessTerminalGUIObject = gui; - - this.loadFromNBT(); + super(ip, gui, true); final IItemHandler crafting = this.craftingGrid; @@ -104,11 +99,13 @@ public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell i } } + @Override protected void loadFromNBT() { + super.loadFromNBT(); + this.craftingGrid = new AppEngInternalInventory(this, 9); NBTTagCompound data = wirelessTerminalGUIObject.getItemStack().getTagCompound(); if (data != null) { this.craftingGrid.readFromNBT(data, "craftingGrid"); - upgrades.readFromNBT(wirelessTerminalGUIObject.getItemStack().getTagCompound().getCompoundTag("upgrades")); } } diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java index e6aefca4e..f41f79b7b 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java @@ -48,7 +48,7 @@ import net.minecraftforge.items.IItemHandler; import static appeng.helpers.PatternHelper.CRAFTING_GRID_DIMENSION; -public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder implements IUpgradeableCellContainer { +public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder implements IUpgradeableCellContainer, IInventorySlotAware { private final WirelessTerminalGuiObject wirelessTerminalGUIObject; private final int slot; @@ -259,9 +259,19 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im if (wirelessTerminalGUIObject != null) { for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) { this.addSlotToContainer( - (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 187, upgradeSlot * 18 - 2, this.getInventoryPlayer())) + (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 206, 135 + upgradeSlot * 18, this.getInventoryPlayer())) .setNotDraggable()); } } } + + @Override + public int getInventorySlot() { + return wirelessTerminalGUIObject.getInventorySlot(); + } + + @Override + public boolean isBaubleSlot() { + return wirelessTerminalGUIObject.isBaubleSlot(); + } } diff --git a/src/main/java/appeng/core/sync/GuiBridge.java b/src/main/java/appeng/core/sync/GuiBridge.java index 4b3d5d4ca..b913d1f27 100644 --- a/src/main/java/appeng/core/sync/GuiBridge.java +++ b/src/main/java/appeng/core/sync/GuiBridge.java @@ -43,6 +43,7 @@ import appeng.container.AEBaseContainer; import appeng.container.ContainerNull; import appeng.container.ContainerOpenContext; import appeng.container.implementations.*; +import appeng.container.interfaces.IInventorySlotAware; import appeng.fluids.container.*; import appeng.fluids.helper.IFluidInterfaceHost; import appeng.fluids.parts.PartFluidFormationPlane; @@ -243,10 +244,10 @@ public enum GuiBridge implements IGuiHandler { } else { if (stem) { if (player.openContainer instanceof IInventorySlotAware) { - int slot = ((IInventorySlotAware)player.openContainer).getInventorySlot(); + int slot = ((IInventorySlotAware) player.openContainer).getInventorySlot(); it = BaublesApi.getBaublesHandler(player).getStackInSlot(slot); } - }else { + } else { it = BaublesApi.getBaublesHandler(player).getStackInSlot(x); } } @@ -363,7 +364,14 @@ public enum GuiBridge implements IGuiHandler { it = player.inventory.getStackInSlot(x); } } else { - it = BaublesApi.getBaublesHandler(player).getStackInSlot(x); + if (stem) { + if (player.openContainer instanceof IInventorySlotAware) { + int slot = ((IInventorySlotAware) player.openContainer).getInventorySlot(); + it = BaublesApi.getBaublesHandler(player).getStackInSlot(slot); + } + } else { + it = BaublesApi.getBaublesHandler(player).getStackInSlot(x); + } } final Object myItem = this.getGuiObject(it, player, w, x, y, z); if (myItem != null && ID.CorrectTileOrPart(myItem)) { diff --git a/src/main/java/appeng/fluids/client/gui/GuiWirelessFluidTerminal.java b/src/main/java/appeng/fluids/client/gui/GuiWirelessFluidTerminal.java index bd3dc0882..9f7ce30b0 100644 --- a/src/main/java/appeng/fluids/client/gui/GuiWirelessFluidTerminal.java +++ b/src/main/java/appeng/fluids/client/gui/GuiWirelessFluidTerminal.java @@ -22,12 +22,34 @@ package appeng.fluids.client.gui; import appeng.api.implementations.guiobjects.IPortableCell; import appeng.fluids.container.ContainerWirelessFluidTerminal; import appeng.helpers.WirelessTerminalGuiObject; +import net.minecraft.client.gui.Gui; import net.minecraft.entity.player.InventoryPlayer; +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + public class GuiWirelessFluidTerminal extends GuiMEPortableFluidCell { public GuiWirelessFluidTerminal(final InventoryPlayer inventoryPlayer, final WirelessTerminalGuiObject te) { super(inventoryPlayer, te, new ContainerWirelessFluidTerminal(inventoryPlayer, te)); } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) { + this.bindTexture("guis/wirelessupgrades.png"); + Gui.drawModalRectWithCustomSizedTexture(offsetX + 175, offsetY + 131, 0, 0, 32, 32, 32, 32); + super.drawBG(offsetX, offsetY, mouseX, mouseY); + } + + @Override + public List getJEIExclusionArea() { + List ea = new ArrayList<>(); + ea.add(new Rectangle(this.guiLeft + 174, + this.guiTop + 131, + 32, + 32)); + return ea; + } } diff --git a/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java index b13824efa..40f50dbc6 100644 --- a/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java +++ b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java @@ -65,7 +65,7 @@ import javax.annotation.Nonnull; import java.io.IOException; import java.nio.BufferOverflowException; -public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAEAppEngInventory, IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver, IUpgradeableCellContainer { +public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAEAppEngInventory, IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver, IUpgradeableCellContainer, IInventorySlotAware { protected final WirelessTerminalGuiObject wirelessTerminalGUIObject; @@ -552,7 +552,7 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE if (wirelessTerminalGUIObject != null) { for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) { this.addSlotToContainer( - (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 187, 139 + upgradeSlot * 18, this.getInventoryPlayer())) + (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 183, 139 + upgradeSlot * 18, this.getInventoryPlayer())) .setNotDraggable()); } } @@ -578,4 +578,14 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE @Override public void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) { } + + @Override + public int getInventorySlot() { + return wirelessTerminalGUIObject.getInventorySlot(); + } + + @Override + public boolean isBaubleSlot() { + return wirelessTerminalGUIObject.isBaubleSlot(); + } } From 8bad14f982db33350fc0ff8d7f224c62522c2f93 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Thu, 2 Feb 2023 19:24:03 -0300 Subject: [PATCH 25/35] cursed recipes --- .../aerecipes/inscriber/card_magnet.json | 27 +++++++++++++++++++ .../inscriber/card_quantum_link.json | 27 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/main/resources/assets/appliedenergistics2/aerecipes/inscriber/card_magnet.json create mode 100644 src/main/resources/assets/appliedenergistics2/aerecipes/inscriber/card_quantum_link.json diff --git a/src/main/resources/assets/appliedenergistics2/aerecipes/inscriber/card_magnet.json b/src/main/resources/assets/appliedenergistics2/aerecipes/inscriber/card_magnet.json new file mode 100644 index 000000000..2a231453b --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/aerecipes/inscriber/card_magnet.json @@ -0,0 +1,27 @@ +{ + "conditions": [ + { + "type": "appliedenergistics2:material_exists", + "material": "material.card_magnet" + } + ], + "type": "appliedenergistics2:inscriber", + "mode": "press", + "result": { + "part": "material.card_magnet" + }, + "ingredients": { + "top": { + "type": "forge:ore_dict", + "ore": "blockRedstone" + }, + "middle": { + "type": "appliedenergistics2:part", + "part": "material.basic_card" + }, + "bottom": { + "type": "forge:ore_dict", + "ore": "blockLapis" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/appliedenergistics2/aerecipes/inscriber/card_quantum_link.json b/src/main/resources/assets/appliedenergistics2/aerecipes/inscriber/card_quantum_link.json new file mode 100644 index 000000000..387407235 --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/aerecipes/inscriber/card_quantum_link.json @@ -0,0 +1,27 @@ +{ + "conditions": [ + { + "type": "appliedenergistics2:material_exists", + "material": "material.card_quantum_link" + } + ], + "type": "appliedenergistics2:inscriber", + "mode": "press", + "result": { + "part": "material.card_quantum_link" + }, + "ingredients": { + "top": { + "type": "appliedenergistics2:part", + "part": "material.singularity" + }, + "middle": { + "type": "appliedenergistics2:part", + "part": "material.advanced_card" + }, + "bottom": { + "type": "appliedenergistics2:part", + "part": "material.singularity" + } + } +} \ No newline at end of file From fb2aa213370378efdd48a6999facca453b217090 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Thu, 2 Feb 2023 20:00:56 -0300 Subject: [PATCH 26/35] cleaning --- .../java/appeng/container/AEBaseContainer.java | 10 ++++++++-- .../ContainerMEPortableCell.java | 3 --- .../ContainerWirelessCraftingTerminal.java | 1 - .../implementations/ContainerWirelessTerm.java | 18 ------------------ .../ContainerMEPortableFluidCell.java | 2 +- 5 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/main/java/appeng/container/AEBaseContainer.java b/src/main/java/appeng/container/AEBaseContainer.java index 201d10b25..95262d730 100644 --- a/src/main/java/appeng/container/AEBaseContainer.java +++ b/src/main/java/appeng/container/AEBaseContainer.java @@ -37,7 +37,14 @@ import appeng.api.storage.data.IAEItemStack; import appeng.client.me.SlotME; import appeng.container.guisync.GuiSync; import appeng.container.guisync.SyncData; -import appeng.container.slot.*; +import appeng.container.slot.AppEngSlot; +import appeng.container.slot.SlotCraftingMatrix; +import appeng.container.slot.SlotCraftingTerm; +import appeng.container.slot.SlotDisabled; +import appeng.container.slot.SlotFake; +import appeng.container.slot.SlotInaccessible; +import appeng.container.slot.SlotPlayerHotBar; +import appeng.container.slot.SlotPlayerInv; import appeng.core.AELog; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketInventoryAction; @@ -48,7 +55,6 @@ import appeng.helpers.InventoryAction; import appeng.me.helpers.PlayerSource; import appeng.util.InventoryAdaptor; import appeng.util.Platform; -import appeng.util.helpers.ItemHandlerUtil; import appeng.util.inv.AdaptorItemHandler; import appeng.util.inv.WrapperCursorItemHandler; import appeng.util.item.AEItemStack; diff --git a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java index b5a8c3ef5..3a98274d8 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java +++ b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java @@ -21,9 +21,7 @@ package appeng.container.implementations; import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; -import appeng.api.config.SecurityPermissions; import appeng.api.implementations.IUpgradeableCellContainer; -import appeng.api.implementations.tiles.IViewCellStorage; import appeng.api.networking.security.IActionHost; import appeng.container.interfaces.IInventorySlotAware; import appeng.container.slot.SlotRestrictedInput; @@ -36,7 +34,6 @@ import appeng.util.Platform; import appeng.util.inv.IAEAppEngInventory; import appeng.util.inv.InvOperation; import baubles.api.BaublesApi; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java index 78435661d..0856bdabe 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessCraftingTerminal.java @@ -26,7 +26,6 @@ import appeng.helpers.IContainerCraftingPacket; import appeng.helpers.WirelessTerminalGuiObject; import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.Platform; -import appeng.util.inv.IAEAppEngInventory; import appeng.util.inv.InvOperation; import appeng.util.inv.WrapperInvItemHandler; import net.minecraft.entity.player.InventoryPlayer; diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessTerm.java b/src/main/java/appeng/container/implementations/ContainerWirelessTerm.java index cd9eae785..7148e98e5 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessTerm.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessTerm.java @@ -19,10 +19,7 @@ package appeng.container.implementations; -import appeng.core.AEConfig; -import appeng.core.localization.PlayerMessages; import appeng.helpers.WirelessTerminalGuiObject; -import appeng.util.Platform; import net.minecraft.entity.player.InventoryPlayer; @@ -31,19 +28,4 @@ public class ContainerWirelessTerm extends ContainerMEPortableCell { public ContainerWirelessTerm(final InventoryPlayer ip, final WirelessTerminalGuiObject gui) { super(ip, gui, true); } - - @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - - if (!this.wirelessTerminalGUIObject.rangeCheck()) { - if (Platform.isServer() && this.isValidContainer()) { - this.getPlayerInv().player.sendMessage(PlayerMessages.OutOfRange.get()); - } - - this.setValidContainer(false); - } else { - this.setPowerMultiplier(AEConfig.instance().wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange())); - } - } } diff --git a/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java index 40f50dbc6..3f55c4804 100644 --- a/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java +++ b/src/main/java/appeng/fluids/container/ContainerMEPortableFluidCell.java @@ -237,7 +237,7 @@ public class ContainerMEPortableFluidCell extends AEBaseContainer implements IAE AELog.debug(e); } } - //this.updatePowerStatus(); + super.detectAndSendChanges(); } } From 9d7dacdc299a174c6f2c895e09a00f3ca5e48668 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Thu, 2 Feb 2023 21:45:31 -0300 Subject: [PATCH 27/35] Toggle magnet on/off from container/gui --- .../appeng/api/definitions/IMaterials.java | 4 +-- .../ContainerMEPortableCell.java | 34 ++++++++++++++++-- .../ContainerWirelessPatternTerminal.java | 35 +++++++++++++++++-- .../appeng/items/materials/ItemMaterial.java | 11 ++++++ .../tools/powered/ToolWirelessTerminal.java | 20 ++++++++--- .../appliedenergistics2/lang/en_us.lang | 2 ++ 6 files changed, 93 insertions(+), 13 deletions(-) diff --git a/src/api/java/appeng/api/definitions/IMaterials.java b/src/api/java/appeng/api/definitions/IMaterials.java index 09d03120f..64b5dcfd6 100644 --- a/src/api/java/appeng/api/definitions/IMaterials.java +++ b/src/api/java/appeng/api/definitions/IMaterials.java @@ -90,9 +90,9 @@ public interface IMaterials { IItemDefinition cardPatternExpansion(); - public IItemDefinition cardQuantumLink(); + IItemDefinition cardQuantumLink(); - public IItemDefinition cardMagnet(); + IItemDefinition cardMagnet(); IItemDefinition cardFuzzy(); diff --git a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java index 3a98274d8..1df595b4d 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java +++ b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java @@ -34,7 +34,9 @@ import appeng.util.Platform; import appeng.util.inv.IAEAppEngInventory; import appeng.util.inv.InvOperation; import baubles.api.BaublesApi; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ClickType; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -49,6 +51,7 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I private int ticks = 0; protected AppEngInternalInventory upgrades; + protected SlotRestrictedInput magnetSlot; public ContainerMEPortableCell(InventoryPlayer ip, WirelessTerminalGuiObject monitorable, boolean bindInventory) { super(ip, monitorable, bindInventory); @@ -110,6 +113,31 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I } } + @Override + public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) { + if (clickTypeIn == ClickType.PICKUP && dragType == 1) { + if (this.inventorySlots.get(slotId) == magnetSlot) { + ItemStack itemStack = magnetSlot.getStack(); + if (!magnetSlot.getStack().isEmpty()) { + NBTTagCompound tag = itemStack.getTagCompound(); + if (tag == null) { + tag = new NBTTagCompound(); + } + if (tag.hasKey("enabled")) { + boolean e = tag.getBoolean("enabled"); + tag.setBoolean("enabled", !e); + } else { + tag.setBoolean("enabled", false); + } + magnetSlot.getStack().setTagCompound(tag); + magnetSlot.onSlotChanged(); + return ItemStack.EMPTY; + } + } + } + return super.slotClick(slotId, dragType, clickTypeIn, player); + } + @Override protected IActionHost getActionHost() { return this.wirelessTerminalGUIObject; @@ -132,9 +160,9 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I public void setupUpgrades() { if (wirelessTerminalGUIObject != null) { for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) { - this.addSlotToContainer( - (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 206, 135 + upgradeSlot * 18, this.getInventoryPlayer())) - .setNotDraggable()); + this.magnetSlot = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 206, 135 + upgradeSlot * 18, this.getInventoryPlayer()); + this.magnetSlot.setNotDraggable(); + this.addSlotToContainer(magnetSlot); } } } diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java index f41f79b7b..8b760b636 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java @@ -40,7 +40,9 @@ import appeng.util.Platform; import appeng.util.helpers.ItemHandlerUtil; import appeng.util.inv.InvOperation; import baubles.api.BaublesApi; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ClickType; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.items.IItemHandler; @@ -56,6 +58,8 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im protected AppEngInternalInventory pattern; protected AppEngInternalInventory upgrades; + protected SlotRestrictedInput magnetSlot; + private double powerMultiplier = 0.5; private int ticks = 0; @@ -158,6 +162,31 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im } } + @Override + public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) { + if (clickTypeIn == ClickType.PICKUP && dragType == 1) { + if (this.inventorySlots.get(slotId) == magnetSlot) { + ItemStack itemStack = magnetSlot.getStack(); + if (!magnetSlot.getStack().isEmpty()) { + NBTTagCompound tag = itemStack.getTagCompound(); + if (tag == null) { + tag = new NBTTagCompound(); + } + if (tag.hasKey("enabled")) { + boolean e = tag.getBoolean("enabled"); + tag.setBoolean("enabled", !e); + } else { + tag.setBoolean("enabled", false); + } + magnetSlot.getStack().setTagCompound(tag); + magnetSlot.onSlotChanged(); + return ItemStack.EMPTY; + } + } + } + return super.slotClick(slotId, dragType, clickTypeIn, player); + } + private double getPowerMultiplier() { return this.powerMultiplier; } @@ -258,9 +287,9 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im public void setupUpgrades() { if (wirelessTerminalGUIObject != null) { for (int upgradeSlot = 0; upgradeSlot < availableUpgrades(); upgradeSlot++) { - this.addSlotToContainer( - (new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 206, 135 + upgradeSlot * 18, this.getInventoryPlayer())) - .setNotDraggable()); + this.magnetSlot = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, upgradeSlot, 206, 135 + upgradeSlot * 18, this.getInventoryPlayer()); + this.magnetSlot.setNotDraggable(); + this.addSlotToContainer(magnetSlot); } } } diff --git a/src/main/java/appeng/items/materials/ItemMaterial.java b/src/main/java/appeng/items/materials/ItemMaterial.java index 17250b6c6..553abcb74 100644 --- a/src/main/java/appeng/items/materials/ItemMaterial.java +++ b/src/main/java/appeng/items/materials/ItemMaterial.java @@ -95,6 +95,17 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent, lines.add(c.getString("InscribeName")); } + if (mt == MaterialType.CARD_MAGNET) { + final NBTTagCompound c = Platform.openNbtData(stack); + if (!c.hasKey("enabled") || c.getBoolean("enabled")) { + lines.add(I18n.translateToLocal("gui.tooltips.appliedenergistics2.Enable")); + } else { + lines.add(I18n.translateToLocal("gui.tooltips.appliedenergistics2.Disabled")); + } + lines.add(I18n.translateToLocal("item.appliedenergistics2.material.card_magnet.usage")); + lines.add(I18n.translateToLocal("item.appliedenergistics2.material.card_magnet.partition")); + } + final Upgrades u = this.getType(stack); if (u != null) { final List textList = new ArrayList<>(); diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java index 68daf4dad..2360c533a 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java @@ -20,7 +20,13 @@ package appeng.items.tools.powered; import appeng.api.AEApi; -import appeng.api.config.*; +import appeng.api.config.Actionable; +import appeng.api.config.FuzzyMode; +import appeng.api.config.Settings; +import appeng.api.config.SortDir; +import appeng.api.config.SortOrder; +import appeng.api.config.Upgrades; +import appeng.api.config.ViewItems; import appeng.api.features.IWirelessTermHandler; import appeng.api.util.IConfigManager; import appeng.core.AEConfig; @@ -189,6 +195,10 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless for (int s = 0; s < siu.getSlots(); s++) { ItemStack is = siu.getStackInSlot(s); if (AEApi.instance().definitions().materials().cardMagnet().isSameAs(is)) { + NBTTagCompound tag = is.getTagCompound(); + if (tag != null && !tag.getBoolean("enabled")) { + return; + } ItemMaterial im = (ItemMaterial) is.getItem(); CellConfig c = (CellConfig) im.getConfigInventory(is); CellUpgrades u = (CellUpgrades) im.getUpgradesInventory(is); @@ -235,11 +245,11 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless } } if (emptyFilter) { - teleportItem(i,entityIn); + teleportItem(i, entityIn); } else if (matched && !inverted) { - teleportItem(i,entityIn); + teleportItem(i, entityIn); } else if (!matched && inverted) { - teleportItem(i,entityIn); + teleportItem(i, entityIn); } } } @@ -248,7 +258,7 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless } } - private void teleportItem(EntityItem i, Entity entityIn){ + private void teleportItem(EntityItem i, Entity entityIn) { i.motionX = i.motionY = i.motionZ = 0; i.setPosition(entityIn.posX, entityIn.posY, entityIn.posZ); } diff --git a/src/main/resources/assets/appliedenergistics2/lang/en_us.lang b/src/main/resources/assets/appliedenergistics2/lang/en_us.lang index bd2527ddd..419c6a767 100644 --- a/src/main/resources/assets/appliedenergistics2/lang/en_us.lang +++ b/src/main/resources/assets/appliedenergistics2/lang/en_us.lang @@ -463,6 +463,8 @@ item.appliedenergistics2.material.calculation_processor.name=Calculation Process item.appliedenergistics2.material.card_capacity.name=Capacity Card item.appliedenergistics2.material.card_pattern_expansion.name=Pattern Expansion Card item.appliedenergistics2.material.card_magnet.name=Magnet Card +item.appliedenergistics2.material.card_magnet.usage=Right click with an empty hand while equipped on a terminal to toggle ON or OFF +item.appliedenergistics2.material.card_magnet.partition=Can be configured in a Cell Workbench item.appliedenergistics2.material.card_quantum_link.name=Quantum Link Card item.appliedenergistics2.material.card_fuzzy.name=Fuzzy Card item.appliedenergistics2.material.card_inverter.name=Inverter Card From 56268aba79a723f486cf170a006e6bfc13d59c89 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Fri, 3 Feb 2023 12:53:04 -0300 Subject: [PATCH 28/35] fix autocrafting gui not opening --- src/main/java/appeng/core/sync/GuiBridge.java | 4 ++-- src/main/java/appeng/items/materials/ItemMaterial.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/appeng/core/sync/GuiBridge.java b/src/main/java/appeng/core/sync/GuiBridge.java index b913d1f27..e040ea9a3 100644 --- a/src/main/java/appeng/core/sync/GuiBridge.java +++ b/src/main/java/appeng/core/sync/GuiBridge.java @@ -241,7 +241,7 @@ public enum GuiBridge implements IGuiHandler { } else if (x >= 0 && x < player.inventory.mainInventory.size()) { it = player.inventory.getStackInSlot(x); } - } else { + } else if (y == 1 && z == 0) { if (stem) { if (player.openContainer instanceof IInventorySlotAware) { int slot = ((IInventorySlotAware) player.openContainer).getInventorySlot(); @@ -363,7 +363,7 @@ public enum GuiBridge implements IGuiHandler { } else if (x >= 0 && x < player.inventory.mainInventory.size()) { it = player.inventory.getStackInSlot(x); } - } else { + } else if (y == 1 && z == 0) { if (stem) { if (player.openContainer instanceof IInventorySlotAware) { int slot = ((IInventorySlotAware) player.openContainer).getInventorySlot(); diff --git a/src/main/java/appeng/items/materials/ItemMaterial.java b/src/main/java/appeng/items/materials/ItemMaterial.java index 553abcb74..1352b0a65 100644 --- a/src/main/java/appeng/items/materials/ItemMaterial.java +++ b/src/main/java/appeng/items/materials/ItemMaterial.java @@ -56,6 +56,7 @@ import net.minecraft.util.EnumHand; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import net.minecraft.util.text.translation.I18n; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; From 472f1e65a2573cb918c7816942d2e87f11e8316b Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Fri, 3 Feb 2023 13:49:27 -0300 Subject: [PATCH 29/35] more autocrafting fixes --- .../container/implementations/ContainerCraftConfirm.java | 4 +++- src/main/java/appeng/util/Platform.java | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/appeng/container/implementations/ContainerCraftConfirm.java b/src/main/java/appeng/container/implementations/ContainerCraftConfirm.java index b4d2dc323..cf06bf389 100644 --- a/src/main/java/appeng/container/implementations/ContainerCraftConfirm.java +++ b/src/main/java/appeng/container/implementations/ContainerCraftConfirm.java @@ -54,6 +54,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IContainerListener; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.text.TextComponentString; import net.minecraft.world.World; @@ -279,7 +280,8 @@ public class ContainerCraftConfirm extends AEBaseContainer { final IActionHost ah = this.getActionHost(); if (ah instanceof WirelessTerminalGuiObject) { - originalGui = GuiBridge.GUI_WIRELESS_TERM; + ItemStack myIcon = ((WirelessTerminalGuiObject) ah).getItemStack(); + originalGui = (GuiBridge) AEApi.instance().registries().wireless().getWirelessTerminalHandler(myIcon).getGuiHandler(myIcon); } if (ah instanceof PartTerminal) { diff --git a/src/main/java/appeng/util/Platform.java b/src/main/java/appeng/util/Platform.java index 186174f1e..a20ba333f 100644 --- a/src/main/java/appeng/util/Platform.java +++ b/src/main/java/appeng/util/Platform.java @@ -324,8 +324,8 @@ public class Platform { } int x; - int y = (int) p.posY; - int z = (int) p.posZ; + int y = 0; + int z = 0; if (tile != null) { x = tile.getPos().getX(); y = tile.getPos().getY(); From d7e7ef0cb4bbfc8680cbef348a27c0d460ba38b6 Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Fri, 3 Feb 2023 15:07:55 -0300 Subject: [PATCH 30/35] wip --- src/main/java/appeng/core/sync/GuiBridge.java | 2 +- .../core/sync/packets/PacketTerminalUse.java | 8 +++---- src/main/java/appeng/util/Platform.java | 21 ++++++------------- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/main/java/appeng/core/sync/GuiBridge.java b/src/main/java/appeng/core/sync/GuiBridge.java index e040ea9a3..7d3a105c1 100644 --- a/src/main/java/appeng/core/sync/GuiBridge.java +++ b/src/main/java/appeng/core/sync/GuiBridge.java @@ -241,7 +241,7 @@ public enum GuiBridge implements IGuiHandler { } else if (x >= 0 && x < player.inventory.mainInventory.size()) { it = player.inventory.getStackInSlot(x); } - } else if (y == 1 && z == 0) { + } else if (y == 1 && z == Integer.MIN_VALUE) { if (stem) { if (player.openContainer instanceof IInventorySlotAware) { int slot = ((IInventorySlotAware) player.openContainer).getInventorySlot(); diff --git a/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java b/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java index 5e4d90eab..62de87ebd 100644 --- a/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java +++ b/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java @@ -1,5 +1,6 @@ package appeng.core.sync.packets; +import appeng.api.util.AEPartLocation; import appeng.core.sync.AppEngPacket; import appeng.core.sync.network.INetworkInfo; import appeng.items.tools.powered.Terminal; @@ -31,17 +32,16 @@ public class PacketTerminalUse extends AppEngPacket { @Override public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player) { NonNullList mainInventory = player.inventory.mainInventory; - for (int i = 0; i < mainInventory.size(); i++) { - ItemStack is = mainInventory.get(i); + for (ItemStack is : mainInventory) { if (terminal.getItemDefinition().isSameAs(is)) { - Platform.openGUI(player, i, terminal.getBridge(), false); + Platform.openGUI(player, null, AEPartLocation.INTERNAL, terminal.getBridge()); return; } } for (int i = 0; i < BaublesApi.getBaublesHandler(player).getSlots(); i++) { ItemStack is = BaublesApi.getBaublesHandler(player).getStackInSlot(i); if (terminal.getItemDefinition().isSameAs(is)) { - Platform.openGUI(player, i, terminal.getBridge(), true); + Platform.openGUI(player, null, AEPartLocation.INTERNAL, terminal.getBridge()); break; } } diff --git a/src/main/java/appeng/util/Platform.java b/src/main/java/appeng/util/Platform.java index a20ba333f..d59e0290e 100644 --- a/src/main/java/appeng/util/Platform.java +++ b/src/main/java/appeng/util/Platform.java @@ -324,8 +324,9 @@ public class Platform { } int x; - int y = 0; - int z = 0; + int y; + int z; + if (tile != null) { x = tile.getPos().getX(); y = tile.getPos().getY(); @@ -333,10 +334,12 @@ public class Platform { } else { if (p.openContainer instanceof IInventorySlotAware) { x = ((IInventorySlotAware) p.openContainer).getInventorySlot(); - y = ((IInventorySlotAware)p.openContainer).isBaubleSlot() ? 1 : 0; + y = ((IInventorySlotAware) p.openContainer).isBaubleSlot() ? 1 : 0; } else { x = p.inventory.currentItem; + y = 0; } + z = Integer.MIN_VALUE; } if ((type.getType().isItem() && tile == null) || type.hasPermissions(tile, x, y, z, side, p)) { @@ -350,18 +353,6 @@ public class Platform { } } - public static void openGUI(@Nonnull final EntityPlayer p, int i, @Nonnull final GuiBridge type, boolean isBauble) { - if (isClient()) { - return; - } - - if (type.getType().isItem()) { - if (type.getType() == GuiHostType.ITEM) { - p.openGui(AppEng.instance(), type.ordinal() << 4, p.getEntityWorld(), i, isBauble ? 1 : 0, 0); - } - } - } - /* * returns true if the code is on the client. */ From 269d3766db588942c4d7a140093af16582f8fb7a Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Fri, 3 Feb 2023 20:56:17 -0300 Subject: [PATCH 31/35] implement tall interface terminal (part, not wireless) --- .../implementations/GuiInterfaceTerminal.java | 126 ++++++++++++++++-- .../ContainerInterfaceTerminal.java | 2 +- 2 files changed, 117 insertions(+), 11 deletions(-) diff --git a/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java b/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java index 1e7bda09f..531ccae1b 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java +++ b/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java @@ -22,6 +22,7 @@ package appeng.client.gui.implementations; import appeng.api.AEApi; import appeng.api.config.ActionItems; import appeng.api.config.Settings; +import appeng.api.config.TerminalStyle; import appeng.api.storage.channels.IItemStorageChannel; import appeng.client.gui.AEBaseGui; import appeng.client.gui.widgets.GuiImgButton; @@ -30,6 +31,8 @@ import appeng.client.gui.widgets.MEGuiTextField; import appeng.client.me.ClientDCInternalInv; import appeng.client.me.SlotDisconnected; import appeng.container.implementations.ContainerInterfaceTerminal; +import appeng.container.slot.AppEngSlot; +import appeng.core.AEConfig; import appeng.core.localization.GuiText; import appeng.helpers.DualityInterface; import appeng.parts.reporting.PartInterfaceTerminal; @@ -39,6 +42,7 @@ import com.google.common.collect.HashMultimap; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -49,7 +53,13 @@ import net.minecraftforge.common.DimensionManager; import org.lwjgl.input.Mouse; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.WeakHashMap; import static appeng.client.render.BlockPosHighlighter.hilightBlock; import static appeng.helpers.ItemStackHelper.stackFromNBT; @@ -57,10 +67,13 @@ import static appeng.helpers.ItemStackHelper.stackFromNBT; public class GuiInterfaceTerminal extends AEBaseGui { - private static final int LINES_ON_PAGE = 6; + private int rows = 6; // TODO: copied from GuiMEMonitorable. It looks not changed, maybe unneeded? private final int offsetX = 21; + private int maxRows = Integer.MAX_VALUE; + + private int reservedSpace = 0; private final HashMap byId = new HashMap<>(); private final HashMultimap byName = HashMultimap.create(); @@ -79,7 +92,10 @@ public class GuiInterfaceTerminal extends AEBaseGui { private final PartInterfaceTerminal partInterfaceTerminal; private GuiButton guiButtonHide; private GuiButton guiButtonNextAssembler; + private GuiImgButton terminalStyleBox; + private final HashMap dimHashMap = new HashMap<>(); + private int drawnRows = 0; public GuiInterfaceTerminal(final InventoryPlayer inventoryPlayer, final PartInterfaceTerminal te) { super(new ContainerInterfaceTerminal(inventoryPlayer, te)); @@ -89,10 +105,33 @@ public class GuiInterfaceTerminal extends AEBaseGui { this.setScrollBar(scrollbar); this.xSize = 208; this.ySize = 255; + this.setReservedSpace(82); } @Override public void initGui() { + this.maxRows = AEConfig.instance() + .getConfigManager() + .getSetting( + Settings.TERMINAL_STYLE) != TerminalStyle.TALL ? 6 : Integer.MAX_VALUE; + + final int magicNumber = 82 + 14; + final int extraSpace = this.height - magicNumber - this.reservedSpace; + + this.rows = (int) Math.floor(extraSpace / 18); + if (this.rows > this.maxRows) { + this.rows = this.maxRows; + } + + if (this.rows < 6) { + this.rows = 6; + } + + 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)); + super.initGui(); this.getScrollBar().setLeft(189); @@ -115,6 +154,17 @@ public class GuiInterfaceTerminal extends AEBaseGui { this.searchFieldInputs.setText(partInterfaceTerminal.in); this.searchFieldOutputs.setText(partInterfaceTerminal.out); + + this.fontRenderer.drawString(this.getGuiDisplayName(GuiText.InterfaceTerminal.getLocal()), 8, 6, 4210752); + this.fontRenderer.drawString(GuiText.inventory.getLocal(), this.offsetX + 2, this.ySize - 96 + 3, 4210752); + + } + + protected void repositionSlot(final AppEngSlot s) { + this.ySize = 82 + 14 + this.drawnRows * 18 + this.reservedSpace; + + s.yPos = s.getY() + this.ySize - 112; + s.xPos = s.getX() + 14; } @Override @@ -127,9 +177,6 @@ public class GuiInterfaceTerminal extends AEBaseGui { public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { this.buttonList.clear(); - this.fontRenderer.drawString(this.getGuiDisplayName(GuiText.InterfaceTerminal.getLocal()), 8, 6, 4210752); - this.fontRenderer.drawString(GuiText.inventory.getLocal(), this.offsetX + 2, this.ySize - 96 + 3, 4210752); - final int currentScroll = this.getScrollBar().getCurrentScroll(); this.guiButtonNextAssembler = new GuiImgButton(guiLeft + 123, guiTop + 25, Settings.ACTIONS, ActionItems.FREE_MOLECULAR_SLOT_SHORTCUT); @@ -138,11 +185,15 @@ public class GuiInterfaceTerminal extends AEBaseGui { guiButtonHide = new GuiImgButton(guiLeft + 141, guiTop + 25, Settings.ACTIONS, this.partInterfaceTerminal.onlyInterfacesWithFreeSlots ? ActionItems.TOGGLE_SHOW_FULL_INTERFACES_OFF : ActionItems.TOGGLE_SHOW_FULL_INTERFACES_ON); this.buttonList.add(guiButtonHide); + this.buttonList.add(this.terminalStyleBox = new GuiImgButton(this.guiLeft - 18, guiTop + 18, Settings.TERMINAL_STYLE, AEConfig.instance() + .getConfigManager() + .getSetting(Settings.TERMINAL_STYLE))); + this.inventorySlots.inventorySlots.removeIf(slot -> slot instanceof SlotDisconnected); int offset = 52; int linesDraw = 0; - for (int x = 0; x < LINES_ON_PAGE && linesDraw < LINES_ON_PAGE && currentScroll + x < this.lines.size(); x++) { + for (int x = 0; x < rows && linesDraw < rows && currentScroll + x < this.lines.size(); x++) { final Object lineObj = this.lines.get(currentScroll + x); if (lineObj instanceof ClientDCInternalInv) { final ClientDCInternalInv inv = (ClientDCInternalInv) lineObj; @@ -152,7 +203,7 @@ public class GuiInterfaceTerminal extends AEBaseGui { this.buttonList.add(guiButton); int extraLines = numUpgradesMap.get(inv); - for (int row = 0; row < 1 + extraLines && linesDraw < LINES_ON_PAGE; ++row) { + for (int row = 0; row < 1 + extraLines && linesDraw < rows; ++row) { for (int z = 0; z < 9; z++) { this.inventorySlots.inventorySlots.add(new SlotDisconnected(inv, z + (row * 9), (z * 18 + 22), offset)); if (this.matchedStacks.contains(inv.getInventory().getStackInSlot(z + (row * 9)))) { @@ -227,6 +278,25 @@ public class GuiInterfaceTerminal extends AEBaseGui { mc.player.closeScreen(); } + 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().getConfigManager().putSetting(iBtn.getSetting(), next); + } + + iBtn.set(next); + + if (next.getClass() == TerminalStyle.class) { + this.reinitalize(); + } + } + } if (btn == guiButtonHide) { partInterfaceTerminal.onlyInterfacesWithFreeSlots = !partInterfaceTerminal.onlyInterfacesWithFreeSlots; this.refreshList(); @@ -247,15 +317,21 @@ public class GuiInterfaceTerminal extends AEBaseGui { } } + private void reinitalize() { + 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, this.ySize); + //split the texture for the top + this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, 166); int offset = 51; final int ex = this.getScrollBar().getCurrentScroll(); int linesDraw = 0; - for (int x = 0; x < LINES_ON_PAGE && linesDraw < LINES_ON_PAGE && ex + x < this.lines.size(); x++) { + for (int x = 0; x < rows && linesDraw < rows && ex + x < this.lines.size(); x++) { final Object lineObj = this.lines.get(ex + x); if (lineObj instanceof ClientDCInternalInv) { GlStateManager.color(1, 1, 1, 1); @@ -263,8 +339,15 @@ public class GuiInterfaceTerminal extends AEBaseGui { int extraLines = numUpgradesMap.get(lineObj); - for (int row = 0; row < 1 + extraLines && linesDraw < LINES_ON_PAGE; ++row) { + for (int row = 0; row < 1 + extraLines && linesDraw < rows; ++row) { + if (linesDraw == 6) { + this.drawTexturedModalRect(offsetX, offsetY + offset + 7, 0, 166, 189, 7); + this.drawTexturedModalRect(offsetX, offsetY + offset + 14, 0, 166, 189, 4); + } else if (linesDraw >= 7) { + this.drawTexturedModalRect(offsetX, offsetY + offset, 0, 173, 189, 18); + } this.drawTexturedModalRect(offsetX + 20, offsetY + offset, 20, 173, width, 18); + offset += 18; linesDraw++; } @@ -273,6 +356,21 @@ public class GuiInterfaceTerminal extends AEBaseGui { linesDraw++; } } + offset = 51 + Math.max(6 * 18, linesDraw * 18); + if (linesDraw > 6) { + this.drawTexturedModalRect(offsetX, offsetY + offset, 0, 166, 189, 7); + } + this.drawTexturedModalRect(offsetX, offsetY + offset + 7, 0, 166, this.xSize, 90); + + this.drawnRows = Math.max(6, linesDraw); + + for (final Slot s : this.inventorySlots.inventorySlots) { + if (s instanceof AppEngSlot) { + if (s.xPos < 197) { + this.repositionSlot((AppEngSlot) s); + } + } + } if (this.searchFieldInputs != null) { this.searchFieldInputs.drawTextBox(); @@ -523,4 +621,12 @@ public class GuiInterfaceTerminal extends AEBaseGui { return o; } + + int getReservedSpace() { + return this.reservedSpace; + } + + void setReservedSpace(final int reservedSpace) { + this.reservedSpace = reservedSpace; + } } diff --git a/src/main/java/appeng/container/implementations/ContainerInterfaceTerminal.java b/src/main/java/appeng/container/implementations/ContainerInterfaceTerminal.java index 25dacb995..8948592b9 100644 --- a/src/main/java/appeng/container/implementations/ContainerInterfaceTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerInterfaceTerminal.java @@ -79,7 +79,7 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer { this.grid = anchor.getActionableNode().getGrid(); } - this.bindPlayerInventory(ip, 14, 256 - /* height of player inventory */82); + this.bindPlayerInventory(ip, 0, 0); } @Override From 7b985c72bd64001343f915cae83b7515f1003f5e Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Fri, 3 Feb 2023 22:22:09 -0300 Subject: [PATCH 32/35] fix slots and texture --- .../implementations/GuiInterfaceTerminal.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java b/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java index 531ccae1b..56c2bf108 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java +++ b/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java @@ -191,6 +191,14 @@ public class GuiInterfaceTerminal extends AEBaseGui { this.inventorySlots.inventorySlots.removeIf(slot -> slot instanceof SlotDisconnected); + for (final Slot s : this.inventorySlots.inventorySlots) { + if (s instanceof AppEngSlot) { + if (s.xPos < 197) { + this.repositionSlot((AppEngSlot) s); + } + } + } + int offset = 52; int linesDraw = 0; for (int x = 0; x < rows && linesDraw < rows && currentScroll + x < this.lines.size(); x++) { @@ -341,10 +349,10 @@ public class GuiInterfaceTerminal extends AEBaseGui { for (int row = 0; row < 1 + extraLines && linesDraw < rows; ++row) { if (linesDraw == 6) { - this.drawTexturedModalRect(offsetX, offsetY + offset + 7, 0, 166, 189, 7); - this.drawTexturedModalRect(offsetX, offsetY + offset + 14, 0, 166, 189, 4); + this.drawTexturedModalRect(offsetX, offsetY + offset + 7, 0, 166, 190, 7); + this.drawTexturedModalRect(offsetX, offsetY + offset + 14, 0, 166, 190, 4); } else if (linesDraw >= 7) { - this.drawTexturedModalRect(offsetX, offsetY + offset, 0, 173, 189, 18); + this.drawTexturedModalRect(offsetX, offsetY + offset, 0, 173, 190, 18); } this.drawTexturedModalRect(offsetX + 20, offsetY + offset, 20, 173, width, 18); @@ -352,26 +360,26 @@ public class GuiInterfaceTerminal extends AEBaseGui { linesDraw++; } } else { + if (linesDraw == 6) { + this.drawTexturedModalRect(offsetX, offsetY + offset + 7, 0, 166, 190, 7); + this.drawTexturedModalRect(offsetX, offsetY + offset + 14, 0, 166, 190, 4); + this.drawTexturedModalRect(offsetX, offsetY + offset, 0, 53, 183, 18); + } else if (linesDraw >= 7) { + this.drawTexturedModalRect(offsetX, offsetY + offset, 0, 53, 183, 18); + this.drawTexturedModalRect(offsetX + 183, offsetY + offset, 183, 166, 7, 18); + } offset += 18; linesDraw++; } } offset = 51 + Math.max(6 * 18, linesDraw * 18); if (linesDraw > 6) { - this.drawTexturedModalRect(offsetX, offsetY + offset, 0, 166, 189, 7); + this.drawTexturedModalRect(offsetX, offsetY + offset, 0, 166, 190, 7); } this.drawTexturedModalRect(offsetX, offsetY + offset + 7, 0, 166, this.xSize, 90); this.drawnRows = Math.max(6, linesDraw); - for (final Slot s : this.inventorySlots.inventorySlots) { - if (s instanceof AppEngSlot) { - if (s.xPos < 197) { - this.repositionSlot((AppEngSlot) s); - } - } - } - if (this.searchFieldInputs != null) { this.searchFieldInputs.drawTextBox(); } From dcd36b3b2f7ce623ecddcc48127e7234ca98dada Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Fri, 3 Feb 2023 23:08:13 -0300 Subject: [PATCH 33/35] wip --- .../gui/implementations/GuiInterfaceTerminal.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java b/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java index 56c2bf108..0dd2b4395 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java +++ b/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java @@ -52,11 +52,13 @@ import net.minecraft.util.text.TextComponentString; import net.minecraftforge.common.DimensionManager; import org.lwjgl.input.Mouse; +import java.awt.*; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.WeakHashMap; @@ -173,6 +175,14 @@ public class GuiInterfaceTerminal extends AEBaseGui { super.onGuiClosed(); } + @Override + public List getJEIExclusionArea() { + Rectangle craftingCPUArea = new Rectangle(this.guiLeft - 18, this.guiTop, 18, 18); + List area = new ArrayList<>(); + area.add(craftingCPUArea); + return area; + } + @Override public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { this.buttonList.clear(); @@ -551,7 +561,7 @@ public class GuiInterfaceTerminal extends AEBaseGui { final NBTTagCompound encodedValue = itemStack.getTagCompound(); if (encodedValue == null) { - return false; + return searchTerm.matches(GuiText.InvalidPattern.getLocal()); } NBTTagList tag = new NBTTagList(); From 15dff5d53d89a4b0090ab3af0a3dc38e9c1cc23c Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Sun, 5 Feb 2023 23:04:20 -0300 Subject: [PATCH 34/35] fix JEI integration --- .../gui/implementations/GuiCraftingTerm.java | 4 -- .../GuiWirelessCraftingTerminal.java | 4 -- .../ContainerMEMonitorable.java | 5 ++- .../modules/jei/CraftableCallBack.java | 14 ++++--- .../modules/jei/JEIMissingItem.java | 37 ++++++++++--------- .../modules/jei/RecipeTransferHandler.java | 3 +- 6 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/main/java/appeng/client/gui/implementations/GuiCraftingTerm.java b/src/main/java/appeng/client/gui/implementations/GuiCraftingTerm.java index e2189f45e..4fb6bafc4 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiCraftingTerm.java +++ b/src/main/java/appeng/client/gui/implementations/GuiCraftingTerm.java @@ -82,8 +82,4 @@ public class GuiCraftingTerm extends GuiMEMonitorable { protected String getBackground() { return "guis/crafting.png"; } - - public ItemRepo getRepo() { - return this.repo; - } } diff --git a/src/main/java/appeng/client/gui/implementations/GuiWirelessCraftingTerminal.java b/src/main/java/appeng/client/gui/implementations/GuiWirelessCraftingTerminal.java index fa4b4a821..c3debca98 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiWirelessCraftingTerminal.java +++ b/src/main/java/appeng/client/gui/implementations/GuiWirelessCraftingTerminal.java @@ -90,8 +90,4 @@ public class GuiWirelessCraftingTerminal extends GuiMEMonitorable { protected String getBackground() { return "guis/crafting.png"; } - - public ItemRepo getRepo() { - return this.repo; - } } diff --git a/src/main/java/appeng/container/implementations/ContainerMEMonitorable.java b/src/main/java/appeng/container/implementations/ContainerMEMonitorable.java index 409f0e6f8..c79a4e9aa 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEMonitorable.java +++ b/src/main/java/appeng/container/implementations/ContainerMEMonitorable.java @@ -116,7 +116,7 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa if (monitorable instanceof IPortableCell) { this.setPowerSource((IEnergySource) monitorable); - if ( monitorable instanceof WirelessTerminalGuiObject) { + if (monitorable instanceof WirelessTerminalGuiObject) { this.networkNode = ((WirelessTerminalGuiObject) monitorable).getActionableNode(); } } else if (monitorable instanceof IMEChest) { @@ -381,6 +381,9 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa } public void postUpdate(final List list) { + for (final IAEItemStack is : list) { + this.items.add(is); + } ((GuiMEMonitorable) this.gui).postUpdate(list); } } diff --git a/src/main/java/appeng/integration/modules/jei/CraftableCallBack.java b/src/main/java/appeng/integration/modules/jei/CraftableCallBack.java index e8c52929d..6b1c53c17 100644 --- a/src/main/java/appeng/integration/modules/jei/CraftableCallBack.java +++ b/src/main/java/appeng/integration/modules/jei/CraftableCallBack.java @@ -7,8 +7,10 @@ import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; import appeng.container.AEBaseContainer; import appeng.container.implementations.ContainerCraftingTerm; +import appeng.container.implementations.ContainerMEMonitorable; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketInventoryAction; +import appeng.helpers.IContainerCraftingPacket; import appeng.helpers.InventoryAction; import appeng.util.Platform; import appeng.util.item.AEItemStack; @@ -41,7 +43,7 @@ public class CraftableCallBack implements ITooltipCallback { if (!input) return; if (list != null) { - IItemList available = mergeInventories(list, (ContainerCraftingTerm) container); + IItemList available = mergeInventories(list, (ContainerMEMonitorable) container); IAEItemStack search = AEItemStack.fromItemStack(ingredient); if (ingredient.getItem().isDamageable() || Platform.isGTDamageableItem(ingredient.getItem())) { @@ -100,7 +102,7 @@ public class CraftableCallBack implements ITooltipCallback { } } - IItemList mergeInventories(IItemList repo, ContainerCraftingTerm containerCraftingTerm) { + IItemList mergeInventories(IItemList repo, ContainerMEMonitorable containerCraftingTerm) { IItemList itemList = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); for (IAEItemStack i : repo) { itemList.addStorage(i); @@ -111,9 +113,11 @@ public class CraftableCallBack implements ITooltipCallback { itemList.addStorage(AEItemStack.fromItemStack(invWrapper.getStackInSlot(i))); } - IItemHandler itemHandler = containerCraftingTerm.getInventoryByName("crafting"); - for (int i = 0; i < itemHandler.getSlots(); i++) { - itemList.addStorage(AEItemStack.fromItemStack(itemHandler.getStackInSlot(i))); + if (containerCraftingTerm instanceof IContainerCraftingPacket) { + IItemHandler itemHandler = ((IContainerCraftingPacket) containerCraftingTerm).getInventoryByName("crafting"); + for (int i = 0; i < itemHandler.getSlots(); i++) { + itemList.addStorage(AEItemStack.fromItemStack(itemHandler.getStackInSlot(i))); + } } return itemList; } diff --git a/src/main/java/appeng/integration/modules/jei/JEIMissingItem.java b/src/main/java/appeng/integration/modules/jei/JEIMissingItem.java index f660f8efd..7943ab62e 100644 --- a/src/main/java/appeng/integration/modules/jei/JEIMissingItem.java +++ b/src/main/java/appeng/integration/modules/jei/JEIMissingItem.java @@ -2,11 +2,17 @@ package appeng.integration.modules.jei; import appeng.api.AEApi; import appeng.api.config.FuzzyMode; +import appeng.api.implementations.tiles.ISegmentedInventory; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; import appeng.client.gui.implementations.GuiCraftingTerm; +import appeng.client.gui.implementations.GuiWirelessCraftingTerminal; import appeng.container.implementations.ContainerCraftingTerm; +import appeng.container.implementations.ContainerMEMonitorable; +import appeng.container.implementations.ContainerWirelessCraftingTerminal; +import appeng.helpers.IContainerCraftingPacket; +import appeng.util.IConfigManagerHost; import appeng.util.Platform; import appeng.util.item.AEItemStack; import mezz.jei.api.gui.IGuiIngredient; @@ -39,13 +45,10 @@ public class JEIMissingItem implements IRecipeTransferError { IItemList used = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); JEIMissingItem(Container container, @Nonnull IRecipeLayout recipeLayout) { - if (container instanceof ContainerCraftingTerm) { - ContainerCraftingTerm craftingTerm = (ContainerCraftingTerm) container; - GuiCraftingTerm g = (GuiCraftingTerm) craftingTerm.getGui(); - - IItemList ir = g.getRepo().getList(); - - IItemList available = mergeInventories(ir, (ContainerCraftingTerm) container); + if (container instanceof ContainerMEMonitorable) { + IItemList ir = ((ContainerMEMonitorable) container).items; + + IItemList available = mergeInventories(ir, (ContainerMEMonitorable) container); boolean found; this.errored = false; @@ -109,11 +112,9 @@ public class JEIMissingItem implements IRecipeTransferError { @Override public void showError(Minecraft minecraft, int mouseX, int mouseY, @Nonnull IRecipeLayout recipeLayout, int recipeX, int recipeY) { Container c = minecraft.player.openContainer; - if (c instanceof ContainerCraftingTerm) { - ContainerCraftingTerm craftingTerm = (ContainerCraftingTerm) c; - - GuiCraftingTerm g = (GuiCraftingTerm) craftingTerm.getGui(); - IItemList ir = g.getRepo().getList(); + if (c instanceof ContainerMEMonitorable) { + ContainerMEMonitorable container = (ContainerMEMonitorable) c; + IItemList ir = ((ContainerMEMonitorable) c).items; boolean found; boolean craftable; int currentSlot = 0; @@ -121,7 +122,7 @@ public class JEIMissingItem implements IRecipeTransferError { if (System.currentTimeMillis() - lastUpdate > 1000) { lastUpdate = System.currentTimeMillis(); - available = mergeInventories(ir, (ContainerCraftingTerm) minecraft.player.openContainer); + available = mergeInventories(ir, container); this.foundSlots.clear(); this.craftableSlots.clear(); } else { @@ -219,7 +220,7 @@ public class JEIMissingItem implements IRecipeTransferError { } } - IItemList mergeInventories(IItemList repo, ContainerCraftingTerm containerCraftingTerm) { + IItemList mergeInventories(IItemList repo, ContainerMEMonitorable containerCraftingTerm) { IItemList itemList = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); for (IAEItemStack i : repo) { itemList.addStorage(i); @@ -230,9 +231,11 @@ public class JEIMissingItem implements IRecipeTransferError { itemList.addStorage(AEItemStack.fromItemStack(invWrapper.getStackInSlot(i))); } - IItemHandler itemHandler = containerCraftingTerm.getInventoryByName("crafting"); - for (int i = 0; i < itemHandler.getSlots(); i++) { - itemList.addStorage(AEItemStack.fromItemStack(itemHandler.getStackInSlot(i))); + if (containerCraftingTerm instanceof IContainerCraftingPacket) { + IItemHandler itemHandler = ((IContainerCraftingPacket) containerCraftingTerm).getInventoryByName("crafting"); + for (int i = 0; i < itemHandler.getSlots(); i++) { + itemList.addStorage(AEItemStack.fromItemStack(itemHandler.getStackInSlot(i))); + } } return itemList; } diff --git a/src/main/java/appeng/integration/modules/jei/RecipeTransferHandler.java b/src/main/java/appeng/integration/modules/jei/RecipeTransferHandler.java index 5bfa3ba85..d3c99c025 100644 --- a/src/main/java/appeng/integration/modules/jei/RecipeTransferHandler.java +++ b/src/main/java/appeng/integration/modules/jei/RecipeTransferHandler.java @@ -22,6 +22,7 @@ package appeng.integration.modules.jei; import appeng.container.implementations.ContainerCraftingTerm; import appeng.container.implementations.ContainerPatternEncoder; import appeng.container.implementations.ContainerPatternTerm; +import appeng.container.implementations.ContainerWirelessCraftingTerminal; import appeng.container.slot.SlotCraftingMatrix; import appeng.container.slot.SlotFakeCraftingMatrix; import appeng.core.AELog; @@ -75,7 +76,7 @@ class RecipeTransferHandler implements IRecipeTransferHandl } if (!doTransfer) { - if (container instanceof ContainerCraftingTerm && recipeType.equals(VanillaRecipeCategoryUid.CRAFTING)) { + if (recipeType.equals(VanillaRecipeCategoryUid.CRAFTING) && (container instanceof ContainerCraftingTerm || container instanceof ContainerWirelessCraftingTerminal)) { JEIMissingItem error = new JEIMissingItem(container, recipeLayout); if (error.errored()) return error; From 51522019ca229fe1f32909e7938f147dd5cb767f Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Mon, 6 Feb 2023 13:27:52 -0300 Subject: [PATCH 35/35] fix wireless terminals not opening again --- src/main/java/appeng/core/sync/GuiBridge.java | 2 +- .../core/sync/packets/PacketTerminalUse.java | 7 +++-- src/main/java/appeng/util/Platform.java | 30 +++++++++++-------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/main/java/appeng/core/sync/GuiBridge.java b/src/main/java/appeng/core/sync/GuiBridge.java index 7d3a105c1..1a87a138b 100644 --- a/src/main/java/appeng/core/sync/GuiBridge.java +++ b/src/main/java/appeng/core/sync/GuiBridge.java @@ -363,7 +363,7 @@ public enum GuiBridge implements IGuiHandler { } else if (x >= 0 && x < player.inventory.mainInventory.size()) { it = player.inventory.getStackInSlot(x); } - } else if (y == 1 && z == 0) { + } else if (y == 1 && z == Integer.MIN_VALUE) { if (stem) { if (player.openContainer instanceof IInventorySlotAware) { int slot = ((IInventorySlotAware) player.openContainer).getInventorySlot(); diff --git a/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java b/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java index 62de87ebd..0e813bed1 100644 --- a/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java +++ b/src/main/java/appeng/core/sync/packets/PacketTerminalUse.java @@ -32,16 +32,17 @@ public class PacketTerminalUse extends AppEngPacket { @Override public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player) { NonNullList mainInventory = player.inventory.mainInventory; - for (ItemStack is : mainInventory) { + for (int i = 0; i < mainInventory.size(); i++) { + ItemStack is = mainInventory.get(i); if (terminal.getItemDefinition().isSameAs(is)) { - Platform.openGUI(player, null, AEPartLocation.INTERNAL, terminal.getBridge()); + Platform.openGUI(player, i, terminal.getBridge(), false); return; } } for (int i = 0; i < BaublesApi.getBaublesHandler(player).getSlots(); i++) { ItemStack is = BaublesApi.getBaublesHandler(player).getStackInSlot(i); if (terminal.getItemDefinition().isSameAs(is)) { - Platform.openGUI(player, null, AEPartLocation.INTERNAL, terminal.getBridge()); + Platform.openGUI(player, i, terminal.getBridge(), true); break; } } diff --git a/src/main/java/appeng/util/Platform.java b/src/main/java/appeng/util/Platform.java index d59e0290e..386aaed3f 100644 --- a/src/main/java/appeng/util/Platform.java +++ b/src/main/java/appeng/util/Platform.java @@ -323,28 +323,19 @@ public class Platform { return; } - int x; - int y; - int z; + int x = 0; + int y = 0; + int z = Integer.MIN_VALUE; if (tile != null) { x = tile.getPos().getX(); y = tile.getPos().getY(); z = tile.getPos().getZ(); - } else { - if (p.openContainer instanceof IInventorySlotAware) { - x = ((IInventorySlotAware) p.openContainer).getInventorySlot(); - y = ((IInventorySlotAware) p.openContainer).isBaubleSlot() ? 1 : 0; - } else { - x = p.inventory.currentItem; - y = 0; - } - z = Integer.MIN_VALUE; } if ((type.getType().isItem() && tile == null) || type.hasPermissions(tile, x, y, z, side, p)) { if (tile == null && type.getType() == GuiHostType.ITEM) { - p.openGui(AppEng.instance(), type.ordinal() << 4, p.getEntityWorld(), x, 0, 0); + p.openGui(AppEng.instance(), type.ordinal() << 4, p.getEntityWorld(), x, y, z); } else if (tile == null || type.getType() == GuiHostType.ITEM) { p.openGui(AppEng.instance(), type.ordinal() << 4 | (1 << 3), p.getEntityWorld(), x, y, z); } else { @@ -353,6 +344,19 @@ public class Platform { } } + public static void openGUI(@Nonnull final EntityPlayer p, int slot, @Nonnull final GuiBridge type, boolean isBauble) { + if (isClient()) { + return; + } + + if (type.getType().isItem()) { + if (type.getType() == GuiHostType.ITEM) { + p.openGui(AppEng.instance(), type.ordinal() << 4, p.getEntityWorld(), slot, isBauble ? 1 : 0, Integer.MIN_VALUE); + } + } + } + + /* * returns true if the code is on the client. */