Use blank patterns directly from the network (#1200)

Co-authored-by: lc-1337 <62835225+lc-1337@users.noreply.github.com>
This commit is contained in:
Kogepan229andlc-1337 authored and GitHub committed 2026-04-18 17:11:53 +02:00
1 parent 5b7c10648b
commit e4d79f500d
7 files changed
+212 -55

No files matched your search

@@ -145,8 +145,8 @@ public class GuiMEMonitorable extends AEBaseGui
private final Map<TypeToggleButton, IAEStackType<?>> typeToggleButtons = new IdentityHashMap<>();
private boolean canBeAutoFocused = false;
private boolean isAutoFocused = false;
private int currentMouseX = 0;
private int currentMouseY = 0;
protected int currentMouseX = 0;
protected int currentMouseY = 0;
private PinsRows craftingPinsRows;
private PinsRows playerPinsRows;
public final boolean hasPinHost;
@@ -18,11 +18,18 @@ import java.util.List;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import com.gtnewhorizon.gtnhlib.util.numberformatting.NumberFormatUtil;
import com.gtnewhorizon.gtnhlib.util.numberformatting.options.FormatOptions;
import appeng.api.AEApi;
import appeng.api.config.ActionItems;
import appeng.api.config.ItemSubstitution;
import appeng.api.config.PatternBeSubstitution;
@@ -39,6 +46,7 @@ import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.container.implementations.ContainerPatternTerm;
import appeng.container.slot.AppEngSlot;
import appeng.container.slot.SlotRestrictedInput;
import appeng.core.AELog;
import appeng.core.localization.ButtonToolTips;
import appeng.core.localization.GuiColors;
@@ -57,6 +65,8 @@ public class GuiPatternTerm extends GuiMEMonitorable {
private static final String CRAFTMODE_CRFTING = "1";
private static final String CRAFTMODE_PROCESSING = "0";
private static final FormatOptions FORMAT_OPTIONS = new FormatOptions().disableExponentialFormatting();
private final ContainerPatternTerm container;
private GuiTabButton tabCraftButton;
@@ -72,6 +82,8 @@ public class GuiPatternTerm extends GuiMEMonitorable {
protected VirtualMEPatternSlot[] craftingSlots;
protected VirtualMEPatternSlot[] outputSlots;
private boolean craftingMode;
@NotNull
private IAEItemStack blankPatternView = ContainerPatternTerm.BLANK_PATTERN.copy().setStackSize(0);
public GuiPatternTerm(final InventoryPlayer inventoryPlayer, final ITerminalHost te,
final ContainerPatternTerm containerPatternTerm) {
@@ -376,9 +388,59 @@ public class GuiPatternTerm extends GuiMEMonitorable {
}
}
Slot s = getSlot(mouseX, mouseY);
if (s instanceof SlotRestrictedInput slot
&& slot.getItemType() == SlotRestrictedInput.PlacableItemType.BLANK_PATTERN
&& !slot.getHasStack()) {
lines.add(GuiText.BlankPatternInNetwork.getLocal());
lines.add(
EnumChatFormatting.GRAY + String.format(
ButtonToolTips.ItemsStored.getLocal(),
NumberFormatUtil.formatNumber(this.blankPatternView.getStackSize(), FORMAT_OPTIONS)));
}
return lines;
}
@Override
public void postUpdate(List<IAEStack<?>> list) {
super.postUpdate(list);
for (IAEStack<?> stack : list) {
if (stack instanceof IAEItemStack ais
&& AEApi.instance().definitions().materials().blankPattern().isSameAs(ais.getItemStack())) {
this.blankPatternView = ais;
}
}
}
@Override
public void func_146977_a(Slot s) {
if (s instanceof SlotRestrictedInput slot
&& slot.getItemType() == SlotRestrictedInput.PlacableItemType.BLANK_PATTERN
&& !slot.getHasStack()) {
this.blankPatternView.drawInGui(this.mc, slot.xDisplayPosition, slot.yDisplayPosition);
this.blankPatternView
.drawOverlayInGui(this.mc, slot.xDisplayPosition, slot.yDisplayPosition, true, true, true, true);
} else {
super.func_146977_a(s);
}
}
@Override
public ItemStack getHoveredStack() {
Slot s = getSlot(this.currentMouseX, this.currentMouseY);
if (s instanceof SlotRestrictedInput slot
&& slot.getItemType() == SlotRestrictedInput.PlacableItemType.BLANK_PATTERN
&& !slot.getHasStack()) {
if (this.blankPatternView.getStackSize() > 0) {
return this.blankPatternView.getItemStackForNEI();
} else {
return this.blankPatternView.getItemStackForNEI(1);
}
}
return super.getHoveredStack();
}
/**
* Used in addon
*/
@@ -684,14 +684,7 @@ public class ContainerMEMonitorable extends AEBaseContainer
if (slotItem == null) return;
IAEItemStack ais = slotItem.copy();
ais.setStackSize(ais.getItemStack().getMaxStackSize());
ais = Platform.poweredExtraction(this.getPowerSource(), itemMonitor, ais, this.getActionSource());
if (ais != null) {
player.inventory.setItemStack(ais.getItemStack());
} else {
player.inventory.setItemStack(null);
}
this.updateHeld(player);
this.pickupStoredItems(ais, player, itemMonitor);
} else {
IAEItemStack ais = AEApi.instance().storage().createItemStack(hand);
ais = Platform.poweredInsert(this.getPowerSource(), itemMonitor, ais, this.getActionSource());
@@ -713,23 +706,7 @@ public class ContainerMEMonitorable extends AEBaseContainer
if (slotItem == null) return;
IAEItemStack ais = slotItem.copy();
final long maxSize = ais.getItemStack().getMaxStackSize();
ais.setStackSize(maxSize);
ais = itemMonitor.extractItems(ais, Actionable.SIMULATE, this.getActionSource());
if (ais != null) {
final long stackSize = Math.min(maxSize, ais.getStackSize());
ais.setStackSize((stackSize + 1) >> 1);
ais = Platform
.poweredExtraction(this.getPowerSource(), itemMonitor, ais, this.getActionSource());
}
if (ais != null) {
player.inventory.setItemStack(ais.getItemStack());
} else {
player.inventory.setItemStack(null);
}
this.updateHeld(player);
this.splitStoredItems(ais, player, itemMonitor);
} else {
IAEItemStack ais = AEApi.instance().storage().createItemStack(player.inventory.getItemStack());
ais.setStackSize(1);
@@ -1044,6 +1021,36 @@ public class ContainerMEMonitorable extends AEBaseContainer
}
}
protected void pickupStoredItems(IAEItemStack ais, EntityPlayerMP player, IMEMonitor<IAEItemStack> itemMonitor) {
ais.setStackSize(ais.getItemStack().getMaxStackSize());
ais = Platform.poweredExtraction(this.getPowerSource(), itemMonitor, ais, this.getActionSource());
if (ais != null) {
player.inventory.setItemStack(ais.getItemStack());
} else {
player.inventory.setItemStack(null);
}
this.updateHeld(player);
}
protected void splitStoredItems(IAEItemStack ais, EntityPlayerMP player, IMEMonitor<IAEItemStack> itemMonitor) {
final long maxSize = ais.getItemStack().getMaxStackSize();
ais.setStackSize(maxSize);
ais = itemMonitor.extractItems(ais, Actionable.SIMULATE, this.getActionSource());
if (ais != null) {
final long stackSize = Math.min(maxSize, ais.getStackSize());
ais.setStackSize((stackSize + 1) >> 1);
ais = Platform.poweredExtraction(this.getPowerSource(), itemMonitor, ais, this.getActionSource());
}
if (ais != null) {
player.inventory.setItemStack(ais.getItemStack());
} else {
player.inventory.setItemStack(null);
}
this.updateHeld(player);
}
@Nullable
private IAEStackType<?> getStackTypeForContainer(final ItemStack itemStack) {
if (itemStack == null) return null;
@@ -1115,7 +1122,7 @@ public class ContainerMEMonitorable extends AEBaseContainer
return null;
}
private ItemStack shiftStoreItem(final ItemStack input) {
protected ItemStack shiftStoreItem(final ItemStack input) {
IMEMonitor<IAEItemStack> itemMonitor = this.getMonitorWithFilter(ITEM_STACK_TYPE);
if (this.getPowerSource() == null || itemMonitor == null) {
return input;
@@ -11,6 +11,7 @@
package appeng.container.implementations;
import static appeng.parts.reporting.PartPatternTerminal.*;
import static appeng.util.IterationCounter.fetchNewId;
import static appeng.util.Platform.isServer;
import java.util.ArrayList;
@@ -29,8 +30,11 @@ import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import org.jetbrains.annotations.NotNull;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.networking.security.MachineSource;
@@ -42,12 +46,16 @@ import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.container.ContainerNull;
import appeng.container.ContainerOpenContext;
import appeng.container.PrimaryGui;
import appeng.container.guisync.GuiSync;
import appeng.container.interfaces.IVirtualSlotHolder;
import appeng.container.interfaces.IVirtualSlotSource;
import appeng.container.slot.AppEngSlot;
import appeng.container.slot.IOptionalSlotHost;
import appeng.container.slot.SlotPatternTerm;
import appeng.container.slot.SlotRestrictedInput;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.packets.PacketPatternSlot;
import appeng.helpers.IContainerCraftingPacket;
import appeng.items.contents.WirelessPatternTerminalGuiObject;
@@ -67,6 +75,10 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost,
IContainerCraftingPacket, IVirtualSlotHolder, IVirtualSlotSource {
@NotNull
public static final IAEItemStack BLANK_PATTERN = AEItemStack
.create(AEApi.instance().definitions().materials().blankPattern().maybeStack(1).get());
public static final int MULTIPLE_OF_BUTTON_CLICK = 2;
public static final int MULTIPLE_OF_BUTTON_CLICK_ON_SHIFT = 8;
protected final IPatternTerminal patternTerminal;
@@ -161,7 +173,6 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
this.patternSlotOUT.setStackLimit(1);
this.updateOrderOfOutputSlots();
refillBlankPatterns(patternSlotIN);
// need because InventoryBogoSorter looking for specific slot number for bind buttons
// bindPlayerInventory in MEMonitorable break it
@@ -244,7 +255,6 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
getPlayerInv().player.entityDropItem(output, 0);
}
this.patternSlotOUT.putStack(null);
refillBlankPatterns(patternSlotIN);
}
}
@@ -274,17 +284,22 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
} // if nothing is there we should snag a new pattern.
else {
ItemStack blank = this.patternSlotIN.getStack();
if (!this.isBlankPattern(blank)) {
if (this.isBlankPattern(blank)) {
blank.stackSize--;
if (blank.stackSize == 0) {
this.patternSlotIN.putStack(null);
}
} else if (blank == null) {
IMEMonitor<IAEItemStack> itemMonitor = this.getItemMonitor();
IAEItemStack extracted = Platform
.poweredExtraction(this.getPowerSource(), itemMonitor, BLANK_PATTERN, this.getActionSource());
if (extracted == null || extracted.getStackSize() <= 0) {
return;
}
} else {
return;
}
// remove one, and clear the input slot.
blank.stackSize--;
if (blank.stackSize == 0) {
this.patternSlotIN.putStack(null);
}
refillBlankPatterns(patternSlotIN);
}
// add a new encoded pattern.
@@ -555,24 +570,95 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
this.updateVirtualSlots(StorageName.CRAFTING_OUTPUT, this.outputs, outputSlotsClient);
}
protected void refillBlankPatterns(Slot slot) {
if (Platform.isServer()) {
ItemStack blanks = slot.getStack();
int blanksToRefill = 64;
if (blanks != null) blanksToRefill -= blanks.stackSize;
if (blanksToRefill <= 0) return;
final AEItemStack request = AEItemStack
.create(AEApi.instance().definitions().materials().blankPattern().maybeStack(blanksToRefill).get());
final IAEItemStack extracted = Platform
.poweredExtraction(this.getPowerSource(), this.getItemMonitor(), request, this.getActionSource());
if (extracted != null) {
if (blanks != null) blanks.stackSize += (int) extracted.getStackSize();
else {
blanks = extracted.getItemStack();
@Override
public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer player) {
if (slotId >= 0 && slotId < this.inventorySlots.size()
&& this.inventorySlots.get(slotId) instanceof SlotRestrictedInput slot
&& slot.getItemType() == SlotRestrictedInput.PlacableItemType.BLANK_PATTERN
&& player instanceof EntityPlayerMP epmp) {
final boolean leftClick = mode == 0 && clickedButton == 0;
final boolean rightClick = mode == 0 && clickedButton == 1;
final boolean middleClick = mode == 3; // pick block
if (!slot.getHasStack() && player.inventory.getItemStack() == null) {
IMEMonitor<IAEItemStack> monitor = getItemMonitor();
if (monitor == null) return null;
IAEItemStack blank = monitor.getAvailableItem(BLANK_PATTERN, fetchNewId());
if (blank != null && blank.getStackSize() > 0 && (leftClick || rightClick)) {
if (this.getPowerSource() == null) return null;
if (leftClick) {
this.pickupStoredItems(BLANK_PATTERN.copy(), epmp, monitor);
} else {
this.splitStoredItems(BLANK_PATTERN.copy(), epmp, monitor);
}
return null;
}
if (middleClick && blank != null && blank.isCraftable()) {
final PrimaryGui pGui = this.createPrimaryGui();
final ContainerOpenContext context = this.getOpenContext();
if (context != null) {
final TileEntity te = context.getTile();
Platform.openGUI(
player,
te,
context.getSide(),
GuiBridge.GUI_CRAFTING_AMOUNT,
this.getTargetSlotIndex());
if (player.openContainer instanceof ContainerCraftAmount cca) {
cca.setPrimaryGui(pGui);
cca.setItemToCraft(blank);
cca.setInitialCraftAmount(1);
cca.detectAndSendChanges();
}
}
return null;
} else if (middleClick && player.capabilities.isCreativeMode && !slot.getHasStack()) {
ItemStack blankStack = BLANK_PATTERN.getItemStack();
blankStack.stackSize = blankStack.getMaxStackSize();
player.inventory.setItemStack(blankStack);
this.updateHeld(epmp);
return null;
}
slot.putStack(blanks);
}
}
return super.slotClick(slotId, clickedButton, mode, player);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer p, int idx) {
if (Platform.isClient()) {
return null;
}
final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get(idx); // require AE SLots!
if (!this.isValidSrcSlotForTransfer(clickSlot)) {
return null;
}
// Attempt to insert into the network before inserting into the blank pattern slot.
if (clickSlot.isPlayerSide()
&& AEApi.instance().definitions().materials().blankPattern().isSameAs(clickSlot.getStack())) {
ItemStack stackInSlot = clickSlot.getStack();
ItemStack leftover = this.shiftStoreItem(stackInSlot);
if (leftover == null || leftover.stackSize < stackInSlot.stackSize) {
clickSlot.putStack(leftover);
this.detectAndSendChanges();
}
if (leftover == null) {
return null;
}
}
return super.transferStackInSlot(p, idx);
}
@Override
@@ -296,6 +296,7 @@ public enum GuiText implements Localization {
Inputs,
Outputs,
BlankPatternInNetwork,
CPUAllowMode,
CPUAllowAll,
CPUOnlyAllowNonPlayer,
+1 -1
View File
@@ -226,9 +226,9 @@ public abstract class AEStack<StackType extends IAEStack<StackType>> implements
PATTERN,
(int) ((x + 10) * 2.5),
(int) (y * 2.5));
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glScalef(2.5f, 2.5f, 2.5f);
GL11.glPopMatrix();
}
}
}
@@ -359,6 +359,7 @@ gui.appliedenergistics2.VoidCellTooltip=Deletes §4everything§7 stored on it
gui.appliedenergistics2.CellView=Cell View
gui.appliedenergistics2.Inputs=Inputs
gui.appliedenergistics2.Outputs=Outputs
gui.appliedenergistics2.BlankPatternInNetwork=§bUses blank patterns directly from the network
gui.appliedenergistics2.EncodedPattern=Encoded Pattern
gui.appliedenergistics2.TunnelPatternInfo1=Use as an input when encoding processing patterns.
gui.appliedenergistics2.TunnelPatternInfo2=Its inputs are inlined into the encoded pattern.