aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHarry <harryyunull@gmail.com>2023-08-28 14:31:11 +0800
committerGitHub <noreply@github.com>2023-08-28 08:31:11 +0200
commitadf838e7ff067f64a6518cd659f55dd566306497 (patch)
tree533e62b199c644ce6baf237506c54f6a16500fe6 /src
parentc18e91469b33a60df690cde8cbace1b7c38bbee2 (diff)
downloadGT5-Unofficial-adf838e7ff067f64a6518cd659f55dd566306497.tar.gz
GT5-Unofficial-adf838e7ff067f64a6518cd659f55dd566306497.tar.bz2
GT5-Unofficial-adf838e7ff067f64a6518cd659f55dd566306497.zip
Crafting input hatches QoLs (#2200)
* Fixes + Detect Inventory Slot Changes * support rename + check for updates * add back onChangeListener + fix npe * ICustomNameObject TileEntity * Fix NPEs * Use IInterfaceTerminalSupport * fix * register * dep * spotless * General Crafting Input Hatch QoL fixes (#2212) * feat: refactor naming && include circuit and catalyst in default name * feat: add 4 more slot to solve my ocd * fix: formatting * feat: migrate from 4x8 to 4x9 * spotlessApply (#2213) Co-authored-by: GitHub GTNH Actions <> * QoLs * 9 manual items * spotless * feat: open master GUI when used, without holding a data-stick (#2221) * fix destpos * optimize empty check * Fix error when fluidInventory.size() == 0 If the fluidInventory size is 0, there is no element to get. Add a check for it. * name in waila + fix int overflow * unnecssary super * update deps --------- Co-authored-by: Fox_white <39846845+foxwhite25@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Firenoo <49818773+firenoo@users.noreply.github.com> Co-authored-by: Martin Robertz <dream-master@gmx.net>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/gregtech/GT_Mod.java3
-rw-r--r--src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java19
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_ME.java223
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_Slave.java67
4 files changed, 273 insertions, 39 deletions
diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java
index 0456350d16..6875769e95 100644
--- a/src/main/java/gregtech/GT_Mod.java
+++ b/src/main/java/gregtech/GT_Mod.java
@@ -33,6 +33,7 @@ import org.apache.logging.log4j.Logger;
import com.google.common.base.Stopwatch;
import appeng.api.AEApi;
+import appeng.helpers.InterfaceTerminalSupportedClassProvider;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
@@ -84,6 +85,7 @@ import gregtech.common.entities.GT_Entity_Arrow_Potion;
import gregtech.common.misc.GT_Command;
import gregtech.common.misc.spaceprojects.commands.SPM_Command;
import gregtech.common.misc.spaceprojects.commands.SP_Command;
+import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_CraftingInput_ME;
import gregtech.common.tileentities.storage.GT_MetaTileEntity_DigitalChestBase;
import gregtech.crossmod.Waila;
import gregtech.loaders.load.GT_CoverBehaviorLoader;
@@ -272,6 +274,7 @@ public class GT_Mod implements IGT_Mod {
EntityRegistry.registerModEntity(GT_Entity_Arrow.class, "GT_Entity_Arrow", 1, GT_Values.GT, 160, 1, true);
EntityRegistry
.registerModEntity(GT_Entity_Arrow_Potion.class, "GT_Entity_Arrow_Potion", 2, GT_Values.GT, 160, 1, true);
+ InterfaceTerminalSupportedClassProvider.register(GT_MetaTileEntity_Hatch_CraftingInput_ME.class);
GT_PreLoad.runMineTweakerCompat();
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
index 882a94599e..1c403dcf7f 100644
--- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
@@ -44,6 +44,7 @@ import appeng.api.networking.IGridNode;
import appeng.api.networking.security.IActionHost;
import appeng.api.util.AECableType;
import appeng.api.util.DimensionalCoord;
+import appeng.helpers.ICustomNameObject;
import appeng.me.helpers.AENetworkProxy;
import appeng.me.helpers.IGridProxyable;
import appeng.tile.TileEvent;
@@ -87,7 +88,7 @@ import mcp.mobius.waila.api.IWailaDataAccessor;
*/
public class BaseMetaTileEntity extends CommonMetaTileEntity
implements IGregTechTileEntity, IActionHost, IGridProxyable, IAlignmentProvider, IConstructableProvider,
- IDebugableTileEntity, IGregtechWailaProvider, ICleanroomReceiver {
+ IDebugableTileEntity, IGregtechWailaProvider, ICleanroomReceiver, ICustomNameObject {
private static final Field ENTITY_ITEM_HEALTH_FIELD = ReflectionHelper
.findField(EntityItem.class, "health", "field_70291_e");
@@ -2446,4 +2447,20 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity
public int[] getTimeStatistics() {
return mTimeStatistics;
}
+
+ @Override
+ public String getCustomName() {
+ return getMetaTileEntity() instanceof ICustomNameObject customNameObject ? customNameObject.getCustomName()
+ : null;
+ }
+
+ @Override
+ public boolean hasCustomName() {
+ return getMetaTileEntity() instanceof ICustomNameObject customNameObject && customNameObject.hasCustomName();
+ }
+
+ @Override
+ public void setCustomName(String name) {
+ if (getMetaTileEntity() instanceof ICustomNameObject customNameObject) customNameObject.setCustomName(name);
+ }
}
diff --git a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_ME.java b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_ME.java
index ab8271e8fe..430067ecf7 100644
--- a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_ME.java
+++ b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_ME.java
@@ -9,6 +9,7 @@ import javax.annotation.Nullable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
@@ -20,6 +21,7 @@ import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection;
+import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.fluids.FluidStack;
import org.apache.commons.lang3.ArrayUtils;
@@ -27,9 +29,10 @@ import org.jetbrains.annotations.NotNull;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.google.common.collect.ImmutableList;
+import com.gtnewhorizons.modularui.api.math.Alignment;
+import com.gtnewhorizons.modularui.api.math.Size;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
-import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot;
import com.gtnewhorizons.modularui.common.widget.ButtonWidget;
import com.gtnewhorizons.modularui.common.widget.SlotGroup;
import com.gtnewhorizons.modularui.common.widget.SlotWidget;
@@ -51,7 +54,12 @@ import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.AECableType;
import appeng.api.util.DimensionalCoord;
+import appeng.core.AppEng;
+import appeng.core.sync.GuiBridge;
+import appeng.helpers.ICustomNameObject;
+import appeng.helpers.IInterfaceTerminalSupport;
import appeng.items.misc.ItemEncodedPattern;
+import appeng.items.tools.quartz.ToolQuartzCuttingKnife;
import appeng.me.GridAccessException;
import appeng.me.helpers.AENetworkProxy;
import appeng.me.helpers.IGridProxyable;
@@ -76,7 +84,7 @@ import mcp.mobius.waila.api.IWailaDataAccessor;
public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_Hatch_InputBus
implements IConfigurationCircuitSupport, IAddGregtechLogo, IAddUIWidgets, IPowerChannelState, ICraftingProvider,
- IGridProxyable, IDualInputHatch {
+ IGridProxyable, IDualInputHatch, ICustomNameObject, IInterfaceTerminalSupport {
// Each pattern slot in the crafting input hatch has its own internal inventory
public static class PatternSlot implements IDualInputInventory {
@@ -148,10 +156,13 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_
private boolean isEmpty() {
// if one item / fluid is empty then it should be safe to assume all other is empty,
// or at least won't require a recipe check, as long as the pattern is sane
- if (!itemInventory.isEmpty()) return itemInventory.get(0) == null || itemInventory.get(0).stackSize <= 0;
-
- if (!fluidInventory.isEmpty()) return fluidInventory.get(0) == null || fluidInventory.get(0).amount <= 0;
+ if (!itemInventory.isEmpty()) {
+ return itemInventory.get(0) == null || itemInventory.get(0).stackSize <= 0;
+ }
+ if (!fluidInventory.isEmpty()) {
+ return fluidInventory.get(0) == null || fluidInventory.get(0).amount <= 0;
+ }
return true;
}
@@ -291,10 +302,15 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_
}
// mInventory is used for storing patterns, circuit and manual slot (typically NC items)
- private static final int MAX_PATTERN_COUNT = 4 * 8;
- private static final int MAX_INV_COUNT = MAX_PATTERN_COUNT + 2;
- private static final int SLOT_MANUAL = MAX_INV_COUNT - 1;
- private static final int SLOT_CIRCUIT = MAX_INV_COUNT - 2;
+ private static final int MAX_PATTERN_COUNT = 4 * 9;
+ private static final int SLOT_MANUAL_SIZE = 9;
+ private static final int MAX_INV_COUNT = MAX_PATTERN_COUNT + SLOT_MANUAL_SIZE + 1;
+ private static final int SLOT_CIRCUIT = MAX_PATTERN_COUNT;
+ private static final int SLOT_MANUAL_START = SLOT_CIRCUIT + 1;
+ private static final int MANUAL_SLOT_WINDOW = 10;
+ private static final PatternsConfiguration[] patternConfigurations = new PatternsConfiguration[] {
+ new PatternsConfiguration(0, 9), new PatternsConfiguration(9, 9), new PatternsConfiguration(18, 9),
+ new PatternsConfiguration(27, 9) };
private BaseActionSource requestSource = null;
private @Nullable AENetworkProxy gridProxy = null;
@@ -308,6 +324,7 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_
private boolean needPatternSync = true;
private boolean justHadNewItems = false;
+ private String customName = null;
private boolean supportFluids;
public GT_MetaTileEntity_Hatch_CraftingInput_ME(int aID, String aName, String aNameRegional,
@@ -399,6 +416,44 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_
}
@Override
+ public PatternsConfiguration[] getPatternsConfigurations() {
+ return patternConfigurations;
+ }
+
+ @Override
+ public IInventory getPatterns(int i) {
+ return this;
+ }
+
+ @Override
+ public String getName() {
+ if (hasCustomName()) {
+ return getCustomName();
+ }
+ StringBuilder name = new StringBuilder();
+ if (getCrafterIcon() != null) {
+ name.append(getCrafterIcon().getDisplayName());
+ } else {
+ name.append(getInventoryName());
+ }
+
+ if (mInventory[SLOT_CIRCUIT] != null) {
+ name.append(" - ");
+ name.append(mInventory[SLOT_CIRCUIT].getItemDamage());
+ }
+ if (mInventory[SLOT_MANUAL_START] != null) {
+ name.append(" - ");
+ name.append(mInventory[SLOT_MANUAL_START].getDisplayName());
+ }
+ return name.toString();
+ }
+
+ @Override
+ public TileEntity getTileEntity() {
+ return (TileEntity) getBaseMetaTileEntity();
+ }
+
+ @Override
public void gridChanged() {
needPatternSync = true;
}
@@ -429,7 +484,7 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_
}
}
aNBT.setTag("internalInventory", internalInventoryNBT);
-
+ if (customName != null) aNBT.setString("customName", customName);
if (GregTech_API.mAE2) {
getProxy().writeToNBT(aNBT);
}
@@ -458,6 +513,20 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_
}
}
+ // Migrate from 4x8 to 4x9 pattern inventory
+ int oldPatternCount = 4 * 8;
+ int oldSlotManual = oldPatternCount + 1;
+ int oldSlotCircuit = oldPatternCount;
+
+ if (internalInventory[oldSlotManual] == null && mInventory[oldSlotManual] != null) {
+ mInventory[SLOT_MANUAL_START] = mInventory[oldSlotManual];
+ mInventory[oldSlotManual] = null;
+ }
+ if (internalInventory[oldSlotCircuit] == null && mInventory[oldSlotCircuit] != null) {
+ mInventory[SLOT_CIRCUIT] = mInventory[oldSlotCircuit];
+ mInventory[oldSlotCircuit] = null;
+ }
+
// reconstruct patternDetailsPatternSlotMap
patternDetailsPatternSlotMap.clear();
for (PatternSlot patternSlot : internalInventory) {
@@ -466,6 +535,8 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_
}
}
+ if (aNBT.hasKey("customName")) customName = aNBT.getString("customName");
+
if (GregTech_API.mAE2) {
getProxy().readFromNBT(aNBT);
}
@@ -545,7 +616,7 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_
@Override
public int getCircuitSlotX() {
- return 152;
+ return 170;
}
@Override
@@ -559,9 +630,15 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_
}
@Override
+ public int getGUIWidth() {
+ return super.getGUIWidth() + 16;
+ }
+
+ @Override
public void addUIWidgets(ModularWindow.@NotNull Builder builder, UIBuildContext buildContext) {
+ buildContext.addSyncedWindow(MANUAL_SLOT_WINDOW, this::createSlotManualWindow);
builder.widget(
- SlotGroup.ofItemHandler(inventoryHandler, 8)
+ SlotGroup.ofItemHandler(inventoryHandler, 9)
.startFromSlot(0)
.endAtSlot(MAX_PATTERN_COUNT - 1)
.phantom(false)
@@ -578,13 +655,20 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_
return output != null ? output : stack;
}
}.setFilter(itemStack -> itemStack.getItem() instanceof ICraftingPatternItem)
- .setChangeListener(() -> onPatternChange(slot)))
+ .setChangeListener(() -> onPatternChange(slot.getSlotIndex(), slot.getStack())))
.build()
.setPos(7, 9))
- .widget(
- new SlotWidget(inventoryHandler, SLOT_MANUAL).setShiftClickPriority(11)
- .setBackground(getGUITextureSet().getItemSlot())
- .setPos(151, 45))
+ .widget(new ButtonWidget().setOnClick((clickData, widget) -> {
+ if (clickData.mouseButton == 0) {
+ widget.getContext()
+ .openSyncedWindow(MANUAL_SLOT_WINDOW);
+ }
+ })
+ .setPlayClickSound(true)
+ .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_PLUS_LARGE)
+ .addTooltips(ImmutableList.of("Place manual items"))
+ .setSize(16, 16)
+ .setPos(170, 45))
.widget(new ButtonWidget().setOnClick((clickData, widget) -> {
if (clickData.mouseButton == 0) {
refundAll();
@@ -594,12 +678,14 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_
.setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_EXPORT)
.addTooltips(ImmutableList.of("Return all internally stored items back to AE"))
.setSize(16, 16)
- .setPos(152, 28));
+ .setPos(170, 28));
}
@Override
public void updateSlots() {
- if (mInventory[SLOT_MANUAL] != null && mInventory[SLOT_MANUAL].stackSize <= 0) mInventory[SLOT_MANUAL] = null;
+ for (int slotId = SLOT_MANUAL_START; slotId < SLOT_MANUAL_START + SLOT_MANUAL_SIZE; ++slotId) {
+ if (mInventory[slotId] != null && mInventory[slotId].stackSize <= 0) mInventory[slotId] = null;
+ }
}
private BaseActionSource getRequest() {
@@ -607,19 +693,19 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_
return requestSource;
}
- private void onPatternChange(BaseSlot slot) {
+ private void onPatternChange(int index, ItemStack newItem) {
if (!getBaseMetaTileEntity().isServerSide()) return;
var world = getBaseMetaTileEntity().getWorld();
// remove old if applicable
- var originalPattern = internalInventory[slot.getSlotIndex()];
+ var originalPattern = internalInventory[index];
if (originalPattern != null) {
- if (originalPattern.hasChanged(slot.getStack(), world)) {
+ if (originalPattern.hasChanged(newItem, world)) {
try {
originalPattern.refund(getProxy(), getRequest());
} catch (GridAccessException ignored) {}
- internalInventory[slot.getSlotIndex()] = null;
+ internalInventory[index] = null;
needPatternSync = true;
} else {
return; // nothing has changed
@@ -627,30 +713,33 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_
}
// original does not exist or has changed
- var pattern = slot.getStack();
- if (pattern == null || !(pattern.getItem() instanceof ICraftingPatternItem)) return;
+ if (newItem == null || !(newItem.getItem() instanceof ICraftingPatternItem)) return;
- var patternSlot = new PatternSlot(pattern, world, this::getSharedItems);
- internalInventory[slot.getSlotIndex()] = patternSlot;
+ var patternSlot = new PatternSlot(newItem, world, this::getSharedItems);
+ internalInventory[index] = patternSlot;
patternDetailsPatternSlotMap.put(patternSlot.getPatternDetails(), patternSlot);
needPatternSync = true;
}
private ItemStack[] getSharedItems() {
- return new ItemStack[] { mInventory[SLOT_CIRCUIT], mInventory[SLOT_MANUAL] };
+ ItemStack[] sharedItems = new ItemStack[SLOT_MANUAL_SIZE + 1];
+ sharedItems[0] = mInventory[SLOT_CIRCUIT];
+ System.arraycopy(mInventory, SLOT_MANUAL_START, sharedItems, 1, SLOT_MANUAL_SIZE);
+ return sharedItems;
}
@Override
public void getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor,
IWailaConfigHandler config) {
NBTTagCompound tag = accessor.getNBTData();
+ currenttip.add(EnumChatFormatting.AQUA + tag.getString("name") + EnumChatFormatting.RESET);
if (tag.hasKey("inventory")) {
var inventory = tag.getTagList("inventory", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < inventory.tagCount(); ++i) {
var item = inventory.getCompoundTagAt(i);
var name = item.getString("name");
- var amount = item.getInteger("amount");
+ var amount = item.getLong("amount");
currenttip.add(
name + ": "
+ EnumChatFormatting.GOLD
@@ -666,20 +755,20 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_
int z) {
NBTTagList inventory = new NBTTagList();
- HashMap<String, Integer> nameToAmount = new HashMap<>();
+ HashMap<String, Long> nameToAmount = new HashMap<>();
for (Iterator<PatternSlot> it = inventories(); it.hasNext();) {
var i = it.next();
for (var item : i.itemInventory) {
if (item != null && item.stackSize > 0) {
var name = item.getDisplayName();
- var amount = nameToAmount.getOrDefault(name, 0);
+ var amount = nameToAmount.getOrDefault(name, 0L);
nameToAmount.put(name, amount + item.stackSize);
}
}
for (var fluid : i.fluidInventory) {
if (fluid != null && fluid.amount > 0) {
var name = fluid.getLocalizedName();
- var amount = nameToAmount.getOrDefault(name, 0);
+ var amount = nameToAmount.getOrDefault(name, 0L);
nameToAmount.put(name, amount + fluid.amount);
}
}
@@ -687,11 +776,12 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_
for (var entry : nameToAmount.entrySet()) {
var item = new NBTTagCompound();
item.setString("name", entry.getKey());
- item.setInteger("amount", entry.getValue());
+ item.setLong("amount", entry.getValue());
inventory.appendTag(item);
}
tag.setTag("inventory", inventory);
+ tag.setString("name", getName());
super.getWailaNBTData(player, tile, tag, world, x, y, z);
}
@@ -787,6 +877,25 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_
}
@Override
+ public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side,
+ float aX, float aY, float aZ) {
+ final ItemStack is = aPlayer.inventory.getCurrentItem();
+ if (is != null && is.getItem() instanceof ToolQuartzCuttingKnife) {
+ if (ForgeEventFactory.onItemUseStart(aPlayer, is, 1) <= 0) return false;
+ var te = getBaseMetaTileEntity();
+ aPlayer.openGui(
+ AppEng.instance(),
+ GuiBridge.GUI_RENAMER.ordinal() << 5 | (side.ordinal()),
+ te.getWorld(),
+ te.getXCoord(),
+ te.getYCoord(),
+ te.getZCoord());
+ return true;
+ }
+ return super.onRightclick(aBaseMetaTileEntity, aPlayer, side, aX, aY, aZ);
+ }
+
+ @Override
public ItemStack getCrafterIcon() {
return getMachineCraftingIcon();
}
@@ -803,4 +912,52 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_
return true;
}
+ protected ModularWindow createSlotManualWindow(final EntityPlayer player) {
+ final int WIDTH = 68;
+ final int HEIGHT = 68;
+ final int PARENT_WIDTH = getGUIWidth();
+ final int PARENT_HEIGHT = getGUIHeight();
+ ModularWindow.Builder builder = ModularWindow.builder(WIDTH, HEIGHT);
+ builder.setBackground(GT_UITextures.BACKGROUND_SINGLEBLOCK_DEFAULT);
+ builder.setGuiTint(getGUIColorization());
+ builder.setDraggable(true);
+ // make sure the manual window is within the parent window
+ // otherwise picking up manual items would toss them
+ // See GuiContainer.java flag1
+ builder.setPos(
+ (size, window) -> Alignment.Center.getAlignedPos(size, new Size(PARENT_WIDTH, PARENT_HEIGHT))
+ .add(Alignment.TopRight.getAlignedPos(new Size(PARENT_WIDTH, PARENT_HEIGHT), new Size(WIDTH, HEIGHT))));
+ builder.widget(
+ SlotGroup.ofItemHandler(inventoryHandler, 3)
+ .startFromSlot(SLOT_MANUAL_START)
+ .endAtSlot(SLOT_MANUAL_START + SLOT_MANUAL_SIZE - 1)
+ .phantom(false)
+ .background(getGUITextureSet().getItemSlot())
+ .build()
+ .setPos(7, 7));
+ return builder.build();
+ }
+
+ @Override
+ public void setInventorySlotContents(int aIndex, ItemStack aStack) {
+ super.setInventorySlotContents(aIndex, aStack);
+ if (aIndex >= MAX_PATTERN_COUNT) return;
+ onPatternChange(aIndex, aStack);
+ needPatternSync = true;
+ }
+
+ @Override
+ public String getCustomName() {
+ return customName;
+ }
+
+ @Override
+ public boolean hasCustomName() {
+ return customName != null;
+ }
+
+ @Override
+ public void setCustomName(String name) {
+ customName = name;
+ }
}
diff --git a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_Slave.java b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_Slave.java
index 14599360e0..16ffeecf65 100644
--- a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_Slave.java
+++ b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_Slave.java
@@ -8,7 +8,10 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import gregtech.api.enums.ItemList;
@@ -17,6 +20,8 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus;
import gregtech.api.render.TextureFactory;
+import mcp.mobius.waila.api.IWailaConfigHandler;
+import mcp.mobius.waila.api.IWailaDataAccessor;
public class GT_MetaTileEntity_Hatch_CraftingInput_Slave extends GT_MetaTileEntity_Hatch_InputBus
implements IDualInputHatch {
@@ -158,13 +163,16 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_Slave extends GT_MetaTileEnti
return master;
}
- @Override
- public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
- if (!(aPlayer instanceof EntityPlayerMP)) return false;
+ private boolean tryLinkDataStick(EntityPlayer aPlayer) {
ItemStack dataStick = aPlayer.inventory.getCurrentItem();
- if (!ItemList.Tool_DataStick.isStackEqual(dataStick, true, true)) return false;
- if (!dataStick.hasTagCompound() || !"CraftingInputBuffer".equals(dataStick.stackTagCompound.getString("type")))
+
+ if (!ItemList.Tool_DataStick.isStackEqual(dataStick, true, true)) {
+ return false;
+ }
+ if (!dataStick.hasTagCompound() || !dataStick.stackTagCompound.getString("type")
+ .equals("CraftingInputBuffer")) {
return false;
+ }
NBTTagCompound nbt = dataStick.stackTagCompound;
int x = nbt.getInteger("x");
@@ -175,6 +183,55 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_Slave extends GT_MetaTileEnti
return true;
}
aPlayer.addChatMessage(new ChatComponentText("Link failed"));
+ return true;
+ }
+
+ @Override
+ public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
+ if (!(aPlayer instanceof EntityPlayerMP)) {
+ return false;
+ }
+ if (tryLinkDataStick(aPlayer)) {
+ return true;
+ }
+ var master = getMaster();
+ if (master != null) {
+ return master.onRightclick(master.getBaseMetaTileEntity(), aPlayer);
+ }
return false;
}
+
+ @Override
+ public void getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor,
+ IWailaConfigHandler config) {
+ NBTTagCompound tag = accessor.getNBTData();
+ currenttip.add((tag.getBoolean("linked") ? "Linked" : "Not linked"));
+
+ if (tag.hasKey("masterX")) {
+ currenttip.add(
+ "Bound to " + tag
+ .getInteger("masterX") + ", " + tag.getInteger("masterY") + ", " + tag.getInteger("masterZ"));
+ }
+
+ if (tag.hasKey("masterName")) {
+ currenttip.add(EnumChatFormatting.GOLD + tag.getString("masterName") + EnumChatFormatting.RESET);
+ }
+
+ super.getWailaBody(itemStack, currenttip, accessor, config);
+ }
+
+ @Override
+ public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y,
+ int z) {
+
+ tag.setBoolean("linked", getMaster() != null);
+ if (masterSet) {
+ tag.setInteger("masterX", masterX);
+ tag.setInteger("masterY", masterY);
+ tag.setInteger("masterZ", masterZ);
+ }
+ if (getMaster() != null) tag.setString("masterName", getMaster().getName());
+
+ super.getWailaNBTData(player, tile, tag, world, x, y, z);
+ }
}