diff --git a/src/main/java/org/arsparadox/mobtalkerredux/DemoCommand.java b/src/main/java/org/arsparadox/mobtalkerredux/DemoCommand.java index 235dc8d..289206f 100644 --- a/src/main/java/org/arsparadox/mobtalkerredux/DemoCommand.java +++ b/src/main/java/org/arsparadox/mobtalkerredux/DemoCommand.java @@ -68,7 +68,7 @@ private static void clientSideRenderDialogueScreen(VisualNovelEngine vnEngine) { Minecraft.getInstance().execute(() -> { try { //Minecraft.getInstance().setScreen(new DialogueScreen(vnEngine,player)); - Minecraft.getInstance().setScreen(new DialogueScreen(vnEngine,null)); + Minecraft.getInstance().setScreen(new DialogueScreen(vnEngine,null,null)); } catch (FileNotFoundException e) { throw new RuntimeException(e); } diff --git a/src/main/java/org/arsparadox/mobtalkerredux/MobTalkerItem.java b/src/main/java/org/arsparadox/mobtalkerredux/MobTalkerItem.java index 2ef90ef..0be49f6 100644 --- a/src/main/java/org/arsparadox/mobtalkerredux/MobTalkerItem.java +++ b/src/main/java/org/arsparadox/mobtalkerredux/MobTalkerItem.java @@ -2,16 +2,13 @@ import net.minecraft.client.Minecraft; import net.minecraft.network.chat.Component; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import org.arsparadox.mobtalkerredux.command.MobFreezer; import org.arsparadox.mobtalkerredux.vn.controller.VisualNovelEngine; import org.arsparadox.mobtalkerredux.vn.controller.vnmodules.PlayerInventoryHandler; import org.arsparadox.mobtalkerredux.vn.model.ScriptLoader; @@ -37,18 +34,15 @@ public MobTalkerItem() { // Check if the entity has a custom name if (target.getCustomName() != null) { String entityName = target.getCustomName().getString().toLowerCase().replace(" ", "_"); - String entityType = target.getType().toString(); + String entityType = target.getType().toShortString(); if (!world.isClientSide()) { // Safely check and cast to ServerPlayer - if (player instanceof ServerPlayer serverPlayer) { - if(target instanceof Mob mob){ - MobFreezer.freezeMob(mob); - } - } } else { // Client-side: Open dialogue screen Minecraft minecraft = Minecraft.getInstance(); minecraft.execute(() -> { - serverSideExecute(player, entityName+".json", entityName+".json",target); + sendClientMessage(player,"The Entity's type is: "+entityType); + VisualNovelEngine vn = serverSideExecute(player, entityType, entityName,target); + clientSideRenderDialogueScreen(vn,target,player); }); } return InteractionResult.SUCCESS; @@ -60,7 +54,7 @@ public MobTalkerItem() { return InteractionResult.PASS; // Return PASS if the entity doesn't have a custom name } - private static void serverSideExecute(Player player, String entityType,String entityName, LivingEntity target) { + private static VisualNovelEngine serverSideExecute(Player player, String entityType,String entityName, LivingEntity target) { //String uid = player.getName().toString();//literal{Dev} String uid = player.getName().getString();//Dev PlayerInventoryHandler inventory = new PlayerInventoryHandler(player); @@ -81,8 +75,9 @@ private static void serverSideExecute(Player player, String entityType,String en globalSave, localSave ); + return vnEngine; // sendClientMessage(player, "Trying to load the file mobtalkerredux/" + scriptFileName); - clientSideRenderDialogueScreen(vnEngine,target); + //clientSideRenderDialogueScreen(vnEngine,target,player); } else{ //sendClientMessage(player, "Failed to find the file mobtalkerredux/" + scriptFileName); @@ -91,12 +86,13 @@ private static void serverSideExecute(Player player, String entityType,String en //sendClientMessage(player, "Failed to find the file mobtalkerredux/" + scriptFileName); throw new RuntimeException(e); } + return null; } - private static void clientSideRenderDialogueScreen(VisualNovelEngine vnEngine, LivingEntity target) { + private static void clientSideRenderDialogueScreen(VisualNovelEngine vnEngine, LivingEntity target,Player player) { Minecraft.getInstance().execute(() -> { try { - Minecraft.getInstance().setScreen(new DialogueScreen(vnEngine,target)); + Minecraft.getInstance().setScreen(new DialogueScreen(vnEngine,target,player)); } catch (FileNotFoundException e) { throw new RuntimeException(e); } diff --git a/src/main/java/org/arsparadox/mobtalkerredux/MobTalkerRedux.java b/src/main/java/org/arsparadox/mobtalkerredux/MobTalkerRedux.java index 785e2e3..359d4cb 100644 --- a/src/main/java/org/arsparadox/mobtalkerredux/MobTalkerRedux.java +++ b/src/main/java/org/arsparadox/mobtalkerredux/MobTalkerRedux.java @@ -20,7 +20,6 @@ import net.minecraftforge.registries.RegistryObject; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.arsparadox.mobtalkerredux.vn.model.TextureLoader; import java.util.stream.Collectors; @@ -48,7 +47,7 @@ public MobTalkerRedux() { private void setup(final FMLCommonSetupEvent event) { LOGGER.info("HELLO FROM PREINIT"); - TextureLoader.loadTexturesFromConfig(); + } private void enqueueIMC(final InterModEnqueueEvent event) { diff --git a/src/main/java/org/arsparadox/mobtalkerredux/command/MobFreezer.java b/src/main/java/org/arsparadox/mobtalkerredux/command/MobFreezer.java index afd272f..f1a3ecd 100644 --- a/src/main/java/org/arsparadox/mobtalkerredux/command/MobFreezer.java +++ b/src/main/java/org/arsparadox/mobtalkerredux/command/MobFreezer.java @@ -1,101 +1,15 @@ package org.arsparadox.mobtalkerredux.command; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.entity.Mob; -import net.minecraft.world.entity.ai.attributes.AttributeModifier; -import net.minecraft.world.entity.ai.attributes.Attributes; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import org.arsparadox.mobtalkerredux.vn.view.DialogueScreen; public class MobFreezer { - private static final Map frozenMobs = new HashMap<>(); - private static final UUID MOVEMENT_SPEED_MODIFIER = UUID.fromString("708396DC-7DEA-4EDD-B915-A3B97ADFF457"); - - /** - * Freezes a mob in place, disabling AI and movement - * @param mob The mob to freeze - * @return true if the mob was frozen, false if already frozen - */ - public static boolean freezeMob(Mob mob) { - if (mob == null || frozenMobs.containsKey(mob.getUUID())) { - return false; - } - - // Store current AI state - frozenMobs.put(mob.getUUID(), mob.isNoAi()); - - // Disable AI - mob.setNoAi(true); - - // Stop all current goals -// mob.goalSelector.removeAllGoals(); -// mob.targetSelector.removeAllGoals(); - - // Freeze movement speed - mob.getAttribute(Attributes.MOVEMENT_SPEED).addTransientModifier( - new AttributeModifier(MOVEMENT_SPEED_MODIFIER, "Freeze movement", -1.0D, AttributeModifier.Operation.MULTIPLY_TOTAL) - ); - - // Stop any current movement/path - mob.getNavigation().stop(); - mob.setDeltaMovement(0, mob.getDeltaMovement().y, 0); // Preserve Y movement for gravity - - return true; - } - - /** - * Freezes a mob by UUID if it exists in the world - * @param level The server level to search in - * @param uuid The UUID of the mob to freeze - * @return true if the mob was found and frozen - */ - public static boolean freezeMobByUUID(ServerLevel level, UUID uuid) { - if (level.getEntity(uuid) instanceof Mob mob) { - return freezeMob(mob); - } - return false; - } - - /** - * Unfreezes a previously frozen mob - * @param mob The mob to unfreeze - * @return true if the mob was unfrozen, false if it wasn't frozen - */ - public static boolean unfreezeMob(Mob mob) { - if (mob == null || !frozenMobs.containsKey(mob.getUUID())) { - return false; - } - - // Restore original AI state - mob.setNoAi(frozenMobs.remove(mob.getUUID())); - - // Remove movement speed modifier - mob.getAttribute(Attributes.MOVEMENT_SPEED) - .removeModifier(MOVEMENT_SPEED_MODIFIER); - - // The mob's AI goals will be reinstated automatically when needed - return true; - } - - /** - * Unfreezes a mob by UUID if it exists in the world - * @param level The server level to search in - * @param uuid The UUID of the mob to unfreeze - * @return true if the mob was found and unfrozen - */ - public static boolean unfreezeMobByUUID(ServerLevel level, UUID uuid) { - if (level.getEntity(uuid) instanceof Mob mob) { - return unfreezeMob(mob); - } - return false; + public static void freezeMob(DialogueScreen ds) { + ds.mob.setNoAi(true); + ds.mob.setNoGravity(true); } - /** - * Checks if a mob is currently frozen - */ - public static boolean isFrozen(UUID uuid) { - return frozenMobs.containsKey(uuid); + public static void unfreezeMob(DialogueScreen ds) { + ds.mob.setNoAi(false); + ds.mob.setNoGravity(false); } } \ No newline at end of file diff --git a/src/main/java/org/arsparadox/mobtalkerredux/vn/controller/VisualNovelEngine.java b/src/main/java/org/arsparadox/mobtalkerredux/vn/controller/VisualNovelEngine.java index d8dba3e..607a2f6 100644 --- a/src/main/java/org/arsparadox/mobtalkerredux/vn/controller/VisualNovelEngine.java +++ b/src/main/java/org/arsparadox/mobtalkerredux/vn/controller/VisualNovelEngine.java @@ -152,9 +152,9 @@ private void processAction(Map action) { } break; case "unlock_dialogues": - List events = (List) this.globalVariables.getOrDefault("unlocked_events", new ArrayList<>()); + List events = (List) this.localVariables.getOrDefault("unlocked_events", new ArrayList<>()); events.addAll((List) action.get("events")); - this.globalVariables.put("unlocked_events", events); + this.localVariables.put("unlocked_events", events); this.currentState.incrementAndGet(); break; case "play_sound": diff --git a/src/main/java/org/arsparadox/mobtalkerredux/vn/controller/vnmodules/DialogueHandler.java b/src/main/java/org/arsparadox/mobtalkerredux/vn/controller/vnmodules/DialogueHandler.java index 5a34edc..7d8a2c3 100644 --- a/src/main/java/org/arsparadox/mobtalkerredux/vn/controller/vnmodules/DialogueHandler.java +++ b/src/main/java/org/arsparadox/mobtalkerredux/vn/controller/vnmodules/DialogueHandler.java @@ -115,7 +115,7 @@ public static void processIdleChat( // Alright, Null Handling Time // Fuck... //System.out.println(vn.globalVariables.get("unlocked_events")); - List chats = (List) vn.globalVariables.getOrDefault("unlocked_events", new ArrayList<>()); + List chats = (List) vn.localVariables.getOrDefault("unlocked_events", new ArrayList<>()); if (!chats.isEmpty()) { Random random = new Random(); diff --git a/src/main/java/org/arsparadox/mobtalkerredux/vn/model/ScriptLoader.java b/src/main/java/org/arsparadox/mobtalkerredux/vn/model/ScriptLoader.java index 15cd08b..076cd9e 100644 --- a/src/main/java/org/arsparadox/mobtalkerredux/vn/model/ScriptLoader.java +++ b/src/main/java/org/arsparadox/mobtalkerredux/vn/model/ScriptLoader.java @@ -106,26 +106,26 @@ public static String getWorldName() { */ public static List> loadScript(String name,String type, String playerUID) throws IOException { // Try loading from the save folder (level or player UID folder) - name = name.toLowerCase(); - + name = name.toLowerCase()+".json"; + type = type.toLowerCase()+".json"; // If not found in save or config, try loading from resources System.out.println("Loading from resources: " + name); List> script = loadFromResource(name); if(script!=null){ - return loadFromResource(name); + return script; }else{ return loadFromResource(type); } } - public static List> loadSave(String fileName, String playerUID) { + public static List> loadSave(String entityName, String playerUID) { // Try loading from the save folder (level or player UID folder) - fileName = fileName.toLowerCase(); - File saveFile = new File(getSaveFilePath(fileName, playerUID,getWorldName())); + entityName = entityName.toLowerCase()+".json"; + File saveFile = new File(getSaveFilePath(entityName, playerUID,getWorldName())); if (saveFile.exists()) { - System.out.println("Loading from save folder: " + fileName); + System.out.println("Loading from save folder: " + entityName); return loadJsonFromFile(saveFile.getPath()); } return null; @@ -149,7 +149,7 @@ public static List> loadGlobal(String playerUID) { * @param playerName Player-specific UID for saving to a specific folder. */ public static void saveState(List> gameState, String fileName, String playerName) { - fileName = fileName.toLowerCase(); + fileName = fileName.toLowerCase()+".json"; playerName = playerName.toLowerCase(); String filePath = getSaveFilePath(fileName, playerName,getWorldName()); try (Writer writer = new FileWriter(filePath)) { diff --git a/src/main/java/org/arsparadox/mobtalkerredux/vn/model/TextureLoader.java b/src/main/java/org/arsparadox/mobtalkerredux/vn/model/TextureLoader.java deleted file mode 100644 index e59a197..0000000 --- a/src/main/java/org/arsparadox/mobtalkerredux/vn/model/TextureLoader.java +++ /dev/null @@ -1,107 +0,0 @@ -package org.arsparadox.mobtalkerredux.vn.model; - -import net.minecraft.client.Minecraft; -import net.minecraft.server.packs.repository.Pack; -import net.minecraft.server.packs.repository.PackRepository; -import net.minecraftforge.fml.loading.FMLPaths; -import org.arsparadox.mobtalkerredux.MobTalkerRedux; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -public class TextureLoader { - private static final String PACK_NAME = "mobtalkerredux_generated"; - - public static void loadTexturesFromConfig() { - Path configTexturePath = FMLPaths.CONFIGDIR.get().resolve(MobTalkerRedux.MODID).resolve("textures"); - Path modPath = FMLPaths.GAMEDIR.get().resolve("resourcepacks").resolve(PACK_NAME); - Path modTexturePath = modPath.resolve("assets").resolve(MobTalkerRedux.MODID).resolve("textures"); - - try { - // Create directories if they don't exist - Files.createDirectories(modTexturePath); - - // Create pack.mcmeta - Path mcmetaPath = modPath.resolve("pack.mcmeta"); - if (!Files.exists(mcmetaPath)) { - String mcmeta = """ - { - "pack": { - "description": "Generated MobTalker Redux textures", - "pack_format": 15 - } - }"""; - Files.writeString(mcmetaPath, mcmeta); - } - - // Copy all files from config to mod directory - if (Files.exists(configTexturePath)) { - Files.walk(configTexturePath) - .filter(Files::isRegularFile) - .forEach(source -> { - try { - Path relativePath = configTexturePath.relativize(source); - Path targetPath = modTexturePath.resolve(relativePath); - - // Create parent directories if they don't exist - Files.createDirectories(targetPath.getParent()); - - // Copy file, replacing if it exists - Files.copy(source, targetPath, StandardCopyOption.REPLACE_EXISTING); - - MobTalkerRedux.LOGGER.info("Copied texture: {} to {}", source, targetPath); - } catch (IOException e) { - MobTalkerRedux.LOGGER.error("Failed to copy texture: " + source, e); - } - }); - MobTalkerRedux.LOGGER.info("Finished copying textures from config to resource pack"); - } - - // Queue the resource pack to be loaded - Minecraft.getInstance().execute(() -> { - try { - PackRepository packRepo = Minecraft.getInstance().getResourcePackRepository(); - - // Force a reload of available packs - packRepo.reload(); - - // Try to get the pack after reloading - Pack pack = packRepo.getPack(PACK_NAME); - - if (pack != null) { - // If the pack isn't already enabled - if (!packRepo.getSelectedIds().contains(pack.getId())) { - // Enable the pack - List enabled = new ArrayList<>(packRepo.getSelectedPacks()); - enabled.add(pack); - - // Update selected packs - packRepo.setSelected(enabled.stream().map(Pack::getId).collect(Collectors.toList())); - - // Reload resources - Minecraft.getInstance().reloadResourcePacks(); - MobTalkerRedux.LOGGER.info("Successfully loaded generated resource pack"); - } - } else { - MobTalkerRedux.LOGGER.error("Could not find generated resource pack. Path exists: " + - Files.exists(modPath) + ", Pack folder contents: " + - Files.list(FMLPaths.GAMEDIR.get().resolve("resourcepacks")) - .map(Path::getFileName) - .map(Object::toString) - .collect(Collectors.joining(", "))); - } - } catch (Exception e) { - MobTalkerRedux.LOGGER.error("Failed to load resource pack", e); - } - }); - - } catch (IOException e) { - MobTalkerRedux.LOGGER.error("Failed to initialize texture loading", e); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/arsparadox/mobtalkerredux/vn/view/DialogueScreen.java b/src/main/java/org/arsparadox/mobtalkerredux/vn/view/DialogueScreen.java index 699437a..72841c1 100644 --- a/src/main/java/org/arsparadox/mobtalkerredux/vn/view/DialogueScreen.java +++ b/src/main/java/org/arsparadox/mobtalkerredux/vn/view/DialogueScreen.java @@ -8,11 +8,10 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.Mob; -import org.arsparadox.mobtalkerredux.command.MobFreezer; +import net.minecraft.world.entity.player.Player; import org.arsparadox.mobtalkerredux.vn.controller.VisualNovelEngine; import org.arsparadox.mobtalkerredux.vn.data.DialogueState; import org.arsparadox.mobtalkerredux.vn.data.SpriteState; -import org.arsparadox.mobtalkerredux.vn.model.TextureLoader; import org.arsparadox.mobtalkerredux.vn.view.components.DialogueBoxManager; import org.arsparadox.mobtalkerredux.vn.view.components.ForegroundComponent; @@ -39,19 +38,20 @@ public class DialogueScreen extends Screen{ private String music; private String sound; private SoundUtils se; - private Mob mob; + public Mob mob; + private Player player; - public DialogueScreen(VisualNovelEngine vn, LivingEntity target) throws FileNotFoundException { + public DialogueScreen(VisualNovelEngine vn, LivingEntity target, Player player) throws FileNotFoundException { super(Component.empty()); this.vn = vn; this.se = new SoundUtils(); this.mob = (Mob)target; - TextureLoader.loadTexturesFromConfig(); - //this.player = player; - //dialogueBox = new DialogueBoxComponent(); + this.player = player; + + } @Override @@ -216,7 +216,6 @@ public void renderChoiceButtons() { public void onClose() { assert this.minecraft != null; this.minecraft.setScreen(null); - MobFreezer.unfreezeMob(this.mob); }