Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
CreatureChat
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Public
CreatureChat
Commits
ea71b5ae
Commit
ea71b5ae
authored
Apr 07, 2024
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Large refactor of code into packages, updated documentation, optimizing imports, etc...
parent
979637b0
Pipeline
#11956
passed with stage
in 24 seconds
Changes
15
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
69 additions
and
40 deletions
+69
-40
ClientInit.java
src/client/java/com/owlmaddie/ClientInit.java
+0
-0
ModPackets.java
src/client/java/com/owlmaddie/network/ModPackets.java
+6
-5
BubbleRenderer.java
src/client/java/com/owlmaddie/ui/BubbleRenderer.java
+0
-0
ChatScreen.java
src/client/java/com/owlmaddie/ui/ChatScreen.java
+6
-2
ClickHandler.java
src/client/java/com/owlmaddie/ui/ClickHandler.java
+7
-5
ClientEntityFinder.java
src/client/java/com/owlmaddie/utils/ClientEntityFinder.java
+5
-2
EntityRendererAccessor.java
...ient/java/com/owlmaddie/utils/EntityRendererAccessor.java
+1
-1
TextureLoader.java
src/client/java/com/owlmaddie/utils/TextureLoader.java
+1
-1
ModInit.java
src/main/java/com/owlmaddie/ModInit.java
+5
-15
ChatDataManager.java
src/main/java/com/owlmaddie/chat/ChatDataManager.java
+4
-1
ChatGPTRequest.java
src/main/java/com/owlmaddie/chat/ChatGPTRequest.java
+2
-1
LineWrapper.java
src/main/java/com/owlmaddie/chat/LineWrapper.java
+3
-3
RarityItemCollector.java
src/main/java/com/owlmaddie/items/RarityItemCollector.java
+4
-2
RandomUtils.java
src/main/java/com/owlmaddie/utils/RandomUtils.java
+20
-0
ServerEntityFinder.java
src/main/java/com/owlmaddie/utils/ServerEntityFinder.java
+5
-2
No files found.
src/client/java/com/owlmaddie/ClientInit.java
View file @
ea71b5ae
This diff is collapsed.
Click to expand it.
src/client/java/com/owlmaddie/ModPackets.java
→
src/client/java/com/owlmaddie/
network/
ModPackets.java
View file @
ea71b5ae
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
());
...
...
src/client/java/com/owlmaddie/ui/BubbleRenderer.java
0 → 100644
View file @
ea71b5ae
This diff is collapsed.
Click to expand it.
src/client/java/com/owlmaddie/ChatScreen.java
→
src/client/java/com/owlmaddie/
ui/
ChatScreen.java
View file @
ea71b5ae
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
;
...
...
src/client/java/com/owlmaddie/ClickHandler.java
→
src/client/java/com/owlmaddie/
ui/
ClickHandler.java
View file @
ea71b5ae
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
);
...
...
src/client/java/com/owlmaddie/ClientEntityFinder.java
→
src/client/java/com/owlmaddie/
utils/
ClientEntityFinder.java
View file @
ea71b5ae
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
())
{
...
...
src/client/java/com/owlmaddie/EntityRendererAccessor.java
→
src/client/java/com/owlmaddie/
utils/
EntityRendererAccessor.java
View file @
ea71b5ae
package
com
.
owlmaddie
;
package
com
.
owlmaddie
.
utils
;
import
net.minecraft.client.MinecraftClient
;
import
net.minecraft.client.render.entity.EntityRenderDispatcher
;
...
...
src/client/java/com/owlmaddie/TextureLoader.java
→
src/client/java/com/owlmaddie/
utils/
TextureLoader.java
View file @
ea71b5ae
package
com
.
owlmaddie
;
package
com
.
owlmaddie
.
utils
;
import
net.minecraft.client.MinecraftClient
;
import
net.minecraft.resource.Resource
;
...
...
src/main/java/com/owlmaddie/ModInit.java
View file @
ea71b5ae
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
(
thi
s
.
RandomLetter
()).
append
(
"' "
);
userMessageBuilder
.
append
(
"and which uses "
).
append
(
thi
s
.
RandomNumber
(
4
)
+
1
).
append
(
" syllables "
);
userMessageBuilder
.
append
(
"whose name starts with the letter '"
).
append
(
RandomUtil
s
.
RandomLetter
()).
append
(
"' "
);
userMessageBuilder
.
append
(
"and which uses "
).
append
(
RandomUtil
s
.
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
())
{
...
...
src/main/java/com/owlmaddie/ChatDataManager.java
→
src/main/java/com/owlmaddie/
chat/
ChatDataManager.java
View file @
ea71b5ae
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
;
...
...
src/main/java/com/owlmaddie/ChatGPTRequest.java
→
src/main/java/com/owlmaddie/
chat/
ChatGPTRequest.java
View file @
ea71b5ae
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
;
...
...
src/main/java/com/owlmaddie/LineWrapper.java
→
src/main/java/com/owlmaddie/
chat/
LineWrapper.java
View file @
ea71b5ae
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
{
...
...
src/main/java/com/owlmaddie/RarityItemCollector.java
→
src/main/java/com/owlmaddie/
items/
RarityItemCollector.java
View file @
ea71b5ae
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
)
{
...
...
src/main/java/com/owlmaddie/utils/RandomUtils.java
0 → 100644
View file @
ea71b5ae
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
);
}
}
src/main/java/com/owlmaddie/ServerEntityFinder.java
→
src/main/java/com/owlmaddie/
utils/
ServerEntityFinder.java
View file @
ea71b5ae
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
())
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment