Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There's a lot, actually #8

Merged
merged 7 commits into from
Nov 13, 2024
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
6 changes: 4 additions & 2 deletions src/main/java/org/arsparadox/mobtalkerredux/DemoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import org.arsparadox.mobtalkerredux.vn.controller.vnmodules.PlayerInventoryHandler;
import org.arsparadox.mobtalkerredux.vn.controller.VisualNovelEngine;
import org.arsparadox.mobtalkerredux.vn.model.ScriptLoader;
import org.arsparadox.mobtalkerredux.vn.view.DialogueScreen;
Expand Down Expand Up @@ -36,10 +37,10 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {

private static void serverSideExecute(ServerPlayer player, String scriptFileName) {
String uid = player.getName().toString();

PlayerInventoryHandler inventory = new PlayerInventoryHandler(player);
boolean day = player.level().isDay();
try {
VisualNovelEngine vnEngine = new VisualNovelEngine(ScriptLoader.loadScript(scriptFileName,uid), scriptFileName, uid,day);
VisualNovelEngine vnEngine = new VisualNovelEngine(ScriptLoader.loadScript(scriptFileName,uid), scriptFileName, uid,day,inventory);
sendClientMessage(player, "Trying to load the file config/mobtalkerredux/" + scriptFileName);
clientSideRenderDialogueScreen(vnEngine,player);
} catch (IOException e) {
Expand All @@ -49,6 +50,7 @@ private static void serverSideExecute(ServerPlayer player, String scriptFileName
}

private static void clientSideRenderDialogueScreen(VisualNovelEngine vnEngine,ServerPlayer player) {

Minecraft.getInstance().execute(() -> {
try {
//Minecraft.getInstance().setScreen(new DialogueScreen(vnEngine,player));
Expand Down
47 changes: 30 additions & 17 deletions src/main/java/org/arsparadox/mobtalkerredux/MobTalkerItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.arsparadox.mobtalkerredux.vn.controller.VisualNovelEngine;
import org.arsparadox.mobtalkerredux.vn.controller.vnmodules.PlayerInventoryHandler;
import org.arsparadox.mobtalkerredux.vn.model.ScriptLoader;
import org.arsparadox.mobtalkerredux.vn.view.DialogueScreen;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Map;

public class MobTalkerItem extends Item {

Expand All @@ -25,47 +28,57 @@ public MobTalkerItem() {
@Override
public InteractionResult interactLivingEntity(ItemStack stack, Player player, LivingEntity target, InteractionHand hand) {
Level world = player.level();
try{
// Check if the entity has a custom name
if (target.getCustomName() != null) {
String entityName = target.getCustomName().getString();
boolean day = world.isDay();

// Check if the entity has a custom name
if (target.getCustomName() != null) {
String entityName = target.getCustomName().getString();
boolean day = world.isDay();
if (!world.isClientSide()) { // Only run on the server side

if (!world.isClientSide()) { // Only run on the server side
player.sendSystemMessage(Component.literal("Hewwo World~"));
} else { // Client-side: Open dialogue screen
Minecraft minecraft = Minecraft.getInstance();
minecraft.execute(() -> {
} else { // Client-side: Open dialogue screen
Minecraft minecraft = Minecraft.getInstance();
minecraft.execute(() -> {

serverSideExecute(player, entityName+".json");
serverSideExecute(player, entityName+".json");

});
});
}
return InteractionResult.SUCCESS;
}
return InteractionResult.SUCCESS;
} catch (Exception ignored) {

}


return InteractionResult.PASS; // Return PASS if the entity doesn't have a custom name
}

private static void serverSideExecute(Player player, String scriptFileName) {
//String uid = player.getName().toString();//literal{Dev}
String uid = player.getName().getString();//Dev
PlayerInventoryHandler inventory = new PlayerInventoryHandler(player);
long timeOfDay = player.level().getDayTime() % 24000; // Minecraft-style day/night cycle in ticks
boolean day = (timeOfDay >= 0 && timeOfDay < 12000);
try {
VisualNovelEngine vnEngine = new VisualNovelEngine(ScriptLoader.loadScript(scriptFileName,uid), scriptFileName, uid,day);
sendClientMessage(player, "Trying to load the file config/mobtalkerredux/" + scriptFileName);
clientSideRenderDialogueScreen(vnEngine);
List<Map<String,Object>> script = ScriptLoader.loadScript(scriptFileName,uid);
if(script!=null){
VisualNovelEngine vnEngine = new VisualNovelEngine(script, scriptFileName, uid,day,inventory);
sendClientMessage(player, "Trying to load the file mobtalkerredux/" + scriptFileName);
clientSideRenderDialogueScreen(vnEngine);
}
else{
sendClientMessage(player, "Failed to find the file mobtalkerredux/" + scriptFileName);
}
} catch (IOException e) {
sendClientMessage(player, "Failed to find the file config/mobtalkerredux/" + scriptFileName);
sendClientMessage(player, "Failed to find the file mobtalkerredux/" + scriptFileName);
throw new RuntimeException(e);
}
}

private static void clientSideRenderDialogueScreen(VisualNovelEngine vnEngine) {
Minecraft.getInstance().execute(() -> {
try {
//Minecraft.getInstance().setScreen(new DialogueScreen(vnEngine,player));
Minecraft.getInstance().setScreen(new DialogueScreen(vnEngine));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
Expand Down
Loading