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; + } }