Split pattern value from old slot sync system (#1322)

This commit is contained in:
lc-1337 authored and GitHub committed 2026-05-25 19:40:14 +02:00
1 parent 19f6b896f5
commit 07e76b2fe2
4 files changed
+42 -15

No files matched your search

@@ -8,6 +8,7 @@ import net.minecraft.item.ItemStack;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketPatternValueSet;
import appeng.core.sync.packets.PacketSwitchGuis;
import appeng.tile.inventory.IAEStackInventory;
@@ -28,6 +29,9 @@ public class VirtualMEPatternSlot extends VirtualMEPhantomSlot {
} else {
NetworkHandler.instance.sendToServer(new PacketSwitchGuis(GuiBridge.GUI_PATTERN_VALUE_AMOUNT));
}
NetworkHandler.instance.sendToServer(
new PacketPatternValueSet(this.getAEStack(), this.getStorageName(), this.getSlotIndex(), true));
}
}
@@ -9,6 +9,7 @@ import net.minecraft.item.ItemStack;
import appeng.container.sync.handlers.AEStackInventorySyncHandler;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketPatternValueSet;
import appeng.core.sync.packets.PacketSwitchGuis;
public class VirtualMEPhantomSlotPrecise extends VirtualMEPhantomSlot {
@@ -23,8 +24,15 @@ public class VirtualMEPhantomSlotPrecise extends VirtualMEPhantomSlot {
public void handleMouseClicked(@Nullable ItemStack itemStack, boolean isExtraAction, int mouseButton) {
if (mouseButton == keyBindPickBlockAction) {
if (this.getAEStack() != null) {
if (!isExtraAction)
if (!isExtraAction) {
NetworkHandler.instance.sendToServer(new PacketSwitchGuis(GuiBridge.GUI_PATTERN_VALUE_AMOUNT));
NetworkHandler.instance.sendToServer(
new PacketPatternValueSet(
this.getAEStack(),
this.getStorageName(),
this.getSlotIndex(),
true));
}
}
}
@@ -12,13 +12,12 @@ import appeng.api.storage.data.IAEStack;
import appeng.client.gui.implementations.GuiPatternItemRenamer;
import appeng.client.gui.implementations.GuiPatternValueAmount;
import appeng.container.ContainerSubGui;
import appeng.container.interfaces.IVirtualSlotHolder;
import appeng.container.interfaces.IVirtualSlotSource;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketVirtualSlot;
import appeng.core.sync.packets.PacketPatternValueSet;
import appeng.util.Platform;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
public class ContainerPatternValueAmount extends ContainerSubGui implements IVirtualSlotHolder {
public class ContainerPatternValueAmount extends ContainerSubGui implements IVirtualSlotSource {
private StorageName invName;
private IAEStack<?> aes;
@@ -29,16 +28,15 @@ public class ContainerPatternValueAmount extends ContainerSubGui implements IVir
}
@Override
public void receiveSlotStacks(StorageName invName, Int2ObjectMap<IAEStack<?>> slotStacks) {
var entry = slotStacks.int2ObjectEntrySet().iterator().next();
public void updateVirtualSlot(StorageName invName, int slotId, IAEStack<?> aes) {
this.invName = invName;
this.aes = entry.getValue();
this.slotIndex = entry.getIntKey();
this.aes = aes;
this.slotIndex = slotId;
if (Platform.isServer()) {
for (ICrafting crafter : this.crafters) {
final EntityPlayerMP emp = (EntityPlayerMP) crafter;
NetworkHandler.instance.sendTo(new PacketVirtualSlot(invName, slotIndex, aes), emp);
NetworkHandler.instance.sendTo(new PacketPatternValueSet(aes, invName, slotId), emp);
}
} else {
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
@@ -17,9 +17,11 @@ import io.netty.buffer.Unpooled;
public class PacketPatternValueSet extends AppEngPacket {
private final static int UPDATE_ONLY_OFFSET = 1_000_000;
private final IAEStack<?> aes;
private final StorageName invName;
private final int slotIndex;
private int slotIndex;
public PacketPatternValueSet(final ByteBuf stream) {
this.aes = readStackByte(stream);
@@ -28,9 +30,13 @@ public class PacketPatternValueSet extends AppEngPacket {
}
public PacketPatternValueSet(IAEStack<?> aes, StorageName invName, int slotIndex) {
this(aes, invName, slotIndex, false);
}
public PacketPatternValueSet(IAEStack<?> aes, StorageName invName, int slotIndex, boolean onlyUpdate) {
this.aes = aes;
this.invName = invName;
this.slotIndex = slotIndex;
this.slotIndex = onlyUpdate ? slotIndex + UPDATE_ONLY_OFFSET : slotIndex;
final ByteBuf data = Unpooled.buffer();
@@ -45,12 +51,23 @@ public class PacketPatternValueSet extends AppEngPacket {
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player) {
if (player.openContainer instanceof AEBaseContainer bc) {
PrimaryGui pGui = bc.getPrimaryGui();
assert pGui != null;
pGui.open(player);
if (this.slotIndex >= UPDATE_ONLY_OFFSET) {
this.slotIndex -= UPDATE_ONLY_OFFSET;
} else {
PrimaryGui pGui = bc.getPrimaryGui();
assert pGui != null;
pGui.open(player);
}
if (player.openContainer instanceof IVirtualSlotSource vss) {
vss.updateVirtualSlot(invName, slotIndex, aes);
}
}
}
@Override
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player) {
if (player.openContainer instanceof IVirtualSlotSource vss)
vss.updateVirtualSlot(this.invName, this.slotIndex, this.aes);
}
}