-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Iteranya/1.20.1
Added a little confirmation that it failed to run the thing that it t…
- Loading branch information
Showing
2 changed files
with
68 additions
and
35 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/main/java/org/arsparadox/mobtalkerredux/DemoCommand.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,55 @@ | ||
package org.arsparadox.mobtalkerredux; | ||
|
||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.arguments.StringArgumentType; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.commands.CommandSourceStack; | ||
import net.minecraft.commands.Commands; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import org.arsparadox.mobtalkerredux.vn.controller.VisualNovelEngine; | ||
import org.arsparadox.mobtalkerredux.vn.model.ScriptLoader; | ||
import org.arsparadox.mobtalkerredux.vn.view.DialogueScreen; | ||
|
||
import java.io.IOException; | ||
|
||
public class DemoCommand { | ||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) { | ||
dispatcher.register(Commands.literal("mob_talker") | ||
// Basic command: /demo | ||
.executes(context -> { | ||
if (context.getSource().getEntity() instanceof ServerPlayer player) { | ||
Minecraft.getInstance().execute(() -> { | ||
try { | ||
Minecraft.getInstance().setScreen(new DialogueScreen(new VisualNovelEngine(ScriptLoader.loadDemo()))); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
); | ||
} | ||
return 1; | ||
}) | ||
// Command with argument: /demo <name> | ||
.then(Commands.argument("scriptFile", StringArgumentType.word()) | ||
.executes(context -> { | ||
String name = StringArgumentType.getString(context, "scriptFile"); | ||
if (context.getSource().getEntity() instanceof ServerPlayer player) { | ||
Minecraft.getInstance().execute(() -> { | ||
try { | ||
player.sendSystemMessage(Component.literal("Trying to load the file config/mobtalkerredux/"+name)); | ||
Minecraft.getInstance().setScreen(new DialogueScreen(new VisualNovelEngine(ScriptLoader.loadScript(name)))); | ||
|
||
} catch (IOException e) { | ||
player.sendSystemMessage(Component.literal("Failed to find the file config/mobtalkerredux/"+name)); | ||
throw new RuntimeException(e); | ||
|
||
} | ||
} | ||
); | ||
} | ||
return 1; | ||
})) | ||
); | ||
} | ||
} |
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