1- package github.kasuminova.novaeng.common.crafttweaker.expansion ;
1+ package github.kasuminova.novaeng.common.crafttweaker.expansion
22
3- import crafttweaker.annotations.ZenRegister;
4- import github.kasuminova.novaeng.common.crafttweaker.util.NovaEngUtils;
5- import github.kasuminova.novaeng.common.hypernet.old.NetNodeCache;
6- import github.kasuminova.novaeng.common.hypernet.old.NetNodeImpl;
7- import github.kasuminova.novaeng.common.hypernet.old.research.ResearchCognitionData;
8- import github.kasuminova.novaeng.common.registry.RegistryHyperNet;
9- import hellfirepvp.modularmachinery.common.integration.crafttweaker.RecipePrimer;
10- import hellfirepvp.modularmachinery.common.tiles.base.TileMultiblockMachineController;
11- import net.minecraft.client.resources.I18n;
12- import net.minecraft.util.text.TextFormatting;
13- import net.minecraftforge.fml.common.FMLCommonHandler;
14- import stanhebben.zenscript.annotations.Optional;
15- import stanhebben.zenscript.annotations.ZenExpansion;
16- import stanhebben.zenscript.annotations.ZenMethod;
17-
18- import java.util.Arrays;
19- import java.util.Objects;
20- import java.util.stream.Collectors;
3+ import crafttweaker.annotations.ZenRegister
4+ import github.kasuminova.novaeng.common.crafttweaker.util.NovaEngUtils
5+ import github.kasuminova.novaeng.common.hypernet.old.NetNodeCache
6+ import github.kasuminova.novaeng.common.hypernet.old.NetNodeImpl
7+ import github.kasuminova.novaeng.common.hypernet.old.research.ResearchCognitionData
8+ import github.kasuminova.novaeng.common.registry.RegistryHyperNet
9+ import hellfirepvp.modularmachinery.common.integration.crafttweaker.RecipePrimer
10+ import net.minecraft.client.resources.I18n
11+ import net.minecraft.util.text.TextFormatting
12+ import net.minecraftforge.fml.common.FMLCommonHandler
13+ import stanhebben.zenscript.annotations.Optional
14+ import stanhebben.zenscript.annotations.ZenExpansion
15+ import stanhebben.zenscript.annotations.ZenMethod
16+ import java.util.Arrays
17+ import java.util.Objects
18+ import java.util.stream.Collectors
2119
2220@ZenRegister
2321@ZenExpansion(" mods.modularmachinery.RecipePrimer" )
24- public class RecipePrimerHyperNet {
22+ object RecipePrimerHyperNet {
2523
2624 /* *
2725 * 为一个配方添加算力要求。
28- * 用法:{@code requireComputationPoint(1.0F);}
26+ * 用法:` requireComputationPoint(1.0F);`
2927 */
30- public static RecipePrimer requireComputationPoint(final RecipePrimer primer,
31- final float required) {
32- return requireComputationPoint(primer, required, false );
28+ @JvmStatic
29+ fun RecipePrimer.requireComputationPoint (
30+ required : Float
31+ ): RecipePrimer {
32+ return this .requireComputationPoint(required, false )
3333 }
3434
35+ @JvmStatic
3536 @ZenMethod
36- public static RecipePrimer requireComputationPoint(final RecipePrimer primer,
37- final float required,
38- @Optional final boolean triggerFailure) {
39- if (FMLCommonHandler .instance().getSide().isClient()) {
40- primer.addRecipeTooltip(
41- I18n .format(" novaeng.hypernet.computation_point_required.tip" ,
42- NovaEngUtils .formatFLOPS(required)).intern()
43- );
37+ fun RecipePrimer.requireComputationPoint (
38+ required : Float ,
39+ @Optional triggerFailure : Boolean
40+ ): RecipePrimer {
41+ if (FMLCommonHandler .instance().side.isClient) {
42+ this .addRecipeTooltip(
43+ I18n .format(
44+ " novaeng.hypernet.computation_point_required.tip" ,
45+ NovaEngUtils .formatFLOPS(required.toDouble())
46+ ).intern()
47+ )
4448 }
4549
46- return primer.addPreCheckHandler(event -> {
47- TileMultiblockMachineController ctrl = event.getController();
48- NetNodeImpl node = NetNodeCache .getCache(ctrl, NetNodeImpl .class );
49- if (node != null ) {
50- node.checkComputationPoint(event, required);
51- }
52- }).addStartHandler(event -> {
53- TileMultiblockMachineController ctrl = event.getController();
54- NetNodeImpl node = NetNodeCache .getCache(ctrl, NetNodeImpl .class );
55- if (node != null ) {
56- node.onRecipeStart(event, required);
57- }
58- }).addFactoryStartHandler(event -> {
59- TileMultiblockMachineController ctrl = event.getController();
60- NetNodeImpl node = NetNodeCache .getCache(ctrl, NetNodeImpl .class );
61- if (node != null ) {
62- node.onRecipeStart(event, required);
63- }
64- }).addPreTickHandler(event -> {
65- TileMultiblockMachineController ctrl = event.getController();
66- NetNodeImpl node = NetNodeCache .getCache(ctrl, NetNodeImpl .class );
67- if (node != null ) {
68- node.onRecipePreTick(event, required, triggerFailure);
69- }
70- }).addFactoryPreTickHandler(event -> {
71- TileMultiblockMachineController ctrl = event.getController();
72- NetNodeImpl node = NetNodeCache .getCache(ctrl, NetNodeImpl .class );
73- if (node != null ) {
74- node.onRecipePreTick(event, required, triggerFailure);
75- }
76- }).addFactoryFinishHandler(event -> {
77- TileMultiblockMachineController ctrl = event.getController();
78- NetNodeImpl node = NetNodeCache .getCache(ctrl, NetNodeImpl .class );
79- if (node != null ) {
80- node.onRecipeFinished(event.getRecipeThread());
81- }
82- }).addFinishHandler(event -> {
83- TileMultiblockMachineController ctrl = event.getController();
84- NetNodeImpl node = NetNodeCache .getCache(ctrl, NetNodeImpl .class );
85- if (node != null ) {
86- node.onRecipeFinished(event.getRecipeThread());
87- }
88- });
50+ return this .addPreCheckHandler {
51+ val ctrl = it.getController()
52+ val node = NetNodeCache .getCache(ctrl, NetNodeImpl ::class .java)
53+ node?.checkComputationPoint(it, required.toDouble())
54+ }.addStartHandler {
55+ val ctrl = it.getController()
56+ val node = NetNodeCache .getCache(ctrl, NetNodeImpl ::class .java)
57+ node?.onRecipeStart(it, required.toDouble())
58+ }.addFactoryStartHandler {
59+ val ctrl = it.getController()
60+ val node = NetNodeCache .getCache(ctrl, NetNodeImpl ::class .java)
61+ node?.onRecipeStart(it, required.toDouble())
62+ }.addPreTickHandler {
63+ val ctrl = it.getController()
64+ val node = NetNodeCache .getCache(ctrl, NetNodeImpl ::class .java)
65+ node?.onRecipePreTick(it, required.toDouble(), triggerFailure)
66+ }.addFactoryPreTickHandler {
67+ val ctrl = it.getController()
68+ val node = NetNodeCache .getCache(ctrl, NetNodeImpl ::class .java)
69+ node?.onRecipePreTick(it, required.toDouble(), triggerFailure)
70+ }.addFactoryFinishHandler {
71+ val ctrl = it.getController()
72+ val node = NetNodeCache .getCache(ctrl, NetNodeImpl ::class .java)
73+ node?.onRecipeFinished(it.getRecipeThread())
74+ }.addFinishHandler {
75+ val ctrl = it.getController()
76+ val node = NetNodeCache .getCache(ctrl, NetNodeImpl ::class .java)
77+ node?.onRecipeFinished(it.recipeThread)
78+ }
8979 }
9080
9181 /* *
9282 * 为一个配方添加研究认知要求。
93- * 用法:{@code requireResearch("research_name_a", "research_name_b")}
83+ * 用法:` requireResearch("research_name_a", "research_name_b")`
9484 */
85+ @JvmStatic
9586 @ZenMethod
96- public static RecipePrimer requireResearch(final RecipePrimer primer,
97- final String .. . researchNames) {
98- return requireResearch(primer, Arrays .stream(researchNames)
99- .map(RegistryHyperNet ::getResearchCognitionData)
100- .filter(Objects ::nonNull)
101- .toArray(ResearchCognitionData []::new));
87+ fun RecipePrimer.requireResearch (
88+ vararg researchNames : String
89+ ): RecipePrimer {
90+ return this .requireResearch(
91+ * Arrays .stream(researchNames)
92+ .map {
93+ RegistryHyperNet .getResearchCognitionData(it)
94+ }
95+ .filter { Objects .nonNull(it) }
96+ .toArray { arrayOf<ResearchCognitionData >() }
97+ )
10298 }
10399
100+ @JvmStatic
104101 @ZenMethod
105- public static RecipePrimer requireResearch(final RecipePrimer primer,
106- final ResearchCognitionData .. . researchRequired) {
107- if (FMLCommonHandler .instance().getSide().isClient()) {
108- String researchTip = Arrays .stream(researchRequired)
109- .map(ResearchCognitionData ::getTranslatedName)
110- .collect(Collectors .joining(TextFormatting .RESET + " , " ));
111- primer.addRecipeTooltip(I18n .format(" novaeng.hypernet.research_required.tip" , researchTip).intern());
102+ fun RecipePrimer.requireResearch (
103+ vararg researchRequired : ResearchCognitionData
104+ ): RecipePrimer {
105+ if (FMLCommonHandler .instance().side.isClient) {
106+ val researchTip = Arrays .stream(researchRequired)
107+ .map { it.translatedName }
108+ .collect(Collectors .joining(" ${TextFormatting .RESET } , " ))
109+ this .addRecipeTooltip(I18n .format(" novaeng.hypernet.research_required.tip" , researchTip).intern())
112110 }
113111
114- return primer.addPostCheckHandler(event -> {
115- NetNodeImpl cache = NetNodeCache .getCache(event.getController(), NetNodeImpl .class );
116- if (cache != null ) {
117- cache.checkResearch(event, researchRequired);
118- }
119- });
112+ return this .addPostCheckHandler {
113+ val cache = NetNodeCache .getCache(it.getController(), NetNodeImpl ::class .java)
114+ cache?.checkResearch(it, * researchRequired)
115+ }
120116 }
121- }
117+ }
0 commit comments