Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@
import appeng.menu.me.items.PatternEncodingTermMenu;
import appeng.parts.encoding.EncodingMode;

import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;

import com.bawnorton.mixinsquared.TargetHandler;
import com.extendedae_plus.api.upload.IPatternEncodeRequestSync;
import com.extendedae_plus.util.uploadPattern.MatrixUploadUtil;
import com.extendedae_plus.api.upload.IPatternEncodeRequestSync.EncodeRequest;
import com.extendedae_plus.api.upload.IPatternUploadMenu;
import com.extendedae_plus.api.upload.UploadPreferences;
import com.extendedae_plus.util.uploadPattern.ProviderUploadUtil;
import com.extendedae_plus.util.uploadPattern.ProviderUploadUtil.UploadOutcome;
import me.fallenbreath.conditionalmixin.api.annotation.Condition;
import me.fallenbreath.conditionalmixin.api.annotation.Restriction;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -33,7 +39,7 @@
public abstract class PatternEncodingTermMenuExtendedaeplusMixin implements EaepPatternEncodingHandoff {

@Unique
private boolean dataEnergistics$eaepUploadPending;
private @Nullable EncodeRequest dataEnergistics$eaepUploadRequest;

@TargetHandler(
mixin = "com.extendedae_plus.mixin.ae2.menu.ContainerPatternEncodingTermMenuMixin",
Expand All @@ -48,23 +54,27 @@ public abstract class PatternEncodingTermMenuExtendedaeplusMixin implements Eaep

@Override
public void data_energistics$beginEaepEncodeHandoff(boolean dataEnergisticsUploadEnabled) {
this.dataEnergistics$eaepUploadPending = false;
boolean shiftUpload = ((IPatternEncodeRequestSync) this).eap$consumeEncodeRequest() instanceof IPatternEncodeRequestSync.EncodeRequest request && request.shiftDown();
this.dataEnergistics$eaepUploadPending = !dataEnergisticsUploadEnabled && !shiftUpload;
this.dataEnergistics$eaepUploadRequest = null;
EncodeRequest request = ((IPatternEncodeRequestSync) this).eap$consumeEncodeRequest();
if (!dataEnergisticsUploadEnabled && (request == null || !request.shiftDown())) {
this.dataEnergistics$eaepUploadRequest = request == null ? new EncodeRequest(false, null, UploadPreferences.defaults()) : request;
}
}

@Override
public void data_energistics$finishEaepEncodeHandoff(boolean encodedSuccessfully) {
var menu = (PatternEncodingTermMenu) (Object) this;
boolean shouldUpload = this.dataEnergistics$eaepUploadPending;
this.dataEnergistics$eaepUploadPending = false;
if (!shouldUpload || !encodedSuccessfully) {
EncodeRequest request = this.dataEnergistics$eaepUploadRequest;
this.dataEnergistics$eaepUploadRequest = null;
if (request == null || !encodedSuccessfully) {
return;
}

try {
var menu = (PatternEncodingTermMenu) (Object) this;
EncodingMode mode = menu.getMode();
if (mode != EncodingMode.CRAFTING && mode != EncodingMode.SMITHING_TABLE && mode != EncodingMode.STONECUTTING) {
boolean processing = mode == EncodingMode.PROCESSING;
Component provider = request.uniqueProvider();
if (processing && provider == null) {
return;
}

Expand All @@ -73,23 +83,30 @@ public abstract class PatternEncodingTermMenuExtendedaeplusMixin implements Eaep
return;
}

PatternEncodingRankingContext rankingContext = Objects.requireNonNull(
PatternEncodingSourceHelper.resolveFixedModeRankingContext(
PatternEncodingRankingContext rankingContext = processing ?
((PatternEncodingPreferenceMenu) menu).data_energistics$getPreferenceSession().rankingContext() :
Objects.requireNonNull(PatternEncodingSourceHelper.resolveFixedModeRankingContext(
mode, PatternEncodingSourceHelper.resolveFallbackWorkstationForMode(mode)),
"Missing fixed-mode ranking context for " + mode);
"Missing fixed-mode ranking context for " + mode);
EaepPatternUploadScope.UploadSnapshot snapshot = EaepPatternUploadScope.capture(
serverPlayer, menu, rankingContext);
serverPlayer.server.execute(() -> {
try (EaepPatternUploadScope.ScopeToken ignored = EaepPatternUploadScope.open(snapshot)) {
MatrixUploadUtil.uploadFromEncodingMenuToMatrix(serverPlayer, menu);
if (provider != null && ProviderUploadUtil.uploadFromEncodingMenuToNamedProvider(
serverPlayer, (IPatternUploadMenu) menu, provider) != UploadOutcome.FAILED) {
return;
}
if (!processing) {
ProviderUploadUtil.uploadFromEncodingMenuByPriority(serverPlayer, menu, request.prefs());
}
} catch (RuntimeException exception) {
Data_Energistics.LOGGER.error(
"ExtendedAE-Plus matrix upload failed after pattern encoding", exception);
"ExtendedAE-Plus upload failed after pattern encoding", exception);
}
});
} catch (RuntimeException exception) {
Data_Energistics.LOGGER.error(
"Could not schedule ExtendedAE-Plus matrix upload after pattern encoding", exception);
"Could not schedule ExtendedAE-Plus upload after pattern encoding", exception);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.fish_dan_.data_energistics.core.mixins.normal.com.extendedae_plus.client;

import com.fish_dan_.data_energistics.client.screen.patternencoding.PatternEncodingUploadClient;

import appeng.client.gui.me.items.PatternEncodingTermScreen;

import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;

import com.extendedae_plus.client.ProviderListCache;
import me.fallenbreath.conditionalmixin.api.annotation.Condition;
import me.fallenbreath.conditionalmixin.api.annotation.Restriction;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
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;

@Restriction(require = @Condition("extendedae_plus"))
@Mixin(value = ProviderListCache.class, remap = false)
@NullMarked
public abstract class ProviderListCacheMixin {

@Inject(method = "findUniqueMatch", at = @At("HEAD"), cancellable = true)
private static void dataEnergistics$preserveUploadSearchKey(@Nullable String rawSearchKey, CallbackInfoReturnable<@Nullable Component> cir) {
// ExtendedAE Plus consumes the search key when this lookup returns an automatic upload target.
if (Minecraft.getInstance().screen instanceof PatternEncodingTermScreen<?> screen && PatternEncodingUploadClient.enabled(screen.getMenu())) {
cir.setReturnValue(null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public interface EaepPatternEncodingHandoff {

/**
* Starts one encode handoff and consumes the one-shot ExtendedAE-Plus Shift marker.
* Takes the one-shot ExtendedAE-Plus request before encoding, including its target and preferences.
*
* @param dataEnergisticsUploadEnabled whether Data Energistics owns the encoded-pattern upload
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public final class EaepPatternUploadScope {
private EaepPatternUploadScope() {}

/**
* Captures the exact menu session and ranking context before a server upload is queued.
* Captures the menu session and any known ranking context before a server upload is queued.
*/
public static UploadSnapshot capture(ServerPlayer player, PatternEncodingTermMenu menu,
PatternEncodingRankingContext rankingContext) {
if (player == null || menu == null || rankingContext == null) {
throw new IllegalArgumentException("ExtendedAE-Plus upload snapshot requires a player, menu, and context");
@Nullable PatternEncodingRankingContext rankingContext) {
if (player == null || menu == null) {
throw new IllegalArgumentException("ExtendedAE-Plus upload snapshot requires a player and menu");
}
if (menu.getPlayer() != player) {
throw new IllegalArgumentException("ExtendedAE-Plus upload snapshot player does not own the encoding menu");
Expand Down Expand Up @@ -151,7 +151,7 @@ private static final class Scope {

private final ServerPlayer player;
private final PatternEncodingPreferenceSession preferenceSession;
private final PatternEncodingRankingContext rankingContext;
private final @Nullable PatternEncodingRankingContext rankingContext;
private boolean consumed;

private Scope(UploadSnapshot snapshot) {
Expand All @@ -168,11 +168,11 @@ public static final class UploadSnapshot {

private final ServerPlayer player;
private final PatternEncodingPreferenceSession preferenceSession;
private final PatternEncodingRankingContext rankingContext;
private final @Nullable PatternEncodingRankingContext rankingContext;

private UploadSnapshot(ServerPlayer player,
PatternEncodingPreferenceSession preferenceSession,
PatternEncodingRankingContext rankingContext) {
@Nullable PatternEncodingRankingContext rankingContext) {
this.player = player;
this.preferenceSession = preferenceSession;
this.rankingContext = rankingContext;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/data_energistics.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"normal.appeng.integration.modules.emi.AbstractRecipeHandlerMixin",
"normal.appeng.integration.modules.emi.EmiEncodePatternHandlerMixin",
"normal.cn.dancingsnow.neoecoae.client.NeoECOAEClientMixin",
"normal.com.extendedae_plus.client.ProviderListCacheMixin",
"normal.committee.nova.mods.avaritia.init.compat.emi.category.ExtremeSmithingRecipeCategoryMixin",
"normal.dev.emi.emi.registry.EmiRecipeFillerMixin",
"normal.dev.emi.emi.registry.EmiStackProvidersMixin",
Expand Down
Loading