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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ dependencies {

implementation 'curse.maven:jei-238222:3040523'

compileOnly rfg.deobf('curse.maven:packmode-278398:2567799')
if (project.debug_packmode.toBoolean()) {
runtimeOnly rfg.deobf('curse.maven:packmode-278398:2567799')
}

compileOnly rfg.deobf('curse.maven:codechicken_lib_1_8-242818:2779848')
if (project.debug_avaritia.toBoolean() || project.debug_draconic_evolution.toBoolean()) {
runtimeOnly rfg.deobf('curse.maven:codechicken_lib_1_8-242818:2779848')
Expand Down
8 changes: 8 additions & 0 deletions examples/postInit/hard_mode.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// PACKMODE: hard

crafting.shapedBuilder()
.output(item('placeholdername:clay_2'))
.shape([[null, item('minecraft:diamond'), null],
[item('minecraft:diamond'), null, item('minecraft:diamond')],
[null, item('minecraft:diamond'), null]])
.register()
10 changes: 10 additions & 0 deletions examples/postInit/normal_mode.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

// PACKMODE: normal

crafting.removeByOutput(item('minecraft:furnace'))
crafting.shapedBuilder()
.output(item('placeholdername:clay_2'))
.shape([[null, item('minecraft:iron_ingot'), null],
[item('minecraft:iron_ingot'), null, item('minecraft:iron_ingot')],
[null, item('minecraft:iron_ingot'), null]])
.register()
2 changes: 1 addition & 1 deletion examples/postInit/vanilla.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ crafting.shapedBuilder()
crafting.remove('minecraft:mossy_stonebrick') // Remove the entry with the recipe ID
crafting.remove(resource('minecraft:stonebrick'))
crafting.removeByOutput(item('minecraft:gold_ingot')) // Remove all recipes with the output
crafting.removeByInput(item('minecraft:iron_ingot')) // Remove all recipes containing the ingredient as an input
//crafting.removeByInput(item('minecraft:iron_ingot')) // Remove all recipes containing the ingredient as an input
//crafting.removeAll()


Expand Down
11 changes: 9 additions & 2 deletions examples/runConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@
"preInit": [
"preInit/"
],
"init": [
],
"init": [],
"postInit": [
"postInit/"
]
},
"packmode": {
"values": [
"normal",
"hard"
],
"default": "normal",
"integratePackmodeMod": false
}
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ debug_industrial_craft_2_classic = false
debug_industrial_craft_2_experimental = false
debug_inspirations = false
debug_mekanism = false
debug_packmode = false
debug_roots = false
debug_thaum = false
debug_thermal = false
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/cleanroommc/groovyscript/DisabledConfigGui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.cleanroommc.groovyscript;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.fml.client.IModGuiFactory;

import java.util.Set;

public class DisabledConfigGui implements IModGuiFactory {

@Override
public void initialize(Minecraft minecraftInstance) {
}

@Override
public boolean hasConfigGui() {
return false;
}

@Override
public GuiScreen createConfigGui(GuiScreen parentScreen) {
return null;
}

@Override
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
return null;
}
}
44 changes: 28 additions & 16 deletions src/main/java/com/cleanroommc/groovyscript/GroovyScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.cleanroommc.groovyscript.command.CustomClickAction;
import com.cleanroommc.groovyscript.command.GSCommand;
import com.cleanroommc.groovyscript.compat.content.GroovyResourcePack;
import com.cleanroommc.groovyscript.compat.loot.Loot;
import com.cleanroommc.groovyscript.compat.mods.ModSupport;
import com.cleanroommc.groovyscript.compat.mods.tinkersconstruct.TinkersConstruct;
import com.cleanroommc.groovyscript.compat.vanilla.VanillaModule;
Expand All @@ -29,7 +28,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.command.ICommandSender;
import net.minecraft.item.Item;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentString;
Expand Down Expand Up @@ -70,7 +69,8 @@
@Mod(modid = GroovyScript.ID,
name = GroovyScript.NAME,
version = GroovyScript.VERSION,
dependencies = "after:universaltweaks@[1.8.0,);")
dependencies = "after:universaltweaks@[1.8.0,);",
guiFactory = "com.cleanroommc.groovyscript.DisabledConfigGui")
@Mod.EventBusSubscriber(modid = GroovyScript.ID)
public class GroovyScript {

Expand Down Expand Up @@ -119,6 +119,7 @@ public void onConstruction(FMLConstructionEvent event) {
}

FluidRegistry.enableUniversalBucket();
getRunConfig().initPackmode();
}

