Toggle magnet on/off from container/gui

This commit is contained in:
PrototypeTrousers
2023-02-02 21:45:31 -03:00
parent fb2aa21337
commit 9d7dacdc29
6 changed files with 93 additions and 13 deletions
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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<String> textList = new ArrayList<>();
@@ -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);
}