Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
import java.util.List;
import java.util.Map;


import appeng.container.slot.SlotRestrictedInput;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.items.contents.NetworkToolViewer;
import appeng.items.tools.ToolNetworkTool;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.entity.player.EntityPlayerMP;
Expand Down Expand Up @@ -90,8 +96,76 @@ public abstract class ContainerCellTerminalBase extends AEBaseContainer {
protected long currentNetworkId = 0;
protected IGrid currentNetworkGrid = null; // Cached grid for current network (main or subnet)

// AE2's code mostly refers to the network tool as the "toolbox" so we use that name
// to distinguish it from our network tools
private int toolboxSlot;
private NetworkToolViewer toolboxInventory;

public ContainerCellTerminalBase(InventoryPlayer ip, IPart part) {
super(ip, null, part);

this.setupToolbox();
}

public ContainerCellTerminalBase(
InventoryPlayer ip,
WirelessTerminalGuiObject guiObject
) {

super(ip, guiObject);

if (Platform.isServer()) {
IGridNode node = guiObject.getActionableNode();
if (node != null && node.isActive()) {
this.grid = node.getGrid();
}
}

this.setupToolbox();
}

public void setupToolbox() {

final IInventory pi = this.getPlayerInv();
ItemStack toolbox = null;
for (int x = 0; x < pi.getSizeInventory(); x++) {
final ItemStack pii = pi.getStackInSlot(x);
if (!pii.isEmpty() && pii.getItem() instanceof ToolNetworkTool) {
this.lockPlayerInventorySlot(x);
this.toolboxSlot = x;
toolbox = pii;
break;
}
}

if (toolbox != null) {
IGridNode node = this.getActionHost().getActionableNode();
this.toolboxInventory = new NetworkToolViewer(
toolbox,
node != null ? node.getMachine() : null
);


for (int v = 0; v < 3; v++) {
for (int u = 0; u < 3; u++) {
this.addSlotToContainer(
new SlotRestrictedInput(
SlotRestrictedInput.PlacableItemType.UPGRADES,
this.toolboxInventory.getInternalInventory(),
u + v * 3,
8 + 9 * 18 + 14 + 18 + 1 + u * 18,
v * 18,
this.getInventoryPlayer()
).setPlayerSide()
);
}
}
}
}

public boolean hasToolbox() {

return this.toolboxInventory != null;
}

@Override
Expand Down Expand Up @@ -124,6 +198,32 @@ public void detectAndSendChanges() {

this.pendingData = new NBTTagCompound();
}

this.checkToolbox();
}

public void checkToolbox() {

if (hasToolbox()) {
final ItemStack currentItem = this.getPlayerInv().getStackInSlot(this.toolboxSlot);

if (currentItem != this.toolboxInventory.getItemStack()) {
if (!currentItem.isEmpty()) {
if (ItemStack.areItemsEqual(this.toolboxInventory.getItemStack(), currentItem)) {
this
.getPlayerInv()
.setInventorySlotContents(
this.toolboxSlot,
this.toolboxInventory.getItemStack()
);
} else {
this.setValidContainer(false);
}
} else {
this.setValidContainer(false);
}
}
}
}

/**
Expand Down
145 changes: 0 additions & 145 deletions src/main/java/com/cellterminal/container/ContainerWUTCellTerminal.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,70 +1,46 @@
package com.cellterminal.container;

import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import com.cellterminal.integration.AE2WUTIntegration;
import com.cellterminal.items.ItemWirelessCellTerminal;
import com.cellterminal.util.AE2OldVersionSupport;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.Optional;

import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.features.ILocatable;
import appeng.api.features.IWirelessTermHandler;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.IActionHost;
import appeng.core.AEConfig;
import appeng.core.localization.PlayerMessages;
import appeng.util.Platform;
import appeng.helpers.WirelessTerminalGuiObject;

import baubles.api.BaublesApi;

import com.cellterminal.items.ItemWirelessCellTerminal;


/**
* Container for the Wireless Cell Terminal GUI.
* Similar to ContainerCellTerminal but works with wireless connection.
*/
@Optional.Interface(iface = "appeng.helpers.WirelessTerminalGuiObject", modid = "ae2wut")
public class ContainerWirelessCellTerminal extends ContainerCellTerminalBase {

private final WirelessTerminalGuiObject wirelessTerminalGuiObject;
private final int slot;
private final boolean isBauble;
private final ItemStack terminalStack;

private int ticks = 0;

public ContainerWirelessCellTerminal(InventoryPlayer ip, int slot, boolean isBauble) {
super(ip, null);
this.slot = slot;
this.isBauble = isBauble;

if (isBauble) {
this.terminalStack = getBaubleStack(ip.player, slot);
} else {
this.terminalStack = ip.getStackInSlot(slot);
this.lockPlayerInventorySlot(slot);
}

if (Platform.isServer() && !terminalStack.isEmpty()) {
IWirelessTermHandler handler = AEApi.instance().registries().wireless().getWirelessTerminalHandler(terminalStack);

if (handler != null) {
String encKey = handler.getEncryptionKey(terminalStack);
public ContainerWirelessCellTerminal(InventoryPlayer ip, WirelessTerminalGuiObject wth) {
super(ip, wth);

try {
long parsedKey = Long.parseLong(encKey);
ILocatable obj = AEApi.instance().registries().locatable().getLocatableBy(parsedKey);
this.wirelessTerminalGuiObject = wth;
this.slot = wth.getInventorySlot();
this.isBauble = AE2OldVersionSupport.wirelessTerminalGuiObjectIsBauble(wth, ip);

if (obj instanceof IActionHost) {
IGridNode n = ((IActionHost) obj).getActionableNode();
if (n != null) {
this.grid = n.getGrid();
}
}
} catch (NumberFormatException e) {
// Invalid key
}
}
}
// Lock the slot if it's in the main inventory
if (!isBauble && slot >= 0 && slot < ip.mainInventory.size()) this.lockPlayerInventorySlot(slot);

this.bindPlayerInventory(ip, 0, 0);
}
Expand All @@ -73,14 +49,27 @@ public ContainerWirelessCellTerminal(InventoryPlayer ip, int slot, boolean isBau
private ItemStack getBaubleStack(EntityPlayer player, int baubleSlot) {
return BaublesApi.getBaublesHandler(player).getStackInSlot(baubleSlot);
}
/**
* Get the WirelessTerminalGuiObject for this container.
* Used by the GUI to access WUT functionality.
*/
public WirelessTerminalGuiObject getWirelessTerminalGuiObject() {
return this.wirelessTerminalGuiObject;
}

private ItemStack getTerminalStack() {
if (isBauble) return getBaubleStack(getPlayerInv().player, slot);

return getPlayerInv().getStackInSlot(slot);
}



@Override
protected boolean canSendUpdates() {
// Check terminal is still valid
ItemStack currentStack = isBauble ? getBaubleStack(getPlayerInv().player, slot)
: getPlayerInv().getStackInSlot(slot);
ItemStack currentStack = getTerminalStack();

if (currentStack.isEmpty() || !(currentStack.getItem() instanceof ItemWirelessCellTerminal)) {
if (currentStack.isEmpty() || !(currentStack.getItem() instanceof ItemWirelessCellTerminal || AE2WUTIntegration.isWirelessUniversalTerminal(currentStack))) {
this.setValidContainer(false);

return false;
Expand Down
Loading