@Mod.EventHandler
Expand All @@ -141,7 +142,7 @@ public static void initializeRunConfig(File minecraftHome) {
}
runConfigFile = new File(scriptPath, "runConfig.json");
resourcesFile = new File(scriptPath, "assets");
reloadRunConfig();
reloadRunConfig(true);
}

@ApiStatus.Internal
Expand All @@ -164,11 +165,13 @@ public static void initializeGroovyPreInit() {
}

@ApiStatus.Internal
public static void runGroovyScriptsInLoader(LoadStage loadStage) {
public static long runGroovyScriptsInLoader(LoadStage loadStage) {
// called via mixin between fml post init and load complete
long time = System.currentTimeMillis();
getSandbox().run(loadStage);
LOGGER.info("Running Groovy scripts during {} took {} ms", loadStage.getName(), System.currentTimeMillis() - time);
time = System.currentTimeMillis() - time;
LOGGER.info("Running Groovy scripts during {} took {} ms", loadStage.getName(), time);
return time;
}

@Mod.EventHandler
Expand Down Expand Up @@ -216,6 +219,14 @@ public static File getResourcesFile() {
return resourcesFile;
}

@NotNull
public static File getRunConfigFile() {
if (runConfigFile == null) {
throw new IllegalStateException("GroovyScript is not yet loaded!");
}
return runConfigFile;
}

@NotNull
public static GroovyScriptSandbox getSandbox() {
if (sandbox == null) {
Expand All @@ -233,7 +244,7 @@ public static RunConfig getRunConfig() {
}

@ApiStatus.Internal
public static void reloadRunConfig() {
public static void reloadRunConfig(boolean init) {
JsonElement element = JsonHelper.loadJson(runConfigFile);
if (element == null || !element.isJsonObject()) element = new JsonObject();
JsonObject json = element.getAsJsonObject();
Expand All @@ -245,7 +256,7 @@ public static void reloadRunConfig() {
runConfig = new RunConfig(json);
}
}
runConfig.reload(json);
runConfig.reload(json, init);
}

private static RunConfig createRunConfig(JsonObject json) {
Expand All @@ -270,28 +281,29 @@ public static File makeFile(File parent, String... pieces) {
return new File(parent, fileJoiner.join(pieces));
}

public static void postScriptRunResult(EntityPlayerMP player, boolean startup, boolean running) {
public static void postScriptRunResult(ICommandSender sender, boolean onlyLogFails, boolean running, boolean packmode, long time) {
List<String> errors = GroovyLogImpl.LOG.collectErrors();
if (errors.isEmpty()) {
if (!startup) {
if (!onlyLogFails) {
if (running) {
player.sendMessage(new TextComponentString(TextFormatting.GREEN + "Successfully ran scripts"));
String s = packmode ? "changes packmode" : "reloaded scripts";
sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "Successfully " + s + TextFormatting.WHITE + " in " + time + "ms"));
} else {
player.sendMessage(new TextComponentString(TextFormatting.GREEN + "No syntax errors found :)"));
sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "No syntax errors found :)"));
}
}
} else {
String executing = running ? "running" : "checking";
player.sendMessage(new TextComponentString(TextFormatting.RED + "Found " + errors.size() + " errors while " + executing + " scripts"));
sender.sendMessage(new TextComponentString(TextFormatting.RED + "Found " + errors.size() + " errors while " + executing + " scripts"));
int n = errors.size();
if (errors.size() >= 10) {
player.sendMessage(new TextComponentString("Displaying the first 7 errors:"));
sender.sendMessage(new TextComponentString("Displaying the first 7 errors:"));
n = 7;
}
for (int i = 0; i < n; i++) {
player.sendMessage(new TextComponentString(TextFormatting.RED + errors.get(i)));
sender.sendMessage(new TextComponentString(TextFormatting.RED + errors.get(i)));
}
player.server.commandManager.executeCommand(player, "/gs log");
GSCommand.postLogFiles(sender);
}
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/cleanroommc/groovyscript/GroovyScriptConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.cleanroommc.groovyscript;

import net.minecraftforge.common.config.Config;
import org.jetbrains.annotations.ApiStatus;

@Config(modid = GroovyScript.ID)
public class GroovyScriptConfig {

@ApiStatus.Internal
@Config.Comment("The current set packmode")
public static String packmode = "";
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.cleanroommc.groovyscript.api;

import net.minecraft.util.ResourceLocation;
import org.jetbrains.annotations.ApiStatus;

/**
* Access interface for reloadable forge registries
Expand All @@ -12,4 +13,10 @@ public interface IReloadableForgeRegistry<V> {
void removeEntry(ResourceLocation name);

void onReload();

@ApiStatus.Internal
void groovyscript$putDummy(V dummy, V realEntry, ResourceLocation name, int id, Object owner);

@ApiStatus.Internal
void groovyscript$forceAdd(V entry, int id, Object owner);
}
35 changes: 17 additions & 18 deletions src/main/java/com/cleanroommc/groovyscript/command/GSCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.cleanroommc.groovyscript.compat.mods.jei.JeiPlugin;
import com.cleanroommc.groovyscript.event.GsHandEvent;
import com.cleanroommc.groovyscript.network.NetworkHandler;
import com.cleanroommc.groovyscript.network.SReloadJei;
import com.cleanroommc.groovyscript.network.SReloadScripts;
import com.cleanroommc.groovyscript.sandbox.LoadStage;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
Expand Down Expand Up @@ -39,7 +39,7 @@
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import java.nio.file.Path;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -54,21 +54,13 @@ public static void runReload(EntityPlayerMP player, MinecraftServer server) {
return;
}
GroovyLog.get().info("========== Reloading Groovy scripts ==========");
long time = System.currentTimeMillis();
GroovyScript.getSandbox().run(LoadStage.POST_INIT);
time = System.currentTimeMillis() - time;
player.sendMessage(new TextComponentString("Reloading Groovy took " + time + "ms"));
GroovyScript.postScriptRunResult(player, false, true);

NetworkHandler.sendToPlayer(new SReloadJei(), player);
long time = GroovyScript.runGroovyScriptsInLoader(LoadStage.POST_INIT);
GroovyScript.postScriptRunResult(player, false, true, false, time);
NetworkHandler.sendToPlayer(new SReloadScripts(null, false, true), player);
}

public GSCommand() {

addSubcommand(new SimpleCommand("log", (server, sender, args) -> {
sender.sendMessage(getTextForFile("Groovy Log", GroovyLog.get().getLogFilerPath(), new TextComponentString("Click to open GroovyScript log")));
sender.sendMessage(getTextForFile("Minecraft Log", GroovyLog.get().getLogFilerPath().getParent(), new TextComponentString("Click to open Minecraft log")));
}));
addSubcommand(new SimpleCommand("log", (server, sender, args) -> postLogFiles(sender)));

addSubcommand(new SimpleCommand("reload", (server, sender, args) -> {
if (sender instanceof EntityPlayerMP) {
Expand All @@ -83,10 +75,12 @@ public GSCommand() {
GroovyScript.getSandbox().checkSyntax();
time = System.currentTimeMillis() - time;
sender.sendMessage(new TextComponentString("Checking syntax took " + time + "ms"));
GroovyScript.postScriptRunResult((EntityPlayerMP) sender, false, false);
GroovyScript.postScriptRunResult((EntityPlayerMP) sender, false, false, false, time);
}
}));

addSubcommand(new PackmodeCommand());

addSubcommand(new SimpleCommand("hand", (server, sender, args) -> {
if (sender instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) sender;
Expand Down Expand Up @@ -169,7 +163,7 @@ public GSCommand() {
GroovyLog.get().getWriter().println(" - " + tab.getTabLabel());
}
sender.sendMessage(new TextComponentString("Creative tabs has been logged to the ")
.appendSibling(GSCommand.getTextForFile("Groovy Log", GroovyLog.get().getLogFilerPath(), new TextComponentString("Click to open GroovyScript log"))));
.appendSibling(GSCommand.getTextForFile("Groovy Log", GroovyLog.get().getLogFilerPath().toString(), new TextComponentString("Click to open GroovyScript log"))));
}));

if (ModSupport.MEKANISM.isLoaded()) {
Expand Down Expand Up @@ -198,10 +192,15 @@ public String getUsage(@NotNull ICommandSender sender) {
return "/gs []";
}

public static ITextComponent getTextForFile(String name, Path path, ITextComponent hoverText) {
public static void postLogFiles(ICommandSender sender) {
sender.sendMessage(getTextForFile("Groovy Log", GroovyLog.get().getLogFilerPath().toString(), new TextComponentString("Click to open GroovyScript log")));
sender.sendMessage(getTextForFile("Minecraft Log", GroovyLog.get().getLogFilerPath().getParent().toString() + File.separator + "latest.log", new TextComponentString("Click to open Minecraft log")));
}

public static ITextComponent getTextForFile(String name, String path, ITextComponent hoverText) {
return new TextComponentString(TextFormatting.UNDERLINE + (TextFormatting.GOLD + name))
.setStyle(new Style()
.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, path.toString()))
.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, path))
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.cleanroommc.groovyscript.command;

import com.cleanroommc.groovyscript.GroovyScript;
import com.cleanroommc.groovyscript.network.NetworkHandler;
import com.cleanroommc.groovyscript.network.SReloadScripts;
import com.cleanroommc.groovyscript.packmode.Packmode;
import com.cleanroommc.groovyscript.packmode.PackmodeSaveData;
import io.sommers.packmode.PackModeCommand;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.text.TextComponentString;
import org.jetbrains.annotations.NotNull;

public class PackmodeCommand extends CommandBase {

@Override
public @NotNull String getName() {
return "packmode";
}

@Override
public @NotNull String getUsage(@NotNull ICommandSender sender) {
return "packmode [mode]";
}

@Override
public void execute(@NotNull MinecraftServer server, @NotNull ICommandSender sender, String @NotNull [] args) throws CommandException {
if (GroovyScript.getRunConfig().isIntegratePackmodeMod()) {
new PackModeCommand().execute(server, sender, args);
return;
}
if (server.isDedicatedServer()) throw new CommandException("Can't change packmodes on the fly on dedicated servers!");
if (!Packmode.needsPackmode()) throw new CommandException("Packmodes are not configured!");
if (args.length == 0) {
sender.sendMessage(new TextComponentString("Current packmode is " + Packmode.getPackmode()));
}
String packmode = args[0];
if (!Packmode.isValidPackmode(packmode)) throw new CommandException("Invalid packmode: " + packmode);
SReloadScripts.updatePackmode(sender, packmode);
PackmodeSaveData saveData = PackmodeSaveData.get(server);
saveData.setPackmode(Packmode.getPackmode());
NetworkHandler.sendToPlayer(new SReloadScripts(null, true, true), (EntityPlayerMP) sender);
}
}
Loading