add upgrade slots

This commit is contained in:
PrototypeTrousers
2023-01-30 14:58:55 -03:00
parent 7c4e5679a3
commit 13c3067068
13 changed files with 198 additions and 97 deletions
@@ -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());
}
}
}
}
@@ -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<IAEItemStack> 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));
}
}
}
@@ -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();
@@ -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());
}
}
}
}
@@ -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;
}