支持装配矩阵样板取回
This commit is contained in:
parent
3405e20dca
commit
cc5c7d2258
|
|
@ -2,17 +2,23 @@ package com.extendedae_plus.network.provider;
|
||||||
|
|
||||||
import appeng.api.crafting.PatternDetailsHelper;
|
import appeng.api.crafting.PatternDetailsHelper;
|
||||||
import appeng.api.inventories.InternalInventory;
|
import appeng.api.inventories.InternalInventory;
|
||||||
|
import appeng.api.networking.IGrid;
|
||||||
|
import appeng.api.networking.IGridNode;
|
||||||
import appeng.helpers.patternprovider.PatternContainer;
|
import appeng.helpers.patternprovider.PatternContainer;
|
||||||
import appeng.menu.implementations.PatternAccessTermMenu;
|
import appeng.menu.implementations.PatternAccessTermMenu;
|
||||||
import appeng.menu.me.items.PatternEncodingTermMenu;
|
import appeng.menu.me.items.PatternEncodingTermMenu;
|
||||||
import com.extendedae_plus.util.PatternTerminalUtil;
|
import com.extendedae_plus.util.PatternTerminalUtil;
|
||||||
import com.extendedae_plus.util.uploadPattern.ProviderUploadUtil;
|
import com.extendedae_plus.util.uploadPattern.ProviderUploadUtil;
|
||||||
|
|
||||||
|
import com.glodblock.github.extendedae.common.tileentities.matrix.TileAssemblerMatrixPattern;
|
||||||
|
import com.extendedae_plus.content.matrix.PatternCorePlusBlockEntity;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.network.NetworkEvent;
|
import net.minecraftforge.network.NetworkEvent;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -38,6 +44,39 @@ public class ReturnLastPatternC2SPacket {
|
||||||
return; // Nothing to return
|
return; // Nothing to return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Special ID for Assembly Matrix
|
||||||
|
if (lastProviderId == -999999L) {
|
||||||
|
if (player.containerMenu instanceof PatternEncodingTermMenu encMenu) {
|
||||||
|
IGridNode node = encMenu.getNetworkNode();
|
||||||
|
if (node != null && node.getGrid() != null) {
|
||||||
|
IGrid grid = node.getGrid();
|
||||||
|
// Get all matrix pattern inventories
|
||||||
|
try {
|
||||||
|
Set<TileAssemblerMatrixPattern> allTiles = grid.getMachines(TileAssemblerMatrixPattern.class);
|
||||||
|
for (TileAssemblerMatrixPattern tile : allTiles) {
|
||||||
|
if (tile != null && tile.isFormed() && tile.getMainNode().isActive()) {
|
||||||
|
InternalInventory inv = tile.getTerminalPatternInventory();
|
||||||
|
if (inv != null && returnPatternFromInventory(player, inv)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<PatternCorePlusBlockEntity> myAllTiles = grid.getMachines(PatternCorePlusBlockEntity.class);
|
||||||
|
for (PatternCorePlusBlockEntity tile : myAllTiles) {
|
||||||
|
if (tile != null && tile.isFormed() && tile.getMainNode().isActive()) {
|
||||||
|
InternalInventory inv = tile.getTerminalPatternInventory();
|
||||||
|
if (inv != null && returnPatternFromInventory(player, inv)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
PatternContainer targetContainer = null;
|
PatternContainer targetContainer = null;
|
||||||
|
|
||||||
// Try to resolve the container using encoding menu
|
// Try to resolve the container using encoding menu
|
||||||
|
|
@ -73,22 +112,27 @@ public class ReturnLastPatternC2SPacket {
|
||||||
}
|
}
|
||||||
|
|
||||||
InternalInventory inv = targetContainer.getTerminalPatternInventory();
|
InternalInventory inv = targetContainer.getTerminalPatternInventory();
|
||||||
if (inv == null || inv.size() <= 0) return;
|
if (inv != null && inv.size() > 0) {
|
||||||
|
returnPatternFromInventory(player, inv);
|
||||||
// Find the highest slot with an encoded pattern
|
|
||||||
for (int slot = inv.size() - 1; slot >= 0; slot--) {
|
|
||||||
ItemStack stack = inv.getStackInSlot(slot);
|
|
||||||
if (!stack.isEmpty() && PatternDetailsHelper.isEncodedPattern(stack)) {
|
|
||||||
ItemStack extracted = inv.extractItem(slot, 1, false);
|
|
||||||
if (!extracted.isEmpty()) {
|
|
||||||
if (!player.getInventory().add(extracted)) {
|
|
||||||
player.drop(extracted, false);
|
|
||||||
}
|
|
||||||
return; // Found and returned
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ctx.setPacketHandled(true);
|
ctx.setPacketHandled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean returnPatternFromInventory(ServerPlayer player, InternalInventory inv) {
|
||||||
|
// Find the highest slot with an encoded pattern
|
||||||
|
for (int slot = inv.size() - 1; slot >= 0; slot--) {
|
||||||
|
ItemStack stack = inv.getStackInSlot(slot);
|
||||||
|
if (!stack.isEmpty() && PatternDetailsHelper.isEncodedPattern(stack)) {
|
||||||
|
ItemStack extracted = inv.extractItem(slot, 1, false);
|
||||||
|
if (!extracted.isEmpty()) {
|
||||||
|
if (!player.getInventory().add(extracted)) {
|
||||||
|
player.drop(extracted, false);
|
||||||
|
}
|
||||||
|
return true; // Found and returned
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,7 @@ public final class MatrixUploadUtil {
|
||||||
if (remain.getCount() < pattern.getCount()) {
|
if (remain.getCount() < pattern.getCount()) {
|
||||||
// 上传成功
|
// 上传成功
|
||||||
sendPlayerMessage(player, Component.translatable("extendedae_plus.upload_to_matrix.success"));
|
sendPlayerMessage(player, Component.translatable("extendedae_plus.upload_to_matrix.success"));
|
||||||
|
player.getPersistentData().putLong("eap_last_uploaded_provider_id", -999999L);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -146,7 +147,7 @@ public final class MatrixUploadUtil {
|
||||||
/**
|
/**
|
||||||
* 在给定 AE Grid 中收集所有已成型且在线的装配矩阵“样板核心”的用于外部插入的内部库存
|
* 在给定 AE Grid 中收集所有已成型且在线的装配矩阵“样板核心”的用于外部插入的内部库存
|
||||||
*/
|
*/
|
||||||
private static List<InternalInventory> findAllMatrixPatternInventories(IGrid grid) {
|
public static List<InternalInventory> findAllMatrixPatternInventories(IGrid grid) {
|
||||||
List<InternalInventory> result = new ArrayList<>();
|
List<InternalInventory> result = new ArrayList<>();
|
||||||
if (grid == null) return result;
|
if (grid == null) return result;
|
||||||
|
|
||||||
|
|
@ -242,6 +243,7 @@ public final class MatrixUploadUtil {
|
||||||
stack.shrink(inserted);
|
stack.shrink(inserted);
|
||||||
if (stack.isEmpty()) encodedSlot.set(ItemStack.EMPTY);
|
if (stack.isEmpty()) encodedSlot.set(ItemStack.EMPTY);
|
||||||
sendPlayerMessage(player, Component.translatable("extendedae_plus.upload_to_matrix.success"));
|
sendPlayerMessage(player, Component.translatable("extendedae_plus.upload_to_matrix.success"));
|
||||||
|
player.getPersistentData().putLong("eap_last_uploaded_provider_id", -999999L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user