latest
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package thaumicenergistics.client;
|
||||
|
||||
import appeng.client.gui.me.common.RepoSlot;
|
||||
import appeng.helpers.InventoryAction;
|
||||
import appeng.menu.me.common.MEStorageMenu;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.neoforge.client.event.ScreenEvent;
|
||||
import net.neoforged.neoforge.network.PacketDistributor;
|
||||
import thaumicenergistics.common.integration.appeng.AEssentiaKey;
|
||||
import thaumicenergistics.common.integration.appeng.EssentiaContainerItemStrategy;
|
||||
import thaumicenergistics.common.integration.tc.ThEEssentiaContainers;
|
||||
import thaumicenergistics.common.network.EssentiaTerminalDepositC2SPacket;
|
||||
import thaumicenergistics.common.network.EssentiaTerminalFillC2SPacket;
|
||||
|
||||
/** 屏幕事件覆盖原版和第三方终端,鼠标在工具栏上时不抢占模式切换按钮。 */
|
||||
public final class EssentiaTerminalInputHandler {
|
||||
private EssentiaTerminalInputHandler() {
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void mousePressed(ScreenEvent.MouseButtonPressed.Pre event) {
|
||||
if (event.getButton() != 1 || !(event.getScreen() instanceof AbstractContainerScreen<?> screen)
|
||||
|| !(screen.getMenu() instanceof MEStorageMenu menu)) {
|
||||
return;
|
||||
}
|
||||
var hovered = screen.getSlotUnderMouse();
|
||||
if (hovered == null) return;
|
||||
boolean shift = AbstractContainerScreen.hasShiftDown();
|
||||
if (menu.isPlayerSideSlot(hovered)) {
|
||||
if (shift && ThEEssentiaContainers.isEssentiaContainer(hovered.getItem())) {
|
||||
PacketDistributor.sendToServer(EssentiaTerminalDepositC2SPacket.fromSlot(
|
||||
menu.containerId, hovered.getSlotIndex(), hovered.getItem()));
|
||||
event.setCanceled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!(hovered instanceof RepoSlot repo)) return;
|
||||
var carried = menu.getCarried();
|
||||
if (EssentiaContainerItemStrategy.recoveredContent(carried) != null) {
|
||||
menu.handleInteraction(-1, InventoryAction.EMPTY_ENTIRE_ITEM);
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
}
|
||||
var source = carried.isEmpty() ? menu.getPlayerInventory().player.getMainHandItem() : carried;
|
||||
if (!ThEEssentiaContainers.isEssentiaContainer(source)) return;
|
||||
if (ThEEssentiaContainers.hasEssentia(source)) {
|
||||
if (!carried.isEmpty()) {
|
||||
// carried 的标准抽空通过 AE2 原生协议和 ContainerItemStrategy 处理。
|
||||
menu.handleInteraction(-1, InventoryAction.EMPTY_ENTIRE_ITEM);
|
||||
} else {
|
||||
PacketDistributor.sendToServer(EssentiaTerminalDepositC2SPacket.fromClientStack(
|
||||
menu.containerId, source));
|
||||
}
|
||||
} else if (!shift && repo.getEntry() != null && repo.getEntry().getWhat() instanceof AEssentiaKey key) {
|
||||
PacketDistributor.sendToServer(EssentiaTerminalFillC2SPacket.create(menu.containerId, key.getId(), source));
|
||||
}
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
package thaumicenergistics.client.render.model;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import net.minecraft.client.renderer.FaceInfo;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
import thaumicenergistics.ThaumicEnergistics;
|
||||
import thaumicenergistics.common.entities.BackpackSkins;
|
||||
|
||||
/**
|
||||
* Per-face model loader adapted from Thaumic Energistics: CE (Minecraft 26.1.2).
|
||||
* Copyright (c) 2026 Thaumic Energistics: CE contributors. MIT License.
|
||||
* Full notice: META-INF/licenses/thaumicenergistics-ce-backpack.txt.
|
||||
* Uses direct texture coordinates; these vertices must not use the block atlas.
|
||||
*/
|
||||
@net.neoforged.api.distmarker.OnlyIn(net.neoforged.api.distmarker.Dist.CLIENT)
|
||||
public final class GolemBackpackModels {
|
||||
public static final ResourceLocation RESOURCE = ThaumicEnergistics.id("models/entity/golem_backpack.json");
|
||||
private static volatile GolemBackpackModels current = new GolemBackpackModels(
|
||||
List.of(), Map.of(), Map.of(), Set.of(), "", new Vector3f(), new Vector3f(), new Vector3f(1));
|
||||
|
||||
private final List<Quad> quads;
|
||||
private final Map<String, ResourceLocation> textures;
|
||||
private final Map<String, String> connectedTextures;
|
||||
private final Set<ResourceLocation> emissiveTextures;
|
||||
private final String skinTexture;
|
||||
private final Vector3f translation;
|
||||
private final Vector3f rotation;
|
||||
private final Vector3f scale;
|
||||
private final Map<ResourceLocation, RenderType> renderTypes = new HashMap<>();
|
||||
|
||||
private record Vertex(Vector3f position, float u, float v) {}
|
||||
private record Quad(String texture, List<Vertex> vertices, Vector3f normal) {}
|
||||
|
||||
private GolemBackpackModels(List<Quad> quads, Map<String, ResourceLocation> textures,
|
||||
Map<String, String> connectedTextures, Set<ResourceLocation> emissiveTextures, String skinTexture,
|
||||
Vector3f translation, Vector3f rotation, Vector3f scale) {
|
||||
this.quads = List.copyOf(quads);
|
||||
this.textures = Map.copyOf(textures);
|
||||
this.connectedTextures = Map.copyOf(connectedTextures);
|
||||
this.emissiveTextures = Set.copyOf(emissiveTextures);
|
||||
this.skinTexture = skinTexture;
|
||||
this.translation = translation;
|
||||
this.rotation = rotation;
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
public static GolemBackpackModels current() { return current; }
|
||||
|
||||
public static void reload(ResourceManager resources) {
|
||||
try (var reader = resources.getResourceOrThrow(RESOURCE).openAsReader()) {
|
||||
current = load(JsonParser.parseReader(reader).getAsJsonObject());
|
||||
} catch (Exception error) {
|
||||
ThaumicEnergistics.LOG.error("Failed to load backpack model {}. Keeping the previous model.", RESOURCE, error);
|
||||
}
|
||||
}
|
||||
|
||||
public static GolemBackpackModels load(JsonObject data) {
|
||||
var attachment = data.getAsJsonObject("attachment");
|
||||
var origin = vector(attachment.getAsJsonArray("origin"));
|
||||
var textures = new HashMap<String, ResourceLocation>();
|
||||
data.getAsJsonObject("textures").entrySet().forEach(entry -> {
|
||||
var id = ResourceLocation.parse(entry.getValue().getAsString());
|
||||
String path = id.getPath();
|
||||
if (!path.startsWith("textures/")) path = "textures/" + path;
|
||||
if (!path.endsWith(".png")) path += ".png";
|
||||
textures.put(entry.getKey(), ResourceLocation.fromNamespaceAndPath(id.getNamespace(), path));
|
||||
});
|
||||
var connected = new HashMap<String, String>();
|
||||
data.getAsJsonObject("connected_textures").entrySet().forEach(entry ->
|
||||
connected.put(entry.getKey(), entry.getValue().getAsString()));
|
||||
String skinTexture = data.get("skin_texture").getAsString();
|
||||
if (!textures.containsKey(skinTexture)) throw new IllegalArgumentException("Unknown skin texture: " + skinTexture);
|
||||
connected.forEach((source, target) -> {
|
||||
if (!textures.containsKey(source) || !textures.containsKey(target)) {
|
||||
throw new IllegalArgumentException("Unknown connected texture: " + source + " -> " + target);
|
||||
}
|
||||
});
|
||||
var emissive = new HashSet<ResourceLocation>();
|
||||
if (data.has("emissive_textures")) {
|
||||
for (var value : data.getAsJsonArray("emissive_textures")) {
|
||||
String key = value.getAsString();
|
||||
if (!textures.containsKey(key)) throw new IllegalArgumentException("Unknown emissive texture: " + key);
|
||||
emissive.add(textures.get(key));
|
||||
}
|
||||
}
|
||||
var quads = new ArrayList<Quad>();
|
||||
for (var value : data.getAsJsonArray("elements")) {
|
||||
var element = value.getAsJsonObject();
|
||||
var from = vector(element.getAsJsonArray("from"));
|
||||
var to = vector(element.getAsJsonArray("to"));
|
||||
var transform = elementTransform(element);
|
||||
for (var entry : element.getAsJsonObject("faces").entrySet()) {
|
||||
var direction = Direction.byName(entry.getKey());
|
||||
if (direction == null) throw new IllegalArgumentException("Unknown face: " + entry.getKey());
|
||||
var face = entry.getValue().getAsJsonObject();
|
||||
String texture = face.get("texture").getAsString();
|
||||
if (!texture.startsWith("#") || !textures.containsKey(texture.substring(1))) {
|
||||
throw new IllegalArgumentException("Unknown face texture: " + texture);
|
||||
}
|
||||
var uv = face.getAsJsonArray("uv");
|
||||
if (uv.size() != 4) throw new IllegalArgumentException("Expected four UV coordinates");
|
||||
float u0 = number(uv, 0) / 16, v0 = number(uv, 1) / 16;
|
||||
float u1 = number(uv, 2) / 16, v1 = number(uv, 3) / 16;
|
||||
float[][] corners = {{u0, v0}, {u0, v1}, {u1, v1}, {u1, v0}};
|
||||
int angle = face.has("rotation") ? face.get("rotation").getAsInt() : 0;
|
||||
if (angle % 90 != 0) throw new IllegalArgumentException("Face rotation must be a multiple of 90 degrees");
|
||||
var vertices = new ArrayList<Vertex>(4);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
var position = faceVertex(direction, i, from, to);
|
||||
transform.transformPosition(position);
|
||||
position.sub(origin).div(16);
|
||||
var coordinate = corners[Math.floorMod(i + angle / 90, 4)];
|
||||
vertices.add(new Vertex(position, coordinate[0], coordinate[1]));
|
||||
}
|
||||
var normal = new Vector3f(vertices.get(1).position()).sub(vertices.get(0).position())
|
||||
.cross(new Vector3f(vertices.get(2).position()).sub(vertices.get(0).position()));
|
||||
if (normal.lengthSquared() == 0) continue;
|
||||
normal.normalize();
|
||||
quads.add(new Quad(texture.substring(1), List.copyOf(vertices), normal));
|
||||
}
|
||||
}
|
||||
if (quads.isEmpty()) throw new IllegalArgumentException("Backpack model has no visible faces");
|
||||
return new GolemBackpackModels(quads, textures, connected, emissive, skinTexture,
|
||||
vector(attachment.getAsJsonArray("translation")),
|
||||
vector(attachment.getAsJsonArray("rotation")), vector(attachment.getAsJsonArray("scale")));
|
||||
}
|
||||
|
||||
// Minecraft 1.21.1 exposes the face vertex indices rather than select(from, to).
|
||||
private static Vector3f faceVertex(Direction direction, int index, Vector3f from, Vector3f to) {
|
||||
var vertex = FaceInfo.fromFacing(direction).getVertexInfo(index);
|
||||
float[] bounds = new float[6];
|
||||
bounds[FaceInfo.Constants.MIN_X] = from.x;
|
||||
bounds[FaceInfo.Constants.MIN_Y] = from.y;
|
||||
bounds[FaceInfo.Constants.MIN_Z] = from.z;
|
||||
bounds[FaceInfo.Constants.MAX_X] = to.x;
|
||||
bounds[FaceInfo.Constants.MAX_Y] = to.y;
|
||||
bounds[FaceInfo.Constants.MAX_Z] = to.z;
|
||||
return new Vector3f(bounds[vertex.xFace], bounds[vertex.yFace], bounds[vertex.zFace]);
|
||||
}
|
||||
|
||||
private static Matrix4f elementTransform(JsonObject element) {
|
||||
var transform = new Matrix4f();
|
||||
if (!element.has("rotation")) return transform;
|
||||
var rotation = element.getAsJsonObject("rotation");
|
||||
var origin = vector(rotation.getAsJsonArray("origin"));
|
||||
float angle = (float) Math.toRadians(rotation.get("angle").getAsDouble());
|
||||
if (!Float.isFinite(angle)) throw new IllegalArgumentException("Non-finite element rotation");
|
||||
String axis = rotation.get("axis").getAsString();
|
||||
transform.translate(origin);
|
||||
switch (axis) {
|
||||
case "x" -> transform.rotateX(angle);
|
||||
case "y" -> transform.rotateY(angle);
|
||||
case "z" -> transform.rotateZ(angle);
|
||||
default -> throw new IllegalArgumentException("Unknown rotation axis: " + axis);
|
||||
}
|
||||
if (rotation.has("rescale") && rotation.get("rescale").getAsBoolean()) {
|
||||
float factor = 1 / (float) Math.cos(angle);
|
||||
if (!Float.isFinite(factor)) throw new IllegalArgumentException("Invalid rotation rescale");
|
||||
transform.scale(axis.equals("x") ? 1 : factor,
|
||||
axis.equals("y") ? 1 : factor, axis.equals("z") ? 1 : factor);
|
||||
}
|
||||
return transform.translate(new Vector3f(origin).negate());
|
||||
}
|
||||
|
||||
private static Vector3f vector(JsonArray data) {
|
||||
if (data.size() != 3) throw new IllegalArgumentException("Expected a three-dimensional vector");
|
||||
return new Vector3f(number(data, 0), number(data, 1), number(data, 2));
|
||||
}
|
||||
|
||||
private static float number(JsonArray data, int index) {
|
||||
float number = data.get(index).getAsFloat();
|
||||
if (!Float.isFinite(number)) throw new IllegalArgumentException("Non-finite model coordinate");
|
||||
return number;
|
||||
}
|
||||
|
||||
public void render(PoseStack poses, MultiBufferSource buffers, BackpackSkins skin,
|
||||
boolean working, int light, int overlay) {
|
||||
poses.pushPose();
|
||||
poses.translate(translation.x, translation.y, translation.z);
|
||||
poses.mulPose(new org.joml.Quaternionf().rotationXYZ(
|
||||
(float) Math.toRadians(rotation.x), (float) Math.toRadians(rotation.y), (float) Math.toRadians(rotation.z)));
|
||||
poses.scale(scale.x, scale.y, scale.z);
|
||||
var pose = poses.last();
|
||||
var normal = new Vector3f();
|
||||
for (var quad : quads) {
|
||||
String key = working ? connectedTextures.getOrDefault(quad.texture(), quad.texture()) : quad.texture();
|
||||
var texture = key.equals(skinTexture) ? skin.getTextureLocation() : textures.get(key);
|
||||
boolean emissive = emissiveTextures.contains(texture);
|
||||
VertexConsumer buffer = buffers.getBuffer(renderTypes.computeIfAbsent(texture,
|
||||
id -> emissiveTextures.contains(id)
|
||||
? RenderType.entityTranslucentEmissive(id)
|
||||
: RenderType.entityCutoutNoCull(id)));
|
||||
normal.set(quad.normal());
|
||||
pose.normal().transform(normal).normalize();
|
||||
int faceLight = emissive ? net.minecraft.client.renderer.LightTexture.FULL_BRIGHT : light;
|
||||
for (var vertex : quad.vertices()) {
|
||||
var position = vertex.position();
|
||||
buffer.addVertex(pose, position.x, position.y, position.z)
|
||||
.setColor(255, 255, 255, 255).setUv(vertex.u(), vertex.v())
|
||||
.setOverlay(overlay).setLight(faceLight).setNormal(normal.x, normal.y, normal.z);
|
||||
}
|
||||
}
|
||||
poses.popPose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package thaumicenergistics.common.blocks;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.Containers;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.ItemInteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.level.storage.loot.LootParams;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
/** Decorative dolls sharing Alkusure86's right-click variant and sneak-pickup behavior. */
|
||||
public final class FumoBlock extends Block {
|
||||
public static final BooleanProperty VARIANT = BooleanProperty.create("variant");
|
||||
|
||||
public FumoBlock(Properties properties) {
|
||||
super(properties);
|
||||
registerDefaultState(defaultBlockState().setValue(VARIANT, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||
builder.add(BlockStateProperties.HORIZONTAL_FACING, VARIANT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
||||
return defaultBlockState().setValue(BlockStateProperties.HORIZONTAL_FACING,
|
||||
context.getHorizontalDirection().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos,
|
||||
Player player, InteractionHand hand, BlockHitResult hit) {
|
||||
if (player.isShiftKeyDown()) pickUp(level, pos, player);
|
||||
else toggleVariant(level, pos, state);
|
||||
return ItemInteractionResult.sidedSuccess(level.isClientSide());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos,
|
||||
Player player, BlockHitResult hit) {
|
||||
if (player.isShiftKeyDown()) pickUp(level, pos, player);
|
||||
else toggleVariant(level, pos, state);
|
||||
return InteractionResult.sidedSuccess(level.isClientSide());
|
||||
}
|
||||
|
||||
private void pickUp(Level level, BlockPos pos, Player player) {
|
||||
if (level.isClientSide) return;
|
||||
ItemStack item = new ItemStack(this);
|
||||
level.removeBlock(pos, false);
|
||||
if (player.getMainHandItem().isEmpty()) player.setItemInHand(InteractionHand.MAIN_HAND, item);
|
||||
else if (!player.getInventory().add(item)) {
|
||||
Containers.dropItemStack(level, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, item);
|
||||
}
|
||||
}
|
||||
|
||||
private void toggleVariant(Level level, BlockPos pos, BlockState state) {
|
||||
if (!level.isClientSide) level.setBlock(pos, state.cycle(VARIANT), 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
|
||||
return Shapes.box(0.25, 0, 0.25, 0.75, 0.75, 0.75);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(BlockState state, LootParams.Builder builder) {
|
||||
return List.of(new ItemStack(this));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package thaumicenergistics.common.container;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import appeng.api.inventories.ISegmentedInventory;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.upgrades.IUpgradeInventory;
|
||||
|
||||
/**
|
||||
* 奥术终端宿主契约:统一独立无线奥术终端与 AE2WT 通用终端奥术模式两种宿主,
|
||||
* 供 {@code ContainerArcaneCraftingTerminal} 识别 vis 充能、奇点槽与法杖保存能力,
|
||||
* 替代对具体宿主类的 instanceof 判断。
|
||||
* <p>
|
||||
* 奇点子库存 id 由各宿主自报(独立宿主为本模组命名空间,AE2WT 宿主为
|
||||
* {@code ae2wtlib:singularity} 字符串软查,避免可选 API 类型泄漏到普通加载路径);
|
||||
* 返回 null 表示无奇点槽。
|
||||
*/
|
||||
public interface IArcaneTerminalInventoryHost extends ISegmentedInventory {
|
||||
|
||||
/** ae2wtlib modid(奇点准入等 ModList 守护用)。 */
|
||||
String AE2WTLIB_MODID = "ae2wtlib";
|
||||
|
||||
/** 升级卡库存(vis 连接卡检测;与 AE2 IUpgradeableObject 同名方法兼容)。 */
|
||||
IUpgradeInventory getUpgrades();
|
||||
|
||||
/** 网络操作节点(vis 充能源;与 AE2 IActionHost 同名方法兼容)。 */
|
||||
@Nullable
|
||||
IGridNode getActionableNode();
|
||||
|
||||
/** 法杖槽内容写回终端物品组件(菜单驱动充能后显式调用)。 */
|
||||
void saveWandInv();
|
||||
|
||||
/** Refresh a passive connection without charging menu idle power a second time. */
|
||||
void refreshConnection();
|
||||
|
||||
/** 奇点子库存 id(getSubInventory 寻址);null 表示本宿主无奇点槽。 */
|
||||
@Nullable
|
||||
ResourceLocation getSingularityInvId();
|
||||
|
||||
/**
|
||||
* 奇点槽语义分支:AE2WT 宿主返回 true——奇点槽挂 ae2wtlib 官方 SINGULARITY 组
|
||||
* (滚动升级面板取槽时要求奇点居首且独立成组,并自带量子桥卡门控显隐);
|
||||
* 独立无线宿主保持默认 false——奇点槽并入 UPGRADE 组由普通升级面板渲染。
|
||||
* 经契约虚调用分发,菜单侧不引用 ae2wtlib 类型(该宿主能实例化即证明 ae2wtlib 在场)。
|
||||
*/
|
||||
default boolean useAE2WTSingularitySemantics() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package thaumicenergistics.common.container;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import appeng.api.networking.energy.IEnergySource;
|
||||
import appeng.api.networking.security.IActionHost;
|
||||
import appeng.api.storage.MEStorage;
|
||||
import appeng.menu.me.common.MEStorageMenu;
|
||||
|
||||
/**
|
||||
* 从 {@link MEStorageMenu} 宿主的公开接口取得存储与能量源,
|
||||
* 替代原 MixinMEStorageMenuAccessors 注入的私有字段访问器。
|
||||
* 取得规则与 AE2 菜单构造器一致:存储=宿主 getInventory()(要求非空);
|
||||
* 能量源=宿主实现 IEnergySource 时优先用宿主(无线终端电池扣费语义),
|
||||
* 否则宿主实现 IActionHost 时动态代理——每次扣费重新查询节点与网格,
|
||||
* 不捕获首次结果,保证拆线/重连/网络合并后不使用旧网格;均不成立时用空源。
|
||||
* 不保存世界数据,不引入数据组件,不建立菜单缓存。
|
||||
*/
|
||||
public final class MenuResources {
|
||||
private MenuResources() {
|
||||
}
|
||||
|
||||
public static MEStorage getStorage(MEStorageMenu menu) {
|
||||
Objects.requireNonNull(menu, "menu");
|
||||
return Objects.requireNonNull(
|
||||
menu.getHost().getInventory(), "host inventory is null");
|
||||
}
|
||||
|
||||
public static IEnergySource getEnergySource(MEStorageMenu menu) {
|
||||
Objects.requireNonNull(menu, "menu");
|
||||
var host = menu.getHost();
|
||||
|
||||
if (host instanceof IEnergySource energySource) {
|
||||
return energySource;
|
||||
}
|
||||
|
||||
if (host instanceof IActionHost actionHost) {
|
||||
return (amount, mode, multiplier) -> {
|
||||
var node = actionHost.getActionableNode();
|
||||
if (node == null || !node.isActive()) {
|
||||
return 0.0;
|
||||
}
|
||||
var grid = node.getGrid();
|
||||
if (grid == null) {
|
||||
return 0.0;
|
||||
}
|
||||
return grid.getEnergyService().extractAEPower(
|
||||
amount, mode, multiplier);
|
||||
};
|
||||
}
|
||||
|
||||
return IEnergySource.empty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package thaumicenergistics.common.essentia.capability;
|
||||
|
||||
import java.util.function.LongUnaryOperator;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.networking.IGrid;
|
||||
import thaumicenergistics.common.integration.tc.EssentiaConversionHelper;
|
||||
|
||||
public final class EssentiaEnergy {
|
||||
private EssentiaEnergy() {
|
||||
}
|
||||
|
||||
public static long transfer(IGrid grid, long requested, LongUnaryOperator operation) {
|
||||
var energy = grid.getEnergyService();
|
||||
return TransferBudget.transfer(requested, EssentiaConversionHelper.AE_PER_ESSENTIA,
|
||||
cost -> energy.extractAEPower(cost, Actionable.MODULATE, PowerMultiplier.CONFIG),
|
||||
unused -> energy.injectPower(PowerMultiplier.CONFIG.multiply(unused), Actionable.MODULATE),
|
||||
operation);
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
package thaumicenergistics.common.essentia.capability;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.blockentity.networking.CableBusBlockEntity;
|
||||
import appeng.core.definitions.AEItems;
|
||||
import appeng.parts.automation.ExportBusPart;
|
||||
import net.minecraft.core.Direction;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
import thaumcraft.api.aspects.IEssentiaTransport;
|
||||
import thaumicenergistics.api.storage.AspectStack;
|
||||
import thaumicenergistics.common.integration.appeng.AEssentiaKey;
|
||||
import thaumicenergistics.common.integration.tc.AspectIds;
|
||||
import thaumicenergistics.common.integration.tc.EssentiaEndpoints;
|
||||
import thaumicenergistics.common.integration.tc.EssentiaConversionHelper;
|
||||
import thaumicenergistics.init.ModItems;
|
||||
|
||||
/**
|
||||
* Sided cable-bus endpoint for pull-only TC consumers. Only advertises the export bus's
|
||||
* owned buffer, never the entire ME inventory. Resolve the part on every call so removal,
|
||||
* rotation and card changes cannot leave a cached capability pointing at an old part.
|
||||
*/
|
||||
public final class ExportBusEssentiaTransport implements IEssentiaTransport {
|
||||
private final CableBusBlockEntity host;
|
||||
private final Direction face;
|
||||
|
||||
public ExportBusEssentiaTransport(CableBusBlockEntity host, Direction face) {
|
||||
this.host = host;
|
||||
this.face = face;
|
||||
}
|
||||
|
||||
private ExportBusPart bus(Direction side) {
|
||||
if (side != face || host.isRemoved() || host.getLevel() == null || host.getLevel().isClientSide()
|
||||
|| !(host.getPart(face) instanceof ExportBusPart bus)
|
||||
|| !bus.getUpgrades().isInstalled(ModItems.ESSENTIA_UPGRADE_CARD.get())
|
||||
|| !bus.getMainNode().isActive()) return null;
|
||||
var mode = bus.getRSMode();
|
||||
if (bus.getUpgrades().isInstalled(AEItems.REDSTONE_CARD)
|
||||
&& ((mode == RedstoneMode.HIGH_SIGNAL && !host.hasRedstone())
|
||||
|| (mode == RedstoneMode.LOW_SIGNAL && host.hasRedstone()))) return null;
|
||||
// Pulse mode only exposes stock reserved by an authorized doBusWork invocation.
|
||||
return bus;
|
||||
}
|
||||
|
||||
private AspectStack stock(Direction side) {
|
||||
var bus = bus(side);
|
||||
if (!(bus instanceof EssentiaTransferBuffer buffer)) return AspectStack.EMPTY;
|
||||
var pending = buffer.thE$getTransferBuffer();
|
||||
return !pending.isEmpty() && bus.getConfig().keySet().contains(AEssentiaKey.of(pending.aspectId()))
|
||||
? pending : AspectStack.EMPTY;
|
||||
}
|
||||
|
||||
/** Called only during the bus's normal, power/channel/redstone-controlled work tick. */
|
||||
public static boolean reserveForConsumer(ExportBusPart bus, AEssentiaKey key, int rate,
|
||||
net.minecraft.world.level.block.entity.BlockEntity consumer, Direction consumerSide,
|
||||
appeng.api.networking.IGrid grid, appeng.api.networking.security.IActionSource source) {
|
||||
if (!(bus instanceof EssentiaTransferBuffer buffer) || !buffer.thE$getTransferBuffer().isEmpty()) return false;
|
||||
var transport = EssentiaEndpoints.transport(consumer, consumerSide);
|
||||
var aspect = AspectIds.findAspectById(key.getId());
|
||||
if (aspect == null || transport == null || !transport.isConnectable(consumerSide)
|
||||
|| !transport.canInputFrom(consumerSide) || transport.getSuctionAmount(consumerSide) <= 0) return false;
|
||||
var requested = transport.getSuctionType(consumerSide);
|
||||
if (requested != null && requested != aspect) return false;
|
||||
// Small, persisted stock replaces the intermediary jar without hoarding network resources.
|
||||
long extracted = grid.getStorageService().getInventory().extract(
|
||||
key, Math.min(rate, 8), Actionable.MODULATE, source);
|
||||
if (extracted <= 0) return false;
|
||||
buffer.thE$setTransferBuffer(new AspectStack(key.getId(), extracted));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public boolean isConnectable(Direction side) { return bus(side) != null; }
|
||||
@Override public boolean canInputFrom(Direction side) { return false; }
|
||||
@Override public boolean canOutputTo(Direction side) { return !stock(side).isEmpty(); }
|
||||
@Override public void setSuction(Aspect aspect, int amount) { }
|
||||
@Override public Aspect getSuctionType(Direction side) { return null; }
|
||||
@Override public int getSuctionAmount(Direction side) { return 0; }
|
||||
@Override public int getMinimumSuction() { return 0; }
|
||||
@Override public Aspect getEssentiaType(Direction side) {
|
||||
var stock = stock(side);
|
||||
return stock.isEmpty() ? null : AspectIds.findAspectById(stock.aspectId());
|
||||
}
|
||||
@Override public int getEssentiaAmount(Direction side) { return (int) Math.min(stock(side).amount(), Integer.MAX_VALUE); }
|
||||
@Override public int addEssentia(Aspect aspect, int amount, Direction side) { return 0; }
|
||||
|
||||
@Override
|
||||
public int simulateTakeEssentia(Aspect aspect, int amount, Direction side) {
|
||||
if (aspect == null || amount <= 0) return 0;
|
||||
var bus = bus(side);
|
||||
var stock = stock(side);
|
||||
if (bus == null || stock.isEmpty() || aspect != AspectIds.findAspectById(stock.aspectId())) return 0;
|
||||
var grid = bus.getMainNode().getGrid();
|
||||
if (grid == null) return 0;
|
||||
long wanted = Math.min(amount, stock.amount());
|
||||
double power = grid.getEnergyService().extractAEPower(wanted * EssentiaConversionHelper.AE_PER_ESSENTIA,
|
||||
Actionable.SIMULATE, PowerMultiplier.CONFIG);
|
||||
return (int) Math.min(wanted, (long) Math.floor((power + 1.0e-9) / EssentiaConversionHelper.AE_PER_ESSENTIA));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int takeEssentia(Aspect aspect, int amount, Direction side) {
|
||||
if (aspect == null || amount <= 0) return 0;
|
||||
var bus = bus(side);
|
||||
var stock = stock(side);
|
||||
if (bus == null || stock.isEmpty() || aspect != AspectIds.findAspectById(stock.aspectId())) return 0;
|
||||
var grid = bus.getMainNode().getGrid();
|
||||
if (grid == null) return 0;
|
||||
var buffer = (EssentiaTransferBuffer) bus;
|
||||
return (int) EssentiaEnergy.transfer(grid, Math.min(amount, stock.amount()), allowed -> {
|
||||
long remaining = stock.amount() - allowed;
|
||||
buffer.thE$setTransferBuffer(remaining == 0 ? AspectStack.EMPTY : new AspectStack(stock.aspectId(), remaining));
|
||||
return allowed;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package thaumicenergistics.common.essentia.capability;
|
||||
|
||||
import java.util.function.DoubleConsumer;
|
||||
import java.util.function.DoubleUnaryOperator;
|
||||
import java.util.function.LongUnaryOperator;
|
||||
|
||||
/** 先取得能量预算再搬运,部分接收只结算实际量,退回未使用的预算。 */
|
||||
public final class TransferBudget {
|
||||
private TransferBudget() {
|
||||
}
|
||||
|
||||
public static long transfer(long requested, double unitCost, DoubleUnaryOperator reserve,
|
||||
DoubleConsumer refund, LongUnaryOperator operation) {
|
||||
if (requested <= 0 || !Double.isFinite(unitCost) || unitCost <= 0) {
|
||||
return 0;
|
||||
}
|
||||
double reserved = reserve.applyAsDouble(requested * unitCost);
|
||||
long allowed = Math.min(requested, (long) Math.floor((reserved + 1.0e-9) / unitCost));
|
||||
long moved = 0;
|
||||
try {
|
||||
if (allowed > 0) {
|
||||
long transferred = operation.applyAsLong(allowed);
|
||||
if (transferred < 0 || transferred > allowed) {
|
||||
throw new IllegalStateException("Transfer exceeded its reserved resource budget");
|
||||
}
|
||||
moved = transferred;
|
||||
}
|
||||
return moved;
|
||||
} finally {
|
||||
double unused = reserved - moved * unitCost;
|
||||
if (unused > 1.0e-9) {
|
||||
refund.accept(unused);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package thaumicenergistics.common.features;
|
||||
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.CraftingBookCategory;
|
||||
import net.minecraft.world.item.crafting.CraftingInput;
|
||||
import net.minecraft.world.item.crafting.CustomRecipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.neoforged.fml.ModList;
|
||||
import thaumicenergistics.common.integration.ae2wt.SafeTerminalMerge;
|
||||
import thaumicenergistics.common.integration.ae2wt.AE2WTCompat;
|
||||
import thaumicenergistics.init.ModItems;
|
||||
import thaumicenergistics.init.ModRecipeSerializers;
|
||||
|
||||
public final class SafeTerminalMergeRecipe extends CustomRecipe {
|
||||
private final String partner;
|
||||
|
||||
public SafeTerminalMergeRecipe(String partner) {
|
||||
super(CraftingBookCategory.EQUIPMENT);
|
||||
this.partner = partner;
|
||||
}
|
||||
|
||||
private ItemStack merge(CraftingInput input) {
|
||||
if (!ModList.get().isLoaded("ae2wtlib") || input.ingredientCount() != 2) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
ItemStack arcane = ItemStack.EMPTY;
|
||||
ItemStack other = ItemStack.EMPTY;
|
||||
for (int i = 0; i < input.size(); i++) {
|
||||
var stack = input.getItem(i);
|
||||
if (stack.isEmpty()) continue;
|
||||
if (stack.is(ModItems.WIRELESS_ARCANE_CRAFTING_TERMINAL.get())) {
|
||||
if (!arcane.isEmpty()) return ItemStack.EMPTY;
|
||||
arcane = stack;
|
||||
} else {
|
||||
other = stack;
|
||||
}
|
||||
}
|
||||
return arcane.isEmpty() || other.isEmpty() ? ItemStack.EMPTY
|
||||
: SafeTerminalMerge.merge(arcane, other, partner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(CraftingInput input, Level level) {
|
||||
return !merge(input).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack assemble(CraftingInput input, HolderLookup.Provider registries) {
|
||||
return merge(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCraftInDimensions(int width, int height) {
|
||||
return width * height >= 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
return ModRecipeSerializers.SAFE_TERMINAL_MERGE.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<Ingredient> getIngredients() {
|
||||
var ingredients = NonNullList.<Ingredient>create();
|
||||
if (ModList.get().isLoaded("ae2wtlib")) {
|
||||
var other = AE2WTCompat.displayPartner(partner);
|
||||
if (!other.isEmpty()) {
|
||||
ingredients.add(Ingredient.of(ModItems.WIRELESS_ARCANE_CRAFTING_TERMINAL.get()));
|
||||
ingredients.add(Ingredient.of(other));
|
||||
}
|
||||
}
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getResultItem(HolderLookup.Provider registries) {
|
||||
return displayResult();
|
||||
}
|
||||
|
||||
public ItemStack displayResult() {
|
||||
if (!ModList.get().isLoaded("ae2wtlib")) return ItemStack.EMPTY;
|
||||
return SafeTerminalMerge.merge(new ItemStack(ModItems.WIRELESS_ARCANE_CRAFTING_TERMINAL.get()),
|
||||
AE2WTCompat.displayPartner(partner), partner);
|
||||
}
|
||||
|
||||
public static final class Serializer implements RecipeSerializer<SafeTerminalMergeRecipe> {
|
||||
private static final MapCodec<SafeTerminalMergeRecipe> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
||||
instance.group(com.mojang.serialization.Codec.STRING.optionalFieldOf("partner", "")
|
||||
.forGetter(recipe -> recipe.partner)).apply(instance, SafeTerminalMergeRecipe::new));
|
||||
private static final StreamCodec<RegistryFriendlyByteBuf, SafeTerminalMergeRecipe> STREAM_CODEC =
|
||||
StreamCodec.composite(ByteBufCodecs.STRING_UTF8, recipe -> recipe.partner,
|
||||
SafeTerminalMergeRecipe::new);
|
||||
|
||||
@Override
|
||||
public MapCodec<SafeTerminalMergeRecipe> codec() {
|
||||
return CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamCodec<RegistryFriendlyByteBuf, SafeTerminalMergeRecipe> streamCodec() {
|
||||
return STREAM_CODEC;
|
||||
}
|
||||
}
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
package thaumicenergistics.common.integration.appeng;
|
||||
|
||||
import appeng.api.behaviors.ContainerItemStrategy;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.stacks.GenericStack;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import thaumicenergistics.common.integration.tc.EssentiaItemContainers;
|
||||
import thaumicenergistics.common.integration.tc.TCReflection;
|
||||
import thaumicenergistics.common.integration.tc.ThEEssentiaContainers;
|
||||
|
||||
/** 标准 AE2 填充/抽空和幽灵槽转换共用真实容器上下文。 */
|
||||
public final class EssentiaContainerItemStrategy
|
||||
implements ContainerItemStrategy<AEssentiaKey, EssentiaContainerItemStrategy.Context> {
|
||||
public record Context(Player player, @Nullable AbstractContainerMenu menu, int slot) {
|
||||
ItemStack stack() {
|
||||
return menu != null ? menu.getCarried() : player.getInventory().getItem(slot);
|
||||
}
|
||||
|
||||
void replace(ItemStack replacement) {
|
||||
var source = stack();
|
||||
if (source.getCount() == 1) {
|
||||
if (menu != null) menu.setCarried(replacement);
|
||||
else player.getInventory().setItem(slot, replacement);
|
||||
} else {
|
||||
source.shrink(1);
|
||||
if (!player.getInventory().add(replacement)) player.drop(replacement, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public GenericStack getContainedStack(ItemStack stack) {
|
||||
var recovered = recoveredContent(stack);
|
||||
if (recovered != null) return recovered;
|
||||
var contents = EssentiaItemContainers.contents(stack);
|
||||
for (var aspect : contents.getAspects()) {
|
||||
var id = TCReflection.getAspectId(aspect);
|
||||
if (id != null && contents.getAmount(aspect) > 0) {
|
||||
return new GenericStack(AEssentiaKey.of(id), contents.getAmount(aspect));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Context findCarriedContext(Player player, AbstractContainerMenu menu) {
|
||||
return supported(menu.getCarried())
|
||||
? new Context(player, menu, -1) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Context findPlayerSlotContext(Player player, int slot) {
|
||||
return slot >= 0 && slot < player.getInventory().getContainerSize()
|
||||
&& supported(player.getInventory().getItem(slot))
|
||||
? new Context(player, null, slot) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long extract(Context context, AEssentiaKey key, long amount, Actionable mode) {
|
||||
var recovered = recoveredContent(context.stack());
|
||||
if (recovered != null) {
|
||||
if (!recovered.what().equals(key) || amount <= 0) return 0;
|
||||
long extracted = Math.min(amount, recovered.amount());
|
||||
if (mode == Actionable.MODULATE) {
|
||||
long left = recovered.amount() - extracted;
|
||||
context.replace(left > 0 ? GenericStack.wrapInItemStack(key, left) : ItemStack.EMPTY);
|
||||
}
|
||||
return extracted;
|
||||
}
|
||||
var aspect = TCReflection.findAspectById(key.getId());
|
||||
if (aspect == null || amount <= 0) return 0;
|
||||
var contents = EssentiaItemContainers.contents(context.stack());
|
||||
int extracted = (int) Math.min(amount, contents.getAmount(aspect));
|
||||
if (extracted <= 0) return 0;
|
||||
contents.remove(aspect, extracted);
|
||||
var replacement = EssentiaItemContainers.withContents(context.stack(), contents);
|
||||
if (replacement == null) return 0;
|
||||
if (mode == Actionable.MODULATE) context.replace(replacement);
|
||||
return extracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long insert(Context context, AEssentiaKey key, long amount, Actionable mode) {
|
||||
if (!ThEEssentiaContainers.isEssentiaContainer(context.stack())) return 0;
|
||||
var aspect = TCReflection.findAspectById(key.getId());
|
||||
if (aspect == null || amount <= 0) return 0;
|
||||
var contents = EssentiaItemContainers.contents(context.stack());
|
||||
for (var existing : contents.getAspects()) {
|
||||
if (existing != aspect) return 0;
|
||||
}
|
||||
int capacity = ThEEssentiaContainers.isJar(context.stack()) ? 64 : 8;
|
||||
int inserted = (int) Math.min(amount, Math.max(0, capacity - contents.getAmount(aspect)));
|
||||
if (inserted <= 0) return 0;
|
||||
contents.add(aspect, inserted);
|
||||
var replacement = EssentiaItemContainers.withContents(context.stack(), contents);
|
||||
if (replacement == null) return 0;
|
||||
if (mode == Actionable.MODULATE) context.replace(replacement);
|
||||
return inserted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playFillSound(Player player, AEssentiaKey key) {
|
||||
player.playSound(net.minecraft.sounds.SoundEvents.BOTTLE_FILL, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playEmptySound(Player player, AEssentiaKey key) {
|
||||
player.playSound(net.minecraft.sounds.SoundEvents.BOTTLE_EMPTY, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public GenericStack getExtractableContent(Context context) {
|
||||
return getContainedStack(context.stack());
|
||||
}
|
||||
|
||||
private static boolean supported(ItemStack stack) {
|
||||
return ThEEssentiaContainers.isEssentiaContainer(stack) || recoveredContent(stack) != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static GenericStack recoveredContent(ItemStack stack) {
|
||||
var wrapped = GenericStack.unwrapItemStack(stack);
|
||||
return wrapped != null && wrapped.what() instanceof AEssentiaKey && wrapped.amount() > 0
|
||||
? wrapped : null;
|
||||
}
|
||||
}
|
||||
+263
@@ -0,0 +1,263 @@
|
||||
package thaumicenergistics.common.integration.appeng;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
import appeng.helpers.externalstorage.GenericStackInv;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.stacks.GenericStack;
|
||||
import appeng.api.storage.MEStorage;
|
||||
import appeng.api.upgrades.IUpgradeInventory;
|
||||
import appeng.core.definitions.AEItems;
|
||||
import appeng.helpers.InterfaceLogic;
|
||||
import appeng.helpers.InterfaceLogicHost;
|
||||
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
|
||||
import thaumicenergistics.api.storage.AspectStack;
|
||||
import thaumicenergistics.common.integration.appeng.AEssentiaKey;
|
||||
import thaumicenergistics.common.integration.appeng.IEssentiaInterfaceLogic;
|
||||
import thaumicenergistics.common.integration.tc.AspectIds;
|
||||
import thaumicenergistics.init.ModItems;
|
||||
|
||||
|
||||
/** ME 接口的源质业务状态;Mixin 仅负责转发宿主字段和生命周期。 */
|
||||
public final class EssentiaInterfaceState implements IEssentiaInterfaceLogic {
|
||||
private final Supplier<MEStorage> networkStorage;
|
||||
private final Supplier<GenericStackInv> storage;
|
||||
private final Supplier<IUpgradeInventory> upgrades;
|
||||
private final Supplier<IActionSource> actionSource;
|
||||
private final Supplier<IGridNode> node;
|
||||
private AspectStack thE$essentiaBuffer = AspectStack.EMPTY;
|
||||
|
||||
public EssentiaInterfaceState(Supplier<MEStorage> networkStorage, Supplier<GenericStackInv> storage,
|
||||
Supplier<IUpgradeInventory> upgrades, Supplier<IActionSource> actionSource, Supplier<IGridNode> node) {
|
||||
this.networkStorage = networkStorage;
|
||||
this.storage = storage;
|
||||
this.upgrades = upgrades;
|
||||
this.actionSource = actionSource;
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
private boolean thE$hasEssentiaCard() {
|
||||
return upgrades.get().isInstalled(ModItems.ESSENTIA_UPGRADE_CARD.get());
|
||||
}
|
||||
|
||||
public boolean hasBuffered() {
|
||||
return !thE$essentiaBuffer.isEmpty();
|
||||
}
|
||||
|
||||
public void save(CompoundTag tag) {
|
||||
tag.remove("ThEEssentiaInterfaceBufferAspect");
|
||||
tag.remove("ThEEssentiaInterfaceBufferAmount");
|
||||
if (hasBuffered()) {
|
||||
tag.putString("ThEEssentiaInterfaceBufferAspect", thE$essentiaBuffer.aspectId().toString());
|
||||
tag.putLong("ThEEssentiaInterfaceBufferAmount", thE$essentiaBuffer.amount());
|
||||
}
|
||||
}
|
||||
|
||||
public void load(CompoundTag tag) {
|
||||
clear();
|
||||
var id = ResourceLocation.tryParse(tag.getString("ThEEssentiaInterfaceBufferAspect"));
|
||||
long amount = tag.getLong("ThEEssentiaInterfaceBufferAmount");
|
||||
if (id != null && amount > 0) thE$essentiaBuffer = new AspectStack(id, amount);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
thE$essentiaBuffer = AspectStack.EMPTY;
|
||||
}
|
||||
|
||||
public void addBufferedDrops(List<ItemStack> drops) {
|
||||
if (hasBuffered()) {
|
||||
var key = AEssentiaKey.of(thE$essentiaBuffer.aspectId());
|
||||
drops.add(GenericStack.wrapInItemStack(key, thE$essentiaBuffer.amount()));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean thE$essentiaActive() {
|
||||
// 联网判据用 networkStorage(InterfaceLogic 自身即以它作「是否挂网」的判断,见 getInventory())
|
||||
return thE$hasEssentiaCard() && networkStorage.get() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int thE$simulateAcceptEssentia(Aspect aspect, int amount) {
|
||||
if (!thE$essentiaActive() || aspect == null || amount <= 0) {
|
||||
return 0;
|
||||
}
|
||||
AEssentiaKey key = thE$essentiaKey(aspect);
|
||||
if (key == null) {
|
||||
return 0;
|
||||
}
|
||||
// 模拟只检查容量,不搬动缓冲中的资源。
|
||||
if (!this.thE$essentiaBuffer.isEmpty() && !this.thE$essentiaBuffer.aspectId().equals(key.getId())) {
|
||||
return 0;
|
||||
}
|
||||
int want = Math.min(amount, thE$transportLimit());
|
||||
long room = networkStorage.get().insert(key, want, Actionable.SIMULATE, actionSource.get());
|
||||
return (int) Math.min(room, want);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int thE$acceptEssentia(Aspect aspect, int amount) {
|
||||
if (!thE$essentiaActive() || aspect == null || amount <= 0) {
|
||||
return 0;
|
||||
}
|
||||
AEssentiaKey key = thE$essentiaKey(aspect);
|
||||
if (key == null) {
|
||||
return 0;
|
||||
}
|
||||
// 缓冲被异类占用 → 先冲;仍占用则拒收(源质留在外部,绝不丢弃)
|
||||
if (!this.thE$essentiaBuffer.isEmpty() && !this.thE$essentiaBuffer.aspectId().equals(key.getId())) {
|
||||
thE$flushEssentiaBuffer();
|
||||
if (!this.thE$essentiaBuffer.isEmpty() && !this.thE$essentiaBuffer.aspectId().equals(key.getId())) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
int want = Math.min(amount, thE$transportLimit());
|
||||
long room = networkStorage.get().insert(key, want, Actionable.SIMULATE, actionSource.get());
|
||||
if (room <= 0) {
|
||||
return 0;
|
||||
}
|
||||
int accepted = (int) Math.min(room, want);
|
||||
long existing = this.thE$essentiaBuffer.isEmpty() ? 0 : this.thE$essentiaBuffer.amount();
|
||||
this.thE$essentiaBuffer = new AspectStack(key.getId(), existing + accepted);
|
||||
thE$saveHost();
|
||||
// 尽力立即注入(残留留缓冲,交 tick 循环下轮冲)
|
||||
thE$flushEssentiaBuffer();
|
||||
return accepted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Aspect thE$stockAspect() {
|
||||
if (!thE$essentiaActive()) {
|
||||
return null;
|
||||
}
|
||||
// TC 传输面是单要素契约;遍历实际库存大小以覆盖扩展接口。
|
||||
for (int i = 0; i < storage.get().size(); i++) {
|
||||
if (storage.get().getKey(i) instanceof AEssentiaKey key) {
|
||||
return AspectIds.findAspectById(key.getId());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int thE$stockAmount(Aspect aspect) {
|
||||
if (!thE$essentiaActive() || aspect == null) {
|
||||
return 0;
|
||||
}
|
||||
AEssentiaKey key = thE$essentiaKey(aspect);
|
||||
if (key == null) {
|
||||
return 0;
|
||||
}
|
||||
long sum = 0;
|
||||
for (int i = 0; i < storage.get().size(); i++) {
|
||||
if (storage.get().getKey(i) instanceof AEssentiaKey k && k.equals(key)) {
|
||||
sum += storage.get().getAmount(i);
|
||||
}
|
||||
}
|
||||
return (int) Math.min(sum, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int thE$simulateTakeFromStock(Aspect aspect, int amount) {
|
||||
if (!thE$essentiaActive() || aspect == null || amount <= 0) {
|
||||
return 0;
|
||||
}
|
||||
AEssentiaKey key = thE$essentiaKey(aspect);
|
||||
if (key == null) {
|
||||
return 0;
|
||||
}
|
||||
long canTake = storage.get().extract(key, amount, Actionable.SIMULATE, actionSource.get());
|
||||
return (int) Math.min(canTake, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int thE$takeFromStock(Aspect aspect, int amount) {
|
||||
if (!thE$essentiaActive() || aspect == null || amount <= 0) {
|
||||
return 0;
|
||||
}
|
||||
AEssentiaKey key = thE$essentiaKey(aspect);
|
||||
if (key == null) {
|
||||
return 0;
|
||||
}
|
||||
// 仅从缓存格(stock 槽)取出——禁止直取网络
|
||||
long taken = storage.get().extract(key, amount, Actionable.MODULATE, actionSource.get());
|
||||
return (int) taken;
|
||||
}
|
||||
|
||||
/** 把缓冲里的源质注入网络(成功即落盘 + 按实际入网量 double 记账)。@return 本次注入量 */
|
||||
public long thE$flushEssentiaBuffer() {
|
||||
if (this.thE$essentiaBuffer.isEmpty() || networkStorage.get() == null) {
|
||||
return 0;
|
||||
}
|
||||
AEssentiaKey key = AEssentiaKey.of(this.thE$essentiaBuffer.aspectId());
|
||||
if (key == null) {
|
||||
this.thE$essentiaBuffer = AspectStack.EMPTY;
|
||||
return 0;
|
||||
}
|
||||
var grid = thE$grid();
|
||||
if (grid == null) return 0;
|
||||
long injected = thaumicenergistics.common.essentia.capability.EssentiaEnergy.transfer(
|
||||
grid, this.thE$essentiaBuffer.amount(), allowed -> networkStorage.get().insert(
|
||||
key, allowed, Actionable.MODULATE, actionSource.get()));
|
||||
if (injected <= 0) {
|
||||
return 0;
|
||||
}
|
||||
long left = this.thE$essentiaBuffer.amount() - injected;
|
||||
this.thE$essentiaBuffer = left > 0
|
||||
? new AspectStack(this.thE$essentiaBuffer.aspectId(), left)
|
||||
: AspectStack.EMPTY;
|
||||
thE$saveHost();
|
||||
return injected;
|
||||
}
|
||||
|
||||
/** 通知宿主保存(缓冲为新增字段,需显式落盘)。经节点 owner 取得宿主,不新增 @Shadow。 */
|
||||
private void thE$saveHost() {
|
||||
IGridNode node = thE$actionableNode();
|
||||
Object owner = node != null ? node.getOwner() : null;
|
||||
if (owner instanceof InterfaceLogicHost host) {
|
||||
host.saveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
/** 本逻辑所在网格(未挂网 → null)。经公开 getActionableNode() 取得,避开父类陷阱。 */
|
||||
private IGrid thE$grid() {
|
||||
IGridNode node = thE$actionableNode();
|
||||
return node != null ? node.getGrid() : null;
|
||||
}
|
||||
|
||||
private IGridNode thE$actionableNode() {
|
||||
return node.get();
|
||||
}
|
||||
|
||||
/** 单次搬运上限 = 8 × 每 tick 操作次数(仅计 AE2 加速卡,与供应器同口径)。 */
|
||||
private int thE$transportLimit() {
|
||||
int installed = upgrades.get().getInstalledUpgrades(AEItems.SPEED_CARD);
|
||||
int ops = switch (installed) {
|
||||
default -> 1;
|
||||
case 1 -> 8;
|
||||
case 2 -> 32;
|
||||
case 3 -> 64;
|
||||
case 4 -> 96;
|
||||
};
|
||||
return 8 * Math.max(1, ops);
|
||||
}
|
||||
|
||||
/** Aspect → AEssentiaKey(转换为空 → null)。 */
|
||||
private AEssentiaKey thE$essentiaKey(Aspect aspect) {
|
||||
if (aspect == null) {
|
||||
return null;
|
||||
}
|
||||
ResourceLocation id = AspectIds.getAspectId(aspect);
|
||||
return id == null ? null : AEssentiaKey.of(id);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package thaumicenergistics.common.integration.appeng;
|
||||
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.upgrades.IUpgradeableObject;
|
||||
import appeng.helpers.patternprovider.PatternProviderTarget;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import thaumcraft.api.aspects.IAspectContainer;
|
||||
import thaumicenergistics.common.integration.tc.EssentiaEndpoints;
|
||||
import thaumicenergistics.init.ModItems;
|
||||
|
||||
/** 所有供应器共用已持有资源的输出目标;可选兼容层仅提供宿主和访问面。 */
|
||||
public final class ProviderEssentiaTargets {
|
||||
private ProviderEssentiaTargets() { }
|
||||
|
||||
public static boolean hasCard(Object host) {
|
||||
return host instanceof IUpgradeableObject upgradeable
|
||||
&& upgradeable.getUpgrades().isInstalled(ModItems.ESSENTIA_UPGRADE_CARD.get());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PatternProviderTarget wrap(@Nullable PatternProviderTarget original, @Nullable IGrid grid,
|
||||
IActionSource source, @Nullable BlockEntity target, @Nullable Direction face) {
|
||||
if (grid == null || target == null || !(target instanceof IAspectContainer)
|
||||
&& EssentiaEndpoints.transport(target, face) == null) return original;
|
||||
if (original instanceof ThEEssentiaPushTarget || original instanceof ThECompositePushTarget) return original;
|
||||
var essentia = new ThEEssentiaPushTarget(grid, source, target, face);
|
||||
return original == null ? essentia : new ThECompositePushTarget(original, essentia);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PatternProviderTarget fromSource(@Nullable PatternProviderTarget original, IActionSource source,
|
||||
@Nullable BlockEntity target, @Nullable Direction face) {
|
||||
var machine = source.machine().orElse(null);
|
||||
if (!hasCard(machine)) return original;
|
||||
var node = machine.getActionableNode();
|
||||
return wrap(original, node != null ? node.getGrid() : null, source, target, face);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package thaumicenergistics.common.integration.extendedae;
|
||||
|
||||
import appeng.api.upgrades.Upgrades;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.neoforged.fml.ModList;
|
||||
|
||||
import thaumicenergistics.ThaumicEnergistics;
|
||||
import thaumicenergistics.init.ModItems;
|
||||
|
||||
/**
|
||||
* Extended AE(extendedae)可选兼容:把源质访问卡准入注册到其扩展样板供应器与超大接口。
|
||||
* <p>
|
||||
* 为什么只做注册:EAE 两类宿主(方块/部件)的 Logic 均复用 AE2 的
|
||||
* {@code PatternProviderLogic} 与 {@code InterfaceLogic}(2.2.35 jar javap 实证),
|
||||
* 本项目对这两个 Logic 类的 Mixin(卡槽组 + 源质组)对其自动生效,
|
||||
* 唯一缺口是 {@code Upgrades.add} 宿主准入——此处补齐即可,零 EAE 编译引用。
|
||||
* <p>
|
||||
* 为什么升级库存宿主物品必然匹配:EAE 宿主的 {@code getTerminalIcon()} 覆写返回
|
||||
* EAE 自身物品(部件返回 part item、方块返回 EX_PATTERN_PROVIDER),超大接口走
|
||||
* AE2 {@code createLogic()} 传 {@code getItemFromBlockEntity()} / 构造器 partItem——
|
||||
* 与本类注册的四个 ID 一一对应,AE2 准入查询({@code Upgrades.getMaxInstallable})成立。
|
||||
*/
|
||||
public final class ThEExtendedAE {
|
||||
|
||||
public static final String MOD_ID = "extendedae";
|
||||
|
||||
private ThEExtendedAE() {
|
||||
}
|
||||
|
||||
public static void registerEssentiaUpgrades() {
|
||||
if (!ModList.get().isLoaded(MOD_ID)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Item card = ModItems.ESSENTIA_UPGRADE_CARD.get();
|
||||
|
||||
// 同设备方块/部件显示名相同(EAE zh_cn/en_us lang 实证),tooltipGroup 传
|
||||
// EAE 方块翻译键使「支持设备」列表合并显示,对齐本项目 MGMT-TOOLTIP 范式。
|
||||
registerHost(card, "ex_pattern_provider", "block.extendedae.ex_pattern_provider");
|
||||
registerHost(card, "ex_pattern_provider_part", "block.extendedae.ex_pattern_provider");
|
||||
registerHost(card, "oversize_interface", "block.extendedae.oversize_interface");
|
||||
registerHost(card, "oversize_interface_part", "block.extendedae.oversize_interface");
|
||||
}
|
||||
|
||||
private static void registerHost(Item card, String path, String tooltipGroup) {
|
||||
ResourceLocation id = ResourceLocation.fromNamespaceAndPath(MOD_ID, path);
|
||||
|
||||
Item host = BuiltInRegistries.ITEM.getOptional(id).orElse(null);
|
||||
|
||||
if (host == null || host == Items.AIR) {
|
||||
// EAE 版本差异(增删设备/改 ID)时静默跳过该项,不允许启动失败。
|
||||
ThaumicEnergistics.LOG
|
||||
.warn("Skipping Extended AE essentia upgrade registration: missing host item {}", id);
|
||||
return;
|
||||
}
|
||||
|
||||
Upgrades.add(card, host, 1, tooltipGroup);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package thaumicenergistics.common.integration.tc;
|
||||
|
||||
import java.util.List;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import thaumcraft.api.aspects.EssentiaCapabilities;
|
||||
import thaumcraft.api.aspects.IEssentiaTransport;
|
||||
import thaumcraft.common.blockentities.JarBlockEntity;
|
||||
import thaumicenergistics.api.storage.AspectStack;
|
||||
|
||||
/** TC 能力优先,固定版本的炼金炉等遗留容器由兼容回退处理。 */
|
||||
public final class EssentiaEndpoints {
|
||||
private EssentiaEndpoints() {
|
||||
}
|
||||
|
||||
/** ME accesses the jar's contents from any face; other machines retain their sided ports. */
|
||||
@Nullable
|
||||
public static Direction accessSide(BlockEntity be, @Nullable Direction side) {
|
||||
return be instanceof JarBlockEntity && side != null ? Direction.UP : side;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IEssentiaTransport transport(BlockEntity be, @Nullable Direction side) {
|
||||
return be == null || be.getLevel() == null ? null
|
||||
: EssentiaCapabilities.find(be.getLevel(), be.getBlockPos(), side);
|
||||
}
|
||||
|
||||
public static List<AspectStack> contents(BlockEntity be, @Nullable Direction side) {
|
||||
side = accessSide(be, side);
|
||||
var transport = transport(be, side);
|
||||
if (transport == null || side == null) return TCReflection.listEssentia(be);
|
||||
if (!transport.isConnectable(side) || !transport.canOutputTo(side)) return List.of();
|
||||
var id = AspectIds.getAspectId(transport.getEssentiaType(side));
|
||||
int amount = transport.getEssentiaAmount(side);
|
||||
return id == null || amount <= 0 ? List.of() : List.of(new AspectStack(id, amount));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static AspectStack extract(BlockEntity be, ResourceLocation id, int amount, @Nullable Direction side) {
|
||||
side = accessSide(be, side);
|
||||
var transport = transport(be, side);
|
||||
if (transport == null || side == null) return TCReflection.extractEssentia(be, id, amount);
|
||||
var aspect = AspectIds.findAspectById(id);
|
||||
if (aspect == null || !transport.isConnectable(side) || !transport.canOutputTo(side)) return null;
|
||||
int taken = Math.max(0, Math.min(amount, transport.takeEssentia(aspect, amount, side)));
|
||||
if (taken > 0) {
|
||||
be.setChanged();
|
||||
return new AspectStack(id, taken);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int insert(BlockEntity be, ResourceLocation id, int amount, @Nullable Direction side) {
|
||||
if (amount <= 0 || (be instanceof JarBlockEntity jar
|
||||
&& !jar.doesContainerAccept(AspectIds.findAspectById(id)))) return 0;
|
||||
side = accessSide(be, side);
|
||||
var transport = transport(be, side);
|
||||
if (transport == null || side == null) {
|
||||
return TCReflection.insertEssentia(be, new AspectStack(id, amount));
|
||||
}
|
||||
var aspect = AspectIds.findAspectById(id);
|
||||
if (aspect == null || !transport.isConnectable(side) || !transport.canInputFrom(side)) return 0;
|
||||
int inserted = Math.max(0, Math.min(amount, transport.addEssentia(aspect, amount, side)));
|
||||
if (inserted > 0) be.setChanged();
|
||||
return inserted;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package thaumicenergistics.common.integration.tc;
|
||||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
import thaumcraft.api.aspects.AspectList;
|
||||
import thaumcraft.api.aspects.IEssentiaContainerItem;
|
||||
|
||||
/** 按 TC 的真实物品组件保存剩余源质,不把部分成功假定为可回滚的事务。 */
|
||||
public final class EssentiaItemContainers {
|
||||
private EssentiaItemContainers() {
|
||||
}
|
||||
|
||||
public static AspectList contents(ItemStack stack) {
|
||||
if (ThEEssentiaContainers.isEssentiaContainer(stack)
|
||||
&& stack.getItem() instanceof IEssentiaContainerItem container) {
|
||||
var aspects = container.getAspects(stack);
|
||||
if (aspects != null) {
|
||||
return aspects.copy();
|
||||
}
|
||||
}
|
||||
return new AspectList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ItemStack withContents(ItemStack original, AspectList contents) {
|
||||
ItemStack result;
|
||||
if (ThEEssentiaContainers.isJar(original)) {
|
||||
result = original.copyWithCount(1);
|
||||
} else if (ThEEssentiaContainers.isPhial(original)) {
|
||||
String path = contents.isEmpty() ? "glass_phial" : "phial_of_essentia";
|
||||
var item = BuiltInRegistries.ITEM.getOptional(
|
||||
ResourceLocation.fromNamespaceAndPath("thaumcraft", path)).orElse(null);
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
result = new ItemStack(item);
|
||||
result.applyComponents(original.getComponentsPatch());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
if (result.getItem() instanceof IEssentiaContainerItem container) {
|
||||
container.setAspects(result, contents);
|
||||
var actual = contents(result);
|
||||
for (Aspect aspect : contents.getAspects()) {
|
||||
if (actual.getAmount(aspect) != contents.getAmount(aspect)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (actual.visSize() != contents.visSize()) {
|
||||
return null;
|
||||
}
|
||||
} else if (!contents.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// Jars never change identity when filled or drained. Phials intentionally change item type.
|
||||
// Enforce this for both native AE2 container interactions and our terminal packet paths.
|
||||
if (ThEEssentiaContainers.isJar(original) && result.getItem() != original.getItem()) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package thaumicenergistics.common.integration.tc;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
import thaumcraft.api.aspects.AspectList;
|
||||
import thaumicenergistics.api.storage.AspectStack;
|
||||
|
||||
/** port.261 炼金炉的私有方面缓存兼容,公开 capability 无法覆盖时才调用。 */
|
||||
final class LegacyFurnaceEssentia {
|
||||
private static volatile java.lang.reflect.Field furnaceAspectsField;
|
||||
private static final java.util.Set<Class<?>> WARNED = java.util.concurrent.ConcurrentHashMap.newKeySet();
|
||||
private LegacyFurnaceEssentia() { }
|
||||
|
||||
/** 读取荒古炼金炉 private aspects 字段(不实现 IAspectContainer;只读,返回活引用用于原地修改)。 */
|
||||
@Nullable
|
||||
static AspectList getFurnaceAspects(BlockEntity be) {
|
||||
try {
|
||||
if (furnaceAspectsField == null) {
|
||||
furnaceAspectsField = be.getClass().getDeclaredField("aspects");
|
||||
furnaceAspectsField.setAccessible(true);
|
||||
}
|
||||
Object raw = furnaceAspectsField.get(be);
|
||||
return raw instanceof AspectList list ? list : null;
|
||||
} catch (ReflectiveOperationException | RuntimeException e) {
|
||||
if (WARNED.add(be.getClass())) thaumicenergistics.ThaumicEnergistics.LOG.warn(
|
||||
"Legacy furnace essentia adapter cannot read {}: {}", be.getClass().getName(), e.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** 荒古炼金炉写回(aspects 为 private 字段,无公开写入 API)。返回实际写入量。 */
|
||||
static int addToFurnace(BlockEntity be, Aspect aspect, int amount) {
|
||||
if (amount <= 0) return 0;
|
||||
try {
|
||||
AspectList list = getFurnaceAspects(be);
|
||||
if (list == null) {
|
||||
if (furnaceAspectsField == null) return 0;
|
||||
list = new AspectList();
|
||||
furnaceAspectsField.set(be, list);
|
||||
}
|
||||
list.add(aspect, amount);
|
||||
be.setChanged();
|
||||
return amount;
|
||||
} catch (Exception e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/** 从荒古炼金炉内部源质缓存直接抽取(替代蒸馏釜/罐子中转)。only 非空时只抽指定方面。 */
|
||||
@Nullable
|
||||
static AspectStack extractFromFurnace(BlockEntity be, @Nullable ResourceLocation only, int maxAmount) {
|
||||
AspectList furnaceAspects = getFurnaceAspects(be);
|
||||
if (furnaceAspects == null || furnaceAspects.size() <= 0) return null;
|
||||
for (Aspect aspect : furnaceAspects.getAspects()) {
|
||||
if (aspect == null) continue;
|
||||
int amt = furnaceAspects.getAmount(aspect);
|
||||
if (amt <= 0) continue;
|
||||
ResourceLocation id = AspectIds.getAspectId(aspect);
|
||||
if (id == null) continue;
|
||||
if (only != null && !only.equals(id)) continue;
|
||||
int toExtract = Math.min(amt, maxAmount);
|
||||
furnaceAspects.remove(aspect, toExtract);
|
||||
be.setChanged();
|
||||
return new AspectStack(id, toExtract);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package thaumicenergistics.common.inventory;
|
||||
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.component.ItemContainerContents;
|
||||
import appeng.util.inv.AppEngInternalInventory;
|
||||
import appeng.util.inv.InternalInventoryHost;
|
||||
|
||||
public final class PersistedTerminalInventories {
|
||||
private PersistedTerminalInventories() {
|
||||
}
|
||||
|
||||
public static AppEngInternalInventory createPersistedInv(Player player, ItemStack stack, int size,
|
||||
DataComponentType<ItemContainerContents> component) {
|
||||
var inv = new AppEngInternalInventory(new InternalInventoryHost() {
|
||||
@Override
|
||||
public void saveChangedInventory(AppEngInternalInventory changed) {
|
||||
stack.set(component, changed.toItemContainerContents());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClientSide() {
|
||||
return player.level().isClientSide();
|
||||
}
|
||||
}, size);
|
||||
inv.fromItemContainerContents(stack.getOrDefault(component, ItemContainerContents.EMPTY));
|
||||
return inv;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package thaumicenergistics.common.monitor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import thaumicenergistics.ThaumicEnergistics;
|
||||
|
||||
/** 显示实体的创建、恢复、更新和移除;不负责风险采集或网络状态。 */
|
||||
public final class InfusionMonitorDisplay {
|
||||
private static final String BUBBLE_TAG = "thaumicenergistics:monitor_bubble";
|
||||
private static final int BUBBLE_BG_COLOR = 0xB0333333;
|
||||
private static final int BUBBLE_LINE_WIDTH = 320;
|
||||
private final Supplier<Level> levelSupplier;
|
||||
private final BlockPos position;
|
||||
private net.minecraft.world.entity.Display.TextDisplay bubble;
|
||||
private Component lastText;
|
||||
|
||||
public InfusionMonitorDisplay(Supplier<Level> levelSupplier, BlockPos position) {
|
||||
this.levelSupplier = levelSupplier;
|
||||
this.position = position.immutable();
|
||||
}
|
||||
|
||||
public void update(boolean visible, Component text) {
|
||||
var level = levelSupplier.get();
|
||||
if (level == null || level.isClientSide()) return;
|
||||
if (!visible) { discard(); return; }
|
||||
ensureBubble(level, text);
|
||||
if (bubble != null && !text.equals(lastText)) {
|
||||
applyBubbleNbt(level, text);
|
||||
lastText = text;
|
||||
}
|
||||
}
|
||||
|
||||
/** 确保气泡实体存在(不存在则生成;区块重载后按 Tag 找回旧实体)。 */
|
||||
private void ensureBubble(Level level, Component text) {
|
||||
if (bubble != null && bubble.isAlive()) return;
|
||||
bubble = findBubble(level);
|
||||
if (bubble != null) return;
|
||||
bubble = EntityType.TEXT_DISPLAY.create(level);
|
||||
if (bubble == null) return;
|
||||
bubble.setPos(position.getX() + 0.5, position.getY() + 1.2, position.getZ() + 0.5);
|
||||
// 通过公开实体保存/加载 API 配置 TextDisplay 的文本与显示字段。
|
||||
applyBubbleNbt(level, text);
|
||||
bubble.addTag(BUBBLE_TAG);
|
||||
level.addFreshEntity(bubble);
|
||||
}
|
||||
|
||||
private void applyBubbleNbt(Level level, Component text) {
|
||||
if (bubble == null || level == null) return;
|
||||
try {
|
||||
// 保存完整实体状态,公共 load 路径不会把位置、UUID 等字段重置为默认值。
|
||||
CompoundTag nbt = bubble.saveWithoutId(new CompoundTag());
|
||||
nbt.putString("text", Component.Serializer.toJson(text, level.registryAccess()));
|
||||
nbt.putBoolean("default_background", false);
|
||||
nbt.putInt("background", BUBBLE_BG_COLOR);
|
||||
nbt.putString("billboard", "vertical");
|
||||
nbt.putInt("line_width", BUBBLE_LINE_WIDTH);
|
||||
nbt.putBoolean("shadow", true);
|
||||
nbt.putBoolean("see_through", false);
|
||||
// 必须写 alignment:TextDisplay.readAdditionalSaveData 无条件 decode "alignment",
|
||||
// 缺失时 tag.get 返回 null → Align.CODEC(字符串) decode 失败 → 服务端疯狂刷 "Display entityNot a string"。
|
||||
nbt.putString("alignment", "center");
|
||||
// 文字调小:transformation.scale 整体缩到 0.5(text_display 无字号参数,靠实体缩放)
|
||||
CompoundTag transform = new CompoundTag();
|
||||
transform.put("scale", floatList(0.5F, 0.5F, 0.5F));
|
||||
transform.put("translation", floatList(0F, 0F, 0F));
|
||||
transform.put("left_rotation", floatList(0F, 0F, 0F, 1F));
|
||||
transform.put("right_rotation", floatList(0F, 0F, 0F, 1F));
|
||||
nbt.put("transformation", transform);
|
||||
bubble.load(nbt);
|
||||
} catch (Exception e) {
|
||||
ThaumicEnergistics.LOG.warn("[Monitor] 气泡配置失败: {}", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/** 构造 FloatTag 列表(1.21.1 CompoundTag 无 putFloatArray,需 ListTag)。 */
|
||||
private static net.minecraft.nbt.ListTag floatList(float... values) {
|
||||
net.minecraft.nbt.ListTag list = new net.minecraft.nbt.ListTag();
|
||||
for (float v : values) {
|
||||
list.add(net.minecraft.nbt.FloatTag.valueOf(v));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/** 按 Tag + 方块附近 AABB 查找已存在的气泡。 */
|
||||
private net.minecraft.world.entity.Display.TextDisplay findBubble(Level level) {
|
||||
if (level == null) return null;
|
||||
AABB aabb = new AABB(position).inflate(0.15, 2.0, 0.15);
|
||||
List<net.minecraft.world.entity.Display.TextDisplay> list = level.getEntitiesOfClass(
|
||||
net.minecraft.world.entity.Display.TextDisplay.class, aabb,
|
||||
e -> e.getTags().contains(BUBBLE_TAG)
|
||||
&& e.distanceToSqr(position.getX() + 0.5, position.getY() + 1.2, position.getZ() + 0.5) < 0.01);
|
||||
return list.isEmpty() ? null : list.get(0);
|
||||
}
|
||||
|
||||
/** 销毁气泡(方块拆除/条件不满足时)。 */
|
||||
public void discard() {
|
||||
Level level = levelSupplier.get();
|
||||
if (bubble != null && bubble.isAlive()) {
|
||||
bubble.discard();
|
||||
} else {
|
||||
net.minecraft.world.entity.Display.TextDisplay found = findBubble(level);
|
||||
if (found != null) {
|
||||
found.discard();
|
||||
}
|
||||
}
|
||||
bubble = null;
|
||||
lastText = null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package thaumicenergistics.common.monitor;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import thaumicenergistics.common.tiles.TileInfusionMonitor.RiskData;
|
||||
|
||||
/** 注魔风险的显示文字与颜色。 */
|
||||
public final class InfusionMonitorText {
|
||||
private InfusionMonitorText() { }
|
||||
|
||||
/** 风险数据 → 气泡多行文本(2 行:注魔风险/不稳定度;不显示基础+祭坛细分,细分在聊天栏)。 */
|
||||
public static Component bubble(RiskData risk) {
|
||||
// 内边距必须用不间断空格(\u00A0):普通空格在行尾会被字体布局裁剪,
|
||||
// 导致背景只包住左侧、右侧贴边。NBSP 有真实字形,两侧都保留。
|
||||
String pad = "\u00A0\u00A0"; // 左右内边距(NBSP)
|
||||
String tierWord = tierWord(risk.tier());
|
||||
|
||||
Component line1 = Component.literal(pad + "注魔风险: " + tierWord + pad)
|
||||
.withStyle(style -> style.withColor(tierColor(risk.tier())));
|
||||
Component line2 = Component.literal(pad + "不稳定度: " + risk.instability() + pad)
|
||||
.withStyle(style -> style.withColor(0xFFFFFFFF));
|
||||
|
||||
// 上下各留一个空行(垂直内边距)
|
||||
return Component.literal("\n")
|
||||
.append(line1).append("\n")
|
||||
.append(line2).append("\n");
|
||||
}
|
||||
|
||||
/** 5 档文字(无星星)。 */
|
||||
public static String tierWord(int tier) {
|
||||
return switch (tier) {
|
||||
case 1 -> "极低";
|
||||
case 2 -> "低";
|
||||
case 3 -> "中";
|
||||
case 4 -> "高";
|
||||
case 5 -> "极高";
|
||||
default -> "?";
|
||||
};
|
||||
}
|
||||
|
||||
/** 5 档描述(神秘时代风)。 */
|
||||
public static String tierDesc(int tier) {
|
||||
return switch (tier) {
|
||||
case 1 -> "灵光如镜,仪式安然";
|
||||
case 2 -> "灵光微澜,无碍仪式";
|
||||
case 3 -> "符文低鸣,灵光流转不宁";
|
||||
case 4 -> "裂隙于虚空中睁开,注视着祭坛";
|
||||
case 5 -> "咒波翻涌,裂隙将吞没一切";
|
||||
default -> "";
|
||||
};
|
||||
}
|
||||
|
||||
/** 档位颜色:1 绿 → 5 红。 */
|
||||
public static int tierColor(int tier) {
|
||||
return switch (tier) {
|
||||
case 1 -> 0xFF55FF55;
|
||||
case 2 -> 0xFFAAFF55;
|
||||
case 3 -> 0xFFFFFF55;
|
||||
case 4 -> 0xFFFFAA55;
|
||||
default -> 0xFFFF5555;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package thaumicenergistics.common.parts;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import appeng.helpers.WirelessTerminalMenuHost;
|
||||
import appeng.integration.modules.curios.CuriosIntegration;
|
||||
import appeng.items.tools.powered.WirelessTerminalItem;
|
||||
import appeng.menu.AEBaseMenu;
|
||||
import appeng.menu.locator.MenuLocators;
|
||||
import appeng.menu.locator.ItemMenuHostLocator;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.component.ItemContainerContents;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.ModList;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
||||
import net.neoforged.neoforge.event.server.ServerStoppedEvent;
|
||||
import net.neoforged.neoforge.event.tick.PlayerTickEvent;
|
||||
import thaumicenergistics.ThaumicEnergistics;
|
||||
import thaumicenergistics.common.container.IArcaneTerminalInventoryHost;
|
||||
import thaumicenergistics.common.integration.ae2wt.AE2WTCompat;
|
||||
import thaumicenergistics.common.items.WirelessArcaneCraftingTerminalItem;
|
||||
import thaumicenergistics.init.ModComponents;
|
||||
import thaumicenergistics.init.ModItems;
|
||||
|
||||
/** One server-side charging path for closed terminals and every universal-terminal mode. */
|
||||
@EventBusSubscriber(modid = ThaumicEnergistics.MODID)
|
||||
public final class WirelessArcaneChargingHandler {
|
||||
// Hosts retain native AE2's ten-tick idle-energy buffer. Recreating one every tick would overcharge power.
|
||||
private static final Map<UUID, Map<Integer, PassiveHost>> HOSTS = new HashMap<>();
|
||||
private record PassiveHost(ServerPlayer player, ItemStack stack, ItemContainerContents wands,
|
||||
WirelessTerminalMenuHost<?> host) { }
|
||||
private WirelessArcaneChargingHandler() { }
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerTick(PlayerTickEvent.Post event) {
|
||||
if (!(event.getEntity() instanceof ServerPlayer player)) return;
|
||||
for (int slot = 0; slot < player.getInventory().getContainerSize(); slot++) {
|
||||
replenishCarriedTerminal(player, slot);
|
||||
}
|
||||
// AE2 exposes this capability without a Curios runtime dependency; absent mods return null.
|
||||
var curios = player.getCapability(CuriosIntegration.ITEM_HANDLER);
|
||||
int curioSlots = curios == null ? 0 : curios.getSlots();
|
||||
for (int slot = 0; slot < curioSlots; slot++) {
|
||||
replenishCarriedTerminal(player, -slot - 1, MenuLocators.forCurioSlot(slot));
|
||||
}
|
||||
var hosts = HOSTS.get(player.getUUID());
|
||||
if (hosts != null) {
|
||||
hosts.keySet().removeIf(key -> key < 0 && -key - 1 >= curioSlots);
|
||||
if (hosts.isEmpty()) HOSTS.remove(player.getUUID());
|
||||
}
|
||||
}
|
||||
|
||||
public static void replenishCarriedTerminal(ServerPlayer player, int slot) {
|
||||
replenishCarriedTerminal(player, slot, MenuLocators.forInventorySlot(slot));
|
||||
}
|
||||
|
||||
private static void replenishCarriedTerminal(ServerPlayer player, int slot, ItemMenuHostLocator locator) {
|
||||
ItemStack stack = locator.locateItem(player);
|
||||
var hosts = HOSTS.computeIfAbsent(player.getUUID(), ignored -> new HashMap<>());
|
||||
var openHost = player.containerMenu instanceof AEBaseMenu menu
|
||||
&& menu.getTarget() instanceof WirelessTerminalMenuHost<?> terminal
|
||||
&& terminal.getItemStack() == stack ? terminal : null;
|
||||
|
||||
if (!(stack.getItem() instanceof WirelessTerminalItem item)
|
||||
|| !item.getUpgrades(stack).isInstalled(ModItems.VIS_CONNECTOR_CARD.get())) {
|
||||
hosts.remove(slot);
|
||||
return;
|
||||
}
|
||||
// Use the live wand inventory while the arcane menu is open; never overwrite it with a saved copy.
|
||||
if (openHost instanceof IArcaneTerminalInventoryHost arcane) {
|
||||
hosts.remove(slot);
|
||||
if (openHost.getLinkStatus().connected() && WirelessArcaneVis.replenish(arcane)) {
|
||||
player.getInventory().setChanged();
|
||||
}
|
||||
return;
|
||||
}
|
||||
var wands = stack.getOrDefault(ModComponents.WAND_INV.get(), ItemContainerContents.EMPTY);
|
||||
if (wands.getSlots() == 0 || !ArcaneVisReplenish.needsCharge(wands.getStackInSlot(0))) {
|
||||
hosts.remove(slot);
|
||||
return;
|
||||
}
|
||||
var cached = hosts.get(slot);
|
||||
WirelessTerminalMenuHost<?> host;
|
||||
if (cached != null && cached.player() == player && cached.stack() == stack
|
||||
&& cached.wands().equals(wands)) {
|
||||
host = cached.host();
|
||||
} else {
|
||||
if (item instanceof WirelessArcaneCraftingTerminalItem arcane) {
|
||||
host = arcane.getMenuHost(player, locator, null);
|
||||
} else if (ModList.get().isLoaded(IArcaneTerminalInventoryHost.AE2WTLIB_MODID)) {
|
||||
host = AE2WTCompat.createPassiveArcaneHost(player, locator);
|
||||
} else {
|
||||
host = null;
|
||||
}
|
||||
if (host == null) {
|
||||
hosts.remove(slot);
|
||||
return;
|
||||
}
|
||||
hosts.put(slot, new PassiveHost(player, stack, wands, host));
|
||||
}
|
||||
if (!(host instanceof IArcaneTerminalInventoryHost arcane)) return;
|
||||
if (openHost == null) {
|
||||
// Refresh range/quantum connection and let the native host own terminal power accounting.
|
||||
host.tick();
|
||||
} else {
|
||||
// A different universal-terminal mode already ticks its host. Do not debit its idle power twice.
|
||||
arcane.refreshConnection();
|
||||
}
|
||||
if (host.getLinkStatus().connected() && WirelessArcaneVis.replenish(arcane)) {
|
||||
player.getInventory().setChanged();
|
||||
}
|
||||
// Detect external wand replacement while retaining the host for our own persisted charge updates.
|
||||
hosts.put(slot, new PassiveHost(player, stack,
|
||||
stack.getOrDefault(ModComponents.WAND_INV.get(), ItemContainerContents.EMPTY), host));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onLogout(PlayerEvent.PlayerLoggedOutEvent event) {
|
||||
HOSTS.remove(event.getEntity().getUUID());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onServerStopped(ServerStoppedEvent event) {
|
||||
HOSTS.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package thaumicenergistics.common.parts;
|
||||
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import thaumicenergistics.common.container.IArcaneTerminalInventoryHost;
|
||||
import thaumicenergistics.common.items.VisConnectorCardItem;
|
||||
|
||||
/** 无线终端法杖补充,打开菜单与玩家携带时共用。 */
|
||||
public final class WirelessArcaneVis {
|
||||
private WirelessArcaneVis() { }
|
||||
|
||||
public static boolean replenish(IArcaneTerminalInventoryHost host) {
|
||||
var upgrades = host.getUpgrades();
|
||||
for (int i = 0; i < upgrades.size(); i++) {
|
||||
if (!(upgrades.getStackInSlot(i).getItem() instanceof VisConnectorCardItem)) continue;
|
||||
var node = host.getActionableNode();
|
||||
if (node == null || !node.isActive()) return false;
|
||||
var inventory = host.getSubInventory(ArcaneCraftingTerminalPart.INV_WAND);
|
||||
var wand = inventory != null ? inventory.getStackInSlot(0) : ItemStack.EMPTY;
|
||||
boolean changed = ArcaneVisReplenish.replenishAuto(node.getGrid(), wand);
|
||||
if (changed) host.saveWandInv();
|
||||
return changed;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package thaumicenergistics.common.storage;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
import java.util.Objects;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.IncludeExclude;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.StorageFilter;
|
||||
import appeng.api.config.YesNo;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.stacks.AEKey;
|
||||
import appeng.api.stacks.KeyCounter;
|
||||
import appeng.api.storage.MEStorage;
|
||||
import appeng.core.definitions.AEItems;
|
||||
import appeng.me.storage.MEInventoryHandler;
|
||||
import appeng.parts.storagebus.StorageBusPart;
|
||||
import appeng.util.prioritylist.IPartitionList;
|
||||
|
||||
/** 新增视图也经过总线的访问和过滤规则;设置即时读取,避免与原句柄分叉。 */
|
||||
public final class EssentiaStorageBusInventory extends MEInventoryHandler {
|
||||
private final Supplier<StorageBusPart> host;
|
||||
private AEKey[] cachedFilter;
|
||||
private FuzzyMode cachedFuzzyMode;
|
||||
|
||||
public EssentiaStorageBusInventory(MEStorage storage, Supplier<StorageBusPart> host) {
|
||||
super(storage);
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
private void configure() {
|
||||
var bus = host.get();
|
||||
var settings = bus.getConfigManager();
|
||||
var access = settings.getSetting(Settings.ACCESS);
|
||||
setAllowInsertion(access.isAllowInsertion());
|
||||
setAllowExtraction(access.isAllowExtraction());
|
||||
setWhitelist(bus.getUpgrades().isInstalled(AEItems.INVERTER_CARD)
|
||||
? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST);
|
||||
int usable = 18 + bus.getInstalledUpgrades(AEItems.CAPACITY_CARD) * 9;
|
||||
var config = bus.getConfig();
|
||||
int size = Math.min(usable, config.size());
|
||||
FuzzyMode fuzzy = bus.getUpgrades().isInstalled(AEItems.FUZZY_CARD)
|
||||
? settings.getSetting(Settings.FUZZY_MODE) : null;
|
||||
boolean changed = cachedFilter == null || cachedFilter.length != size || cachedFuzzyMode != fuzzy;
|
||||
if (!changed) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (!Objects.equals(cachedFilter[i], config.getKey(i))) {
|
||||
changed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
var builder = IPartitionList.builder();
|
||||
if (fuzzy != null) builder.fuzzyMode(fuzzy);
|
||||
cachedFilter = new AEKey[size];
|
||||
cachedFuzzyMode = fuzzy;
|
||||
for (int i = 0; i < size; i++) {
|
||||
cachedFilter[i] = config.getKey(i);
|
||||
builder.add(cachedFilter[i]);
|
||||
}
|
||||
setPartitionList(builder.build());
|
||||
}
|
||||
boolean filter = settings.getSetting(Settings.FILTER_ON_EXTRACT) == YesNo.YES;
|
||||
setExtractFiltering(filter, filter
|
||||
&& settings.getSetting(Settings.STORAGE_FILTER) == StorageFilter.EXTRACTABLE_ONLY);
|
||||
setVoidOverflow(bus.getUpgrades().isInstalled(AEItems.VOID_CARD));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long insert(AEKey key, long amount, Actionable mode, IActionSource source) {
|
||||
configure();
|
||||
return super.insert(key, amount, mode, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long extract(AEKey key, long amount, Actionable mode, IActionSource source) {
|
||||
configure();
|
||||
if (!host.get().getConfigManager().getSetting(Settings.ACCESS).isAllowExtraction()) {
|
||||
return 0;
|
||||
}
|
||||
return super.extract(key, amount, mode, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAvailableStacks(KeyCounter stacks) {
|
||||
configure();
|
||||
super.getAvailableStacks(stacks);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package thaumicenergistics.init;
|
||||
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||
import java.util.function.Supplier;
|
||||
import thaumicenergistics.ThaumicEnergistics;
|
||||
import thaumicenergistics.common.features.SafeTerminalMergeRecipe;
|
||||
|
||||
public final class ModRecipeSerializers {
|
||||
public static final DeferredRegister<RecipeSerializer<?>> REGISTRY =
|
||||
DeferredRegister.create(Registries.RECIPE_SERIALIZER, ThaumicEnergistics.MODID);
|
||||
public static final Supplier<RecipeSerializer<SafeTerminalMergeRecipe>> SAFE_TERMINAL_MERGE =
|
||||
REGISTRY.register("safe_terminal_merge", SafeTerminalMergeRecipe.Serializer::new);
|
||||
|
||||
private ModRecipeSerializers() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package thaumicenergistics.mixins;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
import net.neoforged.fml.loading.LoadingModList;
|
||||
|
||||
/** 在目标类加载前排除缺席的可选模组,不依赖尚未创建的 ModList。 */
|
||||
public final class ThEOptionalMixinPlugin implements IMixinConfigPlugin {
|
||||
@Override public void onLoad(String mixinPackage) { }
|
||||
@Override public String getRefMapperConfig() { return null; }
|
||||
@Override public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
||||
if (mixinClassName.contains(".compat.aae.")) {
|
||||
return loaded("advanced_ae") && (mixinClassName.endsWith("Essentia") || !loaded("appflux"));
|
||||
}
|
||||
if (mixinClassName.contains(".compat.ae2lt.")) return loaded("ae2lt");
|
||||
if (!mixinClassName.contains(".eap.")) return true;
|
||||
return loaded("extendedae_plus");
|
||||
}
|
||||
|
||||
private static boolean loaded(String id) {
|
||||
var mods = LoadingModList.get();
|
||||
return mods != null && mods.getMods().stream()
|
||||
.anyMatch(mod -> mod.getModId().equals(id));
|
||||
}
|
||||
@Override public void acceptTargets(Set<String> mine, Set<String> others) { }
|
||||
@Override public List<String> getMixins() { return null; }
|
||||
@Override public void preApply(String target, ClassNode node, String mixin, IMixinInfo info) { }
|
||||
@Override public void postApply(String target, ClassNode node, String mixin, IMixinInfo info) { }
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package thaumicenergistics.mixins.compat.aae;
|
||||
|
||||
import appeng.api.networking.IManagedGridNode;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.helpers.patternprovider.PatternProviderTarget;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.pedroksl.advanced_ae.common.logic.AdvPatternProviderLogic;
|
||||
import net.pedroksl.advanced_ae.common.logic.AdvPatternProviderLogicHost;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import thaumicenergistics.common.integration.appeng.ProviderEssentiaTargets;
|
||||
|
||||
/** 双参数出口覆盖普通输出、定向输出与 sendList 重试。 */
|
||||
@Mixin(value = AdvPatternProviderLogic.class, remap = false)
|
||||
public abstract class MixinAdvProviderEssentia {
|
||||
@Shadow @Final private AdvPatternProviderLogicHost host;
|
||||
@Shadow @Final private IManagedGridNode mainNode;
|
||||
@Shadow @Final private IActionSource actionSource;
|
||||
|
||||
@Inject(method = "findAdapter(Lnet/minecraft/core/Direction;Lnet/minecraft/core/Direction;)Lappeng/helpers/patternprovider/PatternProviderTarget;", at = @At("RETURN"), cancellable = true)
|
||||
private void thE$target(Direction direction, Direction face, CallbackInfoReturnable<PatternProviderTarget> cir) {
|
||||
if (!ProviderEssentiaTargets.hasCard(this)) return;
|
||||
var owner = host.getBlockEntity();
|
||||
if (owner == null || !(owner.getLevel() instanceof ServerLevel level)) return;
|
||||
var pos = owner.getBlockPos().relative(direction);
|
||||
if (!level.isLoaded(pos)) return;
|
||||
cir.setReturnValue(ProviderEssentiaTargets.wrap(cir.getReturnValue(), mainNode.getGrid(), actionSource,
|
||||
level.getBlockEntity(pos), face != null ? face : direction.getOpposite()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package thaumicenergistics.mixins.compat.aae;
|
||||
|
||||
import appeng.api.upgrades.IUpgradeInventory;
|
||||
import appeng.api.upgrades.IUpgradeableObject;
|
||||
import net.pedroksl.advanced_ae.common.logic.AdvPatternProviderLogicHost;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(value = AdvPatternProviderLogicHost.class, remap = false)
|
||||
public interface MixinAdvProviderHost extends IUpgradeableObject {
|
||||
@Override
|
||||
default IUpgradeInventory getUpgrades() {
|
||||
return ((IUpgradeableObject) ((AdvPatternProviderLogicHost) this).getLogic()).getUpgrades();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package thaumicenergistics.mixins.compat.aae;
|
||||
|
||||
import appeng.api.upgrades.IUpgradeInventory;
|
||||
import appeng.api.upgrades.IUpgradeableObject;
|
||||
import appeng.menu.AEBaseMenu;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.pedroksl.advanced_ae.common.logic.AdvPatternProviderLogic;
|
||||
import net.pedroksl.advanced_ae.common.logic.AdvPatternProviderLogicHost;
|
||||
import net.pedroksl.advanced_ae.gui.advpatternprovider.AdvPatternProviderMenu;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(value = AdvPatternProviderMenu.class, remap = false)
|
||||
public abstract class MixinAdvProviderMenu extends AEBaseMenu implements IUpgradeableObject {
|
||||
@Shadow @Final protected AdvPatternProviderLogic logic;
|
||||
|
||||
protected MixinAdvProviderMenu(MenuType<?> type, int id, Inventory player, Object host) { super(type, id, player, host); }
|
||||
|
||||
@Inject(method = "<init>(Lnet/minecraft/world/inventory/MenuType;ILnet/minecraft/world/entity/player/Inventory;Lnet/pedroksl/advanced_ae/common/logic/AdvPatternProviderLogicHost;)V", at = @At("TAIL"))
|
||||
private void thE$slots(MenuType<?> type, int id, Inventory player, AdvPatternProviderLogicHost host, CallbackInfo ci) {
|
||||
setupUpgrades(((IUpgradeableObject) host).getUpgrades());
|
||||
}
|
||||
|
||||
@Override public IUpgradeInventory getUpgrades() { return ((IUpgradeableObject) logic).getUpgrades(); }
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package thaumicenergistics.mixins.compat.aae;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import appeng.api.upgrades.IUpgradeableObject;
|
||||
import appeng.api.upgrades.Upgrades;
|
||||
import appeng.client.gui.AEBaseScreen;
|
||||
import appeng.client.gui.style.ScreenStyle;
|
||||
import appeng.client.gui.widgets.UpgradesPanel;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.menu.SlotSemantics;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.pedroksl.advanced_ae.client.gui.AdvPatternProviderScreen;
|
||||
import net.pedroksl.advanced_ae.gui.advpatternprovider.AdvPatternProviderMenu;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(value = AdvPatternProviderScreen.class, remap = false)
|
||||
public abstract class MixinAdvProviderScreen extends AEBaseScreen<AdvPatternProviderMenu> {
|
||||
protected MixinAdvProviderScreen(AdvPatternProviderMenu menu, Inventory player, Component title, ScreenStyle style) {
|
||||
super(menu, player, title, style);
|
||||
}
|
||||
|
||||
@Inject(method = "<init>", at = @At("TAIL"))
|
||||
private void thE$panel(AdvPatternProviderMenu menu, Inventory player, Component title, ScreenStyle style, CallbackInfo ci) {
|
||||
widgets.add("upgrades", new UpgradesPanel(menu.getSlots(SlotSemantics.UPGRADE), () -> {
|
||||
List<Component> tooltip = new ArrayList<>();
|
||||
tooltip.add(GuiText.CompatibleUpgrades.text());
|
||||
tooltip.addAll(Upgrades.getTooltipLinesForMachine(((IUpgradeableObject) menu).getUpgrades().getUpgradableItem()));
|
||||
return tooltip;
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package thaumicenergistics.mixins.compat.aae;
|
||||
|
||||
import java.util.List;
|
||||
import appeng.api.networking.IManagedGridNode;
|
||||
import appeng.api.upgrades.IUpgradeInventory;
|
||||
import appeng.api.upgrades.IUpgradeableObject;
|
||||
import appeng.api.upgrades.UpgradeInventories;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.pedroksl.advanced_ae.common.logic.AdvPatternProviderLogic;
|
||||
import net.pedroksl.advanced_ae.common.logic.AdvPatternProviderLogicHost;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
/** AAE 独立逻辑的升级库存;与 AAE 自带 AppFlux 卡槽组互斥。 */
|
||||
@Mixin(value = AdvPatternProviderLogic.class, remap = false)
|
||||
public abstract class MixinAdvProviderUpgrades implements IUpgradeableObject {
|
||||
@Shadow @Final private AdvPatternProviderLogicHost host;
|
||||
@Shadow @Final private IManagedGridNode mainNode;
|
||||
@Unique private IUpgradeInventory thE$upgrades = UpgradeInventories.empty();
|
||||
|
||||
@Override public IUpgradeInventory getUpgrades() { return thE$upgrades; }
|
||||
|
||||
@Inject(method = "<init>(Lappeng/api/networking/IManagedGridNode;Lnet/pedroksl/advanced_ae/common/logic/AdvPatternProviderLogicHost;I)V", at = @At("TAIL"))
|
||||
private void thE$init(IManagedGridNode node, AdvPatternProviderLogicHost owner, int size, CallbackInfo ci) {
|
||||
thE$upgrades = UpgradeInventories.forMachine(owner.getTerminalIcon().getItem(), 1, () -> {
|
||||
host.saveChanges();
|
||||
mainNode.ifPresent((grid, gridNode) -> grid.getTickManager().alertDevice(gridNode));
|
||||
});
|
||||
}
|
||||
|
||||
@Inject(method = "writeToNBT", at = @At("TAIL"))
|
||||
private void thE$save(CompoundTag tag, HolderLookup.Provider registries, CallbackInfo ci) {
|
||||
thE$upgrades.writeToNBT(tag, "upgrades", registries);
|
||||
}
|
||||
|
||||
@Inject(method = "readFromNBT", at = @At("TAIL"))
|
||||
private void thE$load(CompoundTag tag, HolderLookup.Provider registries, CallbackInfo ci) {
|
||||
thE$upgrades.readFromNBT(tag, "upgrades", registries);
|
||||
}
|
||||
|
||||
@Inject(method = "addDrops", at = @At("TAIL"))
|
||||
private void thE$drops(List<ItemStack> drops, CallbackInfo ci) {
|
||||
for (var upgrade : thE$upgrades) if (!upgrade.isEmpty()) drops.add(upgrade.copy());
|
||||
}
|
||||
|
||||
@Inject(method = "clearContent", at = @At("TAIL"))
|
||||
private void thE$clear(CallbackInfo ci) { thE$upgrades.clear(); }
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package thaumicenergistics.mixins.compat.aae;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import appeng.api.upgrades.IUpgradeableObject;
|
||||
import appeng.api.upgrades.Upgrades;
|
||||
import appeng.client.gui.AEBaseScreen;
|
||||
import appeng.client.gui.style.ScreenStyle;
|
||||
import appeng.client.gui.widgets.UpgradesPanel;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.menu.SlotSemantics;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.pedroksl.advanced_ae.client.gui.SmallAdvPatternProviderScreen;
|
||||
import net.pedroksl.advanced_ae.gui.advpatternprovider.SmallAdvPatternProviderMenu;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(value = SmallAdvPatternProviderScreen.class, remap = false)
|
||||
public abstract class MixinSmallAdvProviderScreen extends AEBaseScreen<SmallAdvPatternProviderMenu> {
|
||||
protected MixinSmallAdvProviderScreen(SmallAdvPatternProviderMenu menu, Inventory player, Component title, ScreenStyle style) {
|
||||
super(menu, player, title, style);
|
||||
}
|
||||
|
||||
@Inject(method = "<init>", at = @At("TAIL"))
|
||||
private void thE$panel(SmallAdvPatternProviderMenu menu, Inventory player, Component title, ScreenStyle style, CallbackInfo ci) {
|
||||
widgets.add("upgrades", new UpgradesPanel(menu.getSlots(SlotSemantics.UPGRADE), () -> {
|
||||
List<Component> tooltip = new ArrayList<>();
|
||||
tooltip.add(GuiText.CompatibleUpgrades.text());
|
||||
tooltip.addAll(Upgrades.getTooltipLinesForMachine(((IUpgradeableObject) menu).getUpgrades().getUpgradableItem()));
|
||||
return tooltip;
|
||||
}));
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package thaumicenergistics.mixins.compat.ae2lt;
|
||||
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.helpers.patternprovider.PatternProviderTarget;
|
||||
import com.moakiee.ae2lt.logic.provider.ProviderTarget;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import thaumicenergistics.common.integration.appeng.ProviderEssentiaTargets;
|
||||
|
||||
/** 复用 AE2LT 原生批量调度及余量队列,只扩展物理目标解析出口。 */
|
||||
@Mixin(value = ProviderTarget.class, remap = false)
|
||||
public abstract class MixinOverloadedProviderTarget {
|
||||
@Inject(method = "resolveStorageTarget(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/Direction;Lappeng/api/networking/security/IActionSource;)Lappeng/helpers/patternprovider/PatternProviderTarget;", at = @At("RETURN"), cancellable = true)
|
||||
private void thE$target(ServerLevel level, Direction face, IActionSource source,
|
||||
CallbackInfoReturnable<PatternProviderTarget> cir) {
|
||||
var target = (ProviderTarget) (Object) this;
|
||||
cir.setReturnValue(ProviderEssentiaTargets.fromSource(cir.getReturnValue(), source,
|
||||
target.resolveBlockEntity(level), face));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package thaumicenergistics.mixins.tc;
|
||||
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import thaumcraft.common.entities.golem.ThaumcraftGolemEntity;
|
||||
import thaumcraft.common.items.GolemItems;
|
||||
import thaumicenergistics.common.entities.GolemBackpackHandler;
|
||||
|
||||
/**
|
||||
* 在 TC 傀儡打包/放置链路挂载无线背包数据通道。
|
||||
* saveGolem/loadGolem 均为白名单式读写且不含 TE 字段,SDK 无对应 API 扩展点,
|
||||
* 故 TAIL 注入补写/还原 ThEGolemBackpack 子树。
|
||||
*/
|
||||
@Mixin(GolemItems.class)
|
||||
public abstract class MixinGolemItems {
|
||||
|
||||
@Inject(method = "saveGolem", at = @At("TAIL"))
|
||||
private static void te$saveBackpackData(ItemStack stack, ThaumcraftGolemEntity golem, CallbackInfo ci) {
|
||||
GolemBackpackHandler.saveBackpackToStack(stack, golem);
|
||||
}
|
||||
|
||||
@Inject(method = "loadGolem", at = @At("TAIL"))
|
||||
private static void te$restoreBackpackData(ItemStack stack, ThaumcraftGolemEntity golem, CallbackInfo ci) {
|
||||
GolemBackpackHandler.restoreBackpackFromStack(stack, golem);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package thaumicenergistics.mixins.tc;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import thaumcraft.common.entities.golem.ThaumcraftGolemEntity;
|
||||
import thaumicenergistics.common.entities.GolemBackpackHandler;
|
||||
|
||||
/**
|
||||
* 铃铛 shift+左键拆解(dismantle=true)只按散件返还,不含无线背包。
|
||||
* TAIL 注入在 discard 前补掉背包与 Facade 并清数据;普通回收(dismantle=false)
|
||||
* 的数据保全由 MixinGolemItems 的 saveGolem TAIL 承担,两路不重叠。
|
||||
*/
|
||||
@Mixin(ThaumcraftGolemEntity.class)
|
||||
public abstract class MixinThaumcraftGolemEntity {
|
||||
|
||||
@Inject(method = "packWithBell", at = @At("TAIL"))
|
||||
private void te$dropBackpackOnDismantle(Player player, boolean dismantle, CallbackInfo ci) {
|
||||
if (!dismantle) {
|
||||
return;
|
||||
}
|
||||
GolemBackpackHandler.dropAndClearBackpack((ThaumcraftGolemEntity) (Object) this, player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
{
|
||||
"format_version": "1.9.0",
|
||||
"credit": "Made with _leng",
|
||||
"render_type": "cutout",
|
||||
"textures": {
|
||||
"1": "thaumicenergistics:block/maiqilin_fumo",
|
||||
"particle": "thaumicenergistics:block/maiqilin_fumo"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"name": "Head",
|
||||
"from": [4.35, 4.69613, 8.33113],
|
||||
"to": [11.65, 11.99613, 15.63113],
|
||||
"rotation": {"angle": 22.5, "axis": "x", "origin": [7.975, 8.42113, 11.90613]},
|
||||
"faces": {
|
||||
"north": {"uv": [2, 2, 4, 4], "texture": "#1"},
|
||||
"east": {"uv": [0, 2, 2, 4], "texture": "#1"},
|
||||
"south": {"uv": [6, 2, 8, 4], "texture": "#1"},
|
||||
"west": {"uv": [4, 2, 6, 4], "texture": "#1"},
|
||||
"up": {"uv": [4, 2, 2, 0], "texture": "#1"},
|
||||
"down": {"uv": [4, 0, 6, 2], "texture": "#1"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Hat Layer",
|
||||
"from": [4.1, 4.69613, 7.98113],
|
||||
"to": [11.8, 12.29613, 15.68113],
|
||||
"rotation": {"angle": 22.5, "axis": "x", "origin": [7.975, 8.42113, 11.90613]},
|
||||
"faces": {
|
||||
"north": {"uv": [10, 2, 12, 4], "texture": "#1"},
|
||||
"east": {"uv": [8, 2, 10, 4], "texture": "#1"},
|
||||
"south": {"uv": [14, 2, 16, 4], "texture": "#1"},
|
||||
"west": {"uv": [12, 2, 14, 4], "texture": "#1"},
|
||||
"up": {"uv": [12, 2, 10, 0], "texture": "#1"},
|
||||
"down": {"uv": [12, 0, 14, 2], "texture": "#1"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Left Arm",
|
||||
"from": [3.89, -0.36401, 9.01167],
|
||||
"to": [5.39, 5.63599, 11.01167],
|
||||
"rotation": {"angle": -22.5, "axis": "z", "origin": [4.6527, 2.63599, 10.01167]},
|
||||
"faces": {
|
||||
"north": {"uv": [9, 13, 9.75, 16], "texture": "#1"},
|
||||
"east": {"uv": [8, 13, 9, 16], "texture": "#1"},
|
||||
"south": {"uv": [10.75, 13, 11.5, 16], "texture": "#1"},
|
||||
"west": {"uv": [9.75, 13, 10.5, 16], "texture": "#1"},
|
||||
"up": {"uv": [9, 12, 9.75, 13], "texture": "#1"},
|
||||
"down": {"uv": [10.5, 12, 9.75, 13], "texture": "#1"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Left Arm Layer",
|
||||
"from": [3.8154, -0.46401, 8.91167],
|
||||
"to": [5.5154, 5.73599, 11.11167],
|
||||
"rotation": {"angle": -22.5, "axis": "z", "origin": [4.6527, 2.63599, 10.01167]},
|
||||
"faces": {
|
||||
"north": {"uv": [13, 13, 13.75, 16], "texture": "#1"},
|
||||
"east": {"uv": [12, 13, 13, 16], "texture": "#1"},
|
||||
"south": {"uv": [14.5, 13, 15.25, 16], "texture": "#1"},
|
||||
"west": {"uv": [13.75, 13, 14.5, 16], "texture": "#1"},
|
||||
"up": {"uv": [13, 12, 13.75, 13], "texture": "#1"},
|
||||
"down": {"uv": [13.75, 12, 14.5, 13], "texture": "#1"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "RightArm",
|
||||
"from": [10.48, -0.44754, 8.979],
|
||||
"to": [11.98, 5.55246, 10.979],
|
||||
"rotation": {"angle": 22.5, "axis": "z", "origin": [11.13663, 2.55246, 9.979]},
|
||||
"faces": {
|
||||
"north": {"uv": [11, 5, 11.75, 8], "texture": "#1"},
|
||||
"east": {"uv": [10, 5, 11, 8], "texture": "#1"},
|
||||
"south": {"uv": [12.75, 5, 13.5, 8], "texture": "#1"},
|
||||
"west": {"uv": [11.75, 5, 12.5, 8], "texture": "#1"},
|
||||
"up": {"uv": [11, 4, 11.75, 5], "texture": "#1"},
|
||||
"down": {"uv": [12.5, 4, 11.75, 5], "texture": "#1"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Right Arm Layer",
|
||||
"from": [10.36163, -0.54754, 8.879],
|
||||
"to": [12.06163, 5.65246, 11.079],
|
||||
"rotation": {"angle": 22.5, "axis": "z", "origin": [11.16163, 2.55246, 9.979]},
|
||||
"faces": {
|
||||
"north": {"uv": [11, 9, 11.75, 12], "texture": "#1"},
|
||||
"east": {"uv": [10, 9, 11, 12], "texture": "#1"},
|
||||
"south": {"uv": [12.75, 9, 13.5, 12], "texture": "#1"},
|
||||
"west": {"uv": [11.75, 9, 12.5, 12], "texture": "#1"},
|
||||
"up": {"uv": [11, 8, 11.75, 9], "texture": "#1"},
|
||||
"down": {"uv": [12.5, 8, 11.75, 9], "texture": "#1"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Left Leg",
|
||||
"from": [7.77, -0.02, -0.23],
|
||||
"to": [10.23, 2.44, 6.23],
|
||||
"rotation": {"angle": -22.5, "axis": "y", "origin": [8, 0.31, 7]},
|
||||
"faces": {
|
||||
"north": {"uv": [2, 4, 3, 5], "texture": "#1"},
|
||||
"east": {"uv": [0, 8, 1, 5], "rotation": 90, "texture": "#1"},
|
||||
"south": {"uv": [1, 4, 2, 5], "texture": "#1"},
|
||||
"west": {"uv": [2, 5, 3, 8], "rotation": 90, "texture": "#1"},
|
||||
"up": {"uv": [2, 8, 1, 5], "texture": "#1"},
|
||||
"down": {"uv": [3, 5, 4, 8], "texture": "#1"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Left Leg Layer",
|
||||
"from": [7.67, -0.12, -0.33],
|
||||
"to": [10.33, 2.54, 6.33],
|
||||
"rotation": {"angle": -22.5, "axis": "y", "origin": [8, 0.31, 7]},
|
||||
"faces": {
|
||||
"north": {"uv": [2, 8, 3, 9], "texture": "#1"},
|
||||
"east": {"uv": [0, 12, 1, 9], "rotation": 90, "texture": "#1"},
|
||||
"south": {"uv": [1, 8, 2, 9], "texture": "#1"},
|
||||
"west": {"uv": [2, 9, 3, 12], "rotation": 90, "texture": "#1"},
|
||||
"up": {"uv": [2, 12, 1, 9], "texture": "#1"},
|
||||
"down": {"uv": [3, 9, 4, 12], "texture": "#1"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Right Leg",
|
||||
"from": [5.77, -0.02, -0.23],
|
||||
"to": [8.23, 2.44, 6.23],
|
||||
"rotation": {"angle": 22.5, "axis": "y", "origin": [8, 0.31, 7]},
|
||||
"faces": {
|
||||
"north": {"uv": [6, 12, 7, 13], "texture": "#1"},
|
||||
"east": {"uv": [4, 16, 5, 13], "rotation": 90, "texture": "#1"},
|
||||
"south": {"uv": [5, 12, 6, 13], "texture": "#1"},
|
||||
"west": {"uv": [6, 13, 7, 16], "rotation": 90, "texture": "#1"},
|
||||
"up": {"uv": [6, 16, 5, 13], "texture": "#1"},
|
||||
"down": {"uv": [7, 13, 8, 16], "texture": "#1"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Right Leg Layer",
|
||||
"from": [5.67, -0.12, -0.33],
|
||||
"to": [8.33, 2.54, 6.33],
|
||||
"rotation": {"angle": 22.5, "axis": "y", "origin": [8, 0.31, 7]},
|
||||
"faces": {
|
||||
"north": {"uv": [2, 12, 3, 13], "texture": "#1"},
|
||||
"east": {"uv": [0, 16, 1, 13], "rotation": 90, "texture": "#1"},
|
||||
"south": {"uv": [1, 12, 2, 13], "texture": "#1"},
|
||||
"west": {"uv": [2, 13, 3, 16], "rotation": 90, "texture": "#1"},
|
||||
"up": {"uv": [2, 16, 1, 13], "texture": "#1"},
|
||||
"down": {"uv": [3, 13, 4, 16], "texture": "#1"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Body",
|
||||
"from": [5.6, -0.79, 9.6],
|
||||
"to": [10.4, 5.21, 12.4],
|
||||
"rotation": {"angle": 45, "axis": "x", "origin": [7.975, 5.61, 10.925]},
|
||||
"faces": {
|
||||
"north": {"uv": [5, 5, 7, 8], "texture": "#1"},
|
||||
"east": {"uv": [4, 5, 5, 8], "texture": "#1"},
|
||||
"south": {"uv": [8, 5, 10, 8], "texture": "#1"},
|
||||
"west": {"uv": [7, 5, 8, 8], "texture": "#1"},
|
||||
"up": {"uv": [5, 5, 7, 4], "texture": "#1"},
|
||||
"down": {"uv": [7, 5, 9, 4], "texture": "#1"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Body Layer",
|
||||
"from": [5.5, -0.89, 9.5],
|
||||
"to": [10.5, 5.31, 12.5],
|
||||
"rotation": {"angle": 45, "axis": "x", "origin": [7.975, 5.61, 10.925]},
|
||||
"faces": {
|
||||
"north": {"uv": [5, 9, 7, 12], "texture": "#1"},
|
||||
"east": {"uv": [4, 9, 5, 12], "texture": "#1"},
|
||||
"south": {"uv": [8, 9, 10, 12], "texture": "#1"},
|
||||
"west": {"uv": [7, 9, 8, 12], "texture": "#1"},
|
||||
"up": {"uv": [5, 9, 7, 8], "texture": "#1"},
|
||||
"down": {"uv": [7, 9, 9, 8], "texture": "#1"}
|
||||
}
|
||||
}
|
||||
],
|
||||
"display": {
|
||||
"thirdperson_righthand": {
|
||||
"rotation": [37.5, 0, 0],
|
||||
"translation": [0.25, 3, 3],
|
||||
"scale": [0.5, 0.5, 0.5]
|
||||
},
|
||||
"thirdperson_lefthand": {
|
||||
"rotation": [42.75, 0, 0],
|
||||
"translation": [0.25, 2.75, 3.5],
|
||||
"scale": [0.5, 0.5, 0.5]
|
||||
},
|
||||
"firstperson_righthand": {
|
||||
"rotation": [0, 120, 0],
|
||||
"translation": [0, 3.75, 0],
|
||||
"scale": [0.5, 0.5, 0.5]
|
||||
},
|
||||
"firstperson_lefthand": {
|
||||
"rotation": [0, 123, 0],
|
||||
"translation": [0, 3.75, 0],
|
||||
"scale": [0.5, 0.5, 0.5]
|
||||
},
|
||||
"ground": {
|
||||
"translation": [0, 2, 0],
|
||||
"scale": [0.5, 0.5, 0.5]
|
||||
},
|
||||
"gui": {
|
||||
"rotation": [15, 150, 0],
|
||||
"translation": [0, 1.75, 0],
|
||||
"scale": [0.95, 0.95, 0.95]
|
||||
},
|
||||
"head": {
|
||||
"translation": [12.75, 1.5, 0]
|
||||
},
|
||||
"fixed": {
|
||||
"rotation": [-21.5, 0, 0],
|
||||
"translation": [0, 0, -3.5]
|
||||
}
|
||||
}
|
||||
}
|
||||
+1068
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"parent": "thaumicenergistics:block/maiqilinfumo"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:item/generated",
|
||||
"textures": {
|
||||
"layer0": "thaumicenergistics:item/storage_component_16m"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:item/generated",
|
||||
"textures": {
|
||||
"layer0": "thaumicenergistics:item/storage_component_1m"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:item/generated",
|
||||
"textures": {
|
||||
"layer0": "thaumicenergistics:item/storage_component_256k"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:item/generated",
|
||||
"textures": {
|
||||
"layer0": "thaumicenergistics:item/storage_component_256m"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:item/generated",
|
||||
"textures": {
|
||||
"layer0": "thaumicenergistics:item/storage_component_4m"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:item/generated",
|
||||
"textures": {
|
||||
"layer0": "thaumicenergistics:item/storage_component_64m"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 574 B |
Binary file not shown.
|
After Width: | Height: | Size: 308 B |
Binary file not shown.
|
After Width: | Height: | Size: 594 B |
Binary file not shown.
|
After Width: | Height: | Size: 564 B |
Binary file not shown.
|
After Width: | Height: | Size: 535 B |
Binary file not shown.
|
After Width: | Height: | Size: 575 B |
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"type": "minecraft:stonecutting",
|
||||
"ingredient": {
|
||||
"tag": "minecraft:wool"
|
||||
},
|
||||
"result": {
|
||||
"id": "thaumicenergistics:maiqilinfumo",
|
||||
"count": 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
{
|
||||
"id": "thaumic_tinkerer:ichor",
|
||||
"required": false
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "thaumicenergistics.mixins.compat",
|
||||
"plugin": "thaumicenergistics.mixins.ThEOptionalMixinPlugin",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"mixins": [
|
||||
"aae.MixinAdvProviderUpgrades",
|
||||
"aae.MixinAdvProviderHost",
|
||||
"aae.MixinAdvProviderMenu",
|
||||
"aae.MixinAdvProviderEssentia",
|
||||
"ae2lt.MixinOverloadedProviderTarget"
|
||||
],
|
||||
"client": [
|
||||
"aae.MixinAdvProviderScreen",
|
||||
"aae.MixinSmallAdvProviderScreen"
|
||||
],
|
||||
"injectors": { "defaultRequire": 1 }
|
||||
}
|
||||
Reference in New Issue
Block a user