-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebb65cd
commit f939840
Showing
12 changed files
with
353 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/main/java/com/nomiceu/nomilabs/command/LabsReloadCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.nomiceu.nomilabs.command; | ||
|
||
import java.util.List; | ||
|
||
import net.minecraft.command.ICommandSender; | ||
import net.minecraft.entity.player.EntityPlayerMP; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.util.text.TextComponentString; | ||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage; | ||
import net.minecraftforge.server.command.CommandTreeBase; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.cleanroommc.groovyscript.GroovyScript; | ||
import com.cleanroommc.groovyscript.api.GroovyLog; | ||
import com.cleanroommc.groovyscript.sandbox.LoadStage; | ||
import com.google.common.collect.ImmutableList; | ||
import com.nomiceu.nomilabs.network.LabsFastReloadMessage; | ||
import com.nomiceu.nomilabs.network.LabsLangReloadMessage; | ||
import com.nomiceu.nomilabs.network.LabsNetworkHandler; | ||
import com.nomiceu.nomilabs.network.LabsNoJeiReloadMessage; | ||
|
||
/** | ||
* Provides three variations to the GroovyScript reload command: | ||
* <ul> | ||
* <li>Lang: which reloads language files as well as GrS and JEI, useful for tooltip changes.</li> | ||
* <li>Fast: which reloads JEI faster by reusing the existing Ingredient Filter. Can reduce JEI reload times by | ||
* around 60-80%, and works for recipe modifications, but does not update added/removed items via GrS.</li> | ||
* <li>No JEI: which doesn't reload JEI. Does not update recipe modifications' view in JEI, but can be useful | ||
* in specific situations.</li> | ||
* </ul> | ||
*/ | ||
public class LabsReloadCommand extends CommandTreeBase { | ||
|
||
public LabsReloadCommand() { | ||
addSubcommand(new SimpleCommand("lang", | ||
(server, sender, args) -> runReload(sender, server, new LabsLangReloadMessage()))); | ||
|
||
addSubcommand(new SimpleCommand("fast", | ||
(server, sender, args) -> runReload(sender, server, new LabsFastReloadMessage()))); | ||
|
||
addSubcommand(new SimpleCommand("noJei", | ||
(server, sender, args) -> runReload(sender, server, new LabsNoJeiReloadMessage()))); | ||
} | ||
|
||
/** | ||
* Mostly from {@link com.cleanroommc.groovyscript.command.GSCommand#runReload(EntityPlayerMP, MinecraftServer)}, | ||
* but allows for custom packets for client handling. | ||
*/ | ||
public static void runReload(ICommandSender sender, MinecraftServer server, IMessage reloadMsg) { | ||
if (!(sender instanceof EntityPlayerMP player)) return; | ||
|
||
if (server.isDedicatedServer()) { | ||
player.sendMessage( | ||
new TextComponentString("Reloading in multiplayer is currently not allowed to avoid desync.")); | ||
return; | ||
} | ||
|
||
GroovyLog.get().info("========== Reloading Groovy scripts =========="); | ||
|
||
// noinspection UnstableApiUsage | ||
long time = GroovyScript.runGroovyScriptsInLoader(LoadStage.POST_INIT); | ||
GroovyScript.postScriptRunResult(player, false, true, false, time); | ||
LabsNetworkHandler.NETWORK_HANDLER.sendTo(reloadMsg, player); | ||
} | ||
|
||
@Override | ||
@NotNull | ||
public String getName() { | ||
return "labsGsReload"; | ||
} | ||
|
||
@Override | ||
@NotNull | ||
public List<String> getAliases() { | ||
return ImmutableList.of("lr", "labsReload"); | ||
} | ||
|
||
@Override | ||
@NotNull | ||
public String getUsage(@NotNull ICommandSender sender) { | ||
return "/lr <lang/fast/noJei>"; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/com/nomiceu/nomilabs/command/SimpleCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.nomiceu.nomilabs.command; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import net.minecraft.command.CommandBase; | ||
import net.minecraft.command.CommandException; | ||
import net.minecraft.command.ICommandSender; | ||
import net.minecraft.server.MinecraftServer; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class SimpleCommand extends CommandBase { | ||
|
||
private final String name; | ||
private final String usage; | ||
private final ICommand command; | ||
private final List<String> aliases = new ArrayList<>(); | ||
|
||
public SimpleCommand(String name, String usage, ICommand command, String... aliases) { | ||
this.name = name; | ||
this.usage = usage; | ||
this.command = command; | ||
Collections.addAll(this.aliases, aliases); | ||
} | ||
|
||
public SimpleCommand(String name, ICommand command, String... aliases) { | ||
this(name, "/lr " + name, command, aliases); | ||
} | ||
|
||
@Override | ||
public @NotNull String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public @NotNull String getUsage(@NotNull ICommandSender sender) { | ||
return usage; | ||
} | ||
|
||
@Override | ||
public void execute(@NotNull MinecraftServer server, @NotNull ICommandSender sender, | ||
String @NotNull [] args) throws CommandException { | ||
command.execute(server, sender, args); | ||
} | ||
|
||
@Override | ||
public @NotNull List<String> getAliases() { | ||
return aliases; | ||
} | ||
|
||
@FunctionalInterface | ||
public interface ICommand { | ||
|
||
void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/nomiceu/nomilabs/integration/jei/SavedJEIValues.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.nomiceu.nomilabs.integration.jei; | ||
|
||
import mezz.jei.ingredients.IngredientFilter; | ||
|
||
public class SavedJEIValues { | ||
|
||
public static IngredientFilter savedFilter; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/nomiceu/nomilabs/network/LabsFastReloadMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.nomiceu.nomilabs.network; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage; | ||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; | ||
|
||
import com.cleanroommc.groovyscript.GroovyScript; | ||
import com.cleanroommc.groovyscript.registry.ReloadableRegistryManager; | ||
import com.nomiceu.nomilabs.integration.jei.SavedJEIValues; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import mezz.jei.Internal; | ||
|
||
public class LabsFastReloadMessage implements IMessage { | ||
|
||
public LabsFastReloadMessage() {} | ||
|
||
@Override | ||
public void fromBytes(ByteBuf buf) {} | ||
|
||
@Override | ||
public void toBytes(ByteBuf buf) {} | ||
|
||
public static class MessageHandler extends MainThreadMessageHandler<LabsFastReloadMessage, IMessage> { | ||
|
||
@Override | ||
protected IMessage executeClient(LabsFastReloadMessage message, MessageContext ctx) { | ||
// Save existing JEI values | ||
SavedJEIValues.savedFilter = Internal.getIngredientFilter(); | ||
|
||
// noinspection UnstableApiUsage | ||
ReloadableRegistryManager.reloadJei(true); | ||
|
||
SavedJEIValues.savedFilter = null; | ||
|
||
GroovyScript.postScriptRunResult(Minecraft.getMinecraft().player, true, true, true, 0); | ||
return null; | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/nomiceu/nomilabs/network/LabsLangReloadMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.nomiceu.nomilabs.network; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.util.text.TextComponentString; | ||
import net.minecraftforge.client.resource.VanillaResourceType; | ||
import net.minecraftforge.fml.client.FMLClientHandler; | ||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage; | ||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; | ||
|
||
import com.cleanroommc.groovyscript.GroovyScript; | ||
import com.cleanroommc.groovyscript.registry.ReloadableRegistryManager; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
|
||
public class LabsLangReloadMessage implements IMessage { | ||
|
||
public LabsLangReloadMessage() {} | ||
|
||
@Override | ||
public void fromBytes(ByteBuf buf) {} | ||
|
||
@Override | ||
public void toBytes(ByteBuf buf) {} | ||
|
||
public static class MessageHandler extends MainThreadMessageHandler<LabsLangReloadMessage, IMessage> { | ||
|
||
@Override | ||
protected IMessage executeClient(LabsLangReloadMessage message, MessageContext ctx) { | ||
// Reload Textures, but ONLY Lang | ||
long time = System.currentTimeMillis(); | ||
FMLClientHandler.instance().refreshResources(VanillaResourceType.LANGUAGES); | ||
time = System.currentTimeMillis() - time; | ||
Minecraft.getMinecraft().player.sendMessage( | ||
new TextComponentString("Reloading Language Resources took " + time + "ms")); | ||
|
||
// noinspection UnstableApiUsage | ||
ReloadableRegistryManager.reloadJei(true); | ||
|
||
GroovyScript.postScriptRunResult(Minecraft.getMinecraft().player, true, true, true, 0); | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.