Skip to content

Commit eff63f3

Browse files
Dyeable Pattern (#6)
1 parent cfc44e7 commit eff63f3

31 files changed

Lines changed: 1554 additions & 0 deletions

src/main/java/com/ref/aea/AEA.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.mojang.logging.LogUtils;
44
import com.ref.aea.config.AEAClientConfig;
5+
import com.ref.aea.config.AEAServerConfig;
56
import net.minecraftforge.fml.common.Mod;
67
import net.minecraftforge.fml.config.ModConfig;
78
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@@ -15,5 +16,6 @@ public class AEA {
1516

1617
public AEA(FMLJavaModLoadingContext context) {
1718
context.registerConfig(ModConfig.Type.CLIENT, AEAClientConfig.SPEC);
19+
context.registerConfig(ModConfig.Type.SERVER, AEAServerConfig.SPEC);
1820
}
1921
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.ref.aea.api.mixin.ae.crafting.color;
2+
3+
import appeng.api.crafting.IPatternDetails;
4+
import appeng.api.stacks.AEKey;
5+
import appeng.api.stacks.GenericStack;
6+
import appeng.api.stacks.KeyCounter;
7+
import com.ref.aea.core.color.AEANetworkCraftingProviders;
8+
import java.util.*;
9+
import org.jetbrains.annotations.Nullable;
10+
11+
public record CraftingPlanCompressedRing(
12+
KeyCounter netInputs,
13+
KeyCounter netOutputs,
14+
KeyCounter catalysts,
15+
Map<IPatternDetails, Integer> executionRatio,
16+
Set<AEKey> entryPoints,
17+
boolean isCalculable) {
18+
19+
/** 计算并缓存环的属性。 假设:默认环已经被玩家配平(各模式执行比例为 1:1)。 */
20+
@Nullable
21+
public static CraftingPlanCompressedRing calculateAndCacheRingProperties(
22+
int color, AEANetworkCraftingProviders providers) {
23+
24+
var patternsInRing = providers.getPatternsByColor(color);
25+
if (patternsInRing == null || patternsInRing.isEmpty()) {
26+
return null;
27+
}
28+
29+
KeyCounter totalInputs = new KeyCounter();
30+
KeyCounter totalOutputs = new KeyCounter();
31+
32+
Map<IPatternDetails, Integer> executionRatio = new HashMap<>(patternsInRing.size());
33+
34+
for (IPatternDetails pattern : patternsInRing) {
35+
executionRatio.put(pattern, 1);
36+
37+
for (GenericStack output : pattern.getOutputs()) {
38+
if (output != null && output.amount() > 0) {
39+
totalOutputs.add(output.what(), output.amount());
40+
}
41+
}
42+
43+
for (var input : pattern.getInputs()) {
44+
GenericStack[] possibleInputs = input.getPossibleInputs();
45+
if (possibleInputs != null && possibleInputs.length > 0) {
46+
GenericStack baseStack = possibleInputs[0];
47+
if (baseStack != null && baseStack.amount() > 0) {
48+
long requiredAmount = baseStack.amount() * input.getMultiplier();
49+
totalInputs.add(baseStack.what(), requiredAmount);
50+
}
51+
}
52+
}
53+
}
54+
55+
KeyCounter netInputs = new KeyCounter();
56+
KeyCounter netOutputs = new KeyCounter();
57+
KeyCounter catalysts = new KeyCounter();
58+
59+
Set<AEKey> allKeys = new HashSet<>(totalInputs.keySet());
60+
allKeys.addAll(totalOutputs.keySet());
61+
62+
for (AEKey key : allKeys) {
63+
long in = totalInputs.get(key);
64+
long out = totalOutputs.get(key);
65+
66+
if (in > 0 && out > 0) {
67+
if (out > in) {
68+
netOutputs.add(key, out - in);
69+
catalysts.add(key, in);
70+
} else if (in > out) {
71+
netInputs.add(key, in - out);
72+
} else {
73+
catalysts.add(key, 1);
74+
}
75+
} else if (in > 0) {
76+
netInputs.add(key, in);
77+
} else if (out > 0) {
78+
netOutputs.add(key, out);
79+
}
80+
}
81+
82+
Set<AEKey> entryPoints = new HashSet<>(netOutputs.keySet());
83+
84+
return new CraftingPlanCompressedRing(
85+
netInputs, netOutputs, catalysts, executionRatio, entryPoints, true);
86+
}
87+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.ref.aea.api.mixin.ae.crafting.color;
2+
3+
public interface IMixinCraftingService {
4+
CraftingPlanCompressedRing AEA$getCompressedRing(int color);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.ref.aea.api.mixin.ae.crafting.color;
2+
3+
public interface IMixinPatternDetails {
4+
int AEA$getColor();
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.ref.aea.api.mixin.ae.crafting.color;
2+
3+
public class RingReplacementTriggeredException extends RuntimeException {
4+
@Override
5+
public synchronized Throwable fillInStackTrace() {
6+
return this;
7+
}
8+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.ref.aea.config;
2+
3+
import com.ref.aea.AEA;
4+
import net.minecraftforge.common.ForgeConfigSpec;
5+
import net.minecraftforge.eventbus.api.SubscribeEvent;
6+
import net.minecraftforge.fml.common.Mod;
7+
import net.minecraftforge.fml.event.config.ModConfigEvent;
8+
9+
@Mod.EventBusSubscriber(modid = AEA.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
10+
public class AEAServerConfig {
11+
private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
12+
13+
private static final ForgeConfigSpec.BooleanValue COLOR =
14+
BUILDER.comment("Whether to use Color Pattern").define("Color", true);
15+
16+
private static final ForgeConfigSpec.BooleanValue CPU =
17+
BUILDER.comment("Allows the CPU to store the final output").define("CPU", true);
18+
19+
public static final ForgeConfigSpec SPEC = BUILDER.build();
20+
21+
public static boolean color;
22+
public static boolean cpu;
23+
24+
@SubscribeEvent
25+
static void onLoad(final ModConfigEvent event) {
26+
if (event.getConfig().getSpec() != SPEC) return;
27+
color = COLOR.get();
28+
cpu = CPU.get();
29+
}
30+
}

0 commit comments

Comments
 (0)