diff --git a/build.gradle.kts b/build.gradle.kts index cbb73d3d..0af7bfe2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -159,6 +159,7 @@ repositories { url = uri("http://jenkins.usrv.eu:8081/nexus/content/groups/public/") isAllowInsecureProtocol = true } + //mavenLocal() } dependencies { @@ -194,9 +195,13 @@ dependencies { compileOnly("org.jetbrains.kotlin:kotlin-stdlib:2.2.0") compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1") + compileOnlyApi("org.jetbrains:annotations:24.1.0") + annotationProcessor("org.jetbrains:annotations:24.1.0") + implementation("com.cleanroommc:groovyscript:1.2.5") { isTransitive = false } implementation("CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.+") + implementation(rfg.deobf("curse.maven:had-enough-items-557549:4810661")) - implementation(rfg.deobf("curse.maven:zenutil-401178:5056679")) + compileOnly(rfg.deobf("curse.maven:zenutil-401178:5056679")) implementation(rfg.deobf("curse.maven:RedstoneFlux-270789:2920436")) implementation(rfg.deobf("curse.maven:CodeChickenLib-242818:2779848")) implementation(rfg.deobf("curse.maven:brandonscore-231382:3051539")) @@ -344,4 +349,4 @@ idea { tasks.processIdeaSettings.configure { dependsOn(tasks.injectTags) -} \ No newline at end of file +} diff --git a/src/main/java/github/kasuminova/mmce/common/event/machine/IEventHandler.java b/src/main/java/github/kasuminova/mmce/common/event/machine/IEventHandler.java new file mode 100644 index 00000000..1f9c7d0f --- /dev/null +++ b/src/main/java/github/kasuminova/mmce/common/event/machine/IEventHandler.java @@ -0,0 +1,19 @@ +package github.kasuminova.mmce.common.event.machine; + +import groovy.lang.Closure; +import net.minecraftforge.fml.common.Optional; + +public interface IEventHandler { + + void invoke(T event); + + @Optional.Method(modid = "groovyscript") + static IEventHandler of(Closure listener) { + return listener::call; + } + + @Optional.Method(modid = "crafttweaker") + static IEventHandler of(crafttweaker.util.IEventHandler eventHandler) { + return eventHandler::handle; + } +} diff --git a/src/main/java/github/kasuminova/mmce/common/event/machine/MachineEvent.java b/src/main/java/github/kasuminova/mmce/common/event/machine/MachineEvent.java index 35da05f2..e595a4c3 100644 --- a/src/main/java/github/kasuminova/mmce/common/event/machine/MachineEvent.java +++ b/src/main/java/github/kasuminova/mmce/common/event/machine/MachineEvent.java @@ -1,7 +1,6 @@ package github.kasuminova.mmce.common.event.machine; import crafttweaker.annotations.ZenRegister; -import crafttweaker.util.IEventHandler; import github.kasuminova.mmce.common.handler.UpgradeMachineEventHandler; import github.kasuminova.mmce.common.helper.IMachineController; import hellfirepvp.modularmachinery.ModularMachinery; @@ -69,7 +68,7 @@ public void postCrTEvent() { } for (IEventHandler handler : handlers) { - handler.handle(this); + handler.invoke(this); if (isCanceled()) { break; } diff --git a/src/main/java/github/kasuminova/mmce/common/event/recipe/RecipeEvent.java b/src/main/java/github/kasuminova/mmce/common/event/recipe/RecipeEvent.java index 7ed5b6a9..be03c77e 100644 --- a/src/main/java/github/kasuminova/mmce/common/event/recipe/RecipeEvent.java +++ b/src/main/java/github/kasuminova/mmce/common/event/recipe/RecipeEvent.java @@ -1,7 +1,7 @@ package github.kasuminova.mmce.common.event.recipe; import crafttweaker.annotations.ZenRegister; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.machine.MachineEvent; import hellfirepvp.modularmachinery.common.crafting.ActiveMachineRecipe; import hellfirepvp.modularmachinery.common.crafting.helper.RecipeCraftingContext; @@ -54,7 +54,7 @@ public void postCrTEvent() { return; } for (IEventHandler handler : handlers) { - handler.handle(this); + handler.invoke(this); if (isCanceled()) { break; } diff --git a/src/main/java/github/kasuminova/mmce/common/helper/IMachineController.java b/src/main/java/github/kasuminova/mmce/common/helper/IMachineController.java index dd3e1ab2..099075c0 100644 --- a/src/main/java/github/kasuminova/mmce/common/helper/IMachineController.java +++ b/src/main/java/github/kasuminova/mmce/common/helper/IMachineController.java @@ -16,12 +16,19 @@ import hellfirepvp.modularmachinery.common.modifier.RecipeModifier; import hellfirepvp.modularmachinery.common.tiles.base.TileMultiblockMachineController; import hellfirepvp.modularmachinery.common.util.SmartInterfaceData; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.Optional; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenGetter; import stanhebben.zenscript.annotations.ZenMethod; import stanhebben.zenscript.annotations.ZenSetter; import javax.annotation.Nullable; +import java.util.function.Predicate; @ZenRegister @ZenClass("mods.modularmachinery.IMachineController") @@ -32,33 +39,45 @@ public interface IMachineController { * * @return 世界 */ + @Optional.Method(modid = "crafttweaker") @ZenGetter("world") IWorld getIWorld(); + World getWorld(); + /** * 获取控制器方块。 * * @return IBlockState */ + @Optional.Method(modid = "crafttweaker") @ZenGetter("blockState") IBlockState getIBlockState(); + net.minecraft.block.state.IBlockState getBlockState(); + /** * 获取控制器处于世界中的朝向。 * * @return IFacing */ + @Optional.Method(modid = "crafttweaker") @ZenGetter("facing") IFacing getFacing(); + EnumFacing getEnumFacing(); + /** * 获取控制器所在的坐标 * * @return 坐标 */ + @Optional.Method(modid = "crafttweaker") @ZenGetter("pos") IBlockPos getIPos(); + BlockPos getPos(); + /** * 根据控制器的朝向,将给定的坐标旋转到控制器朝向。 * @@ -137,6 +156,7 @@ public interface IMachineController { * * @return IData */ + @Optional.Method(modid = "crafttweaker") @ZenGetter("customData") IData getCustomData(); @@ -145,9 +165,14 @@ public interface IMachineController { * * @param data IData */ + @Optional.Method(modid = "crafttweaker") @ZenSetter("customData") void setCustomData(IData data); + NBTTagCompound getCustomNbt(); + + void setCustomNbt(NBTTagCompound nbt); + /** * 添加一个半永久 RecipeModifier,会在配方完成的时候自动删除。 * @@ -272,9 +297,12 @@ public interface IMachineController { * @param blockStack 要判断的方块对应的物品,会被自动转换成对应的 IBlockState,如果转换出现问题会输出错误日志。 * @return 存在数量。 */ + @net.minecraftforge.fml.common.Optional.Method(modid = "crafttweaker") @ZenMethod int getBlocksInPattern(final IItemStack blockStack); + int getBlocksInPattern(ItemStack itemStack); + /** * 获取控制器的结构中指定方块的存在数量,只能在控制器成型时使用。
* 会过滤空气方块。
@@ -283,6 +311,7 @@ public interface IMachineController { * @param blockStateMatcher 要判断的方块对应的 IBlockStateMatcher * @return 存在数量。 */ + @net.minecraftforge.fml.common.Optional.Method(modid = "crafttweaker") @ZenMethod int getBlocksInPattern(final IBlockStateMatcher blockStateMatcher); @@ -305,9 +334,12 @@ public interface IMachineController { * @param predicate 自定义判断逻辑。 * @return 存在数量。 */ + @net.minecraftforge.fml.common.Optional.Method(modid = "crafttweaker") @ZenMethod int getBlocksInPattern(final IBlockStatePredicate predicate); + int getBlocksInPattern(Predicate predicate); + /** * 获取控制器的拥有者,如果玩家不在线则返回 null。 * diff --git a/src/main/java/github/kasuminova/mmce/common/integration/Logger.java b/src/main/java/github/kasuminova/mmce/common/integration/Logger.java new file mode 100644 index 00000000..72666e6c --- /dev/null +++ b/src/main/java/github/kasuminova/mmce/common/integration/Logger.java @@ -0,0 +1,67 @@ +package github.kasuminova.mmce.common.integration; + +import com.cleanroommc.groovyscript.GroovyScript; +import com.cleanroommc.groovyscript.api.GroovyLog; +import crafttweaker.CraftTweakerAPI; +import hellfirepvp.modularmachinery.ModularMachinery; +import hellfirepvp.modularmachinery.common.base.Mods; +import org.apache.logging.log4j.message.ParameterizedMessage; + +/** + * A logger which logs to CraftTweaker, GroovyScript and this mods log, depending on if the mods are loaded. + */ +public class Logger { + + private static final String CT_PREFIX = "[ModularMachinery] "; + private static final Object[] NO_ARGS = new Object[0]; + + private static boolean isGroovyScriptRunning() { + return Mods.GROOVYSCRIPT.isPresent() && GroovyScript.getSandbox().isRunning(); + } + + private static String formatMsg(String msg, Object... args) { + return args == null || args.length == 0 ? msg : new ParameterizedMessage(msg, args).getFormattedMessage(); + } + + public static void error(String msg) { + error(msg, NO_ARGS); + } + + public static void warn(String msg) { + warn(msg, NO_ARGS); + } + + public static void info(String msg) { + info(msg, NO_ARGS); + } + + public static void error(String msg, Object... args) { + if (isGroovyScriptRunning()) { + GroovyLog.get().error(msg, args); + } + if (Mods.CRAFTTWEAKER.isPresent()) { + CraftTweakerAPI.logError(CT_PREFIX + formatMsg(msg, args)); + } + ModularMachinery.log.error(msg, args); + } + + public static void warn(String msg, Object... args) { + if (isGroovyScriptRunning()) { + GroovyLog.get().warn(msg, args); + } + if (Mods.CRAFTTWEAKER.isPresent()) { + CraftTweakerAPI.logWarning(formatMsg(msg, args)); + } + ModularMachinery.log.warn(msg, args); + } + + public static void info(String msg, Object... args) { + if (isGroovyScriptRunning()) { + GroovyLog.get().info(msg, args); + } + if (Mods.CRAFTTWEAKER.isPresent()) { + CraftTweakerAPI.logInfo(formatMsg(msg, args)); + } + ModularMachinery.log.info(msg, args); + } +} diff --git a/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/BlockArrayBuilder.java b/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/BlockArrayBuilder.java new file mode 100644 index 00000000..53ad19b4 --- /dev/null +++ b/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/BlockArrayBuilder.java @@ -0,0 +1,332 @@ +package github.kasuminova.mmce.common.integration.groovyscript; + +import com.cleanroommc.groovyscript.api.GroovyBlacklist; +import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.helper.ingredient.NbtHelper; +import com.cleanroommc.groovyscript.sandbox.ClosureHelper; +import groovy.lang.Closure; +import hellfirepvp.modularmachinery.common.crafting.helper.ComponentSelectorTag; +import hellfirepvp.modularmachinery.common.machine.DynamicMachine; +import hellfirepvp.modularmachinery.common.machine.TaggedPositionBlockArray; +import hellfirepvp.modularmachinery.common.modifier.RecipeModifier; +import hellfirepvp.modularmachinery.common.modifier.SingleBlockModifierReplacement; +import hellfirepvp.modularmachinery.common.util.BlockArray; +import hellfirepvp.modularmachinery.common.util.IBlockStateDescriptor; +import it.unimi.dsi.fastutil.chars.Char2ObjectMap; +import it.unimi.dsi.fastutil.chars.Char2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.chars.CharArraySet; +import it.unimi.dsi.fastutil.chars.CharSet; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.BlockPos; + +import javax.annotation.Nullable; +import java.util.*; + +public class BlockArrayBuilder { + + protected final DynamicMachine machine; + private final TaggedPositionBlockArray blockArray; + private final List> tensor = new ArrayList<>(); + private final Char2ObjectMap charMap = new Char2ObjectOpenHashMap<>(); + private final Char2ObjectMap selectorTagMap = new Char2ObjectOpenHashMap<>(); + private final Map> blockModifierMap = new Object2ObjectOpenHashMap<>(); + private final Char2ObjectMap> blockModifierCharMap = new Char2ObjectOpenHashMap<>(); + protected BlockArray.BlockInformation lastInformation = null; + protected char lastChar = Character.MIN_VALUE; + private char controllerChar = Character.MIN_VALUE; + + private static final BlockArray.BlockInformation CONTROLLER = new BlockArray.BlockInformation(Collections.emptyList()); + + public BlockArrayBuilder(DynamicMachine machine) { + this.machine = machine; + this.blockArray = machine.getPattern(); + this.charMap.put(' ', null); + } + + public BlockArrayBuilder layer(String... row) { + this.tensor.add(Arrays.asList(row)); + return this; + } + + public BlockArrayBuilder layer(List row) { + this.tensor.add(row); + return this; + } + + @GroovyBlacklist + public BlockArrayBuilder where(String c, Runnable func) { + // groovy doesn't have char literals + if (c.length() != 1) { + throw new IllegalArgumentException("Argument in `where()` must have exactly one character!"); + } + func.run(); + return this; + } + + public BlockArrayBuilder whereAny(String c) { + return where(c, () -> { + this.lastInformation = null; + this.lastChar = c.charAt(0); + this.charMap.put(this.lastChar, null); + }); + } + + public BlockArrayBuilder whereAir(String c) { + return where(c, Blocks.AIR.getDefaultState()); + } + + public BlockArrayBuilder whereController(String c) { + if (this.controllerChar != Character.MIN_VALUE) { + GroovyLog.get().exception(new IllegalStateException("Controller is already assigned!")); + return this; + } + return where(c, () -> { + this.lastInformation = CONTROLLER; + this.lastChar = c.charAt(0); + this.controllerChar = this.lastChar; + this.charMap.put(this.lastChar, CONTROLLER); + }); + } + + public BlockArrayBuilder where(String c, IBlockState blockStates) { + return where(c, blockStates, null, null, null); + } + + public BlockArrayBuilder where(String c, IBlockState blockStates, @Nullable Map nbt) { + return where(c, blockStates, nbt, nbt, null); + } + + public BlockArrayBuilder where(String c, IBlockState blockStates, @Nullable Map nbt, + @Nullable Map previewNBT) { + return where(c, blockStates, nbt, previewNBT, null); + } + + public BlockArrayBuilder where(String c, IBlockState blockStates, @Nullable Map nbt, + Closure checker) { + return where(c, blockStates, nbt, nbt, checker); + } + + public BlockArrayBuilder where(String c, IBlockState blockStates, @Nullable Map nbt, + @Nullable Map previewNBT, Closure checker) { + return where(c, Collections.singletonList(blockStates), nbt, previewNBT, checker); + } + + public BlockArrayBuilder where(String c, Iterable blockStates) { + return where(c, blockStates, null, null, null); + } + + public BlockArrayBuilder where(String c, Iterable blockStates, @Nullable Map nbt) { + return where(c, blockStates, nbt, nbt, null); + } + + public BlockArrayBuilder where(String c, Iterable blockStates, @Nullable Map nbt, + @Nullable Map previewNBT) { + return where(c, blockStates, nbt, previewNBT, null); + } + + public BlockArrayBuilder where(String c, Iterable blockStates, @Nullable Map nbt, + Closure checker) { + return where(c, blockStates, nbt, nbt, checker); + } + + public BlockArrayBuilder where(String c, Iterable blockStates, @Nullable Map nbt, + @Nullable Map previewNBT, Closure checker) { + return where(c, () -> { + List stateDescriptorList = new ArrayList<>(); + for (IBlockState blockState : blockStates) { + stateDescriptorList.add(new IBlockStateDescriptor(blockState)); + } + this.lastInformation = new BlockArray.BlockInformation(stateDescriptorList); + this.lastChar = c.charAt(0); + this.charMap.put(this.lastChar, this.lastInformation); + if (nbt != null) nbt(nbt); + if (previewNBT != null) previewNbt(previewNBT); + if (checker != null) blockChecker(checker); + }); + } + + public BlockArrayBuilder blockModifier(int x, int y, int z, IBlockState blockStates, String description, RecipeModifier... modifiers) { + return blockModifier(x, y, z, Collections.singletonList(blockStates), description, modifiers); + } + + /** + * 添加单方块配方修改器。 + * + * @param x X + * @param y Y + * @param z Z + * @param blockStates BlockState + * @param description 描述 + * @param modifiers 修改器列表 + */ + public BlockArrayBuilder blockModifier(int x, int y, int z, Iterable blockStates, String description, RecipeModifier... modifiers) { + List stateDescriptorList = new ArrayList<>(); + for (IBlockState blockState : blockStates) { + stateDescriptorList.add(new IBlockStateDescriptor(blockState)); + } + singleBlockModifier(new BlockPos(x, y, z), new BlockArray.BlockInformation(stateDescriptorList), description, modifiers); + return this; + } + + public BlockArrayBuilder whereBlockModifier(String c, IBlockState blockStates, String description, RecipeModifier... modifiers) { + return whereBlockModifier(c, Collections.singletonList(blockStates), description, modifiers); + } + + public BlockArrayBuilder whereBlockModifier(String c, Iterable blockStates, String description, RecipeModifier... modifiers) { + where(c, () -> { + List stateDescriptorList = new ArrayList<>(); + for (IBlockState blockState : blockStates) { + stateDescriptorList.add(new IBlockStateDescriptor(blockState)); + } + singleBlockModifier(c.charAt(0), new BlockArray.BlockInformation(stateDescriptorList), description, modifiers); + }); + return this; + } + + private void singleBlockModifier(BlockPos pos, BlockArray.BlockInformation information, String description, RecipeModifier... modifiers) { + this.lastInformation = information; + this.lastChar = Character.MIN_VALUE; + this.blockModifierMap.computeIfAbsent(pos, k -> new ArrayList<>()) + .add(new SingleBlockModifierReplacement(information, Arrays.asList(modifiers), description)); + } + + private void singleBlockModifier(char c, BlockArray.BlockInformation information, String description, RecipeModifier... modifiers) { + this.lastInformation = information; + this.lastChar = c; + this.blockModifierCharMap.computeIfAbsent(c, k -> new ArrayList<>()) + .add(new SingleBlockModifierReplacement(information, Arrays.asList(modifiers), description)); + } + + public BlockArrayBuilder nbt(Map tag) { + return nbt(NbtHelper.ofMap(tag)); + } + + public BlockArrayBuilder nbt(NBTTagCompound tag) { + if (lastInformation != null) { + lastInformation.setMatchingTag(tag); + if (lastInformation.getPreviewTag() == null) { + lastInformation.setPreviewTag(tag); + } + } + return this; + } + + public BlockArrayBuilder previewNbt(Map data) { + return previewNbt(NbtHelper.ofMap(data)); + } + + public BlockArrayBuilder previewNbt(NBTTagCompound data) { + if (lastInformation != null) { + lastInformation.setPreviewTag(data); + } + return this; + } + + public BlockArrayBuilder blockChecker(Closure checker) { + if (lastInformation != null) { + lastInformation.setNBTChecker((world, pos, blockState, nbt) -> + ClosureHelper.call(true, checker, world, pos, blockState, nbt)); + } + return this; + } + + public BlockArrayBuilder tag(String tag) { + if (lastInformation != null && this.lastChar != Character.MIN_VALUE) { + this.selectorTagMap.put(this.lastChar, new ComponentSelectorTag(tag)); + } + return this; + } + + private BlockPos validate() { + if (this.controllerChar == Character.MIN_VALUE) { + GroovyLog.get().exception(new IllegalStateException("Controller location must be defined!")); + return null; + } + GroovyLog.Msg msg = GroovyLog.msg("Error creating BlockArray").error(); + if (this.tensor.isEmpty()) { + msg.add("no block matrix defined").post(); + return null; + } + CharSet checkedChars = new CharArraySet(); + int foundController = 0; + int cx = 0, cy = 0, cz = 0; + int layerSize = this.tensor.get(0).size(); + for (int x = 0; x < this.tensor.size(); x++) { + List xLayer = this.tensor.get(x); + if (xLayer.isEmpty()) { + msg.add("Layer {} is empty. This is not right", x + 1); + } else if (xLayer.size() != layerSize) { + msg.add("Invalid x-layer size. Expected {}, but got {} at layer {}", layerSize, xLayer.size(), x + 1); + } + int rowSize = xLayer.get(0).length(); + for (int y = 0; y < xLayer.size(); y++) { + String yRow = xLayer.get(y); + if (yRow.isEmpty()) { + msg.add("Row {} in layer {} is empty. This is not right", y + 1, x + 1); + } else if (yRow.length() != rowSize) { + msg.add("Invalid x-layer size. Expected {}, but got {} at row {} in layer {}", layerSize, xLayer.size(), y + 1, x + 1); + } + for (int z = 0; z < yRow.length(); z++) { + char zChar = yRow.charAt(z); + if (!checkedChars.contains(zChar)) { + if (!this.charMap.containsKey(zChar)) { + msg.add("Found char '{}' at char {} in row {} in layer {}, but character was not found in map!", zChar, z + 1, y + 1, x + 1); + } + checkedChars.add(zChar); + } + if (zChar == this.controllerChar) { + cx = x; + cy = y; + cz = z; + foundController++; + } + } + } + } + if (foundController == 0) { + msg.add("No controller was found, but exactly 1 is required"); + } else if (foundController > 1) { + msg.add("{} controller were found, but exactly 1 is required"); + } + if (msg.postIfNotEmpty()) { + return null; + } + return new BlockPos(cx, cy, cz); + } + + public void build() { + BlockPos controller = validate(); + if (controller == null) return; + + for (int x = 0; x < this.tensor.size(); x++) { + List xLayer = this.tensor.get(x); + for (int y = 0; y < xLayer.size(); y++) { + String yRow = xLayer.get(y); + for (int z = 0; z < yRow.length(); z++) { + char zChar = yRow.charAt(z); + BlockArray.BlockInformation info = this.charMap.get(zChar); + if (info == null || info == CONTROLLER) continue; // null -> any allowed -> don't need to check; CONTROLLER -> don't need to check + ComponentSelectorTag tag = this.selectorTagMap.get(zChar); + BlockPos pos = new BlockPos(x - controller.getX(), y - controller.getY(), z - controller.getZ()); + blockArray.addBlock(pos, info); + if (tag != null) { + blockArray.setTag(pos, tag); + } + List modifiers = this.blockModifierMap.get(pos); + if (modifiers != null) { + modifiers.forEach(modifier -> modifier.setPos(pos)); + this.machine.getModifiers().computeIfAbsent(pos, k -> new ArrayList<>()).addAll(modifiers); + } + modifiers = this.blockModifierCharMap.get(zChar); + if (modifiers != null) { + modifiers.forEach(modifier -> modifier.setPos(pos)); + this.machine.getModifiers().computeIfAbsent(pos, k -> new ArrayList<>()).addAll(modifiers); + } + } + } + } + } +} diff --git a/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/GroovyMachine.java b/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/GroovyMachine.java new file mode 100644 index 00000000..b4befe05 --- /dev/null +++ b/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/GroovyMachine.java @@ -0,0 +1,62 @@ +package github.kasuminova.mmce.common.integration.groovyscript; + +import com.cleanroommc.groovyscript.api.GroovyBlacklist; +import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.sandbox.ClosureHelper; +import groovy.lang.Closure; +import hellfirepvp.modularmachinery.common.data.Config; +import hellfirepvp.modularmachinery.common.integration.crafttweaker.MachineBuilder; +import hellfirepvp.modularmachinery.common.machine.DynamicMachine; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import net.minecraft.util.ResourceLocation; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@GroovyBlacklist +public class GroovyMachine { + + public static final Map PRE_LOAD_MACHINES = new Object2ObjectOpenHashMap<>(); + private static final List MACHINES = new ArrayList<>(); + + public static void init() { + MACHINES.forEach(GroovyMachine::build); + } + + public static void setMachineBuilder(String registryName, Closure buildFunction) { + for (GroovyMachine machine : MACHINES) { + if (machine.dynamicMachine.getRegistryName().getPath().equals(registryName)) { + machine.buildFunction = buildFunction; + break; + } + } + } + + private final DynamicMachine dynamicMachine; + private Closure buildFunction; + + @GroovyBlacklist + public GroovyMachine(DynamicMachine dynamicMachine, Closure buildFunction) { + this.dynamicMachine = dynamicMachine; + this.buildFunction = buildFunction; + MACHINES.add(this); + PRE_LOAD_MACHINES.put(dynamicMachine.getRegistryName(), dynamicMachine); + } + + public void build() { + if (this.buildFunction == null) { + GroovyLog.get().error("Machine {} has no builder function!", this.dynamicMachine.getRegistryName().getPath()); + MACHINES.remove(this); + PRE_LOAD_MACHINES.remove(this.dynamicMachine.getRegistryName()); + return; + } + BlockArrayBuilder pattern = new BlockArrayBuilder(this.dynamicMachine); + GroovyMachineBuilder settings = new GroovyMachineBuilder(this.dynamicMachine); + settings.color(Config.machineColor); // default color + ClosureHelper.withEnvironment(this.buildFunction, new MachineBuilderHelper(pattern, settings), true); + ClosureHelper.call(this.buildFunction); + pattern.build(); + MachineBuilder.WAIT_FOR_LOAD.add(this.dynamicMachine); + } +} diff --git a/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/GroovyMachineBuilder.java b/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/GroovyMachineBuilder.java new file mode 100644 index 00000000..a227aba3 --- /dev/null +++ b/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/GroovyMachineBuilder.java @@ -0,0 +1,212 @@ +package github.kasuminova.mmce.common.integration.groovyscript; + +import com.cleanroommc.groovyscript.api.GroovyBlacklist; +import com.cleanroommc.groovyscript.api.GroovyLog; +import github.kasuminova.mmce.common.event.client.ControllerGUIRenderEvent; +import github.kasuminova.mmce.common.event.client.ControllerModelAnimationEvent; +import github.kasuminova.mmce.common.event.client.ControllerModelGetEvent; +import github.kasuminova.mmce.common.event.machine.*; +import groovy.lang.Closure; +import hellfirepvp.modularmachinery.common.machine.DynamicMachine; +import hellfirepvp.modularmachinery.common.machine.RecipeFailureActions; +import hellfirepvp.modularmachinery.common.machine.factory.FactoryRecipeThread; +import hellfirepvp.modularmachinery.common.modifier.MultiBlockModifierReplacement; +import hellfirepvp.modularmachinery.common.util.SmartInterfaceType; +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.Optional; + +public class GroovyMachineBuilder { + + protected final DynamicMachine machine; + + public GroovyMachineBuilder(DynamicMachine machine) { + this.machine = machine; + color(0xFFFFFF); // config is read after grs preInit + } + + /** + * 设置此机械是否受并行控制器影响。 + */ + public GroovyMachineBuilder parallelizable(boolean isParallelizable) { + machine.setParallelizable(isParallelizable); + return this; + } + + /** + * 设置此机械的最大并行数。 + * + * @param maxParallelism 并行数 + */ + public GroovyMachineBuilder maxParallelism(int maxParallelism) { + machine.setMaxParallelism(maxParallelism); + return this; + } + + /** + * 设置此机械的内置并行数。 + * + * @param parallelism 内置并行数 + */ + public GroovyMachineBuilder internalParallelism(int parallelism) { + machine.setInternalParallelism(parallelism); + return this; + } + + /** + * 添加多方块升级配方修改器。 + */ + public GroovyMachineBuilder multiBlockModifier(MultiBlockModifierReplacement multiBlockModifier) { + if (multiBlockModifier != null) { + machine.getMultiBlockModifiers().add(multiBlockModifier); + } + return this; + } + + /** + * 添加智能数据接口类型。 + * + * @param type 类型 + */ + public GroovyMachineBuilder smartInterfaceType(SmartInterfaceType type) { + if (!machine.hasSmartInterfaceType(type.getType())) { + machine.addSmartInterfaceType(type); + } else { + GroovyLog.get().warn("DynamicMachine `" + machine.getRegistryName() + "` is already has SmartInterfaceType `" + type.getType() + "`!"); + } + return this; + } + + /** + * 添加结构形成事件监听器。 + */ + public GroovyMachineBuilder structureFormedHandler(IEventHandler function) { + machine.addMachineEventHandler(MachineStructureFormedEvent.class, function); + return this; + } + + /** + * 添加结构更新事件监听器。 + */ + public GroovyMachineBuilder structureUpdateHandler(IEventHandler function) { + machine.addMachineEventHandler(MachineStructureUpdateEvent.class, function); + return this; + } + + /** + * 添加机器事件监听器。 + */ + public GroovyMachineBuilder tickHandler(IEventHandler function) { + machine.addMachineEventHandler(MachineTickEvent.class, function); + return this; + } + + /** + * 添加控制器 GUI 渲染事件监听器。 + */ + public GroovyMachineBuilder guiRenderHandler(IEventHandler function) { + if (FMLCommonHandler.instance().getSide().isServer()) { + return this; + } + machine.addMachineEventHandler(ControllerGUIRenderEvent.class, function); + return this; + } + + /** + * 添加控制器 GeckoLib 模型动画事件监听器。 + */ + @Optional.Method(modid = "geckolib3") + public GroovyMachineBuilder controllerModelAnimationHandler(IEventHandler function) { + if (FMLCommonHandler.instance().getSide().isServer()) { + return this; + } + machine.addMachineEventHandler(ControllerModelAnimationEvent.class, function); + return this; + } + + /** + * 添加控制器 GeckoLib 模型获取事件监听器。 + */ + @Optional.Method(modid = "geckolib3") + public GroovyMachineBuilder controllerModelGetHandler(IEventHandler function) { + if (FMLCommonHandler.instance().getSide().isServer()) { + return this; + } + machine.addMachineEventHandler(ControllerModelGetEvent.class, function); + return this; + } + + /** + * 添加智能数据接口更新事件监听器 + */ + public GroovyMachineBuilder smartInterfaceUpdateHandler(IEventHandler function) { + machine.addMachineEventHandler(SmartInterfaceUpdateEvent.class, function); + return this; + } + + /** + * 控制器是否需要蓝图 + */ + public GroovyMachineBuilder requiresBlueprint(boolean requiresBlueprint) { + this.machine.setRequiresBlueprint(requiresBlueprint); + return this; + } + + /** + * 设置当此机器配方运行失败时的操作 + * + * @param failureAction Action 可以通过 RecipeFailureActions.getFailureAction(String key) 获得 + */ + public GroovyMachineBuilder failureAction(RecipeFailureActions failureAction) { + this.machine.setFailureAction(failureAction); + return this; + } + + /** + * 设置机械颜色,该结构内的其他组件也将会变为此颜色。 + * + * @param color 颜色,例如:0xFFFFFF + */ + public GroovyMachineBuilder color(int color) { + this.machine.setDefinedColor(color); + return this; + } + + /** + * 设置此机械是否有工厂形式的控制器。 + * + * @param hasFactory true 即为注册,false 即为不注册 + */ + public GroovyMachineBuilder hasFactory(boolean hasFactory) { + this.machine.setHasFactory(hasFactory); + return this; + } + + /** + * 设置此机械是否仅有工厂形式的控制器。 + * + * @param factoryOnly true 即为仅工厂,false 即为普通机械和工厂 + */ + public GroovyMachineBuilder factoryOnly(boolean factoryOnly) { + this.machine.setFactoryOnly(factoryOnly); + return this; + } + + /** + * 设置此机械的工厂最大线程数。 / Sets the maximum number of threads for this machine. + * + * @param maxThreads 最大线程数 / Maximum number of threads + */ + public GroovyMachineBuilder maxThreads(int maxThreads) { + this.machine.setMaxThreads(maxThreads); + return this; + } + + public GroovyMachineBuilder coreThread(FactoryRecipeThread thread) { + this.machine.addCoreThread(thread); + return this; + } + + public DynamicMachine getMachine() { + return machine; + } +} diff --git a/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/GroovyMachineRecipes.java b/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/GroovyMachineRecipes.java new file mode 100644 index 00000000..dcbc2414 --- /dev/null +++ b/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/GroovyMachineRecipes.java @@ -0,0 +1,27 @@ +package github.kasuminova.mmce.common.integration.groovyscript; + +import com.cleanroommc.groovyscript.api.IScriptReloadable; +import com.cleanroommc.groovyscript.helper.Alias; +import com.cleanroommc.groovyscript.registry.NamedRegistry; +import com.google.common.base.CaseFormat; +import net.minecraft.util.ResourceLocation; + +public class GroovyMachineRecipes extends NamedRegistry implements IScriptReloadable { + + private final ResourceLocation name; + + public GroovyMachineRecipes(ResourceLocation name) { + super(Alias.generateOf(name.getPath(), CaseFormat.LOWER_UNDERSCORE)); + this.name = name; + } + + @Override + public void onReload() {} + + @Override + public void afterScriptLoad() {} + + public GroovyRecipe recipeBuilder(String name) { + return new GroovyRecipe(this.name); + } +} diff --git a/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/GroovyRecipe.java b/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/GroovyRecipe.java new file mode 100644 index 00000000..b00323d3 --- /dev/null +++ b/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/GroovyRecipe.java @@ -0,0 +1,1102 @@ +package github.kasuminova.mmce.common.integration.groovyscript; + +import WayofTime.bloodmagic.soul.EnumDemonWillType; +import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.api.IIngredient; +import com.cleanroommc.groovyscript.helper.EnumHelper; +import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper; +import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient; +import com.cleanroommc.groovyscript.helper.recipe.RecipeName; +import com.cleanroommc.groovyscript.sandbox.ClosureHelper; +import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import de.ellpeck.naturesaura.api.aura.type.IAuraType; +import github.kasuminova.mmce.common.event.Phase; +import github.kasuminova.mmce.common.event.machine.IEventHandler; +import github.kasuminova.mmce.common.event.recipe.*; +import github.kasuminova.mmce.common.util.concurrent.Action; +import groovy.lang.Closure; +import hellfirepvp.astralsorcery.common.constellation.ConstellationRegistry; +import hellfirepvp.astralsorcery.common.constellation.IConstellation; +import hellfirepvp.modularmachinery.ModularMachinery; +import hellfirepvp.modularmachinery.common.base.Mods; +import hellfirepvp.modularmachinery.common.crafting.PreparedRecipe; +import hellfirepvp.modularmachinery.common.crafting.RecipeRegistry; +import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement; +import hellfirepvp.modularmachinery.common.crafting.helper.ComponentSelectorTag; +import hellfirepvp.modularmachinery.common.crafting.requirement.*; +import hellfirepvp.modularmachinery.common.data.Config; +import hellfirepvp.modularmachinery.common.integration.crafttweaker.IngredientArrayPrimer; +import hellfirepvp.modularmachinery.common.integration.crafttweaker.RecipePrimer; +import hellfirepvp.modularmachinery.common.machine.DynamicMachine; +import hellfirepvp.modularmachinery.common.machine.IOType; +import hellfirepvp.modularmachinery.common.machine.MachineRegistry; +import hellfirepvp.modularmachinery.common.modifier.RecipeModifier; +import hellfirepvp.modularmachinery.common.util.SmartInterfaceType; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import kport.modularmagic.common.crafting.requirement.*; +import kport.modularmagic.common.integration.jei.ingredient.Aura; +import mekanism.api.gas.GasStack; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fml.common.Optional; +import thaumcraft.api.aspects.Aspect; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +public class GroovyRecipe implements PreparedRecipe { + + protected String name; + protected final ResourceLocation machineName; + private int tickTime = 100, priority = 0; + private boolean doesVoidPerTick = false; + private boolean loadJei = true; + + private final List> components = new ArrayList<>(); + private final List needAfterInitActions = new ArrayList<>(); + private final List toolTipList = new ArrayList<>(); + private final Map, List>> recipeEventHandlers = new Object2ObjectOpenHashMap<>(); + + private boolean parallelized = Config.recipeParallelizeEnabledByDefault; + private int maxThreads = -1; + private String threadName = ""; + private ComponentRequirement lastComponent = null; + + public GroovyRecipe(ResourceLocation owningMachine) { + this.machineName = owningMachine; + } + + public GroovyRecipe name(String name) { + this.name = name; + return this; + } + + public GroovyRecipe time(int time) { + this.tickTime = time; + return this; + } + + public GroovyRecipe priority(int priority) { + this.priority = priority; + return this; + } + + public GroovyRecipe cancelIfPerTickFails(boolean b) { + this.doesVoidPerTick = b; + return this; + } + + public GroovyRecipe parallelizeUnaffected(boolean unaffected) { + if (lastComponent instanceof ComponentRequirement.Parallelizable parallelizable) { + parallelizable.setParallelizeUnaffected(unaffected); + } else { + GroovyLog.get().warn("Target " + lastComponent.getClass() + " cannot be parallelized!"); + } + return this; + } + + public GroovyRecipe parallelized(boolean isParallelized) { + this.parallelized = isParallelized; + return this; + } + + public GroovyRecipe chance(float chance) { + if (lastComponent != null) { + if (lastComponent instanceof ComponentRequirement.ChancedRequirement chancedReq) { + chancedReq.setChance(chance); + } else { + GroovyLog.get().warn("Cannot set chance for not-chance-based Component: " + lastComponent.getClass()); + } + } + return this; + } + + + public GroovyRecipe tag(String selectorTag) { + if (lastComponent != null) { + lastComponent.setTag(new ComponentSelectorTag(selectorTag)); + } + return this; + } + + + public GroovyRecipe preViewNBT(NBTTagCompound nbt) { + if (lastComponent != null) { + if (lastComponent instanceof RequirementItem reqItem) { + reqItem.previewDisplayTag = nbt; + } else { + GroovyLog.get().warn("setPreViewNBT(IData nbt) only can be applied to `Item`!"); + } + } else { + GroovyLog.get().warn("setPreViewNBT(IData nbt) only can be applied to `Item`!"); + } + return this; + } + + + public GroovyRecipe nbtChecker(Closure checker) { + if (lastComponent != null) { + if (lastComponent instanceof RequirementItem reqItem) { + reqItem.setItemChecker((controller, stack) -> ClosureHelper.call(true, checker, controller, stack)); + } else { + GroovyLog.get().warn("setNBTChecker(AdvancedItemNBTChecker checker) only can be applied to `Item`!"); + } + } else { + GroovyLog.get().warn("setNBTChecker(AdvancedItemNBTChecker checker) only can be applied to `Item`!"); + } + return this; + } + + + public GroovyRecipe itemModifier(Closure modifier) { + if (lastComponent != null) { + if (lastComponent instanceof RequirementItem reqItem) { + reqItem.addItemModifier((controller, stack) -> ClosureHelper.call(stack, modifier, controller, stack)); + } else { + GroovyLog.get().warn("addItemModifier(AdvancedItemModifier checker) only can be applied to `Item`!"); + } + } else { + GroovyLog.get().warn("addItemModifier(AdvancedItemModifier checker) only can be applied to `Item`!"); + } + return this; + } + + + public GroovyRecipe amount(int min, int max) { + if (lastComponent != null) { + if (lastComponent instanceof RequirementItem reqItem) { + if (min < max) { + reqItem.minAmount = min; + reqItem.maxAmount = max; + } else { + GroovyLog.get().warn("`min` cannot larger than `max`!"); + } + } else { + GroovyLog.get().warn("setMinMaxOutputAmount(int min, int max) only can be applied to `Item`!"); + } + } else { + GroovyLog.get().warn("setMinMaxOutputAmount(int min, int max) only can be applied to `Item`!"); + } + return this; + } + + /** + *

为某个输入或输出设置特定触发时间。

+ *

注意:如果设置了触发时间,则配方在其他时间不会触发任何消耗或产出动作。

+ * + * @param tickTime 触发的配方时间,实际触发时间受到配方修改器影响 + */ + + public GroovyRecipe triggerTime(int tickTime) { + if (lastComponent != null) { + lastComponent.setTriggerTime(tickTime); + } + return this; + } + + /** + * 使触发时间可以被重复触发。 + * + * @param repeatable true 为可重复,默认 false。 + */ + + public GroovyRecipe triggerRepeatable(boolean repeatable) { + if (lastComponent != null) { + lastComponent.setTriggerRepeatable(repeatable); + } + return this; + } + + /** + *

使一个物品/流体等需求忽略输出检测,对一些大量输出不同种类物品等需求非常有用。

+ *

警告:如果忽略输出则有时可能会导致输出吞物品行为。

+ * + * @param ignoreOutputCheck true 为忽略,默认为 false 不忽略。 + */ + + public GroovyRecipe ignoreOutputCheck(boolean ignoreOutputCheck) { + if (lastComponent != null) { + lastComponent.setIgnoreOutputCheck(ignoreOutputCheck); + } + return this; + } + + + public GroovyRecipe recipeTooltip(String... tooltips) { + toolTipList.addAll(Arrays.asList(tooltips)); + return this; + } + + + public GroovyRecipe smartInterfaceDataInput(String typeStr, float minValue, float maxValue) { + needAfterInitActions.add(() -> { + DynamicMachine machine = MachineRegistry.getRegistry().getMachine(machineName); + if (machine == null) { + GroovyLog.get().error("Could not find machine `" + machineName.toString() + "`!"); + return; + } + SmartInterfaceType type = machine.getSmartInterfaceType(typeStr); + if (type == null) { + GroovyLog.get().error("SmartInterfaceType " + typeStr + " Not Found!"); + return; + } + appendComponent(new RequirementInterfaceNumInput(type, minValue, maxValue)); + }); + return this; + } + + + public GroovyRecipe smartInterfaceDataInput(String typeStr, float value) { + return smartInterfaceDataInput(typeStr, value, value); + } + + /** + * 设置此配方在工厂中同时运行的数量是否不超过指定数值。 + */ + + public GroovyRecipe maxThreads(int maxThreads) { + this.maxThreads = maxThreads; + return this; + } + + /** + * 设置此配方只能被指定的核心线程执行。 + * + * @param name 线程名 + */ + public GroovyRecipe threadName(String name) { + this.threadName = name == null ? "" : name; + return this; + } + + //---------------------------------------------------------------------------------------------- + // EventHandlers + //---------------------------------------------------------------------------------------------- + + public GroovyRecipe preCheckHandler(IEventHandler handler) { + addRecipeEventHandler(RecipeCheckEvent.class, event -> { + if (event.phase != Phase.START) return; + handler.invoke(event); + }); + return this; + } + + + public GroovyRecipe postCheckHandler(IEventHandler handler) { + addRecipeEventHandler(RecipeCheckEvent.class, event -> { + if (event.phase != Phase.END) return; + handler.invoke(event); + }); + return this; + } + + public GroovyRecipe startHandler(IEventHandler handler) { + addRecipeEventHandler(RecipeStartEvent.class, handler); + return this; + } + + public GroovyRecipe preTickHandler(IEventHandler handler) { + addRecipeEventHandler(RecipeTickEvent.class, event -> { + if (event.phase != Phase.START) return; + handler.invoke(event); + }); + return this; + } + + public GroovyRecipe postTickHandler(IEventHandler handler) { + addRecipeEventHandler(RecipeTickEvent.class, event -> { + if (event.phase != Phase.END) return; + handler.invoke(event); + }); + return this; + } + + public GroovyRecipe failureHandler(IEventHandler handler) { + addRecipeEventHandler(RecipeFailureEvent.class, handler); + return this; + } + + public GroovyRecipe finishHandler(IEventHandler handler) { + addRecipeEventHandler(RecipeFinishEvent.class, handler); + return this; + } + + public GroovyRecipe factoryStartHandler(IEventHandler handler) { + addRecipeEventHandler(FactoryRecipeStartEvent.class, handler); + return this; + } + + public GroovyRecipe factoryPreTickHandler(IEventHandler handler) { + addRecipeEventHandler(FactoryRecipeTickEvent.class, event -> { + if (event.phase != Phase.START) { + return; + } + handler.invoke(event); + }); + return this; + } + + public GroovyRecipe factoryPostTickHandler(IEventHandler handler) { + addRecipeEventHandler(FactoryRecipeTickEvent.class, event -> { + if (event.phase != Phase.END) { + return; + } + handler.invoke(event); + }); + return this; + } + + + public GroovyRecipe factoryFailureHandler(IEventHandler handler) { + return eventHandler(FactoryRecipeFailureEvent.class, handler); + } + + public GroovyRecipe factoryFinishHandler(IEventHandler handler) { + return eventHandler(FactoryRecipeFinishEvent.class, handler); + } + + /*public GroovyRecipe eventHandler(IEventHandler<> handler) { + if (handler.getParameterTypes().length > 0 && RecipeEvent.class.isAssignableFrom(handler.getParameterTypes()[0])) { + Class eventClass = (Class) handler.getParameterTypes()[0]; + addRecipeEventHandler(eventClass, handler); + } else { + GroovyLog.get().error("The parameter type must be explicitly declared when using `eventHandler({})`"); + } + return this; + }*/ + + public GroovyRecipe eventHandler(Class clazz, IEventHandler handler) { + addRecipeEventHandler(clazz, handler); + return this; + } + + @SuppressWarnings("unchecked") + private void addRecipeEventHandler(Class hClass, IEventHandler handler) { + recipeEventHandlers.computeIfAbsent(hClass, k -> new ArrayList<>()).add((IEventHandler) handler); + } + + //---------------------------------------------------------------------------------------------- + // General Input & Output + //---------------------------------------------------------------------------------------------- + + public GroovyRecipe input(IIngredient input) { + if (IngredientHelper.isItem(input) || input instanceof OreDictIngredient) { + itemInput(input); + } else if (input instanceof FluidStack liquidStack) { + fluidInput(liquidStack); + } else if (Mods.MEKANISM.isPresent() && input instanceof GasStack gasStack) { + gasInput(gasStack); + } else { + GroovyLog.get().error("Invalid input type {}({})! Ignored.", input, input.getClass()); + } + return this; + } + + public GroovyRecipe input(IIngredient... inputs) { + for (IIngredient input : inputs) { + input(input); + } + return this; + } + + public GroovyRecipe input(Iterable inputs) { + for (IIngredient input : inputs) { + input(input); + } + return this; + } + + public GroovyRecipe output(IIngredient output) { + if (IngredientHelper.isItem(output) || output instanceof OreDictIngredient) { + itemOutput(output); + } else if (output instanceof FluidStack liquidStack) { + fluidOutput(liquidStack); + } else if (Mods.MEKANISM.isPresent() && output instanceof GasStack gasStack) { + gasOutput(gasStack); + } else { + GroovyLog.get().error("Invalid output type {}({})! Ignored.", output, output.getClass()); + } + return this; + } + + public GroovyRecipe output(IIngredient... outputs) { + for (IIngredient output : outputs) { + output(output); + } + return this; + } + + public GroovyRecipe output(Iterable outputs) { + for (IIngredient output : outputs) { + output(output); + } + return this; + } + + //---------------------------------------------------------------------------------------------- + // Energy input & output + //---------------------------------------------------------------------------------------------- + + public GroovyRecipe energyInput(long perTick) { + requireEnergy(IOType.INPUT, perTick); + return this; + } + + + public GroovyRecipe energyOutput(long perTick) { + requireEnergy(IOType.OUTPUT, perTick); + return this; + } + + //---------------------------------------------------------------------------------------------- + // FLUID input & output + //---------------------------------------------------------------------------------------------- + + public GroovyRecipe fluidInput(FluidStack fluid, boolean perTick) { + requireFluid(IOType.INPUT, fluid, perTick); + return this; + } + + public GroovyRecipe fluidInput(FluidStack fluid) { + return fluidInput(fluid, false); + } + + public GroovyRecipe fluidInput(FluidStack... fluids) { + for (FluidStack fluid : fluids) { + fluidInput(fluid); + } + return this; + } + + public GroovyRecipe fluidInput(Iterable fluids, boolean perTick) { + for (FluidStack fluid : fluids) { + fluidInput(fluid, perTick); + } + return this; + } + + public GroovyRecipe fluidInput(Iterable fluids) { + return fluidInput(fluids, false); + } + + public GroovyRecipe fluidOutput(FluidStack fluid) { + return fluidOutput(fluid, false); + } + + public GroovyRecipe fluidOutput(FluidStack fluid, boolean perTick) { + requireFluid(IOType.OUTPUT, fluid, perTick); + return this; + } + + + public GroovyRecipe fluidOutputs(FluidStack... fluids) { + for (FluidStack fluid : fluids) { + fluidOutput(fluid); + } + return this; + } + + public GroovyRecipe fluidOutputs(Iterable fluids, boolean perTick) { + for (FluidStack fluid : fluids) { + fluidOutput(fluid, perTick); + } + return this; + } + + public GroovyRecipe fluidOutputs(Iterable fluids) { + return fluidOutputs(fluids, false); + } + + //---------------------------------------------------------------------------------------------- + // GAS input & output + //---------------------------------------------------------------------------------------------- + + @Optional.Method(modid = "mekanism") + public GroovyRecipe gasInput(GasStack gasStack, boolean perTick) { + requireGas(IOType.INPUT, gasStack, perTick); + return this; + } + + + @Optional.Method(modid = "mekanism") + public GroovyRecipe gasOutput(GasStack gasStack, boolean perTick) { + requireGas(IOType.OUTPUT, gasStack, perTick); + return this; + } + + @Optional.Method(modid = "mekanism") + public GroovyRecipe gasInput(GasStack gasStack) { + return gasInput(gasStack, false); + } + + + @Optional.Method(modid = "mekanism") + public GroovyRecipe gasOutput(GasStack gasStack) { + return gasOutput(gasStack, false); + } + + + @Optional.Method(modid = "mekanism") + public GroovyRecipe gasInput(GasStack... gasStacks) { + for (final GasStack gasStack : gasStacks) { + requireGas(IOType.INPUT, gasStack, false); + } + return this; + } + + @Optional.Method(modid = "mekanism") + public GroovyRecipe gasInput(Iterable gasStacks) { + for (final GasStack gasStack : gasStacks) { + requireGas(IOType.INPUT, gasStack, false); + } + return this; + } + + + @Optional.Method(modid = "mekanism") + public GroovyRecipe gasOutput(GasStack... gasStacks) { + for (final GasStack gasStack : gasStacks) { + requireGas(IOType.OUTPUT, gasStack, false); + } + return this; + } + + @Optional.Method(modid = "mekanism") + public GroovyRecipe gasOutput(Iterable gasStacks) { + for (final GasStack gasStack : gasStacks) { + requireGas(IOType.OUTPUT, gasStack, false); + } + return this; + } + + //---------------------------------------------------------------------------------------------- + // ITEM input + //---------------------------------------------------------------------------------------------- + + public GroovyRecipe itemInput(IIngredient input) { + if (IngredientHelper.isItem(input)) { + requireFuel(IOType.INPUT, IngredientHelper.toItemStack(input)); + } else if (input instanceof OreDictIngredient oreDictIngredient) { + requireFuel(IOType.INPUT, oreDictIngredient.getOreDict(), oreDictIngredient.getAmount()); + } else { + GroovyLog.get().error("Invalid input type {}({})! Only ItemStack and OreDictIngredient is allowed.", input, input.getClass()); + } + + return this; + } + + public GroovyRecipe itemInputs(IIngredient... inputs) { + for (IIngredient input : inputs) { + itemInput(input); + } + return this; + } + + public GroovyRecipe itemInputs(Iterable inputs) { + for (IIngredient input : inputs) { + itemInput(input); + } + return this; + } + + public GroovyRecipe fuelBurnTime(int requiredTotalBurnTime) { + requireFuel(requiredTotalBurnTime); + return this; + } + + // TODO + public GroovyRecipe addIngredientArrayInput(IngredientArrayPrimer ingredientArrayPrimer) { + appendComponent(new RequirementIngredientArray(ingredientArrayPrimer.getIngredientStackList())); + return this; + } + + /** + *

随机选择给定的一组物品中的其中一个输出。

+ *

虽然都使用 IngredientArrayPrimer 作为参数,但是输出的工作机制要稍有不同

+ *

每个 Ingredient 的 chance 代表整个物品列表的随机选择权重,权重越高,输出概率越大。

+ *

同样,setMinMaxAmount() 也能够起作用。

+ */ + // TODO + public GroovyRecipe addRandomItemOutput(IngredientArrayPrimer ingredientArrayPrimer) { + appendComponent(new RequirementIngredientArray(ingredientArrayPrimer.getIngredientStackList(), IOType.OUTPUT)); + return this; + } + + //---------------------------------------------------------------------------------------------- + // ITEM output + //---------------------------------------------------------------------------------------------- + + public GroovyRecipe itemOutput(IIngredient output) { + if (IngredientHelper.isItem(output)) { + requireFuel(IOType.OUTPUT, IngredientHelper.toItemStack(output)); + } else if (output instanceof OreDictIngredient oreDictIngredient) { + requireFuel(IOType.OUTPUT, oreDictIngredient.getOreDict(), oreDictIngredient.getAmount()); + } else { + GroovyLog.get().error("Invalid output type {}({})! Ignored.", output, output.getClass()); + } + + return this; + } + + public GroovyRecipe itemOutputs(IIngredient... inputs) { + for (IIngredient input : inputs) { + itemOutput(input); + } + return this; + } + + //---------------------------------------------------------------------------------------------- + // Catalyst + //---------------------------------------------------------------------------------------------- + + public GroovyRecipe catalyst(IIngredient input, Iterable tooltips, Iterable modifiers) { + if (IngredientHelper.isItem(input)) { + requireCatalyst(IngredientHelper.toItemStack(input), tooltips, modifiers); + } else if (input instanceof OreDictIngredient oreDictIngredient) { + requireCatalyst(oreDictIngredient.getOreDict(), oreDictIngredient.getAmount(), tooltips, modifiers); + } else { + GroovyLog.get().error("Invalid input type {}({})! Ignored.", input, input.getClass()); + } + + return this; + } + + + // TODO + public GroovyRecipe addCatalystInput(IngredientArrayPrimer input, Iterable tooltips, Iterable modifiers) { + requireCatalyst(input, tooltips, modifiers); + return this; + } + + //---------------------------------------------------------------------------------------------- + // Internals + //---------------------------------------------------------------------------------------------- + private void requireEnergy(IOType ioType, long perTick) { + appendComponent(new RequirementEnergy(ioType, perTick)); + } + + private void requireFluid(IOType ioType, FluidStack stack, boolean isPerTick) { + if (IngredientHelper.isEmpty(stack) || stack.getFluid() == null) { + GroovyLog.get().error("FluidStack must not be empty"); + return; + } + + if (isPerTick) { + appendComponent(new RequirementFluidPerTick(ioType, stack)); + } else { + appendComponent(new RequirementFluid(ioType, stack)); + } + } + + @Optional.Method(modid = "mekanism") + private void requireGas(IOType ioType, GasStack gasStack, boolean isPerTick) { + if (gasStack == null || gasStack.amount <= 0 || gasStack.getGas() == null) { + GroovyLog.get().error("GasStack must not be empty"); + return; + } + if (isPerTick) { + appendComponent(new RequirementGasPerTick(ioType, gasStack)); + } else { + appendComponent(new RequirementGas(ioType, gasStack)); + } + } + + private void requireFuel(int requiredTotalBurnTime) { + appendComponent(new RequirementItem(IOType.INPUT, requiredTotalBurnTime)); + } + + private void requireFuel(IOType ioType, ItemStack stack) { + if (stack.isEmpty()) { + GroovyLog.get().error("ItemStack not found/unknown item: " + stack); + return; + } + RequirementItem ri = new RequirementItem(ioType, stack); + if (stack.hasTagCompound()) { + ri.tag = stack.getTagCompound(); + ri.previewDisplayTag = stack.getTagCompound(); + } + appendComponent(ri); + } + + private void requireFuel(IOType ioType, String oreDictName, int amount) { + appendComponent(new RequirementItem(ioType, oreDictName, amount)); + } + + private void requireCatalyst(String oreDictName, int amount, Iterable tooltips, Iterable modifiers) { + RequirementCatalyst catalyst = new RequirementCatalyst(oreDictName, amount); + for (String tooltip : tooltips) { + catalyst.addTooltip(tooltip); + } + for (RecipeModifier modifier : modifiers) { + if (modifier != null) { + catalyst.addModifier(modifier); + } + } + appendComponent(catalyst); + } + + private void requireCatalyst(ItemStack stack, Iterable tooltips, Iterable modifiers) { + if (stack.isEmpty()) { + GroovyLog.get().error("ItemStack not found/unknown item: " + stack); + return; + } + RequirementCatalyst catalyst = new RequirementCatalyst(stack); + for (String tooltip : tooltips) { + catalyst.addTooltip(tooltip); + } + for (RecipeModifier modifier : modifiers) { + if (modifier != null) { + catalyst.addModifier(modifier); + } + } + appendComponent(catalyst); + } + + private void requireCatalyst(IngredientArrayPrimer ingredientArrayPrimer, Iterable tooltips, + Iterable modifiers) { + RequirementCatalyst catalyst = new RequirementCatalyst(ingredientArrayPrimer.getIngredientStackList()); + for (String tooltip : tooltips) { + catalyst.addTooltip(tooltip); + } + for (RecipeModifier modifier : modifiers) { + if (modifier != null) { + catalyst.addModifier(modifier); + } + } + appendComponent(catalyst); + } + + public void appendComponent(ComponentRequirement component) { + this.components.add(component); + this.lastComponent = component; + } + + //---------------------------------------------------------------------------------------------- + // magic + //---------------------------------------------------------------------------------------------- + + public GroovyRecipe aspectInput(String aspectString, int amount) { + Aspect aspect = Aspect.getAspect(aspectString); + if (aspect != null) { + appendComponent(new RequirementAspect(IOType.INPUT, amount, aspect)); + } else { + GroovyLog.get().error("Invalid aspect name : " + aspectString); + } + + return this; + } + + public GroovyRecipe aspectOutput(String aspectString, int amount) { + Aspect aspect = Aspect.getAspect(aspectString); + if (aspect != null) { + appendComponent(new RequirementAspect(IOType.OUTPUT, amount, aspect)); + } else { + GroovyLog.get().error("Invalid aspect name : " + aspectString); + } + + return this; + } + + public GroovyRecipe auraInput(String auraType, int amount) { + IAuraType aura = NaturesAuraAPI.AURA_TYPES.get(new ResourceLocation("naturesaura", auraType)); + if (aura != null) { + appendComponent(new RequirementAura(IOType.INPUT, new Aura(amount, aura), Integer.MAX_VALUE, Integer.MIN_VALUE)); + } else { + GroovyLog.get().error("Invalid aura name : " + auraType); + } + + return this; + } + + public GroovyRecipe auraOutput(String auraType, int amount) { + IAuraType aura = NaturesAuraAPI.AURA_TYPES.get(new ResourceLocation("naturesaura", auraType)); + if (aura != null) { + appendComponent(new RequirementAura(IOType.OUTPUT, new Aura(amount, aura), Integer.MAX_VALUE, Integer.MIN_VALUE)); + } else { + GroovyLog.get().error("Invalid aura name : " + auraType); + } + + return this; + } + + public GroovyRecipe auraInput(String auraType, int amount, int max, int min) { + IAuraType aura = NaturesAuraAPI.AURA_TYPES.get(new ResourceLocation("naturesaura", auraType)); + if (aura != null) { + appendComponent(new RequirementAura(IOType.INPUT, new Aura(amount, aura), max, min)); + } else { + GroovyLog.get().error("Invalid aura name : " + auraType); + } + + return this; + } + + public GroovyRecipe auraOutput(String auraType, int amount, int max, int min) { + IAuraType aura = NaturesAuraAPI.AURA_TYPES.get(new ResourceLocation("naturesaura", auraType)); + if (aura != null) { + appendComponent(new RequirementAura(IOType.OUTPUT, new Aura(amount, aura), max, min)); + } else { + GroovyLog.get().error("Invalid aura name : " + auraType); + } + + return this; + } + + public GroovyRecipe constellationInput(String constellationString) { + IConstellation constellation = ConstellationRegistry.getConstellationByName("astralsorcery.constellation." + constellationString); + if (constellation != null) { + appendComponent(new RequirementConstellation(IOType.INPUT, constellation)); + } else { + GroovyLog.get().error("Invalid constellation : " + constellationString); + } + + return this; + } + + public GroovyRecipe gridPowerInput(int amount) { + if (amount > 0) { + appendComponent(new RequirementGrid(IOType.INPUT, amount)); + } else { + GroovyLog.get().error("Invalid Grid Power amount : " + amount + " (need to be positive and not null)"); + } + + return this; + } + + public GroovyRecipe gridPowerOutput(int amount) { + if (amount > 0) { + appendComponent(new RequirementGrid(IOType.OUTPUT, amount)); + } else { + GroovyLog.get().error("Invalid Grid Power amount : " + amount + " (need to be positive and not null)"); + } + + return this; + } + + public GroovyRecipe rainbowInput() { + appendComponent(new RequirementRainbow()); + return this; + } + + public GroovyRecipe lifeEssenceInput(int amount, boolean perTick) { + if (amount > 0) { + appendComponent(new RequirementLifeEssence(IOType.INPUT, amount, perTick)); + } else { + GroovyLog.get().error("Invalid Life Essence amount : " + amount + " (need to be positive and not null)"); + } + + return this; + } + + public GroovyRecipe lifeEssenceOutput(int amount, boolean perTick) { + if (amount > 0) { + appendComponent(new RequirementLifeEssence(IOType.OUTPUT, amount, perTick)); + } else { + GroovyLog.get().error("Invalid Life Essence amount : " + amount + " (need to be positive and not null)"); + } + + return this; + } + + public GroovyRecipe starlightInput(float amount) { + if (amount > 0) { + appendComponent(new RequirementStarlight(IOType.INPUT, amount)); + } else { + GroovyLog.get().error("Invalid Starlight amount : " + amount + " (need to be positive and not null)"); + } + + return this; + } + + public GroovyRecipe starlightOutput(float amount) { + if (amount > 0) { + appendComponent(new RequirementStarlight(IOType.OUTPUT, amount)); + } else { + GroovyLog.get().error("Invalid Starlight amount : " + amount + " (need to be positive and not null)"); + } + + return this; + } + + public GroovyRecipe willInput(String willTypeString, int amount) { + EnumDemonWillType willType = EnumHelper.valueOfNullable(EnumDemonWillType.class, willTypeString, false); + if (willType != null) { + appendComponent(new RequirementWill(IOType.INPUT, amount, willType, Integer.MIN_VALUE, Integer.MAX_VALUE)); + } else { + GroovyLog.get().error("Invalid demon will type : " + willTypeString); + } + + return this; + } + + public GroovyRecipe willOutput(String willTypeString, int amount) { + EnumDemonWillType willType = EnumHelper.valueOfNullable(EnumDemonWillType.class, willTypeString, false); + if (willType != null) { + appendComponent(new RequirementWill(IOType.OUTPUT, amount, willType, Integer.MIN_VALUE, Integer.MAX_VALUE)); + } else { + GroovyLog.get().error("Invalid demon will type : " + willTypeString); + } + + return this; + } + + public GroovyRecipe willInput(String willTypeString, int amount, int min, int max) { + EnumDemonWillType willType = EnumHelper.valueOfNullable(EnumDemonWillType.class, willTypeString, false); + if (willType != null) { + appendComponent(new RequirementWill(IOType.INPUT, amount, willType, min, max)); + } else { + GroovyLog.get().error("Invalid demon will type : " + willTypeString); + } + + return this; + } + + public GroovyRecipe willOutput(String willTypeString, int amount, int min, int max) { + EnumDemonWillType willType = EnumHelper.valueOfNullable(EnumDemonWillType.class, willTypeString, false); + if (willType != null) { + appendComponent(new RequirementWill(IOType.OUTPUT, amount, willType, min, max)); + } else { + GroovyLog.get().error("Invalid demon will type : " + willTypeString); + } + + return this; + } + + public GroovyRecipe manaInput(int amount, boolean perTick) { + if (amount > 0) { + appendComponent(new RequirementMana(IOType.INPUT, amount, perTick)); + } else { + GroovyLog.get().error("Invalid Mana amount : " + amount + " (need to be positive and not null)"); + } + + return this; + } + + public GroovyRecipe manaOutput(int amount, boolean perTick) { + if (amount > 0) { + appendComponent(new RequirementMana(IOType.OUTPUT, amount, perTick)); + } else { + GroovyLog.get().error("Invalid Mana amount : " + amount + " (need to be positive and not null)"); + } + + return this; + } + + public GroovyRecipe impetusInput(int amount) { + appendComponent(new RequirementImpetus(IOType.INPUT, amount)); + return this; + } + + public GroovyRecipe impetusOutput(int amount) { + appendComponent(new RequirementImpetus(IOType.OUTPUT, amount)); + return this; + } + + public GroovyRecipe hide() { + this.loadJei = false; + return this; + } + + //---------------------------------------------------------------------------------------------- + // build + //---------------------------------------------------------------------------------------------- + + private boolean validate() { + GroovyLog.Msg msg = GroovyLog.msg("Error adding {} recipe", this.name).error(); + if (this.name == null) this.name = RecipeName.generate(); + if (this.tickTime <= 0) this.tickTime = 100; + + return !msg.postIfNotEmpty(); + } + + public void register() { + if (validate()) { + RecipeRegistry.getRegistry().registerRecipeEarly(this); + } + } + + //---------------------------------------------------------------------------------------------- + // lingering stats + //---------------------------------------------------------------------------------------------- + + @Override + public String getFilePath() { + return ""; + } + + @Override + public ResourceLocation getRecipeRegistryName() { + return new ResourceLocation(ModularMachinery.MODID, this.name); + } + + @Override + public ResourceLocation getAssociatedMachineName() { + return machineName; + } + + @Override + public ResourceLocation getParentMachineName() { + return machineName; + } + + @Override + public int getTotalProcessingTickTime() { + return tickTime; + } + + @Override + public int getPriority() { + return priority; + } + + @Override + public boolean voidPerTickFailure() { + return doesVoidPerTick; + } + + @Override + public List> getComponents() { + return components; + } + + @Override + public Map, List>> getRecipeEventHandlers() { + return recipeEventHandlers; + } + + @Override + public List getTooltipList() { + return toolTipList; + } + + @Override + public boolean isParallelized() { + return parallelized; + } + + @Override + public int getMaxThreads() { + return maxThreads; + } + + @Override + public String getThreadName() { + return threadName; + } + + @Override + public void loadNeedAfterInitActions() { + for (Action needAfterInitAction : needAfterInitActions) { + needAfterInitAction.doAction(); + } + } + + @Override + public boolean getLoadJEI() { + return loadJei; + } +} + diff --git a/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/GroovyScriptPlugin.java b/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/GroovyScriptPlugin.java new file mode 100644 index 00000000..406b22a5 --- /dev/null +++ b/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/GroovyScriptPlugin.java @@ -0,0 +1,268 @@ +package github.kasuminova.mmce.common.integration.groovyscript; + +import com.cleanroommc.groovyscript.api.GroovyBlacklist; +import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.api.GroovyPlugin; +import com.cleanroommc.groovyscript.api.INamed; +import com.cleanroommc.groovyscript.compat.mods.GroovyContainer; +import com.cleanroommc.groovyscript.compat.mods.GroovyPropertyContainer; +import com.cleanroommc.groovyscript.event.EventBusType; +import com.cleanroommc.groovyscript.event.GroovyEventManager; +import com.cleanroommc.groovyscript.event.GroovyReloadEvent; +import com.cleanroommc.groovyscript.event.ScriptRunEvent; +import com.cleanroommc.groovyscript.sandbox.ClosureHelper; +import com.cleanroommc.groovyscript.sandbox.LoadStage; +import github.kasuminova.mmce.client.model.DynamicMachineModelRegistry; +import github.kasuminova.mmce.client.resource.GeoModelExternalLoader; +import github.kasuminova.mmce.common.concurrent.RecipeCraftingContextPool; +import github.kasuminova.mmce.common.event.machine.IEventHandler; +import github.kasuminova.mmce.common.event.machine.MachineEvent; +import github.kasuminova.mmce.common.upgrade.registry.RegistryUpgrade; +import groovy.lang.Closure; +import groovy.lang.DelegatesTo; +import hellfirepvp.modularmachinery.ModularMachinery; +import hellfirepvp.modularmachinery.client.ClientProxy; +import hellfirepvp.modularmachinery.common.base.Mods; +import hellfirepvp.modularmachinery.common.crafting.RecipeRegistry; +import hellfirepvp.modularmachinery.common.crafting.adapter.RecipeAdapter; +import hellfirepvp.modularmachinery.common.integration.ModIntegrationJEI; +import hellfirepvp.modularmachinery.common.integration.crafttweaker.MachineBuilder; +import hellfirepvp.modularmachinery.common.integration.crafttweaker.MachineModifier; +import hellfirepvp.modularmachinery.common.integration.crafttweaker.RecipeModifierBuilder; +import hellfirepvp.modularmachinery.common.integration.crafttweaker.event.MMEvents; +import hellfirepvp.modularmachinery.common.integration.crafttweaker.upgrade.MachineUpgradeBuilder; +import hellfirepvp.modularmachinery.common.lib.RegistriesMM; +import hellfirepvp.modularmachinery.common.machine.DynamicMachine; +import hellfirepvp.modularmachinery.common.machine.MachineRegistry; +import hellfirepvp.modularmachinery.common.modifier.RecipeModifier; +import hellfirepvp.modularmachinery.common.util.BlockArrayCache; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.eventhandler.EventPriority; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.CompletableFuture; + +public class GroovyScriptPlugin implements GroovyPlugin { + + private static GroovyContainer container; + + public static GroovyContainer getContainer() { + return container; + } + + @Override + public @NotNull String getModId() { + return ModularMachinery.MODID; + } + + @Override + public @NotNull String getContainerName() { + return ModularMachinery.NAME; + } + + @Override + public @Nullable GroovyPropertyContainer createGroovyPropertyContainer() { + return new Container(); + } + + @Override + public void onCompatLoaded(GroovyContainer container) { + MinecraftForge.EVENT_BUS.register(container.get()); + MinecraftForge.EVENT_BUS.register(GroovyScriptPlugin.class); + GroovyScriptPlugin.container = (GroovyContainer) container; + } + + @Override + public @NotNull Collection getAliases() { + return Arrays.asList("modmach", "modular_machinery"); + } + + @SubscribeEvent + public static void onReload(GroovyReloadEvent event) { + MachineBuilder.WAIT_FOR_LOAD.clear(); + + RegistryUpgrade.clearAll(); + RecipeRegistry.getRegistry().clearAllRecipes(); + // Reset RecipeAdapterIncId + RegistriesMM.ADAPTER_REGISTRY.getValuesCollection().forEach(RecipeAdapter::resetIncId); + + if (FMLCommonHandler.instance().getSide().isClient() && Mods.GECKOLIB.isPresent()) { + DynamicMachineModelRegistry.INSTANCE.onReload(); + } + + for (DynamicMachine loadedMachine : MachineRegistry.getLoadedMachines()) { + loadedMachine.getMachineEventHandlers().clear(); + loadedMachine.getSmartInterfaceTypes().clear(); + loadedMachine.getCoreThreadPreset().clear(); + loadedMachine.getModifiers().clear(); + loadedMachine.getMultiBlockModifiers().clear(); + } + // Reload JSON Machine + MachineRegistry.preloadMachines(); + // Reload All Machine + MachineRegistry.reloadMachine(MachineRegistry.loadMachines(null)); + } + + @SubscribeEvent + public static void afterScriptRun(ScriptRunEvent.Post event) { + if (event.getLoadStage() != LoadStage.POST_INIT) return; + MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); + boolean isServer = server != null && server.isDedicatedServer(); + + MachineRegistry.reloadMachine(MachineBuilder.WAIT_FOR_LOAD); + + if (FMLCommonHandler.instance().getSide().isClient() && Mods.GECKOLIB.isPresent()) { + ClientProxy.clientScheduler.addRunnable(GeoModelExternalLoader.INSTANCE::onReload, 0); + } + + CompletableFuture future = CompletableFuture.runAsync(() -> BlockArrayCache.buildCache(MachineRegistry.getLoadedMachines())); + + MachineModifier.loadAll(); + MMEvents.registryAll(); + + RecipeCraftingContextPool.onReload(); + RecipeRegistry.getRegistry().loadRecipeRegistry(null, true); + // TODO + /*for (Action action : FactoryRecipeThread.WAIT_FOR_ADD) { + action.doAction(); + } + FactoryRecipeThread.WAIT_FOR_ADD.clear();*/ + + if (!isServer) { + ModIntegrationJEI.reloadRecipeWrappers(); + } + + future.join(); + + // Flush the context to preview the changed structure. + if (!isServer) { + ModIntegrationJEI.reloadPreviewWrappers(); + } + } + + private static class Container extends GroovyPropertyContainer { + + private final Map machines = new Object2ObjectOpenHashMap<>(); + public final MachineUpgrades machineUpgrades = new MachineUpgrades(); + + @GroovyBlacklist + @SubscribeEvent + public void onScriptRun(ScriptRunEvent.Pre event) { + for (DynamicMachine machine : MachineRegistry.getRegistry()) { + if (machine.getRegistryName().getNamespace().equals(ModularMachinery.MODID)) { + if (!getProperties().containsKey(machine.getRegistryName().getPath())) { + addProperty(new GroovyMachineRecipes(machine.getRegistryName())); + } + } + } + } + + private GroovyMachineRecipes findMachine(String name) { + INamed named = getProperties().get(name); + if (named instanceof GroovyMachineRecipes machine) { + return machine; + } + GroovyLog.get().error("Could not find modular machine with name '{}'!", name); + return null; + } + + public GroovyMachineRecipes machine(ResourceLocation rl) { + if (rl.getNamespace().equals(ModularMachinery.MODID)) { + return findMachine(rl.getPath()); + } + + GroovyMachineRecipes machine = this.machines.get(rl); + if (machine == null) { + DynamicMachine dynamicMachine = MachineRegistry.getRegistry().getMachine(rl); + if (dynamicMachine != null) { + machine = new GroovyMachineRecipes(rl); + this.machines.put(rl, machine); + } + } else if (MachineRegistry.getRegistry().getMachine(rl) == null) { + this.machines.remove(rl); + machine = null; + } + if (machine == null) { + GroovyLog.get().error("Could not find modular machine with name '{}'!", rl); + return null; + } + return machine; + } + + public GroovyMachineRecipes machine(String mod, String name) { + return machine(new ResourceLocation(mod, name)); + } + + public GroovyMachineRecipes machine(String name) { + String mod; + int i = name.indexOf(":"); + if (i > 0) { + mod = name.substring(0, i); + name = name.substring(i + 1); + return machine(new ResourceLocation(mod, name)); + } + if (i == 0) { + return findMachine(name.substring(1)); + } + return findMachine(name); + } + + public GroovyMachineRecipes getAt(String name) { + return machine(name); + } + + /*public void registerMachine(String registryName) { + registerMachine(registryName, null); + }*/ + + public void registerMachine(String registryName, @DelegatesTo(MachineBuilderHelper.class) Closure buildFunction) { + ResourceLocation rl = new ResourceLocation(ModularMachinery.MODID, registryName); + if (GroovyMachine.PRE_LOAD_MACHINES.containsKey(rl)) { + throw new IllegalStateException("Machine with name '" + registryName + "' already exists!"); + } + new GroovyMachine(new DynamicMachine(registryName), buildFunction); + } + + public void machineEvent(String machineRegistryName, Class clazz, Closure listener) { + GroovyEventManager.INSTANCE.listen(EventPriority.NORMAL, EventBusType.MAIN, clazz, event -> { + DynamicMachine machine = MachineRegistry.getRegistry() + .getMachine(new ResourceLocation(ModularMachinery.MODID, machineRegistryName)); + if (machine != null) { + machine.addMachineEventHandler(clazz, IEventHandler.of(listener)); + } else { + GroovyLog.get().error("Could not find machine `" + machineRegistryName + "`!"); + } + }); + } + + public void machineUpgrade(String name, String localizedName, float level, int maxStack, Closure builder) { + MachineUpgradeBuilder machineUpgradeBuilder = MachineUpgradeBuilder.newBuilder(name, localizedName, level, maxStack); + if (machineUpgradeBuilder == null) return; + ClosureHelper.withEnvironment(builder, machineUpgradeBuilder, true); + builder.call(); + machineUpgradeBuilder.buildAndRegister(); + } + + public RecipeModifierBuilder recipeModifierBuilder() { + return new RecipeModifierBuilder(); + } + + public RecipeModifierBuilder recipeModifierBuilder(String type, String ioTypeStr, float value, int operation, + boolean affectChance) { + return RecipeModifierBuilder.create(type, ioTypeStr, value, operation, affectChance); + } + + public RecipeModifier recipeModifier(String type, String ioTypeStr, float value, int operation, boolean affectChance) { + return recipeModifierBuilder(type, ioTypeStr, value, operation, affectChance).build(); + } + } +} diff --git a/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/MachineBuilderHelper.java b/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/MachineBuilderHelper.java new file mode 100644 index 00000000..1e96ed6c --- /dev/null +++ b/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/MachineBuilderHelper.java @@ -0,0 +1,177 @@ +package github.kasuminova.mmce.common.integration.groovyscript; + +import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.helper.EnumHelper; +import hellfirepvp.modularmachinery.common.block.BlockCasing; +import hellfirepvp.modularmachinery.common.block.prop.EnergyHatchData; +import hellfirepvp.modularmachinery.common.block.prop.FluidHatchSize; +import hellfirepvp.modularmachinery.common.block.prop.ItemBusSize; +import hellfirepvp.modularmachinery.common.integration.crafttweaker.RecipeModifierBuilder; +import hellfirepvp.modularmachinery.common.lib.BlocksMM; +import hellfirepvp.modularmachinery.common.modifier.RecipeModifier; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class MachineBuilderHelper { + + private final BlockArrayBuilder pattern; + private final GroovyMachineBuilder settings; + + public MachineBuilderHelper(BlockArrayBuilder pattern, GroovyMachineBuilder settings) { + this.pattern = pattern; + this.settings = settings; + } + + public BlockArrayBuilder getPattern() { + return pattern; + } + + public GroovyMachineBuilder getSettings() { + return settings; + } + + public RecipeModifierBuilder recipeModifierBuilder() { + return new RecipeModifierBuilder(); + } + + public RecipeModifierBuilder recipeModifierBuilder(String type, String ioTypeStr, float value, int operation, boolean affectChance) { + return RecipeModifierBuilder.create(type, ioTypeStr, value, operation, affectChance); + } + + public RecipeModifier recipeModifier(String type, String ioTypeStr, float value, int operation, boolean affectChance) { + return recipeModifierBuilder(type, ioTypeStr, value, operation, affectChance).build(); + } + + private IBlockState[] getBlockStates(Block block, int min, int max, @Nullable Block additional) { + int s = max - min; + if (additional != null) s++; + IBlockState[] states = new IBlockState[s]; + for (int i = min; i <= max; i++) { + states[i - min] = block.getStateFromMeta(i); + } + if (additional != null) states[s - 1] = additional.getDefaultState(); + return states; + } + + public List allOf(IBlockState[]... blockStates) { + if (blockStates.length == 0) return Collections.emptyList(); + if (blockStates.length == 1) return Arrays.asList(blockStates[0]); + List newBlockStates = new ArrayList<>(); + for (IBlockState[] states : blockStates) { + Collections.addAll(newBlockStates, states); + } + return newBlockStates; + } + + public IBlockState[] itemInputs(int min, int max, boolean allowME) { + return getBlockStates(BlocksMM.itemInputBus, min, max, allowME ? BlocksMM.meItemInputBus : null); + } + + public IBlockState[] itemInputs(boolean allowME) { + return itemInputs(0, ItemBusSize.values().length - 1, allowME); + } + + public IBlockState[] itemInputs() { + return itemInputs(true); + } + + public IBlockState[] itemInputs(int min, int max) { + return itemInputs(min, max, true); + } + + public IBlockState[] itemOutputs(int min, int max, boolean allowME) { + return getBlockStates(BlocksMM.itemOutputBus, min, max, allowME ? BlocksMM.meItemOutputBus : null); + } + + public IBlockState[] itemOutputs(boolean allowME) { + return itemOutputs(0, ItemBusSize.values().length - 1, allowME); + } + + public IBlockState[] itemOutputs() { + return itemOutputs(true); + } + + public IBlockState[] itemOutputs(int min, int max) { + return itemOutputs(min, max, true); + } + + public IBlockState[] fluidInputs(int min, int max, boolean allowME) { + return getBlockStates(BlocksMM.fluidInputHatch, min, max, allowME ? BlocksMM.meFluidInputBus : null); + } + + public IBlockState[] fluidInputs(boolean allowME) { + return fluidInputs(0, FluidHatchSize.values().length - 1, allowME); + } + + public IBlockState[] fluidInputs() { + return fluidInputs(true); + } + + public IBlockState[] fluidInputs(int min, int max) { + return fluidInputs(min, max, true); + } + + public IBlockState[] fluidOutputs(int min, int max, boolean allowME) { + return getBlockStates(BlocksMM.fluidOutputHatch, min, max, allowME ? BlocksMM.meFluidOutputBus : null); + } + + public IBlockState[] fluidOutputs(boolean allowME) { + return fluidOutputs(0, FluidHatchSize.values().length - 1, allowME); + } + + public IBlockState[] fluidOutputs() { + return fluidOutputs(true); + } + + public IBlockState[] fluidOutputs(int min, int max) { + return fluidOutputs(min, max, true); + } + + public IBlockState[] energyInputs(int min, int max) { + return getBlockStates(BlocksMM.energyInputHatch, min, max, null); + } + + public IBlockState[] energyInputs() { + return energyInputs(0, EnergyHatchData.values().length - 1); + } + + public IBlockState[] energyOutputs(int min, int max) { + return getBlockStates(BlocksMM.energyOutputHatch, min, max, null); + } + + public IBlockState[] energyOutputs() { + return energyOutputs(0, EnergyHatchData.values().length - 1); + } + + public IBlockState casing(String type) { + BlockCasing.CasingType casingType = EnumHelper.valueOfNullable(BlockCasing.CasingType.class, type, false); + if (casingType == null) { + GroovyLog.get().error("CasingType fot {} not found!", type); + return Blocks.BEDROCK.getDefaultState(); + } + return BlocksMM.blockCasing.getStateFromMeta(casingType.ordinal()); + } + + public IBlockState casing() { + return BlocksMM.blockCasing.getStateFromMeta(0); + } + + public IBlockState smartInterface() { + return BlocksMM.smartInterface.getDefaultState(); + } + + public IBlockState parallelController() { + return BlocksMM.smartInterface.getDefaultState(); + } + + public IBlockState upgradeBus() { + return BlocksMM.smartInterface.getDefaultState(); + } +} diff --git a/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/MachineUpgrades.java b/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/MachineUpgrades.java new file mode 100644 index 00000000..f660c597 --- /dev/null +++ b/src/main/java/github/kasuminova/mmce/common/integration/groovyscript/MachineUpgrades.java @@ -0,0 +1,105 @@ +package github.kasuminova.mmce.common.integration.groovyscript; + +import com.cleanroommc.groovyscript.registry.NamedRegistry; +import github.kasuminova.mmce.common.capability.CapabilityUpgrade; +import github.kasuminova.mmce.common.integration.Logger; +import github.kasuminova.mmce.common.upgrade.MachineUpgrade; +import github.kasuminova.mmce.common.upgrade.SimpleDynamicMachineUpgrade; +import github.kasuminova.mmce.common.upgrade.SimpleMachineUpgrade; +import github.kasuminova.mmce.common.upgrade.registry.RegistryUpgrade; +import hellfirepvp.modularmachinery.common.integration.crafttweaker.upgrade.MachineUpgradeBuilder; +import net.minecraft.item.ItemStack; + +import javax.annotation.Nullable; + +public class MachineUpgrades extends NamedRegistry { + + public MachineUpgradeBuilder builder(String name, String localizedName, float level, int maxStack) { + return MachineUpgradeBuilder.newBuilder(name, localizedName, level, maxStack); + } + + /** + * 为一个物品注册升级能力,只有在注册了之后才能够添加升级。 + * + * @param stack 物品 + */ + public void registerSupportedItem(ItemStack stack) { + if (!stack.isEmpty()) { + RegistryUpgrade.addSupportedItem(stack); + } + } + + /** + * 为一个物品添加固定的机械升级,会在物品被创建时自动添加物品。 + * + * @param stack 物品 + * @param upgradeName 升级名称 + */ + public void addFixedUpgrade(ItemStack stack, String upgradeName) { + if (stack.isEmpty()) { + return; + } + MachineUpgrade upgrade = RegistryUpgrade.getUpgrade(upgradeName); + if (upgrade == null) { + Logger.error("Cloud not find MachineUpgrade " + upgradeName + '!'); + return; + } + RegistryUpgrade.addFixedUpgrade(stack, upgrade); + } + + /** + * 将一个升级应用至机械升级,相当于直接写入相关升级的 NBT. + * + * @param stack 物品 + * @param upgradeName 名称 + * @return 添加了目标机械升级的物品。 + */ + public ItemStack addUpgradeToIItemStack(ItemStack stack, String upgradeName) { + if (!RegistryUpgrade.supportsUpgrade(stack)) { + Logger.warn(stack.getItem().getRegistryName() + " does not support upgrade!"); + return stack; + } + CapabilityUpgrade capability = stack.getCapability(CapabilityUpgrade.MACHINE_UPGRADE_CAPABILITY, null); + if (capability == null) { + return stack; + } + MachineUpgrade upgrade = RegistryUpgrade.getUpgrade(upgradeName); + if (upgrade == null) { + Logger.warn("Cloud not found MachineUpgrade " + upgradeName + '!'); + return stack; + } + capability.getUpgrades().add(upgrade); + return stack; + } + + /** + * 获取一个已注册的机械升级。 + * + * @param upgradeName 升级名称。 + * @return 机械升级,如果无则为 null + */ + @Nullable + public MachineUpgrade getUpgrade(String upgradeName) { + return RegistryUpgrade.getUpgrade(upgradeName); + } + + /** + * 将 MachineUpgrade 转换为 SimpleDynamicMachineUpgrade + * + * @param upgrade 升级 + * @return 强制转换后的升级,如果不支持则为 null。 + */ + public SimpleDynamicMachineUpgrade castToSimpleDynamicMachineUpgrade(MachineUpgrade upgrade) { + return upgrade instanceof SimpleDynamicMachineUpgrade ? (SimpleDynamicMachineUpgrade) upgrade : null; + } + + /** + * 将 MachineUpgrade 转换为 SimpleMachineUpgrade + * + * @param upgrade 升级 + * @return 强制转换后的升级,如果不支持则为 null。 + */ + public SimpleMachineUpgrade castToSimpleMachineUpgrade(MachineUpgrade upgrade) { + return upgrade instanceof SimpleMachineUpgrade ? (SimpleMachineUpgrade) upgrade : null; + } +} diff --git a/src/main/java/hellfirepvp/modularmachinery/ModularMachinery.java b/src/main/java/hellfirepvp/modularmachinery/ModularMachinery.java index 36d7324a..983cd691 100644 --- a/src/main/java/hellfirepvp/modularmachinery/ModularMachinery.java +++ b/src/main/java/hellfirepvp/modularmachinery/ModularMachinery.java @@ -55,6 +55,7 @@ @Mod(modid = ModularMachinery.MODID, name = ModularMachinery.NAME, version = ModularMachinery.VERSION, dependencies = "required-after:forge@[14.21.0.2371,);" + "required-after:crafttweaker@[4.0.4,);" + + //"after:groovyscript@[1.0.0,);" + // TODO wait for grs 1.0.1 "after:zenutils@[1.12.8,);" + "after:jei@[4.13.1.222,);" + "after:gregtech@[2.7.4-beta,);" + diff --git a/src/main/java/hellfirepvp/modularmachinery/common/CommonProxy.java b/src/main/java/hellfirepvp/modularmachinery/common/CommonProxy.java index fafc9b0b..24fb3632 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/CommonProxy.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/CommonProxy.java @@ -29,6 +29,7 @@ import github.kasuminova.mmce.common.tile.MEItemInputBus; import github.kasuminova.mmce.common.tile.MEItemOutputBus; import github.kasuminova.mmce.common.tile.MEPatternProvider; +import github.kasuminova.mmce.common.integration.groovyscript.GroovyMachine; import github.kasuminova.mmce.common.util.concurrent.Action; import github.kasuminova.mmce.common.world.MMWorldEventListener; import hellfirepvp.modularmachinery.ModularMachinery; @@ -170,6 +171,10 @@ public void init() { IntegrationTypeHelper.filterModIdComponents(); IntegrationTypeHelper.filterModIdRequirementTypes(); + if (Mods.GROOVYSCRIPT.isPresent()) { + // the pattern requires all mod block to be loaded + GroovyMachine.init(); + } if (Mods.TOP.isPresent()) { ModIntegrationTOP.registerProvider(); ModularMachinery.log.info("[ModularMachinery-CE] TheOneProbe integration is enabled! Stop looking at the dark controller gui!"); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/base/Mods.java b/src/main/java/hellfirepvp/modularmachinery/common/base/Mods.java index b8f76d78..24bd7e00 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/base/Mods.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/base/Mods.java @@ -19,6 +19,7 @@ * Date: 02.03.2019 / 17:42 */ public enum Mods { + GROOVYSCRIPT("groovyscript"), CRAFTTWEAKER("crafttweaker"), JEI("jei"), GREGTECH("gregtech"), diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/ActiveMachineRecipe.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/ActiveMachineRecipe.java index b655c000..1d34d501 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/ActiveMachineRecipe.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/ActiveMachineRecipe.java @@ -21,6 +21,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.util.Constants; +import net.minecraftforge.fml.common.Optional; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenGetter; import stanhebben.zenscript.annotations.ZenSetter; @@ -209,11 +210,13 @@ public String getRegistryName() { return recipe.getRegistryName().getPath(); } + @Optional.Method(modid = "crafttweaker") @ZenGetter("data") public IData getData() { return CraftTweakerMC.getIDataModifyable(data); } + @Optional.Method(modid = "crafttweaker") @ZenSetter("data") public void setData(IData data) { this.data = CraftTweakerMC.getNBTCompound(data); @@ -222,4 +225,12 @@ public void setData(IData data) { public NBTTagCompound getDataCompound() { return data; } + + public NBTTagCompound getNbt() { + return data; + } + + public void setNbt(NBTTagCompound nbt) { + this.data = nbt; + } } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/MachineRecipe.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/MachineRecipe.java index 4e572729..894253d8 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/MachineRecipe.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/MachineRecipe.java @@ -16,7 +16,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.ModularMachinery; import hellfirepvp.modularmachinery.common.crafting.command.RecipeCommandContainer; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/PreparedRecipe.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/PreparedRecipe.java index 2373eaa5..d3b49bc0 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/PreparedRecipe.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/PreparedRecipe.java @@ -8,7 +8,7 @@ package hellfirepvp.modularmachinery.common.crafting; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement; import net.minecraft.util.ResourceLocation; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/AdapterMinecraftFurnace.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/AdapterMinecraftFurnace.java index 52d82dc7..c696a8e5 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/AdapterMinecraftFurnace.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/AdapterMinecraftFurnace.java @@ -8,8 +8,8 @@ package hellfirepvp.modularmachinery.common.crafting.adapter; -import crafttweaker.util.IEventHandler; import github.kasuminova.mmce.common.event.Phase; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeCheckEvent; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/DynamicMachineRecipeAdapter.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/DynamicMachineRecipeAdapter.java index 135d25ed..7c6e057b 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/DynamicMachineRecipeAdapter.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/DynamicMachineRecipeAdapter.java @@ -8,7 +8,7 @@ package hellfirepvp.modularmachinery.common.crafting.adapter; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.ModularMachinery; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapter.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapter.java index 8a9d8976..4497eca0 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapter.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapter.java @@ -8,7 +8,7 @@ package hellfirepvp.modularmachinery.common.crafting.adapter; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterAccessor.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterAccessor.java index e7c6b3c5..372d947b 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterAccessor.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterAccessor.java @@ -15,7 +15,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.ModularMachinery; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterRegistry.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterRegistry.java index 80684c12..6c113801 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterRegistry.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterRegistry.java @@ -8,7 +8,7 @@ package hellfirepvp.modularmachinery.common.crafting.adapter; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/ic2/AdapterIC2Compressor.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/ic2/AdapterIC2Compressor.java index 6c6c30f5..d45a0a2a 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/ic2/AdapterIC2Compressor.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/ic2/AdapterIC2Compressor.java @@ -1,6 +1,6 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.ic2; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/ic2/AdapterIC2Macerator.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/ic2/AdapterIC2Macerator.java index c057e528..306a9b59 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/ic2/AdapterIC2Macerator.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/ic2/AdapterIC2Macerator.java @@ -1,6 +1,6 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.ic2; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOAlloyFurnace.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOAlloyFurnace.java index bc9aa364..709d2871 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOAlloyFurnace.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOAlloyFurnace.java @@ -1,6 +1,6 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.nco; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import github.kasuminova.mmce.common.itemtype.ChancedIngredientStack; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOChemicalReactor.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOChemicalReactor.java index 6cb26066..0fd2e56a 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOChemicalReactor.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOChemicalReactor.java @@ -1,6 +1,6 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.nco; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOInfuser.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOInfuser.java index 751e1562..a0d3b8af 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOInfuser.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOInfuser.java @@ -1,6 +1,6 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.nco; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import github.kasuminova.mmce.common.itemtype.ChancedIngredientStack; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOMelter.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOMelter.java index fa5964d8..77ddb604 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOMelter.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOMelter.java @@ -1,6 +1,6 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.nco; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import github.kasuminova.mmce.common.itemtype.ChancedIngredientStack; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tc6/AdapterTC6InfusionMatrix.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tc6/AdapterTC6InfusionMatrix.java index 273c1b4f..d606c0e9 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tc6/AdapterTC6InfusionMatrix.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tc6/AdapterTC6InfusionMatrix.java @@ -1,6 +1,6 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.tc6; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import github.kasuminova.mmce.common.itemtype.ChancedIngredientStack; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tconstruct/AdapterSmelteryAlloyRecipe.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tconstruct/AdapterSmelteryAlloyRecipe.java index 4ab9b06d..9eea6077 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tconstruct/AdapterSmelteryAlloyRecipe.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tconstruct/AdapterSmelteryAlloyRecipe.java @@ -1,6 +1,6 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.tconstruct; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; import hellfirepvp.modularmachinery.common.crafting.adapter.RecipeAdapter; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tconstruct/AdapterSmelteryMeltingRecipe.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tconstruct/AdapterSmelteryMeltingRecipe.java index a766c51c..b8600575 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tconstruct/AdapterSmelteryMeltingRecipe.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tconstruct/AdapterSmelteryMeltingRecipe.java @@ -1,7 +1,7 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.tconstruct; -import crafttweaker.util.IEventHandler; import github.kasuminova.mmce.common.event.Phase; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeCheckEvent; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import github.kasuminova.mmce.common.itemtype.ChancedIngredientStack; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/te5/InsolatorRecipeAdapter.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/te5/InsolatorRecipeAdapter.java index 0c3ac222..8192751e 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/te5/InsolatorRecipeAdapter.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/te5/InsolatorRecipeAdapter.java @@ -1,7 +1,7 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.te5; import cofh.thermalexpansion.util.managers.machine.InsolatorManager; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import github.kasuminova.mmce.common.util.HashedItemStack; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; @@ -168,5 +168,4 @@ public Collection createRecipesFor(final ResourceLocation owningM return recipes; } - } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/BlockArrayBuilder.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/BlockArrayBuilder.java index 6b8d60d0..92118325 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/BlockArrayBuilder.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/BlockArrayBuilder.java @@ -1,12 +1,13 @@ package hellfirepvp.modularmachinery.common.integration.crafttweaker; +import com.cleanroommc.groovyscript.api.GroovyBlacklist; import com.google.gson.JsonParseException; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.block.IBlockState; import crafttweaker.api.data.IData; import crafttweaker.api.item.IItemStack; import crafttweaker.api.minecraft.CraftTweakerMC; +import github.kasuminova.mmce.common.integration.Logger; import hellfirepvp.modularmachinery.common.crafting.helper.ComponentSelectorTag; import hellfirepvp.modularmachinery.common.integration.crafttweaker.helper.AdvancedBlockCheckerCT; import hellfirepvp.modularmachinery.common.machine.TaggedPositionBlockArray; @@ -25,6 +26,7 @@ import java.util.ArrayList; import java.util.List; +@GroovyBlacklist @ZenRegister @ZenClass("mods.modularmachinery.BlockArrayBuilder") public class BlockArrayBuilder { @@ -143,12 +145,12 @@ public BlockArrayBuilder addBlock(int x, int y, int z, IItemStack... ctItemStack net.minecraft.block.state.IBlockState state = block.getStateFromMeta(meta); stateDescriptorList.add(IBlockStateDescriptor.of(state)); } catch (Exception e) { - CraftTweakerAPI.logError(String.format("[ModularMachinery] Failed to get BlockState from <%s>!", - stack.getItem().getRegistryName() + ":" + meta + Logger.error(String.format("[ModularMachinery] Failed to get BlockState from <%s>!", + stack.getItem().getRegistryName() + ":" + meta )); } } else { - CraftTweakerAPI.logError("[ModularMachinery] " + stack.getDisplayName() + " cannot convert to Block!"); + Logger.error("[ModularMachinery] " + stack.getDisplayName() + " cannot convert to Block!"); } } @@ -218,7 +220,7 @@ public BlockArrayBuilder addBlock(int x, int y, int z, String... blockNames) { try { stateDescriptorList.add(BlockArray.BlockInformation.getDescriptor(blockName)); } catch (JsonParseException e) { - CraftTweakerAPI.logError("[ModularMachinery] " + blockName + " is invalid block!", e); + Logger.error("[ModularMachinery] " + blockName + " is invalid block!", e); } } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/IngredientArrayPrimer.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/IngredientArrayPrimer.java index dcb09d95..f9a52ea5 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/IngredientArrayPrimer.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/IngredientArrayPrimer.java @@ -1,12 +1,12 @@ package hellfirepvp.modularmachinery.common.integration.crafttweaker; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.IngredientStack; import crafttweaker.api.minecraft.CraftTweakerMC; import crafttweaker.api.oredict.IOreDictEntry; +import github.kasuminova.mmce.common.integration.Logger; import github.kasuminova.mmce.common.itemtype.ChancedIngredientStack; import hellfirepvp.modularmachinery.common.integration.crafttweaker.helper.AdvancedItemCheckerCT; import hellfirepvp.modularmachinery.common.integration.crafttweaker.helper.AdvancedItemModifierCT; @@ -27,7 +27,7 @@ public IngredientArrayPrimer addIngredient(IIngredient input) { if (input instanceof final IItemStack stackCT) { ItemStack stackMC = CraftTweakerMC.getItemStack(input); if (stackMC.isEmpty()) { - CraftTweakerAPI.logError("[ModularMachinery] ItemStack not found/unknown item: " + stackMC); + Logger.error("ItemStack not found/unknown item: " + stackMC); return this; } ChancedIngredientStack ingredientStack = new ChancedIngredientStack(stackMC); @@ -66,7 +66,7 @@ public IngredientArrayPrimer setMinMaxAmount(int min, int max) { lastIngredientStack.minCount = min; lastIngredientStack.maxCount = max; } else { - CraftTweakerAPI.logWarning("[ModularMachinery] `min` cannot larger than `max`!"); + Logger.warn("`min` cannot larger than `max`!"); } } return this; @@ -101,7 +101,7 @@ public IngredientArrayPrimer addItemModifier(AdvancedItemModifierCT modifier) { @ZenMethod @Deprecated public IngredientArrayPrimer build() { - CraftTweakerAPI.logWarning("[ModularMachinery] IngredientArrayPrimer#build is deprecated, it will be removed in future version."); + Logger.warn("IngredientArrayPrimer#build is deprecated, it will be removed in future version."); return this; } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/MachineBuilder.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/MachineBuilder.java index 4f69913d..86a422cb 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/MachineBuilder.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/MachineBuilder.java @@ -1,7 +1,7 @@ package hellfirepvp.modularmachinery.common.integration.crafttweaker; +import com.cleanroommc.groovyscript.api.GroovyBlacklist; import com.google.gson.JsonParseException; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.block.IBlockState; import crafttweaker.api.data.IData; @@ -16,6 +16,7 @@ import github.kasuminova.mmce.common.event.machine.MachineStructureUpdateEvent; import github.kasuminova.mmce.common.event.machine.MachineTickEvent; import github.kasuminova.mmce.common.event.machine.SmartInterfaceUpdateEvent; +import github.kasuminova.mmce.common.integration.Logger; import hellfirepvp.modularmachinery.ModularMachinery; import hellfirepvp.modularmachinery.common.integration.crafttweaker.helper.AdvancedBlockCheckerCT; import hellfirepvp.modularmachinery.common.machine.DynamicMachine; @@ -45,6 +46,7 @@ import java.util.List; import java.util.Map; +@GroovyBlacklist @ZenRegister @ZenClass("mods.modularmachinery.MachineBuilder") public class MachineBuilder { @@ -287,7 +289,7 @@ public MachineBuilder addSingleBlockModifier(int x, int y, int z, IItemStack ctI stateDescriptorList.add(IBlockStateDescriptor.of(block)); addSingleBlockModifier(new BlockPos(x, y, z), new BlockArray.BlockInformation(stateDescriptorList), description, modifiers); } else { - CraftTweakerAPI.logError("[ModularMachinery] " + item.getDisplayName() + " cannot convert to Block!"); + Logger.error(item.getDisplayName() + " cannot convert to Block!"); } return this; @@ -311,7 +313,7 @@ public MachineBuilder addSingleBlockModifier(int x, int y, int z, String blockNa stateDescriptorList.add(BlockArray.BlockInformation.getDescriptor(blockName)); addSingleBlockModifier(new BlockPos(x, y, z), new BlockArray.BlockInformation(stateDescriptorList), description, modifiers); } catch (JsonParseException e) { - CraftTweakerAPI.logError("[ModularMachinery] " + blockName + " is invalid block!", e); + Logger.error(blockName + " is invalid block!", e); } return this; @@ -338,7 +340,7 @@ public MachineBuilder addSmartInterfaceType(SmartInterfaceType type) { if (!machine.hasSmartInterfaceType(type.getType())) { machine.addSmartInterfaceType(type); } else { - CraftTweakerAPI.logWarning("[ModularMachinery] DynamicMachine `" + machine.getRegistryName() + "` is already has SmartInterfaceType `" + type.getType() + "`!"); + Logger.warn("DynamicMachine `" + machine.getRegistryName() + "` is already has SmartInterfaceType `" + type.getType() + "`!"); } return this; } @@ -348,7 +350,7 @@ public MachineBuilder addSmartInterfaceType(SmartInterfaceType type) { */ @ZenMethod public MachineBuilder addStructureFormedHandler(IEventHandler function) { - machine.addMachineEventHandler(MachineStructureFormedEvent.class, function); + machine.addMachineEventHandler(MachineStructureFormedEvent.class, function::handle); return this; } @@ -357,7 +359,7 @@ public MachineBuilder addStructureFormedHandler(IEventHandler function) { - machine.addMachineEventHandler(MachineStructureUpdateEvent.class, function); + machine.addMachineEventHandler(MachineStructureUpdateEvent.class, function::handle); return this; } @@ -366,7 +368,7 @@ public MachineBuilder addStructureUpdateHandler(IEventHandler function) { - machine.addMachineEventHandler(MachineTickEvent.class, function); + machine.addMachineEventHandler(MachineTickEvent.class, function::handle); return this; } @@ -378,7 +380,7 @@ public MachineBuilder addGUIRenderHandler(IEventHandler function) { - machine.addMachineEventHandler(SmartInterfaceUpdateEvent.class, function); + machine.addMachineEventHandler(SmartInterfaceUpdateEvent.class, function::handle); return this; } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/MachineModifier.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/MachineModifier.java index d54841da..01277b9b 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/MachineModifier.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/MachineModifier.java @@ -1,9 +1,9 @@ package hellfirepvp.modularmachinery.common.integration.crafttweaker; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ZenRegister; import github.kasuminova.mmce.client.model.DynamicMachineModelRegistry; import github.kasuminova.mmce.client.model.MachineControllerModel; +import github.kasuminova.mmce.common.integration.Logger; import github.kasuminova.mmce.common.util.concurrent.Action; import hellfirepvp.modularmachinery.ModularMachinery; import hellfirepvp.modularmachinery.common.machine.DynamicMachine; @@ -28,13 +28,13 @@ public static void addSmartInterfaceType(String machineName, SmartInterfaceType WAIT_FOR_MODIFY.add(() -> { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineName)); if (machine == null) { - CraftTweakerAPI.logError("Could not find machine `" + machineName + "`!"); + Logger.error("Could not find machine `" + machineName + "`!"); return; } if (!machine.hasSmartInterfaceType(type.getType())) { machine.addSmartInterfaceType(type); } else { - CraftTweakerAPI.logWarning("[ModularMachinery] DynamicMachine `" + machine.getRegistryName() + "` is already has SmartInterfaceType `" + type.getType() + "`!"); + Logger.warn("DynamicMachine `" + machine.getRegistryName() + "` is already has SmartInterfaceType `" + type.getType() + "`!"); } }); } @@ -42,12 +42,12 @@ public static void addSmartInterfaceType(String machineName, SmartInterfaceType @ZenMethod public static void setMaxParallelism(String machineName, int maxParallelism) { if (maxParallelism < 1) { - CraftTweakerAPI.logError("Max Parallelism must larger than 1!"); + Logger.error("Max Parallelism must larger than 1!"); } WAIT_FOR_MODIFY.add(() -> { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineName)); if (machine == null) { - CraftTweakerAPI.logError("Could not find machine `" + machineName + "`!"); + Logger.error("Could not find machine `" + machineName + "`!"); return; } machine.setMaxParallelism(maxParallelism); @@ -57,12 +57,12 @@ public static void setMaxParallelism(String machineName, int maxParallelism) { @ZenMethod public static void setInternalParallelism(String machineName, int parallelism) { if (parallelism < 0) { - CraftTweakerAPI.logError("Max Parallelism must larger than 0!"); + Logger.error("Max Parallelism must larger than 0!"); } WAIT_FOR_MODIFY.add(() -> { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineName)); if (machine == null) { - CraftTweakerAPI.logError("Could not find machine `" + machineName + "`!"); + Logger.error("Could not find machine `" + machineName + "`!"); return; } machine.setInternalParallelism(parallelism); @@ -73,12 +73,12 @@ public static void setInternalParallelism(String machineName, int parallelism) { public static void setMaxThreads(String machineName, int maxThreads) { // Maybe the author only wanted to use the core thread? if (maxThreads < 0) { - CraftTweakerAPI.logError("Max Threads must larger than or equal 0!"); + Logger.error("Max Threads must larger than or equal 0!"); } WAIT_FOR_MODIFY.add(() -> { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineName)); if (machine == null) { - CraftTweakerAPI.logError("Could not find machine `" + machineName + "`!"); + Logger.error("Could not find machine `" + machineName + "`!"); return; } machine.setMaxThreads(maxThreads); @@ -90,7 +90,7 @@ public static void addCoreThread(String machineName, FactoryRecipeThread thread) WAIT_FOR_MODIFY.add(() -> { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineName)); if (machine == null) { - CraftTweakerAPI.logError("Could not find machine `" + machineName + "`!"); + Logger.error("Could not find machine `" + machineName + "`!"); return; } machine.addCoreThread(thread); @@ -106,13 +106,13 @@ public static void setMachineGeoModel(String machineName, String modelName) { WAIT_FOR_MODIFY.add(() -> { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineName)); if (machine == null) { - CraftTweakerAPI.logError("Could not find machine `" + machineName + "`!"); + Logger.error("Could not find machine `" + machineName + "`!"); return; } MachineControllerModel model = DynamicMachineModelRegistry.INSTANCE.getMachineModel(modelName); if (model == null) { - CraftTweakerAPI.logError("Could not find geo model `" + modelName + "`!"); + Logger.error("Could not find geo model `" + modelName + "`!"); return; } @@ -129,7 +129,7 @@ public static void setMachinePrefix(String machineName, String prefixName) { WAIT_FOR_MODIFY.add(() -> { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineName)); if (machine == null) { - CraftTweakerAPI.logError("Could not find machine `" + machineName + "`!"); + Logger.error("Could not find machine `" + machineName + "`!"); return; } machine.setPrefix(prefixName); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipeAdapterBuilder.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipeAdapterBuilder.java index 3d6aff5d..a55dbdc8 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipeAdapterBuilder.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipeAdapterBuilder.java @@ -1,7 +1,7 @@ package hellfirepvp.modularmachinery.common.integration.crafttweaker; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ZenRegister; +import github.kasuminova.mmce.common.integration.Logger; import hellfirepvp.modularmachinery.ModularMachinery; import hellfirepvp.modularmachinery.common.crafting.RecipeRegistry; import hellfirepvp.modularmachinery.common.modifier.RecipeModifier; @@ -68,7 +68,7 @@ public void build() { //---------------------------------------------------------------------------------------------- @Override public RecipePrimer setParallelized(boolean isParallelized) { - CraftTweakerAPI.logWarning("[ModularMachinery] RecipeAdapterBuilder cannot set parallelized, it depends on the parent machine recipe!"); + Logger.warn("RecipeAdapterBuilder cannot set parallelized, it depends on the parent machine recipe!"); return this; } } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipeBuilder.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipeBuilder.java index a6de1aed..83fb115e 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipeBuilder.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipeBuilder.java @@ -8,8 +8,9 @@ package hellfirepvp.modularmachinery.common.integration.crafttweaker; -import crafttweaker.CraftTweakerAPI; +import com.cleanroommc.groovyscript.api.GroovyBlacklist; import crafttweaker.annotations.ZenRegister; +import github.kasuminova.mmce.common.integration.Logger; import hellfirepvp.modularmachinery.ModularMachinery; import net.minecraft.util.ResourceLocation; import stanhebben.zenscript.annotations.ZenClass; @@ -22,6 +23,7 @@ * Created by HellFirePvP * Date: 02.01.2018 / 18:16 */ +@GroovyBlacklist @ZenRegister @ZenClass("mods.modularmachinery.RecipeBuilder") public class RecipeBuilder { @@ -49,10 +51,10 @@ public static RecipePrimer newBuilder(String recipeRegistryName, String associat } if (!path.matches("[._\\-a-zA-Z][._\\-a-zA-Z0-9]*")) { - CraftTweakerAPI.logWarning("[ModularMachinery] Dangerous recipe registry name: " + path); + Logger.warn("Dangerous recipe registry name: " + path); } if (processingTickTime <= 0) { - CraftTweakerAPI.logWarning("[ModularMachinery] Recipe processing tick time has to be at least 1 tick!"); + Logger.warn("Recipe processing tick time has to be at least 1 tick!"); processingTickTime = 1; } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipeModifierBuilder.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipeModifierBuilder.java index 510292da..733eec75 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipeModifierBuilder.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipeModifierBuilder.java @@ -1,7 +1,7 @@ package hellfirepvp.modularmachinery.common.integration.crafttweaker; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ZenRegister; +import github.kasuminova.mmce.common.integration.Logger; import hellfirepvp.modularmachinery.common.crafting.requirement.type.RequirementType; import hellfirepvp.modularmachinery.common.lib.RegistriesMM; import hellfirepvp.modularmachinery.common.machine.IOType; @@ -14,7 +14,7 @@ @ZenClass("mods.modularmachinery.RecipeModifierBuilder") public class RecipeModifierBuilder { private String type = ""; - private String ioTypeStr = ""; + private IOType ioType = null; private float value = 0.0f; private int operation = 0; private boolean affectChance = false; @@ -28,7 +28,7 @@ public static RecipeModifierBuilder newBuilder() { public static RecipeModifierBuilder create(String type, String ioTypeStr, float value, int operation, boolean affectChance) { RecipeModifierBuilder builder = new RecipeModifierBuilder(); builder.type = type; - builder.ioTypeStr = ioTypeStr; + builder.ioType = IOType.getByString(ioTypeStr); builder.value = value; builder.operation = operation; builder.affectChance = affectChance; @@ -41,9 +41,26 @@ public RecipeModifierBuilder setRequirementType(String type) { return this; } + public RecipeModifierBuilder requirementType(String type) { + return setRequirementType(type); + } + @ZenMethod public RecipeModifierBuilder setIOType(String ioTypeStr) { - this.ioTypeStr = ioTypeStr; + this.ioType = IOType.getByString(ioTypeStr); + return this; + } + + public RecipeModifierBuilder input() { + return ioType(IOType.INPUT); + } + + public RecipeModifierBuilder output() { + return ioType(IOType.OUTPUT); + } + + public RecipeModifierBuilder ioType(IOType ioType) { + this.ioType = ioType; return this; } @@ -53,36 +70,49 @@ public RecipeModifierBuilder setValue(float value) { return this; } + public RecipeModifierBuilder value(float value) { + return setValue(value); + } + @ZenMethod public RecipeModifierBuilder setOperation(int operation) { this.operation = operation; return this; } + @ZenMethod + public RecipeModifierBuilder add() { + return setOperation(RecipeModifier.OPERATION_ADD); + } + + @ZenMethod + public RecipeModifierBuilder multiply() { + return setOperation(RecipeModifier.OPERATION_MULTIPLY); + } + @ZenMethod public RecipeModifierBuilder isAffectChance(boolean affectChance) { this.affectChance = affectChance; return this; } + public RecipeModifierBuilder affectChance(boolean affectChance) { + return isAffectChance(affectChance); + } + @ZenMethod public RecipeModifier build() { RequirementType target = RegistriesMM.REQUIREMENT_TYPE_REGISTRY.getValue(new ResourceLocation(type)); if (target == null) { - CraftTweakerAPI.logError("Could not find requirementType " + type + "!"); + Logger.error("Could not find requirementType " + type + "!"); return null; } - IOType ioType; - switch (ioTypeStr.toLowerCase()) { - case "input" -> ioType = IOType.INPUT; - case "output" -> ioType = IOType.OUTPUT; - default -> { - CraftTweakerAPI.logError("Invalid ioType " + ioTypeStr + "!"); - return null; - } + if (this.ioType == null) { + Logger.error("IOType was not set or was invalid. Valid values are: ['input', 'output']."); + return null; } if (operation > 1 || operation < 0) { - CraftTweakerAPI.logError("Invalid operation " + operation + "!"); + Logger.error("Invalid operation " + operation + "!"); return null; } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipePrimer.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipePrimer.java index 41a80ca9..15853bf9 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipePrimer.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipePrimer.java @@ -8,7 +8,7 @@ package hellfirepvp.modularmachinery.common.integration.crafttweaker; -import crafttweaker.CraftTweakerAPI; +import com.cleanroommc.groovyscript.api.GroovyBlacklist; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.data.IData; import crafttweaker.api.item.IIngredient; @@ -17,7 +17,6 @@ import crafttweaker.api.liquid.ILiquidStack; import crafttweaker.api.minecraft.CraftTweakerMC; import crafttweaker.api.oredict.IOreDictEntry; -import crafttweaker.util.IEventHandler; import github.kasuminova.mmce.common.event.Phase; import github.kasuminova.mmce.common.event.recipe.FactoryRecipeFailureEvent; import github.kasuminova.mmce.common.event.recipe.FactoryRecipeFinishEvent; @@ -29,6 +28,8 @@ import github.kasuminova.mmce.common.event.recipe.RecipeFinishEvent; import github.kasuminova.mmce.common.event.recipe.RecipeStartEvent; import github.kasuminova.mmce.common.event.recipe.RecipeTickEvent; +import github.kasuminova.mmce.common.event.machine.IEventHandler; +import github.kasuminova.mmce.common.integration.Logger; import github.kasuminova.mmce.common.util.concurrent.Action; import hellfirepvp.modularmachinery.common.base.Mods; import hellfirepvp.modularmachinery.common.crafting.PreparedRecipe; @@ -77,6 +78,7 @@ * Created by HellFirePvP * Date: 02.01.2018 / 18:18 */ +@GroovyBlacklist @ZenRegister @ZenClass("mods.modularmachinery.RecipePrimer") public class RecipePrimer implements PreparedRecipe { @@ -109,7 +111,7 @@ public RecipePrimer setParallelizeUnaffected(boolean unaffected) { if (lastComponent instanceof ComponentRequirement.Parallelizable parallelizable) { parallelizable.setParallelizeUnaffected(unaffected); } else { - CraftTweakerAPI.logWarning("[ModularMachinery] Target " + lastComponent.getClass() + " cannot be parallelized!"); + Logger.warn("Target " + lastComponent.getClass() + " cannot be parallelized!"); } return this; } @@ -120,7 +122,7 @@ public RecipePrimer setChance(float chance) { if (lastComponent instanceof ComponentRequirement.ChancedRequirement chancedReq) { chancedReq.setChance(chance); } else { - CraftTweakerAPI.logWarning("[ModularMachinery] Cannot set chance for not-chance-based Component: " + lastComponent.getClass()); + Logger.warn("Cannot set chance for not-chance-based Component: " + lastComponent.getClass()); } } return this; @@ -140,10 +142,10 @@ public RecipePrimer setPreViewNBT(IData nbt) { if (lastComponent instanceof RequirementItem reqItem) { reqItem.previewDisplayTag = CraftTweakerMC.getNBTCompound(nbt); } else { - CraftTweakerAPI.logWarning("[ModularMachinery] setPreViewNBT(IData nbt) only can be applied to `Item`!"); + Logger.warn("setPreViewNBT(IData nbt) only can be applied to `Item`!"); } } else { - CraftTweakerAPI.logWarning("[ModularMachinery] setPreViewNBT(IData nbt) only can be applied to `Item`!"); + Logger.warn("setPreViewNBT(IData nbt) only can be applied to `Item`!"); } return this; } @@ -154,10 +156,10 @@ public RecipePrimer setNBTChecker(AdvancedItemCheckerCT checker) { if (lastComponent instanceof RequirementItem reqItem) { reqItem.setItemChecker((controller, stack) -> checker.isMatch(controller, CraftTweakerMC.getIItemStack(stack))); } else { - CraftTweakerAPI.logWarning("[ModularMachinery] setNBTChecker(AdvancedItemNBTChecker checker) only can be applied to `Item`!"); + Logger.warn("setNBTChecker(AdvancedItemNBTChecker checker) only can be applied to `Item`!"); } } else { - CraftTweakerAPI.logWarning("[ModularMachinery] setNBTChecker(AdvancedItemNBTChecker checker) only can be applied to `Item`!"); + Logger.warn("setNBTChecker(AdvancedItemNBTChecker checker) only can be applied to `Item`!"); } return this; } @@ -168,10 +170,10 @@ public RecipePrimer addItemModifier(AdvancedItemModifierCT modifier) { if (lastComponent instanceof RequirementItem reqItem) { reqItem.addItemModifier((controller, stack) -> CraftTweakerMC.getItemStack(modifier.apply(controller, CraftTweakerMC.getIItemStackMutable(stack)))); } else { - CraftTweakerAPI.logWarning("[ModularMachinery] addItemModifier(AdvancedItemModifier checker) only can be applied to `Item`!"); + Logger.warn("addItemModifier(AdvancedItemModifier checker) only can be applied to `Item`!"); } } else { - CraftTweakerAPI.logWarning("[ModularMachinery] addItemModifier(AdvancedItemModifier checker) only can be applied to `Item`!"); + Logger.warn("addItemModifier(AdvancedItemModifier checker) only can be applied to `Item`!"); } return this; } @@ -184,13 +186,13 @@ public RecipePrimer setMinMaxAmount(int min, int max) { reqItem.minAmount = min; reqItem.maxAmount = max; } else { - CraftTweakerAPI.logWarning("[ModularMachinery] `min` cannot larger than `max`!"); + Logger.warn("`min` cannot larger than `max`!"); } } else { - CraftTweakerAPI.logWarning("[ModularMachinery] setMinMaxOutputAmount(int min, int max) only can be applied to `Item`!"); + Logger.warn("setMinMaxOutputAmount(int min, int max) only can be applied to `Item`!"); } } else { - CraftTweakerAPI.logWarning("[ModularMachinery] setMinMaxOutputAmount(int min, int max) only can be applied to `Item`!"); + Logger.warn("setMinMaxOutputAmount(int min, int max) only can be applied to `Item`!"); } return this; } @@ -247,12 +249,12 @@ public RecipePrimer addSmartInterfaceDataInput(String typeStr, float minValue, f needAfterInitActions.add(() -> { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(machineName); if (machine == null) { - CraftTweakerAPI.logError("Could not find machine `" + machineName.toString() + "`!"); + Logger.error("Could not find machine `" + machineName.toString() + "`!"); return; } SmartInterfaceType type = machine.getSmartInterfaceType(typeStr); if (type == null) { - CraftTweakerAPI.logError("SmartInterfaceType " + typeStr + " Not Found!"); + Logger.error("SmartInterfaceType " + typeStr + " Not Found!"); return; } appendComponent(new RequirementInterfaceNumInput(type, minValue, maxValue)); @@ -266,7 +268,7 @@ public RecipePrimer addSmartInterfaceDataInput(String typeStr, float value) { } @ZenMethod - public RecipePrimer addPreCheckHandler(IEventHandler handler) { + public RecipePrimer addPreCheckHandler(crafttweaker.util.IEventHandler handler) { addRecipeEventHandler(RecipeCheckEvent.class, event -> { if (event.phase != Phase.START) { return; @@ -277,7 +279,7 @@ public RecipePrimer addPreCheckHandler(IEventHandler handler) } @ZenMethod - public RecipePrimer addPostCheckHandler(IEventHandler handler) { + public RecipePrimer addPostCheckHandler(crafttweaker.util.IEventHandler handler) { addRecipeEventHandler(RecipeCheckEvent.class, event -> { if (event.phase != Phase.END) { return; @@ -289,9 +291,9 @@ public RecipePrimer addPostCheckHandler(IEventHandler handler) @ZenMethod @Deprecated - public RecipePrimer addCheckHandler(IEventHandler handler) { - CraftTweakerAPI.logWarning("[ModularMachinery] Deprecated method addCheckHandler()! Consider using addPostCheckHandler()"); - addRecipeEventHandler(RecipeCheckEvent.class, handler); + public RecipePrimer addCheckHandler(crafttweaker.util.IEventHandler handler) { + Logger.warn("Deprecated method addCheckHandler()! Consider using addPostCheckHandler()"); + addRecipeEventHandler(RecipeCheckEvent.class, handler::handle); return this; } @@ -300,13 +302,13 @@ public RecipePrimer addCheckHandler(IEventHandler handler) { //---------------------------------------------------------------------------------------------- @ZenMethod - public RecipePrimer addStartHandler(IEventHandler handler) { - addRecipeEventHandler(RecipeStartEvent.class, handler); + public RecipePrimer addStartHandler(crafttweaker.util.IEventHandler handler) { + addRecipeEventHandler(RecipeStartEvent.class, handler::handle); return this; } @ZenMethod - public RecipePrimer addPreTickHandler(IEventHandler handler) { + public RecipePrimer addPreTickHandler(crafttweaker.util.IEventHandler handler) { addRecipeEventHandler(RecipeTickEvent.class, event -> { if (event.phase != Phase.START) { return; @@ -317,7 +319,7 @@ public RecipePrimer addPreTickHandler(IEventHandler handler) { } @ZenMethod - public RecipePrimer addPostTickHandler(IEventHandler handler) { + public RecipePrimer addPostTickHandler(crafttweaker.util.IEventHandler handler) { addRecipeEventHandler(RecipeTickEvent.class, event -> { if (event.phase != Phase.END) { return; @@ -328,25 +330,25 @@ public RecipePrimer addPostTickHandler(IEventHandler handler) { } @ZenMethod - public RecipePrimer addFailureHandler(IEventHandler handler) { - addRecipeEventHandler(RecipeFailureEvent.class, handler); + public RecipePrimer addFailureHandler(crafttweaker.util.IEventHandler handler) { + addRecipeEventHandler(RecipeFailureEvent.class, handler::handle); return this; } @ZenMethod - public RecipePrimer addFinishHandler(IEventHandler handler) { - addRecipeEventHandler(RecipeFinishEvent.class, handler); + public RecipePrimer addFinishHandler(crafttweaker.util.IEventHandler handler) { + addRecipeEventHandler(RecipeFinishEvent.class, handler::handle); return this; } @ZenMethod - public RecipePrimer addFactoryStartHandler(IEventHandler handler) { - addRecipeEventHandler(FactoryRecipeStartEvent.class, handler); + public RecipePrimer addFactoryStartHandler(crafttweaker.util.IEventHandler handler) { + addRecipeEventHandler(FactoryRecipeStartEvent.class, handler::handle); return this; } @ZenMethod - public RecipePrimer addFactoryPreTickHandler(IEventHandler handler) { + public RecipePrimer addFactoryPreTickHandler(crafttweaker.util.IEventHandler handler) { addRecipeEventHandler(FactoryRecipeTickEvent.class, event -> { if (event.phase != Phase.START) { return; @@ -357,7 +359,7 @@ public RecipePrimer addFactoryPreTickHandler(IEventHandler handler) { + public RecipePrimer addFactoryPostTickHandler(crafttweaker.util.IEventHandler handler) { addRecipeEventHandler(FactoryRecipeTickEvent.class, event -> { if (event.phase != Phase.END) { return; @@ -368,14 +370,14 @@ public RecipePrimer addFactoryPostTickHandler(IEventHandler handler) { - addRecipeEventHandler(FactoryRecipeFailureEvent.class, handler); + public RecipePrimer addFactoryFailureHandler(crafttweaker.util.IEventHandler handler) { + addRecipeEventHandler(FactoryRecipeFailureEvent.class, handler::handle); return this; } @ZenMethod - public RecipePrimer addFactoryFinishHandler(IEventHandler handler) { - addRecipeEventHandler(FactoryRecipeFinishEvent.class, handler); + public RecipePrimer addFactoryFinishHandler(crafttweaker.util.IEventHandler handler) { + addRecipeEventHandler(FactoryRecipeFinishEvent.class, handler::handle); return this; } @@ -397,7 +399,7 @@ public RecipePrimer addInput(IIngredient input) { addFluidInput(liquidStack); } else if (Mods.MEKANISM.isPresent() && checkIGasStackAndAdd(IOType.INPUT, input)) { } else { - CraftTweakerAPI.logError(String.format("[ModularMachinery] Invalid input type %s(%s)! Ignored.", input, input.getClass())); + Logger.error(String.format("[ModularMachinery] Invalid input type %s(%s)! Ignored.", input, input.getClass())); } return this; } @@ -420,7 +422,7 @@ public RecipePrimer addOutput(IIngredient output) { addFluidOutput((ILiquidStack) output); } else if (Mods.MEKANISM.isPresent() && checkIGasStackAndAdd(IOType.OUTPUT, output)) { } else { - CraftTweakerAPI.logError(String.format("[ModularMachinery] Invalid output type %s(%s)! Ignored.", output, output.getClass())); + Logger.error(String.format("[ModularMachinery] Invalid output type %s(%s)! Ignored.", output, output.getClass())); } return this; } @@ -616,7 +618,7 @@ public RecipePrimer addItemInput(IIngredient input) { } else if (input instanceof IngredientStack && input.getInternal() instanceof IOreDictEntry) { requireItem(IOType.INPUT, ((IOreDictEntry) input.getInternal()).getName(), input.getAmount()); } else { - CraftTweakerAPI.logError(String.format("[ModularMachinery] Invalid input type %s(%s)! Ignored.", input, input.getClass())); + Logger.error(String.format("[ModularMachinery] Invalid input type %s(%s)! Ignored.", input, input.getClass())); } return this; @@ -626,9 +628,9 @@ public RecipePrimer addItemInput(IIngredient input) { @ZenMethod public RecipePrimer addItemInput(IOreDictEntry oreDict, int amount) { requireItem(IOType.INPUT, oreDict.getName(), amount); - CraftTweakerAPI.logWarning(String.format("[ModularMachinery] Deprecated method " + - "`addItemInput(, %s)`! Consider using `addItemInput( * %s)`", - oreDict.getName(), amount, oreDict.getName(), amount) + Logger.warn(String.format("[ModularMachinery] Deprecated method " + + "`addItemInput(, %s)`! Consider using `addItemInput( * %s)`", + oreDict.getName(), amount, oreDict.getName(), amount) ); return this; } @@ -677,7 +679,7 @@ public RecipePrimer addItemOutput(IIngredient output) { } else if (output instanceof IngredientStack && output.getInternal() instanceof IOreDictEntry) { requireItem(IOType.OUTPUT, ((IOreDictEntry) output.getInternal()).getName(), output.getAmount()); } else { - CraftTweakerAPI.logError(String.format("[ModularMachinery] Invalid output type %s(%s)! Ignored.", output, output.getClass())); + Logger.error(String.format("[ModularMachinery] Invalid output type %s(%s)! Ignored.", output, output.getClass())); } return this; @@ -687,9 +689,9 @@ public RecipePrimer addItemOutput(IIngredient output) { @ZenMethod public RecipePrimer addItemOutput(IOreDictEntry oreDict, int amount) { requireItem(IOType.OUTPUT, oreDict.getName(), amount); - CraftTweakerAPI.logWarning(String.format("[ModularMachinery] Deprecated method " + - "`addItemOutput(, %s)`! Consider using `addItemOutput( * %s)`", - oreDict.getName(), amount, oreDict.getName(), amount) + Logger.warn(String.format("[ModularMachinery] Deprecated method " + + "`addItemOutput(, %s)`! Consider using `addItemOutput( * %s)`", + oreDict.getName(), amount, oreDict.getName(), amount) ); return this; } @@ -715,7 +717,7 @@ public RecipePrimer addCatalystInput(IIngredient input, String[] tooltips, Recip } else if (input instanceof IngredientStack && input.getInternal() instanceof IOreDictEntry) { requireCatalyst(((IOreDictEntry) input.getInternal()).getName(), input.getAmount(), tooltips, modifiers); } else { - CraftTweakerAPI.logError(String.format("[ModularMachinery] Invalid input type %s(%s)! Ignored.", input, input.getClass())); + Logger.error(String.format("[ModularMachinery] Invalid input type %s(%s)! Ignored.", input, input.getClass())); } return this; @@ -737,7 +739,7 @@ private void requireEnergy(IOType ioType, long perTick) { private void requireFluid(IOType ioType, ILiquidStack stack, boolean isPerTick) { FluidStack mcFluid = CraftTweakerMC.getLiquidStack(stack); if (mcFluid == null) { - CraftTweakerAPI.logError("[ModularMachinery] FluidStack not found/unknown fluid: " + stack.toString()); + Logger.error("[ModularMachinery] FluidStack not found/unknown fluid: " + stack.toString()); return; } if (stack.getTag() != null) { @@ -756,19 +758,19 @@ private void requireFluid(IOType ioType, ILiquidStack stack, boolean isPerTick) private void requireGas(IOType ioType, String gasName, int amount) { Gas gas = GasRegistry.getGas(gasName); if (gas == null) { - CraftTweakerAPI.logError("[ModularMachinery] GasStack not found/unknown gas: " + gasName); + Logger.error("[ModularMachinery] GasStack not found/unknown gas: " + gasName); return; } int max = Math.max(0, amount); GasStack gasStack = new GasStack(gas, max); switch (ioType) { - case INPUT -> CraftTweakerAPI.logWarning(String.format( - "[ModularMachinery] `addGasInput(%s, %d)` is deprecated, consider using ` * %d`!", - gasName, amount, gasName, amount + case INPUT -> Logger.warn(String.format( + "[ModularMachinery] `addGasInput(%s, %d)` is deprecated, consider using ` * %d`!", + gasName, amount, gasName, amount )); - case OUTPUT -> CraftTweakerAPI.logWarning(String.format( - "[ModularMachinery] `addGasOutput(%s, %d)` is deprecated, consider using ` * %d`!", - gasName, amount, gasName, amount + case OUTPUT -> Logger.warn(String.format( + "[ModularMachinery] `addGasOutput(%s, %d)` is deprecated, consider using ` * %d`!", + gasName, amount, gasName, amount )); } RequirementGas req = new RequirementGas(ioType, gasStack); @@ -793,7 +795,7 @@ private void requireFuel(int requiredTotalBurnTime) { private void requireItem(IOType ioType, IItemStack stack) { ItemStack mcStack = CraftTweakerMC.getItemStack(stack); if (mcStack.isEmpty()) { - CraftTweakerAPI.logError("[ModularMachinery] ItemStack not found/unknown item: " + stack.toString()); + Logger.error("[ModularMachinery] ItemStack not found/unknown item: " + stack.toString()); return; } RequirementItem ri = new RequirementItem(ioType, mcStack); @@ -824,7 +826,7 @@ private void requireCatalyst(String oreDictName, int amount, String[] tooltips, private void requireCatalyst(IItemStack stack, String[] tooltips, RecipeModifier[] modifiers) { ItemStack mcStack = CraftTweakerMC.getItemStack(stack); if (mcStack.isEmpty()) { - CraftTweakerAPI.logError("[ModularMachinery] ItemStack not found/unknown item: " + stack.toString()); + Logger.error("[ModularMachinery] ItemStack not found/unknown item: " + stack.toString()); return; } RequirementCatalyst catalyst = new RequirementCatalyst(mcStack); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/event/MMEvents.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/event/MMEvents.java index dbf5b450..cdc02bc8 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/event/MMEvents.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/event/MMEvents.java @@ -1,6 +1,5 @@ package hellfirepvp.modularmachinery.common.integration.crafttweaker.event; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ZenRegister; import crafttweaker.util.IEventHandler; import github.kasuminova.mmce.common.event.Phase; @@ -21,6 +20,7 @@ import github.kasuminova.mmce.common.event.recipe.RecipeFinishEvent; import github.kasuminova.mmce.common.event.recipe.RecipeStartEvent; import github.kasuminova.mmce.common.event.recipe.RecipeTickEvent; +import github.kasuminova.mmce.common.integration.Logger; import github.kasuminova.mmce.common.util.concurrent.Action; import hellfirepvp.modularmachinery.ModularMachinery; import hellfirepvp.modularmachinery.common.machine.DynamicMachine; @@ -44,9 +44,9 @@ public static void onStructureFormed(String machineRegistryName, IEventHandler { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineRegistryName)); if (machine != null) { - machine.addMachineEventHandler(MachineStructureFormedEvent.class, function); + machine.addMachineEventHandler(MachineStructureFormedEvent.class, function::handle); } else { - CraftTweakerAPI.logError("Could not find machine `" + machineRegistryName + "`!"); + Logger.error("Could not find machine `" + machineRegistryName + "`!"); } }); } @@ -56,9 +56,9 @@ public static void onStructureUpdate(String machineRegistryName, IEventHandler { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineRegistryName)); if (machine != null) { - machine.addMachineEventHandler(MachineStructureUpdateEvent.class, function); + machine.addMachineEventHandler(MachineStructureUpdateEvent.class, function::handle); } else { - CraftTweakerAPI.logError("Could not find machine `" + machineRegistryName + "`!"); + Logger.error("Could not find machine `" + machineRegistryName + "`!"); } }); } @@ -75,7 +75,7 @@ public static void onMachinePreTick(String machineRegistryName, IEventHandler function) { - CraftTweakerAPI.logWarning("[ModularMachinery] Deprecated method onMachineTick()! Consider using onMachinePostTick()"); + Logger.warn("Deprecated method onMachineTick()! Consider using onMachinePostTick()"); onMachinePostTick(machineRegistryName, function); } @@ -112,9 +112,9 @@ public static void onControllerGUIRender(String machineRegistryName, IEventHandl WAIT_FOR_MODIFY.add(() -> { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineRegistryName)); if (machine != null) { - machine.addMachineEventHandler(ControllerGUIRenderEvent.class, function); + machine.addMachineEventHandler(ControllerGUIRenderEvent.class, function::handle); } else { - CraftTweakerAPI.logError("Could not find machine `" + machineRegistryName + "`!"); + Logger.error("Could not find machine `" + machineRegistryName + "`!"); } }); } @@ -128,9 +128,9 @@ public static void onControllerModelAnimation(String machineRegistryName, IEvent WAIT_FOR_MODIFY.add(() -> { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineRegistryName)); if (machine != null) { - machine.addMachineEventHandler(ControllerModelAnimationEvent.class, function); + machine.addMachineEventHandler(ControllerModelAnimationEvent.class, function::handle); } else { - CraftTweakerAPI.logError("Could not find machine `" + machineRegistryName + "`!"); + Logger.error("Could not find machine `" + machineRegistryName + "`!"); } }); } @@ -144,9 +144,9 @@ public static void onControllerModelGet(String machineRegistryName, IEventHandle WAIT_FOR_MODIFY.add(() -> { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineRegistryName)); if (machine != null) { - machine.addMachineEventHandler(ControllerModelGetEvent.class, function); + machine.addMachineEventHandler(ControllerModelGetEvent.class, function::handle); } else { - CraftTweakerAPI.logError("Could not find machine `" + machineRegistryName + "`!"); + Logger.error("Could not find machine `" + machineRegistryName + "`!"); } }); } @@ -156,9 +156,9 @@ public static void onSmartInterfaceUpdate(String machineRegistryName, IEventHand WAIT_FOR_MODIFY.add(() -> { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineRegistryName)); if (machine != null) { - machine.addMachineEventHandler(SmartInterfaceUpdateEvent.class, function); + machine.addMachineEventHandler(SmartInterfaceUpdateEvent.class, function::handle); } else { - CraftTweakerAPI.logError("Could not find machine `" + machineRegistryName + "`!"); + Logger.error("Could not find machine `" + machineRegistryName + "`!"); } }); } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/modifier/MultiBlockModifierBuilder.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/modifier/MultiBlockModifierBuilder.java index 5318bc80..29ae0ea4 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/modifier/MultiBlockModifierBuilder.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/modifier/MultiBlockModifierBuilder.java @@ -1,9 +1,9 @@ package hellfirepvp.modularmachinery.common.integration.crafttweaker.modifier; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IItemStack; import crafttweaker.api.minecraft.CraftTweakerMC; +import github.kasuminova.mmce.common.integration.Logger; import hellfirepvp.modularmachinery.common.modifier.MultiBlockModifierReplacement; import hellfirepvp.modularmachinery.common.modifier.RecipeModifier; import hellfirepvp.modularmachinery.common.util.BlockArray; @@ -64,7 +64,7 @@ public MultiBlockModifierBuilder setDescriptiveStack(final IItemStack descriptiv @ZenMethod public MultiBlockModifierReplacement build() { if (blockArray == null) { - CraftTweakerAPI.logError("BlockArray cannot be null!"); + Logger.error("BlockArray cannot be null!"); return null; } else { return new MultiBlockModifierReplacement(modifierName, blockArray, modifiers, descriptions, descriptiveStack); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/DynamicMachineUpgradeBuilder.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/DynamicMachineUpgradeBuilder.java index 3d2b5a58..cc6c0834 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/DynamicMachineUpgradeBuilder.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/DynamicMachineUpgradeBuilder.java @@ -1,6 +1,5 @@ package hellfirepvp.modularmachinery.common.integration.crafttweaker.upgrade; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ZenRegister; import github.kasuminova.mmce.common.event.Phase; import github.kasuminova.mmce.common.event.client.ControllerGUIRenderEvent; @@ -18,6 +17,7 @@ import github.kasuminova.mmce.common.event.recipe.RecipeFinishEvent; import github.kasuminova.mmce.common.event.recipe.RecipeStartEvent; import github.kasuminova.mmce.common.event.recipe.RecipeTickEvent; +import github.kasuminova.mmce.common.integration.Logger; import github.kasuminova.mmce.common.upgrade.SimpleDynamicMachineUpgrade; import github.kasuminova.mmce.common.upgrade.UpgradeType; import github.kasuminova.mmce.common.upgrade.registry.RegistryUpgrade; @@ -53,7 +53,7 @@ public DynamicMachineUpgradeBuilder(final SimpleDynamicMachineUpgrade machineUpg @ZenMethod public static DynamicMachineUpgradeBuilder newBuilder(String name, String localizedName, float level, int maxStack) { if (RegistryUpgrade.getUpgrade(name) != null) { - CraftTweakerAPI.logError("[ModularMachinery] Already registered SimpleMachineUpgrade " + name + '!'); + Logger.error("[ModularMachinery] Already registered SimpleMachineUpgrade " + name + '!'); return null; } return new DynamicMachineUpgradeBuilder(new SimpleDynamicMachineUpgrade(new UpgradeType(name, localizedName, level, maxStack))); @@ -92,7 +92,7 @@ public DynamicMachineUpgradeBuilder addCompatibleMachines(String... machineNames for (final String machineName : machineNames) { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineName)); if (machine == null) { - CraftTweakerAPI.logError("Cloud not found machine " + machineName); + Logger.error("Cloud not found machine " + machineName); continue; } machineUpgrade.getType().addCompatibleMachine(machine); @@ -112,7 +112,7 @@ public DynamicMachineUpgradeBuilder addIncompatibleMachines(String... machineNam for (final String machineName : machineNames) { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineName)); if (machine == null) { - CraftTweakerAPI.logError("Cloud not found machine " + machineName); + Logger.error("Cloud not found machine " + machineName); continue; } machineUpgrade.getType().addIncompatibleMachine(machine); @@ -131,7 +131,7 @@ public DynamicMachineUpgradeBuilder addIncompatibleMachines(String... machineNam @Deprecated @ZenMethod public DynamicMachineUpgradeBuilder addRecipeCheckHandler(UpgradeEventHandlerCT handler) { - CraftTweakerAPI.logWarning("[ModularMachinery] Deprecated method addRecipeCheckHandler()! Consider using addPostRecipeCheckHandler()"); + Logger.warn("Deprecated method addRecipeCheckHandler()! Consider using addPostRecipeCheckHandler()"); addEventHandler(RecipeCheckEvent.class, handler); return this; } @@ -187,7 +187,7 @@ public DynamicMachineUpgradeBuilder addRecipePostTickHandler(UpgradeEventHandler @ZenMethod @Deprecated public DynamicMachineUpgradeBuilder addRecipeTickHandler(UpgradeEventHandlerCT handler) { - CraftTweakerAPI.logWarning("[ModularMachinery] Deprecated method addTickHandler()! Consider using addPostTickHandler()"); + Logger.warn("Deprecated method addTickHandler()! Consider using addPostTickHandler()"); return addRecipePostTickHandler(handler); } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/MachineUpgradeBuilder.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/MachineUpgradeBuilder.java index 86eddbab..86e65a6c 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/MachineUpgradeBuilder.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/MachineUpgradeBuilder.java @@ -1,6 +1,6 @@ package hellfirepvp.modularmachinery.common.integration.crafttweaker.upgrade; -import crafttweaker.CraftTweakerAPI; +import com.cleanroommc.groovyscript.api.GroovyBlacklist; import crafttweaker.annotations.ZenRegister; import github.kasuminova.mmce.common.event.Phase; import github.kasuminova.mmce.common.event.client.ControllerGUIRenderEvent; @@ -18,6 +18,7 @@ import github.kasuminova.mmce.common.event.recipe.RecipeFinishEvent; import github.kasuminova.mmce.common.event.recipe.RecipeStartEvent; import github.kasuminova.mmce.common.event.recipe.RecipeTickEvent; +import github.kasuminova.mmce.common.integration.Logger; import github.kasuminova.mmce.common.upgrade.SimpleMachineUpgrade; import github.kasuminova.mmce.common.upgrade.UpgradeType; import github.kasuminova.mmce.common.upgrade.registry.RegistryUpgrade; @@ -36,6 +37,7 @@ @ZenRegister @ZenClass("mods.modularmachinery.MachineUpgradeBuilder") public class MachineUpgradeBuilder { + private final SimpleMachineUpgrade machineUpgrade; public MachineUpgradeBuilder(final SimpleMachineUpgrade machineUpgrade) { @@ -54,7 +56,7 @@ public MachineUpgradeBuilder(final SimpleMachineUpgrade machineUpgrade) { @ZenMethod public static MachineUpgradeBuilder newBuilder(String name, String localizedName, float level, int maxStack) { if (RegistryUpgrade.getUpgrade(name) != null) { - CraftTweakerAPI.logError("[ModularMachinery] Already registered SimpleMachineUpgrade " + name + '!'); + Logger.error("Already registered SimpleMachineUpgrade " + name + '!'); return null; } return new MachineUpgradeBuilder(new SimpleMachineUpgrade(new UpgradeType(name, localizedName, level, maxStack))); @@ -95,7 +97,7 @@ public MachineUpgradeBuilder addCompatibleMachines(String... machineNames) { for (final String machineName : machineNames) { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineName)); if (machine == null) { - CraftTweakerAPI.logError("Cloud not found machine " + machineName); + Logger.error("Cloud not found machine " + machineName); continue; } machineUpgrade.getType().addCompatibleMachine(machine); @@ -115,7 +117,7 @@ public MachineUpgradeBuilder addIncompatibleMachines(String... machineNames) { for (final String machineName : machineNames) { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineName)); if (machine == null) { - CraftTweakerAPI.logError("Cloud not found machine " + machineName); + Logger.error("Cloud not found machine " + machineName); continue; } machineUpgrade.getType().addIncompatibleMachine(machine); @@ -168,7 +170,7 @@ public MachineUpgradeBuilder addModifier(boolean stackAble, String modifierKey, @Deprecated @ZenMethod public MachineUpgradeBuilder addRecipeCheckHandler(UpgradeEventHandlerCT handler) { - CraftTweakerAPI.logWarning("[ModularMachinery] Deprecated method addRecipeCheckHandler()! Consider using addPostRecipeCheckHandler()"); + Logger.warn("Deprecated method addRecipeCheckHandler()! Consider using addPostRecipeCheckHandler()"); addEventHandler(RecipeCheckEvent.class, handler); return this; } @@ -224,7 +226,7 @@ public MachineUpgradeBuilder addRecipePostTickHandler(UpgradeEventHandlerCT hand @ZenMethod @Deprecated public MachineUpgradeBuilder addRecipeTickHandler(UpgradeEventHandlerCT handler) { - CraftTweakerAPI.logWarning("[ModularMachinery] Deprecated method addTickHandler()! Consider using addPostTickHandler()"); + Logger.warn("Deprecated method addTickHandler()! Consider using addPostTickHandler()"); return addRecipePostTickHandler(handler); } @@ -322,6 +324,7 @@ public MachineUpgradeBuilder addSmartInterfaceUpdateHandler(UpgradeEventHandlerC return this; } + @GroovyBlacklist @ZenMethod public void buildAndRegister() { RegistryUpgrade.registerUpgrade(machineUpgrade.getType().getName(), machineUpgrade); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/MachineUpgradeHelper.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/MachineUpgradeHelper.java index 9c75f254..ccb797e0 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/MachineUpgradeHelper.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/MachineUpgradeHelper.java @@ -1,10 +1,10 @@ package hellfirepvp.modularmachinery.common.integration.crafttweaker.upgrade; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ZenRegister; import crafttweaker.api.item.IItemStack; import crafttweaker.api.minecraft.CraftTweakerMC; import github.kasuminova.mmce.common.capability.CapabilityUpgrade; +import github.kasuminova.mmce.common.integration.Logger; import github.kasuminova.mmce.common.upgrade.MachineUpgrade; import github.kasuminova.mmce.common.upgrade.SimpleDynamicMachineUpgrade; import github.kasuminova.mmce.common.upgrade.SimpleMachineUpgrade; @@ -46,7 +46,7 @@ public static void addFixedUpgrade(IItemStack itemStack, String upgradeName) { } MachineUpgrade upgrade = RegistryUpgrade.getUpgrade(upgradeName); if (upgrade == null) { - CraftTweakerAPI.logError("[ModularMachinery] Cloud not find MachineUpgrade " + upgradeName + '!'); + Logger.error("Cloud not find MachineUpgrade " + upgradeName + '!'); return; } RegistryUpgrade.addFixedUpgrade(stack, upgrade); @@ -63,7 +63,7 @@ public static void addFixedUpgrade(IItemStack itemStack, String upgradeName) { public static IItemStack addUpgradeToIItemStack(IItemStack stackCT, String upgradeName) { ItemStack stack = CraftTweakerMC.getItemStack(stackCT); if (!RegistryUpgrade.supportsUpgrade(stack)) { - CraftTweakerAPI.logWarning("[ModularMachinery] " + stackCT.getDefinition().getId() + " does not support upgrade!"); + Logger.warn(stackCT.getDefinition().getId() + " does not support upgrade!"); return stackCT; } CapabilityUpgrade capability = stack.getCapability(CapabilityUpgrade.MACHINE_UPGRADE_CAPABILITY, null); @@ -72,7 +72,7 @@ public static IItemStack addUpgradeToIItemStack(IItemStack stackCT, String upgra } MachineUpgrade upgrade = RegistryUpgrade.getUpgrade(upgradeName); if (upgrade == null) { - CraftTweakerAPI.logWarning("[ModularMachinery] Cloud not found MachineUpgrade " + upgradeName + '!'); + Logger.warn("Cloud not found MachineUpgrade " + upgradeName + '!'); return stackCT; } capability.getUpgrades().add(upgrade); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/machine/AbstractMachine.java b/src/main/java/hellfirepvp/modularmachinery/common/machine/AbstractMachine.java index ecc58caf..a0aa2eb1 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/machine/AbstractMachine.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/machine/AbstractMachine.java @@ -14,7 +14,7 @@ public abstract class AbstractMachine { @Nonnull protected final ResourceLocation registryName; - protected String localizedName = ""; + protected String localizedName = null; protected String prefix = ""; protected int definedColor = Config.machineColor; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/machine/DynamicMachine.java b/src/main/java/hellfirepvp/modularmachinery/common/machine/DynamicMachine.java index 52dcde75..92b8eddc 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/machine/DynamicMachine.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/machine/DynamicMachine.java @@ -15,8 +15,8 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; -import crafttweaker.util.IEventHandler; import github.kasuminova.mmce.common.concurrent.RecipeCraftingContextPool; +import github.kasuminova.mmce.common.event.machine.IEventHandler; import github.kasuminova.mmce.common.event.machine.MachineEvent; import github.kasuminova.mmce.common.util.BlockPos2ValueMap; import github.kasuminova.mmce.common.util.DynamicPattern; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/registry/RegistryBlocks.java b/src/main/java/hellfirepvp/modularmachinery/common/registry/RegistryBlocks.java index 24a99b40..51dd6b27 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/registry/RegistryBlocks.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/registry/RegistryBlocks.java @@ -24,6 +24,7 @@ import github.kasuminova.mmce.common.tile.MEItemOutputBus; import github.kasuminova.mmce.common.tile.MEPatternMirrorImage; import github.kasuminova.mmce.common.tile.MEPatternProvider; +import github.kasuminova.mmce.common.integration.groovyscript.GroovyMachine; import hellfirepvp.modularmachinery.ModularMachinery; import hellfirepvp.modularmachinery.common.CommonProxy; import hellfirepvp.modularmachinery.common.base.Mods; @@ -171,9 +172,16 @@ public class RegistryBlocks { public static void initialize() { registerBlocks(); - if (Mods.RESOURCELOADER.isPresent() || Mods.TX_LOADER.isPresent()) { + if (Mods.GROOVYSCRIPT.isPresent()) { + // groovyscript can load resources too try { - RegistryBlocks.writeAllCustomControllerModels(); + RegistryBlocks.writeAllCustomControllerModels("groovy/assets"); + } catch (IOException e) { + ModularMachinery.log.error("Failed to write controller models", e); + } + } else if (Mods.RESOURCELOADER.isPresent() || Mods.TX_LOADER.isPresent()) { + try { + RegistryBlocks.writeAllCustomControllerModels("resources"); } catch (IOException e) { ModularMachinery.log.error("Failed to write controller models", e); } @@ -404,6 +412,8 @@ private static void registerCustomControllers() { waitForLoadMachines.add(builder.getMachine()); } MachineBuilder.PRE_LOAD_MACHINES.clear(); + waitForLoadMachines.addAll(GroovyMachine.PRE_LOAD_MACHINES.values()); + GroovyMachine.PRE_LOAD_MACHINES.clear(); if (Config.mocCompatibleMode) { for (DynamicMachine machine : waitForLoadMachines) { @@ -505,21 +515,21 @@ private static T prepareRegisterWithCustomName(T block) { return block; } - public static void writeAllCustomControllerModels() throws IOException { + public static void writeAllCustomControllerModels(String basePath) throws IOException { IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager(); for (BlockController controller : BlockController.MACHINE_CONTROLLERS.values()) { - writeMachineControllerModelInternal(resourceManager, controller); + writeMachineControllerModelInternal(basePath, resourceManager, controller); } for (BlockFactoryController controller : BlockFactoryController.FACTORY_CONTROLLERS.values()) { - writeFactoryControllerModelInternal(resourceManager, controller); + writeFactoryControllerModelInternal(basePath, resourceManager, controller); } } - private static void writeMachineControllerModelInternal(IResourceManager resourceManager, BlockController controller) throws IOException { + private static void writeMachineControllerModelInternal(String basePath, IResourceManager resourceManager, BlockController controller) throws IOException { IResource blockStateResource = resourceManager.getResource( new ResourceLocation(ModularMachinery.MODID, "blockstates/block_machine_controller.json")); - File blockStateFile = new File("resources/modularmachinery/blockstates/" + controller.getRegistryName().getPath() + ".json"); + File blockStateFile = new File(basePath, "modularmachinery/blockstates/" + controller.getRegistryName().getPath() + ".json"); if (blockStateFile.exists()) { return; } @@ -530,11 +540,11 @@ private static void writeMachineControllerModelInternal(IResourceManager resourc fileOutputStream.close(); } - private static void writeFactoryControllerModelInternal(IResourceManager resourceManager, BlockFactoryController controller) throws IOException { + private static void writeFactoryControllerModelInternal(String basePath, IResourceManager resourceManager, BlockFactoryController controller) throws IOException { IResource blockStateResource = resourceManager.getResource( new ResourceLocation(ModularMachinery.MODID, "blockstates/block_factory_controller.json")); - File blockStateFile = new File("resources/modularmachinery/blockstates/" + controller.getRegistryName().getPath() + ".json"); + File blockStateFile = new File(basePath, "modularmachinery/blockstates/" + controller.getRegistryName().getPath() + ".json"); if (blockStateFile.exists()) { return; } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java b/src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java index ba71b2fb..5c83cd23 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java @@ -898,12 +898,21 @@ public void checkAndAddSmartInterface(MachineComponent component, BlockPos re } } + @net.minecraftforge.fml.common.Optional.Method(modid = "crafttweaker") + @Override public IWorld getIWorld() { return CraftTweakerMC.getIWorld(getWorld()); } + @Override + public IBlockState getBlockState() { + return getWorld().getBlockState(getPos()); + } + + @net.minecraftforge.fml.common.Optional.Method(modid = "crafttweaker") + @Override public crafttweaker.api.block.IBlockState getIBlockState() { - return CraftTweakerMC.getBlockState(getWorld().getBlockState(getPos())); + return CraftTweakerMC.getBlockState(getBlockState()); } @Override @@ -911,29 +920,56 @@ public IFacing getFacing() { return CraftTweakerMC.getIFacing(controllerRotation); } + @Override + public EnumFacing getEnumFacing() { + return controllerRotation; + } + + @net.minecraftforge.fml.common.Optional.Method(modid = "crafttweaker") + @Override public IBlockPos getIPos() { return CraftTweakerMC.getIBlockPos(getPos()); } + @net.minecraftforge.fml.common.Optional.Method(modid = "crafttweaker") @Override public IBlockPos rotateWithControllerFacing(final IBlockPos posCT) { BlockPos pos = CraftTweakerMC.getBlockPos(posCT); - return CraftTweakerMC.getIBlockPos(MiscUtils.rotateYCCWNorthUntil(pos, controllerRotation == null ? EnumFacing.NORTH : controllerRotation)); + return CraftTweakerMC.getIBlockPos(rotateWithControllerFacing(pos)); + } + + public BlockPos rotateWithControllerFacing(final BlockPos pos) { + return MiscUtils.rotateYCCWNorthUntil(pos, controllerRotation == null ? EnumFacing.NORTH : controllerRotation); } public String getFormedMachineName() { return isStructureFormed() ? foundMachine.getRegistryName().toString() : null; } + @net.minecraftforge.fml.common.Optional.Method(modid = "crafttweaker") + @Override public IData getCustomData() { return CraftTweakerMC.getIDataModifyable(customData); } + @net.minecraftforge.fml.common.Optional.Method(modid = "crafttweaker") + @Override public void setCustomData(IData data) { customData = CraftTweakerMC.getNBTCompound(data); markNoUpdateSync(); } + @Override + public NBTTagCompound getCustomNbt() { + return customData; + } + + @Override + public void setCustomNbt(NBTTagCompound nbt) { + this.customData = nbt; + markNoUpdateSync(); + } + public NBTTagCompound getCustomDataTag() { return customData; } @@ -942,6 +978,7 @@ public void setCustomDataTag(NBTTagCompound customData) { this.customData = customData; } + @Override public boolean hasModifier(String key) { return customModifiers.containsKey(key); } @@ -1135,6 +1172,7 @@ public IDynamicPatternInfo getDynamicPattern(final String patternName) { return foundDynamicPatterns.get(patternName); } + @net.minecraftforge.fml.common.Optional.Method(modid = "crafttweaker") @Override public int getBlocksInPattern(final IItemStack blockStack) { if (foundPattern == null || blockStack == null) { @@ -1148,6 +1186,21 @@ public int getBlocksInPattern(final IItemStack blockStack) { } } + @Override + public int getBlocksInPattern(ItemStack blockStack) { + if (foundPattern == null || blockStack == null || blockStack.isEmpty()) { + return 0; + } + Block block = Block.getBlockFromItem(blockStack.getItem()); + if (blockStack.getMetadata() == OreDictionary.WILDCARD_VALUE) { + return getBlocksInPattern((Predicate) state -> state.getBlock() == block); + } else { + IBlockState blockState = block.getStateFromMeta(blockStack.getMetadata()); + return getBlocksInPattern((Predicate) state -> state.equals(blockState)); + } + } + + @net.minecraftforge.fml.common.Optional.Method(modid = "crafttweaker") @Override public int getBlocksInPattern(final IBlockStateMatcher blockStateMatcher) { if (foundPattern == null) { @@ -1165,6 +1218,7 @@ public int getBlocksInPattern(final String blockName) { return getBlocksInPatternInternal(applicable::contains); } + @net.minecraftforge.fml.common.Optional.Method(modid = "crafttweaker") @Override public int getBlocksInPattern(final IBlockStatePredicate predicate) { if (foundPattern == null) { @@ -1173,6 +1227,11 @@ public int getBlocksInPattern(final IBlockStatePredicate predicate) { return getBlocksInPatternInternal(state -> predicate.test(CraftTweakerMC.getBlockState(state))); } + @Override + public int getBlocksInPattern(Predicate predicate) { + return getBlocksInPatternInternal(predicate); + } + public int getBlocksInPatternInternal(final Predicate predicate) { if (foundPattern == null) { return 0; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/util/SmartInterfaceData.java b/src/main/java/hellfirepvp/modularmachinery/common/util/SmartInterfaceData.java index 227ea718..97e418d5 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/util/SmartInterfaceData.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/util/SmartInterfaceData.java @@ -6,6 +6,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.fml.common.Optional; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenGetter; import stanhebben.zenscript.annotations.ZenSetter; @@ -46,6 +47,7 @@ public BlockPos getPos() { /** * 返回此数据对应控制器所在的位置。 */ + @Optional.Method(modid = "crafttweaker") @ZenGetter("pos") public IBlockPos getIPos() { return CraftTweakerMC.getIBlockPos(pos);