Commit ea71b5ae by Jonathan Thomas

Large refactor of code into packages, updated documentation, optimizing imports, etc...

parent 979637b0
Pipeline #11956 passed with stage
in 24 seconds
package com.owlmaddie;
package com.owlmaddie.network;
import com.owlmaddie.ModInit;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.entity.Entity;
import net.minecraft.network.PacketByteBuf;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {@code ModPackets} class provides methods to send packets to the server for generating greetings,
* updating message details, and sending user messages.
*/
public class ModPackets {
public static final Logger LOGGER = LoggerFactory.getLogger("mobgpt");
public static void sendGenerateGreeting(Entity entity) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
......
package com.owlmaddie;
package com.owlmaddie.ui;
import com.owlmaddie.network.ModPackets;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
......@@ -8,7 +9,10 @@ import net.minecraft.entity.Entity;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;
/**
* The {@code ChatScreen} class is used to display a chat dialog UI for the player and handle keyboard
* entry events.
*/
public class ChatScreen extends Screen {
private TextFieldWidget textField;
private ButtonWidget sendButton;
......
package com.owlmaddie;
package com.owlmaddie.ui;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.owlmaddie.ModInit;
import com.owlmaddie.chat.ChatDataManager;
import com.owlmaddie.network.ModPackets;
import com.owlmaddie.utils.ClientEntityFinder;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.client.MinecraftClient;
......@@ -13,8 +17,6 @@ import net.minecraft.entity.mob.MobEntity;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Type;
import java.util.HashMap;
......@@ -29,8 +31,8 @@ import java.util.stream.Collectors;
* back to the server.
*/
public class ClickHandler {
private static final Logger LOGGER = LoggerFactory.getLogger("mobgpt");
private static boolean wasClicked = false;
public static void register() {
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (client.options.useKey.isPressed()) {
......@@ -163,7 +165,7 @@ public class ClickHandler {
ModPackets.sendGenerateGreeting(closestEntity);
} else if (chatData.status == ChatDataManager.ChatStatus.DISPLAY) {
// Update lines read
ModPackets.sendUpdateLineNumber(closestEntity, chatData.currentLineNumber + ClientInit.DISPLAY_NUM_LINES);
ModPackets.sendUpdateLineNumber(closestEntity, chatData.currentLineNumber + BubbleRenderer.DISPLAY_NUM_LINES);
} else if (chatData.status == ChatDataManager.ChatStatus.END) {
// End of chat (open player chat screen)
ModPackets.sendStartChat(closestEntity);
......
package com.owlmaddie;
package com.owlmaddie.utils;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
......@@ -6,7 +6,10 @@ import net.minecraft.entity.mob.MobEntity;
import java.util.UUID;
// Find Client Entity from UUID
/**
* The {@code ClientEntityFinder} class is used to find a specific MobEntity by UUID, since
* there is not a built-in method for this.
*/
public class ClientEntityFinder {
public static MobEntity getEntityByUUID(ClientWorld world, UUID uuid) {
for (Entity entity : world.getEntities()) {
......
package com.owlmaddie;
package com.owlmaddie.utils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
......
package com.owlmaddie;
package com.owlmaddie.utils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.resource.Resource;
......
package com.owlmaddie;
import com.owlmaddie.chat.ChatDataManager;
import com.owlmaddie.goals.EntityBehaviorManager;
import com.owlmaddie.goals.GoalPriority;
import com.owlmaddie.goals.TalkPlayerGoal;
import com.owlmaddie.utils.RandomUtils;
import com.owlmaddie.utils.ServerEntityFinder;
import io.netty.buffer.Unpooled;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
......@@ -19,7 +22,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Locale;
import java.util.Random;
import java.util.UUID;
/**
......@@ -66,8 +68,8 @@ public class ModInit implements ModInitializer {
if (entity.getCustomName() != null) {
userMessageBuilder.append("named '").append(entity.getCustomName().getLiteralString()).append("' ");
} else {
userMessageBuilder.append("whose name starts with the letter '").append(this.RandomLetter()).append("' ");
userMessageBuilder.append("and which uses ").append(this.RandomNumber(4) + 1).append(" syllables ");
userMessageBuilder.append("whose name starts with the letter '").append(RandomUtils.RandomLetter()).append("' ");
userMessageBuilder.append("and which uses ").append(RandomUtils.RandomNumber(4) + 1).append(" syllables ");
}
userMessageBuilder.append("of type '").append(entity.getType().getUntranslatedName().toLowerCase(Locale.ROOT)).append("' ");
userMessageBuilder.append("who lives near the ").append(player_biome).append(".");
......@@ -173,18 +175,6 @@ public class ModInit implements ModInitializer {
LOGGER.info("MobGPT Initialized!");
}
public static String RandomLetter() {
// Return random letter between 'A' and 'Z'
int randomNumber = RandomNumber(26);
return String.valueOf((char) ('A' + randomNumber));
}
public static int RandomNumber(int max) {
// Generate a random integer between 0 and max (inclusive)
Random random = new Random();
return random.nextInt(max);
}
// Send new message to all connected players
public static void BroadcastPacketMessage(ChatDataManager.EntityChatData chatData) {
for (ServerWorld world : serverInstance.getWorlds()) {
......
package com.owlmaddie;
package com.owlmaddie.chat;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.owlmaddie.ModInit;
import com.owlmaddie.goals.*;
import com.owlmaddie.items.RarityItemCollector;
import com.owlmaddie.json.QuestJson;
import com.owlmaddie.message.Behavior;
import com.owlmaddie.message.MessageParser;
import com.owlmaddie.message.ParsedMessage;
import com.owlmaddie.utils.ServerEntityFinder;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
......
package com.owlmaddie;
package com.owlmaddie.chat;
import com.google.gson.Gson;
import com.owlmaddie.ModInit;
import com.owlmaddie.json.ChatGPTResponse;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
......
package com.owlmaddie;
package com.owlmaddie.chat;
import java.util.ArrayList;
import java.util.List;
/*
Wrap lines of text on a space character
/**
* The {@code LineWrapper} class is used to wrap lines of text on the nearest space character
*/
public class LineWrapper {
......
package com.owlmaddie;
package com.owlmaddie.items;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
......@@ -8,7 +8,9 @@ import net.minecraft.util.Rarity;
import java.util.*;
/**
* The {@code RarityItemCollector} class is used to find items & entities by rarity
*/
public class RarityItemCollector {
public static List<String> getItemsByRarity(Rarity rarity, int quantity) {
......
package com.owlmaddie.utils;
import java.util.Random;
/**
* The {@code RandomUtils} class is used to easily generate random Letters or Numbers.
*/
public class RandomUtils {
public static String RandomLetter() {
// Return random letter between 'A' and 'Z'
int randomNumber = RandomNumber(26);
return String.valueOf((char) ('A' + randomNumber));
}
public static int RandomNumber(int max) {
// Generate a random integer between 0 and max (inclusive)
Random random = new Random();
return random.nextInt(max);
}
}
package com.owlmaddie;
package com.owlmaddie.utils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.mob.MobEntity;
......@@ -6,7 +6,10 @@ import net.minecraft.server.world.ServerWorld;
import java.util.UUID;
// Find Server Entity from UUID
/**
* The {@code ServerEntityFinder} class is used to find a specific MobEntity by UUID, since
* there is not a built-in method for this.
*/
public class ServerEntityFinder {
public static MobEntity getEntityByUUID(ServerWorld world, UUID uuid) {
for (Entity entity : world.iterateEntities()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment