Skip to content

Commit

Permalink
Merge pull request #5 from Iteranya/1.20.1
Browse files Browse the repository at this point in the history
Added a little confirmation that it failed to run the thing that it t…
  • Loading branch information
Iteranya authored Nov 3, 2024
2 parents e94bb55 + 6f843e0 commit fdcb4ab
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 35 deletions.
55 changes: 55 additions & 0 deletions src/main/java/org/arsparadox/mobtalkerredux/DemoCommand.java
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;
}))
);
}
}
48 changes: 13 additions & 35 deletions src/main/java/org/arsparadox/mobtalkerredux/MobTalkerRedux.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.arsparadox.mobtalkerredux;

import com.google.gson.JsonObject;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.server.ServerStartingEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
Expand All @@ -17,20 +15,15 @@
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.stream.Collectors;

// The value here should match an entry in the META-INF/mods.toml file
@Mod("mobtalkerredux")
public class MobTalkerRedux {

// Directly reference a slf4j logger
public static final Logger LOGGER = LogManager.getLogger();
public static final String MODID = "mobtalkerredux";
private static JsonObject dialogData;

public MobTalkerRedux() {
// Register the setup method for modloading
Expand All @@ -44,48 +37,41 @@ public MobTalkerRedux() {

// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);
// Register for command registration
MinecraftForge.EVENT_BUS.register(RegistryEvents.class);
}

private void setup(final FMLCommonSetupEvent event) {
// Some preinit code
LOGGER.info("HELLO FROM PREINIT");

}

private void enqueueIMC(final InterModEnqueueEvent event) {
// Some example code to dispatch IMC to another mod
InterModComms.sendTo(MobTalkerRedux.MODID, "helloworld", () -> {
InterModComms.sendTo(MODID, "helloworld", () -> {
LOGGER.info("Hello world from the MDK");
return "Hello world";
});
}

private void processIMC(final InterModProcessEvent event) {
// Some example code to receive and process InterModComms from other mods
LOGGER.info("Got IMC {}", event.getIMCStream().
map(m->m.messageSupplier().get()).
collect(Collectors.toList()));
}

// You can use SubscribeEvent and let the Event Bus discover methods to call
@SubscribeEvent
public void onServerStarting(ServerStartingEvent event) {
// Do something when the server starts
LOGGER.info("HELLO from server starting");
}

// You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
// Event bus for receiving Registry Events)
@Mod.EventBusSubscriber(modid = "mobtalkerredux", bus = Mod.EventBusSubscriber.Bus.MOD)
public class RegistryEvents {



public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, "mobtalkerredux");
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, "mobtalkerredux");
public static class RegistryEvents {
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);

// Example of a registered block and item
public static final RegistryObject<Item> HELLO_WORLD_ITEM = ITEMS.register("hello_world_item",HelloWorldItem::new);
// Move command registration to Forge event bus
@SubscribeEvent
public static void onRegisterCommands(RegisterCommandsEvent event) {
DemoCommand.register(event.getDispatcher());
}

public static void register(IEventBus eventBus) {
BLOCKS.register(eventBus);
Expand All @@ -96,13 +82,5 @@ public static void initialize() {
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
register(modEventBus);
}

@SubscribeEvent
public void buildContents(BuildCreativeModeTabContentsEvent event) {
// Add to ingredients tab
if (event.getTabKey() == CreativeModeTabs.INGREDIENTS) {
event.accept(HELLO_WORLD_ITEM);
}
}
}
}
}

0 comments on commit fdcb4ab

Please sign in to comment.