mirror of
https://github.com/GTNewHorizons/WirelessCraftingTerminal.git
synced 2026-11-20 12:10:02 +00:00
Fix terminal gui open
This commit is contained in:
7 files changed
+84
-22
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package net.p455w0rd.wirelesscraftingterminal.common;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTermHandler;
|
||||
@@ -16,6 +17,7 @@ import appeng.api.AEApi;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.ContainerOpenContext;
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import it.unimi.dsi.fastutil.ints.IntObjectPair;
|
||||
|
||||
public class WCTGuiHandler implements IGuiHandler {
|
||||
|
||||
@@ -33,14 +35,8 @@ public class WCTGuiHandler implements IGuiHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
final WTCGuiObject term = new WTCGuiObject(
|
||||
wh,
|
||||
RandomUtils.getWirelessTerm(player.inventory),
|
||||
player,
|
||||
world,
|
||||
x,
|
||||
y,
|
||||
z);
|
||||
final IntObjectPair<ItemStack> termItem = RandomUtils.getWirelessTermWithSlot(player.inventory);
|
||||
final WTCGuiObject term = new WTCGuiObject(wh, termItem.second(), player, world, x, y, z, termItem.firstInt());
|
||||
|
||||
return switch (guiId) {
|
||||
case Reference.GUI_WCT -> updateGui(
|
||||
@@ -60,14 +56,16 @@ public class WCTGuiHandler implements IGuiHandler {
|
||||
final IWirelessCraftingTermHandler wh = (IWirelessCraftingTermHandler) AEApi.instance().registries().wireless()
|
||||
.getWirelessTerminalHandler(RandomUtils.getWirelessTerm(player.inventory));
|
||||
if (wh != null && guiId == Reference.GUI_WCT) {
|
||||
final IntObjectPair<ItemStack> termItem = RandomUtils.getWirelessTermWithSlot(player.inventory);
|
||||
final WTCGuiObject obj = new WTCGuiObject(
|
||||
wh,
|
||||
RandomUtils.getWirelessTerm(player.inventory),
|
||||
termItem.second(),
|
||||
player,
|
||||
world,
|
||||
x,
|
||||
y,
|
||||
z);
|
||||
z,
|
||||
termItem.firstInt());
|
||||
return new GuiWirelessCraftingTerminal(player.inventory, obj);
|
||||
}
|
||||
if (guiId == Reference.GUI_MAGNET) {
|
||||
|
||||
+2
-2
@@ -292,12 +292,12 @@ public class ContainerWirelessCraftingTerminal extends ContainerMEMonitorable
|
||||
}
|
||||
|
||||
public static WTCGuiObject getGuiObject(final ItemStack it, final EntityPlayer player, final World w, final int x,
|
||||
final int y, final int z) {
|
||||
final int y, final int z, final int slotIndex) {
|
||||
if (it != null) {
|
||||
final IWirelessCraftingTermHandler wh = (IWirelessCraftingTermHandler) AEApi.instance().registries()
|
||||
.wireless().getWirelessTerminalHandler(it);
|
||||
if (wh != null) {
|
||||
return new WTCGuiObject(wh, it, player, w, x, y, z);
|
||||
return new WTCGuiObject(wh, it, player, w, x, y, z, slotIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ import baubles.api.BaublesApi;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import it.unimi.dsi.fastutil.ints.IntObjectImmutablePair;
|
||||
import it.unimi.dsi.fastutil.ints.IntObjectPair;
|
||||
|
||||
public class RandomUtils {
|
||||
|
||||
@@ -86,6 +88,48 @@ public class RandomUtils {
|
||||
return wirelessTerm;
|
||||
}
|
||||
|
||||
public static IntObjectPair<ItemStack> getWirelessTermWithSlot(InventoryPlayer playerInv) {
|
||||
if (playerInv.player.getHeldItem() != null
|
||||
&& playerInv.player.getHeldItem().getItem() instanceof IWirelessCraftingTerminalItem) {
|
||||
return new IntObjectImmutablePair<>(playerInv.player.inventory.currentItem, playerInv.player.getHeldItem());
|
||||
}
|
||||
IntObjectPair<ItemStack> wirelessTerm = null;
|
||||
|
||||
int invSize = playerInv.getSizeInventory();
|
||||
if (invSize <= 0) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < invSize; ++i) {
|
||||
ItemStack item = playerInv.getStackInSlot(i);
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
if (item.getItem() instanceof IWirelessCraftingTerminalItem) {
|
||||
wirelessTerm = new IntObjectImmutablePair<>(i, item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isBaublesLoaded) {
|
||||
IInventory handler = BaublesApi.getBaubles(playerInv.player);
|
||||
if (handler != null) {
|
||||
invSize = handler.getSizeInventory();
|
||||
for (int i = 0; i < invSize; ++i) {
|
||||
ItemStack item = handler.getStackInSlot(i);
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
if (item.getItem() instanceof IWirelessCraftingTerminalItem) {
|
||||
wirelessTerm = new IntObjectImmutablePair<>(i + playerInv.getSizeInventory(), item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return wirelessTerm;
|
||||
}
|
||||
|
||||
public static ItemStack getMagnet(InventoryPlayer playerInv) {
|
||||
// Is player holding a Magnet Card?
|
||||
if (playerInv.player.getHeldItem() != null && playerInv.player.getHeldItem().getItem() instanceof ItemMagnet) {
|
||||
|
||||
+5
-2
@@ -43,6 +43,7 @@ import appeng.util.item.AEItemStack;
|
||||
import appeng.util.prioitylist.IPartitionList;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import it.unimi.dsi.fastutil.ints.IntObjectPair;
|
||||
|
||||
public class PacketNEIRecipe extends WCTPacket {
|
||||
|
||||
@@ -93,13 +94,15 @@ public class PacketNEIRecipe extends WCTPacket {
|
||||
IGridNode node = cct.getNetworkNode();
|
||||
|
||||
if (node == null) {
|
||||
IntObjectPair<ItemStack> termItem = RandomUtils.getWirelessTermWithSlot(player.inventory);
|
||||
WTCGuiObject obj = ContainerWirelessCraftingTerminal.getGuiObject(
|
||||
RandomUtils.getWirelessTerm(player.inventory),
|
||||
termItem.second(),
|
||||
player,
|
||||
player.worldObj,
|
||||
(int) player.posX,
|
||||
(int) player.posY,
|
||||
(int) player.posZ);
|
||||
(int) player.posZ,
|
||||
termItem.firstInt());
|
||||
node = obj.getActionableNode(true);
|
||||
}
|
||||
if (node != null) {
|
||||
|
||||
@@ -11,8 +11,12 @@ import appeng.items.contents.WirelessCraftingTerminalGuiObject;
|
||||
|
||||
public class WTCGuiObject extends WirelessCraftingTerminalGuiObject implements WCTIActionHost {
|
||||
|
||||
public WTCGuiObject(IWirelessTermHandler wh, ItemStack is, EntityPlayer ep, World w, int x, int y, int z) {
|
||||
private final int slotIndex;
|
||||
|
||||
public WTCGuiObject(IWirelessTermHandler wh, ItemStack is, EntityPlayer ep, World w, int x, int y, int z,
|
||||
final int slotIndex) {
|
||||
super(wh, is, ep, w, x, y, z);
|
||||
this.slotIndex = slotIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -24,4 +28,9 @@ public class WTCGuiObject extends WirelessCraftingTerminalGuiObject implements W
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventorySlot() {
|
||||
return this.slotIndex;
|
||||
}
|
||||
}
|
||||
+10
-5
@@ -14,7 +14,7 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTerminalItem;
|
||||
import net.p455w0rd.wirelesscraftingterminal.api.WCTApi;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils;
|
||||
import net.p455w0rd.wirelesscraftingterminal.handlers.LocaleHandler;
|
||||
import net.p455w0rd.wirelesscraftingterminal.integration.EnderIO;
|
||||
@@ -40,7 +40,6 @@ import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.Platform;
|
||||
import baubles.api.BaubleType;
|
||||
import baubles.api.expanded.IBaubleExpanded;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -167,10 +166,16 @@ public class ItemWirelessCraftingTerminal extends AERootPoweredItem
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(final ItemStack itemStack, final World world, final EntityPlayer player) {
|
||||
if (FMLCommonHandler.instance().getSide() == Side.CLIENT) {
|
||||
// Open the gui
|
||||
WCTApi.instance().interact().openWirelessCraftingTerminalGui(player);
|
||||
if (!world.isRemote) {
|
||||
WCTGuiHandler.launchGui(
|
||||
Reference.GUI_WCT,
|
||||
player,
|
||||
player.worldObj,
|
||||
(int) player.posX,
|
||||
(int) player.posY,
|
||||
(int) player.posZ);
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import it.unimi.dsi.fastutil.ints.IntObjectPair;
|
||||
|
||||
public class CommonProxy {
|
||||
|
||||
@@ -204,7 +205,8 @@ public class CommonProxy {
|
||||
}
|
||||
}
|
||||
if (RandomUtils.getWirelessTerm(playerInv) != null) {
|
||||
ItemStack WCTStack = RandomUtils.getWirelessTerm(playerInv);
|
||||
IntObjectPair<ItemStack> termItemPair = RandomUtils.getWirelessTermWithSlot(playerInv);
|
||||
ItemStack WCTStack = termItemPair.second();
|
||||
if (RandomUtils.isMagnetInstalled(playerInv)) {
|
||||
ItemStack magnetStack = RandomUtils.getMagnet(playerInv);
|
||||
if (magnetStack.getItem() instanceof ItemMagnet) {
|
||||
@@ -216,7 +218,8 @@ public class CommonProxy {
|
||||
world,
|
||||
(int) player.posX,
|
||||
(int) player.posY,
|
||||
(int) player.posZ);
|
||||
(int) player.posZ,
|
||||
termItemPair.firstInt());
|
||||
magnet.civ = magnet.obj;
|
||||
magnet.powerSrc = magnet.civ;
|
||||
magnet.monitor = magnet.civ.getItemInventory();
|
||||
|
||||
Reference in new issue
Block a user