Skip to content
Closed
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 @@ -8,35 +8,62 @@
import appeng.api.networking.security.IActionSource;
import appeng.api.stacks.AEKey;
import appeng.api.stacks.KeyCounter;
import appeng.crafting.inv.ListCraftingInventory;
import com.extendedae_plus.api.crafting.IForcedCraftingPlan;
import com.extendedae_plus.api.crafting.IManualCraftingState;
import com.extendedae_plus.crafting.ForcedCraftingPlan;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.pedroksl.advanced_ae.common.cluster.AdvCraftingCPU;
import net.pedroksl.advanced_ae.common.logic.AdvCraftingCPULogic;
import net.pedroksl.advanced_ae.common.logic.ExecutingCraftingJob;
import org.jetbrains.annotations.Nullable;
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;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

@Mixin(value = AdvCraftingCPULogic.class, remap = false)
public abstract class AdvCraftingCPULogicManualWaitingMixin implements IManualCraftingState {
@Unique
private static final String EAP_MANUAL_WAITING_NBT_KEY = "extendedae_plus:manual_waiting";

@Shadow
private AdvCraftingCPU cpu;

@Shadow
private ExecutingCraftingJob job;

@Shadow
private ListCraftingInventory inventory;

@Shadow
protected abstract void postChange(AEKey what);

@Unique
private final Map<AEKey, Long> eap$manualWaitingFor = new LinkedHashMap<>();

@Override
public void eap$setManualWaiting(KeyCounter manualWaiting) {
this.eap$clearManualWaitingInternal();
this.eap$clearManualWaitingInternal(false);
for (var entry : manualWaiting) {
if (entry.getKey() != null && entry.getLongValue() > 0) {
this.eap$manualWaitingFor.put(entry.getKey(), entry.getLongValue());
this.postChange(entry.getKey());
}
}
if (!this.eap$manualWaitingFor.isEmpty()) {
this.cpu.markDirty();
}
}

@Override
Expand Down Expand Up @@ -69,14 +96,14 @@ public abstract class AdvCraftingCPULogicManualWaitingMixin implements IManualCr
if (manualMissing != null) {
this.eap$setManualWaiting(manualMissing);
} else {
this.eap$clearManualWaitingInternal();
this.eap$clearManualWaitingInternal(false);
}
}

@Inject(method = "insert", at = @At("RETURN"), cancellable = true)
private void eap$consumeManualWaitingAfterVanilla(AEKey what, long amount, Actionable type,
CallbackInfoReturnable<Long> cir) {
if (what == null) {
if (what == null || this.job == null) {
return;
}

Expand All @@ -94,6 +121,9 @@ public abstract class AdvCraftingCPULogicManualWaitingMixin implements IManualCr
long consumed = Math.min(remainingAmount, manualWaiting);
if (type == Actionable.MODULATE) {
this.eap$decreaseManualWaiting(what, consumed);
this.cpu.markDirty();
this.postChange(what);
this.inventory.insert(what, consumed, Actionable.MODULATE);
}

cir.setReturnValue(vanillaInserted + consumed);
Expand Down Expand Up @@ -124,7 +154,41 @@ public abstract class AdvCraftingCPULogicManualWaitingMixin implements IManualCr

@Inject(method = "finishJob", at = @At("HEAD"))
private void eap$clearManualWaitingOnFinish(boolean success, CallbackInfo ci) {
this.eap$clearManualWaitingInternal();
this.eap$clearManualWaitingInternal(true);
}

@Inject(method = "writeToNBT(Lnet/minecraft/nbt/CompoundTag;)V", at = @At("TAIL"))
private void eap$writeManualWaitingToNbt(CompoundTag data, CallbackInfo ci) {
data.remove(EAP_MANUAL_WAITING_NBT_KEY);
if (this.job == null || this.eap$manualWaitingFor.isEmpty()) {
return;
}

var entries = new ListTag();
for (var entry : this.eap$manualWaitingFor.entrySet()) {
var entryTag = entry.getKey().toTagGeneric();
entryTag.putLong("#", entry.getValue());
entries.add(entryTag);
}
data.put(EAP_MANUAL_WAITING_NBT_KEY, entries);
}

@Inject(method = "readFromNBT(Lnet/minecraft/nbt/CompoundTag;)V", at = @At("TAIL"))
private void eap$readManualWaitingFromNbt(CompoundTag data, CallbackInfo ci) {
this.eap$manualWaitingFor.clear();
if (this.job == null) {
return;
}

var entries = data.getList(EAP_MANUAL_WAITING_NBT_KEY, Tag.TAG_COMPOUND);
for (int i = 0; i < entries.size(); i++) {
var entryTag = entries.getCompound(i);
var key = AEKey.fromTagGeneric(entryTag);
long amount = entryTag.getLong("#");
if (key != null && amount > 0) {
this.eap$manualWaitingFor.put(key, amount);
}
}
}

@Unique
Expand All @@ -138,10 +202,18 @@ public abstract class AdvCraftingCPULogicManualWaitingMixin implements IManualCr
}

@Unique
private void eap$clearManualWaitingInternal() {
private void eap$clearManualWaitingInternal(boolean notifyChanges) {
if (this.eap$manualWaitingFor.isEmpty()) {
return;
}

var previousKeys = new ArrayList<>(this.eap$manualWaitingFor.keySet());
this.eap$manualWaitingFor.clear();
if (notifyChanges) {
for (var key : previousKeys) {
this.postChange(key);
}
}
this.cpu.markDirty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.extendedae_plus.network.crafting.ManualCraftingStatusS2CPacket;
import net.minecraft.server.level.ServerPlayer;
import net.pedroksl.advanced_ae.common.cluster.AdvCraftingCPU;
import net.pedroksl.advanced_ae.gui.quantumcomputer.QuantumComputerMenu;
import net.minecraftforge.network.PacketDistributor;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
Expand All @@ -19,34 +20,35 @@
import java.util.LinkedHashMap;
import java.util.Map;

@Mixin(value = CraftingCPUMenu.class, remap = false)
@Mixin(value = QuantumComputerMenu.class, priority = 1100, remap = false)
public abstract class CraftingCPUMenuManualStatusAdvancedMixin {
@Unique
private AdvCraftingCPU eap$advancedaeSelectedCpu;

@Unique
private Map<AEKey, Long> eap$advancedaeLastManualWaitingSnapshot = Collections.emptyMap();

@Inject(method = "setCPU", at = @At("HEAD"))
@Inject(
method = "setCPU(Lappeng/api/networking/crafting/ICraftingCPU;)V",
at = @At("HEAD"))
private void eap$trackAdvancedAeCpu(ICraftingCPU cpu, CallbackInfo ci) {
this.eap$advancedaeSelectedCpu = cpu instanceof AdvCraftingCPU advCpu ? advCpu : null;
if (this.eap$advancedaeSelectedCpu == null) {
this.eap$advancedaeLastManualWaitingSnapshot = Collections.emptyMap();
AdvCraftingCPU selectedCpu = cpu instanceof AdvCraftingCPU advCpu ? advCpu : null;
if (this.eap$advancedaeSelectedCpu != selectedCpu) {
this.eap$advancedaeSelectedCpu = selectedCpu;
this.eap$advancedaeLastManualWaitingSnapshot = null;
}
}

@Inject(method = "broadcastChanges", at = @At("TAIL"))
@Inject(method = "broadcastChanges()V", at = @At("TAIL"), remap = true)
private void eap$syncAdvancedAeManualWaitingStatus(CallbackInfo ci) {
CraftingCPUMenu self = (CraftingCPUMenu) (Object) this;
if (self.isClientSide() || !(self.getPlayer() instanceof ServerPlayer serverPlayer)) {
return;
}
if (this.eap$advancedaeSelectedCpu == null) {
return;
}

Map<AEKey, Long> snapshot = Collections.emptyMap();
if (this.eap$advancedaeSelectedCpu.craftingLogic instanceof IManualCraftingState manualState) {
if (this.eap$advancedaeSelectedCpu != null
&& this.eap$advancedaeSelectedCpu.craftingLogic instanceof IManualCraftingState manualState) {
snapshot = manualState.eap$getManualWaitingSnapshot();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.extendedae_plus.mixin.ae2.client.gui;

import appeng.api.client.AEKeyRendering;
import appeng.api.stacks.AmountFormat;
import appeng.api.util.AEColor;
import appeng.client.gui.me.crafting.CraftingCPUScreen;
import appeng.client.gui.me.crafting.CraftingStatusTableRenderer;
import appeng.core.AEConfig;
import appeng.core.localization.GuiText;
import appeng.menu.me.crafting.CraftingStatusEntry;
import com.extendedae_plus.content.ClientManualCraftingStatusStore;
import net.minecraft.ChatFormatting;
Expand Down Expand Up @@ -35,21 +37,49 @@ public abstract class CraftingStatusTableRendererMixin {
}
}

@Inject(method = "getEntryTooltip", at = @At("RETURN"), cancellable = true)
private void eap$appendManualWaitingTooltip(CraftingStatusEntry entry,
@Inject(
method = "getEntryDescription(Lappeng/menu/me/crafting/CraftingStatusEntry;)Ljava/util/List;",
at = @At("HEAD"),
cancellable = true)
private void eap$replaceManualWaitingDescription(CraftingStatusEntry entry,
CallbackInfoReturnable<List<Component>> cir) {
long manualWaiting = this.eap$getManualWaitingAmount(entry);
if (manualWaiting <= 0 || entry.getWhat() == null) {
return;
}

List<Component> lines = new ArrayList<>(cir.getReturnValue());
lines.add(Component.translatable(
"tooltip.extendedae_plus.crafting.manual_waiting",
entry.getWhat().formatAmount(manualWaiting, AmountFormat.FULL)).withStyle(ChatFormatting.AQUA));
List<Component> lines = new ArrayList<>(2);
lines.add(GuiText.FromStorage.text(
entry.getWhat().formatAmount(entry.getStoredAmount(), AmountFormat.SLOT)));
lines.add(this.eap$manualWaitingLine(entry, manualWaiting, AmountFormat.SLOT));
cir.setReturnValue(lines);
}

@Inject(
method = "getEntryTooltip(Lappeng/menu/me/crafting/CraftingStatusEntry;)Ljava/util/List;",
at = @At("HEAD"),
cancellable = true)
private void eap$replaceManualWaitingTooltip(CraftingStatusEntry entry,
CallbackInfoReturnable<List<Component>> cir) {
long manualWaiting = this.eap$getManualWaitingAmount(entry);
if (manualWaiting <= 0 || entry.getWhat() == null) {
return;
}

List<Component> lines = AEKeyRendering.getTooltip(entry.getWhat());
lines.add(GuiText.FromStorage.text(
entry.getWhat().formatAmount(entry.getStoredAmount(), AmountFormat.FULL)));
lines.add(this.eap$manualWaitingLine(entry, manualWaiting, AmountFormat.FULL));
cir.setReturnValue(lines);
}

@Unique
private Component eap$manualWaitingLine(CraftingStatusEntry entry, long manualWaiting, AmountFormat format) {
return Component.translatable(
"tooltip.extendedae_plus.crafting.manual_waiting",
entry.getWhat().formatAmount(manualWaiting, format)).withStyle(ChatFormatting.AQUA);
}

@Unique
private long eap$getManualWaitingAmount(CraftingStatusEntry entry) {
if (entry == null || entry.getWhat() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import appeng.me.cluster.implementations.CraftingCPUCluster;
import com.extendedae_plus.api.crafting.IForcedCraftingPlan;
import com.extendedae_plus.api.crafting.IManualCraftingState;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -30,6 +33,9 @@

@Mixin(value = CraftingCpuLogic.class, remap = false)
public abstract class CraftingCpuLogicManualWaitingMixin implements IManualCraftingState {
@Unique
private static final String EAP_MANUAL_WAITING_NBT_KEY = "extendedae_plus:manual_waiting";

@Shadow
private CraftingCPUCluster cluster;

Expand Down Expand Up @@ -143,6 +149,40 @@ public abstract class CraftingCpuLogicManualWaitingMixin implements IManualCraft
this.eap$clearManualWaitingInternal(true);
}

@Inject(method = "writeToNBT(Lnet/minecraft/nbt/CompoundTag;)V", at = @At("TAIL"))
private void eap$writeManualWaitingToNbt(CompoundTag data, CallbackInfo ci) {
data.remove(EAP_MANUAL_WAITING_NBT_KEY);
if (this.job == null || this.eap$manualWaitingFor.isEmpty()) {
return;
}

var entries = new ListTag();
for (var entry : this.eap$manualWaitingFor.entrySet()) {
var entryTag = entry.getKey().toTagGeneric();
entryTag.putLong("#", entry.getValue());
entries.add(entryTag);
}
data.put(EAP_MANUAL_WAITING_NBT_KEY, entries);
}

@Inject(method = "readFromNBT(Lnet/minecraft/nbt/CompoundTag;)V", at = @At("TAIL"))
private void eap$readManualWaitingFromNbt(CompoundTag data, CallbackInfo ci) {
this.eap$manualWaitingFor.clear();
if (this.job == null) {
return;
}

var entries = data.getList(EAP_MANUAL_WAITING_NBT_KEY, Tag.TAG_COMPOUND);
for (int i = 0; i < entries.size(); i++) {
var entryTag = entries.getCompound(i);
var key = AEKey.fromTagGeneric(entryTag);
long amount = entryTag.getLong("#");
if (key != null && amount > 0) {
this.eap$manualWaitingFor.put(key, amount);
}
}
}

@Unique
private void eap$decreaseManualWaiting(AEKey what, long amount) {
long current = this.eap$manualWaitingFor.getOrDefault(what, 0L);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.extendedae_plus.mixin.ae2.menu;

import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.stacks.AEKey;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.menu.me.crafting.CraftingCPUMenu;
Expand All @@ -9,7 +10,6 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.network.PacketDistributor;
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;
Expand All @@ -19,24 +19,38 @@
import java.util.LinkedHashMap;
import java.util.Map;

@Mixin(value = CraftingCPUMenu.class, remap = false)
@Mixin(value = CraftingCPUMenu.class, priority = 1100, remap = false)
public abstract class CraftingCPUMenuManualStatusMixin {
@Shadow
private CraftingCPUCluster cpu;
@Unique
private ICraftingCPU eap$selectedCpu;

@Unique
private Map<AEKey, Long> eap$lastManualWaitingSnapshot = Collections.emptyMap();

@Inject(method = "broadcastChanges", at = @At("TAIL"))
@Inject(
method = "setCPU(Lappeng/api/networking/crafting/ICraftingCPU;)V",
at = @At("HEAD"))
private void eap$trackSelectedCpu(ICraftingCPU cpu, CallbackInfo ci) {
if (this.eap$selectedCpu != cpu) {
this.eap$selectedCpu = cpu;
this.eap$lastManualWaitingSnapshot = null;
}
}

@Inject(method = "broadcastChanges()V", at = @At("TAIL"), remap = true)
private void eap$syncManualWaitingStatus(CallbackInfo ci) {
CraftingCPUMenu self = (CraftingCPUMenu) (Object) this;
if (self.isClientSide() || !(self.getPlayer() instanceof ServerPlayer serverPlayer)) {
return;
}

Map<AEKey, Long> snapshot = Collections.emptyMap();
if (this.cpu != null && this.cpu.craftingLogic instanceof IManualCraftingState manualState) {
snapshot = manualState.eap$getManualWaitingSnapshot();
if (this.eap$selectedCpu instanceof CraftingCPUCluster selectedCpu) {
if (selectedCpu.craftingLogic instanceof IManualCraftingState manualState) {
snapshot = manualState.eap$getManualWaitingSnapshot();
}
} else if (this.eap$selectedCpu != null) {
return;
}

if (snapshot.equals(this.eap$lastManualWaitingSnapshot)) {
Expand Down