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
13979b85
Commit
13979b85
authored
Jul 03, 2024
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated ServerEntityFinder::getEntityByUUID to be more generic and so it can find players and mobs.
parent
4c63e1dc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
14 deletions
+15
-14
CHANGELOG.md
CHANGELOG.md
+1
-0
ChatDataManager.java
src/main/java/com/owlmaddie/chat/ChatDataManager.java
+2
-2
FollowPlayerGoal.java
src/main/java/com/owlmaddie/goals/FollowPlayerGoal.java
+1
-1
ServerPackets.java
src/main/java/com/owlmaddie/network/ServerPackets.java
+6
-6
ServerEntityFinder.java
src/main/java/com/owlmaddie/utils/ServerEntityFinder.java
+5
-5
No files found.
CHANGELOG.md
View file @
13979b85
...
@@ -15,6 +15,7 @@ All notable changes to **CreatureChat** are documented in this file. The format
...
@@ -15,6 +15,7 @@ All notable changes to **CreatureChat** are documented in this file. The format
-
Improved
**FLEE**
behavior, to make it more reliable and more random.
-
Improved
**FLEE**
behavior, to make it more reliable and more random.
-
Improved
**FOLLOW**
behavior, supporting teleporting entities (Enderman, Endermite, and Shulker)
-
Improved
**FOLLOW**
behavior, supporting teleporting entities (Enderman, Endermite, and Shulker)
-
Refactored
**ATTACK**
behavior to allow more flexibility (in order to support PROTECT behavior)
-
Refactored
**ATTACK**
behavior to allow more flexibility (in order to support PROTECT behavior)
-
Updated ServerEntityFinder::getEntityByUUID to be more generic and so it can find players and mobs.
## [1.0.6] - 2024-06-17
## [1.0.6] - 2024-06-17
...
...
src/main/java/com/owlmaddie/chat/ChatDataManager.java
View file @
13979b85
...
@@ -189,7 +189,7 @@ public class ChatDataManager {
...
@@ -189,7 +189,7 @@ public class ChatDataManager {
contextData
.
put
(
"world_moon_phase"
,
moonPhaseDescription
);
contextData
.
put
(
"world_moon_phase"
,
moonPhaseDescription
);
// Get Entity details
// Get Entity details
MobEntity
entity
=
ServerEntityFinder
.
getEntityByUUID
(
player
.
getServerWorld
(),
UUID
.
fromString
(
entityId
));
MobEntity
entity
=
(
MobEntity
)
ServerEntityFinder
.
getEntityByUUID
(
player
.
getServerWorld
(),
UUID
.
fromString
(
entityId
));
if
(
entity
.
getCustomName
()
==
null
)
{
if
(
entity
.
getCustomName
()
==
null
)
{
contextData
.
put
(
"entity_name"
,
""
);
contextData
.
put
(
"entity_name"
,
""
);
}
else
{
}
else
{
...
@@ -256,7 +256,7 @@ public class ChatDataManager {
...
@@ -256,7 +256,7 @@ public class ChatDataManager {
ParsedMessage
result
=
MessageParser
.
parseMessage
(
output_message
.
replace
(
"\n"
,
" "
));
ParsedMessage
result
=
MessageParser
.
parseMessage
(
output_message
.
replace
(
"\n"
,
" "
));
// Apply behaviors (if any)
// Apply behaviors (if any)
MobEntity
entity
=
ServerEntityFinder
.
getEntityByUUID
(
player
.
getServerWorld
(),
UUID
.
fromString
(
entityId
));
MobEntity
entity
=
(
MobEntity
)
ServerEntityFinder
.
getEntityByUUID
(
player
.
getServerWorld
(),
UUID
.
fromString
(
entityId
));
for
(
Behavior
behavior
:
result
.
getBehaviors
())
{
for
(
Behavior
behavior
:
result
.
getBehaviors
())
{
LOGGER
.
info
(
"Behavior: "
+
behavior
.
getName
()
+
(
behavior
.
getArgument
()
!=
null
?
LOGGER
.
info
(
"Behavior: "
+
behavior
.
getName
()
+
(
behavior
.
getArgument
()
!=
null
?
", Argument: "
+
behavior
.
getArgument
()
:
""
));
", Argument: "
+
behavior
.
getArgument
()
:
""
));
...
...
src/main/java/com/owlmaddie/goals/FollowPlayerGoal.java
View file @
13979b85
...
@@ -30,7 +30,7 @@ public class FollowPlayerGoal extends Goal {
...
@@ -30,7 +30,7 @@ public class FollowPlayerGoal extends Goal {
@Override
@Override
public
boolean
canStart
()
{
public
boolean
canStart
()
{
// Start only if the target player is more than 8 blocks away
// Start only if the target player is more than 8 blocks away
return
this
.
targetPlayer
!=
null
&&
this
.
entity
.
squaredDistanceTo
(
this
.
targetPlayer
)
>
64
;
return
this
.
targetPlayer
!=
null
&&
this
.
targetPlayer
.
isAlive
()
&&
this
.
entity
.
squaredDistanceTo
(
this
.
targetPlayer
)
>
64
;
}
}
@Override
@Override
...
...
src/main/java/com/owlmaddie/network/ServerPackets.java
View file @
13979b85
...
@@ -59,7 +59,7 @@ public class ServerPackets {
...
@@ -59,7 +59,7 @@ public class ServerPackets {
// Ensure that the task is synced with the server thread
// Ensure that the task is synced with the server thread
server
.
execute
(()
->
{
server
.
execute
(()
->
{
MobEntity
entity
=
ServerEntityFinder
.
getEntityByUUID
(
player
.
getServerWorld
(),
entityId
);
MobEntity
entity
=
(
MobEntity
)
ServerEntityFinder
.
getEntityByUUID
(
player
.
getServerWorld
(),
entityId
);
if
(
entity
!=
null
)
{
if
(
entity
!=
null
)
{
ChatDataManager
.
EntityChatData
chatData
=
ChatDataManager
.
getServerInstance
().
getOrCreateChatData
(
entity
.
getUuidAsString
());
ChatDataManager
.
EntityChatData
chatData
=
ChatDataManager
.
getServerInstance
().
getOrCreateChatData
(
entity
.
getUuidAsString
());
if
(
chatData
.
characterSheet
.
isEmpty
())
{
if
(
chatData
.
characterSheet
.
isEmpty
())
{
...
@@ -76,7 +76,7 @@ public class ServerPackets {
...
@@ -76,7 +76,7 @@ public class ServerPackets {
// Ensure that the task is synced with the server thread
// Ensure that the task is synced with the server thread
server
.
execute
(()
->
{
server
.
execute
(()
->
{
MobEntity
entity
=
ServerEntityFinder
.
getEntityByUUID
(
player
.
getServerWorld
(),
entityId
);
MobEntity
entity
=
(
MobEntity
)
ServerEntityFinder
.
getEntityByUUID
(
player
.
getServerWorld
(),
entityId
);
if
(
entity
!=
null
)
{
if
(
entity
!=
null
)
{
// Set talk to player goal (prevent entity from walking off)
// Set talk to player goal (prevent entity from walking off)
TalkPlayerGoal
talkGoal
=
new
TalkPlayerGoal
(
player
,
entity
,
3.5
F
);
TalkPlayerGoal
talkGoal
=
new
TalkPlayerGoal
(
player
,
entity
,
3.5
F
);
...
@@ -96,7 +96,7 @@ public class ServerPackets {
...
@@ -96,7 +96,7 @@ public class ServerPackets {
// Ensure that the task is synced with the server thread
// Ensure that the task is synced with the server thread
server
.
execute
(()
->
{
server
.
execute
(()
->
{
MobEntity
entity
=
ServerEntityFinder
.
getEntityByUUID
(
player
.
getServerWorld
(),
entityId
);
MobEntity
entity
=
(
MobEntity
)
ServerEntityFinder
.
getEntityByUUID
(
player
.
getServerWorld
(),
entityId
);
if
(
entity
!=
null
)
{
if
(
entity
!=
null
)
{
// Set talk to player goal (prevent entity from walking off)
// Set talk to player goal (prevent entity from walking off)
TalkPlayerGoal
talkGoal
=
new
TalkPlayerGoal
(
player
,
entity
,
3.5
F
);
TalkPlayerGoal
talkGoal
=
new
TalkPlayerGoal
(
player
,
entity
,
3.5
F
);
...
@@ -115,7 +115,7 @@ public class ServerPackets {
...
@@ -115,7 +115,7 @@ public class ServerPackets {
// Ensure that the task is synced with the server thread
// Ensure that the task is synced with the server thread
server
.
execute
(()
->
{
server
.
execute
(()
->
{
MobEntity
entity
=
ServerEntityFinder
.
getEntityByUUID
(
player
.
getServerWorld
(),
entityId
);
MobEntity
entity
=
(
MobEntity
)
ServerEntityFinder
.
getEntityByUUID
(
player
.
getServerWorld
(),
entityId
);
if
(
entity
!=
null
)
{
if
(
entity
!=
null
)
{
// Set talk to player goal (prevent entity from walking off)
// Set talk to player goal (prevent entity from walking off)
TalkPlayerGoal
talkGoal
=
new
TalkPlayerGoal
(
player
,
entity
,
7
F
);
TalkPlayerGoal
talkGoal
=
new
TalkPlayerGoal
(
player
,
entity
,
7
F
);
...
@@ -144,7 +144,7 @@ public class ServerPackets {
...
@@ -144,7 +144,7 @@ public class ServerPackets {
// Ensure that the task is synced with the server thread
// Ensure that the task is synced with the server thread
server
.
execute
(()
->
{
server
.
execute
(()
->
{
MobEntity
entity
=
ServerEntityFinder
.
getEntityByUUID
(
player
.
getServerWorld
(),
entityId
);
MobEntity
entity
=
(
MobEntity
)
ServerEntityFinder
.
getEntityByUUID
(
player
.
getServerWorld
(),
entityId
);
if
(
entity
!=
null
)
{
if
(
entity
!=
null
)
{
ChatDataManager
.
EntityChatData
chatData
=
ChatDataManager
.
getServerInstance
().
getOrCreateChatData
(
entity
.
getUuidAsString
());
ChatDataManager
.
EntityChatData
chatData
=
ChatDataManager
.
getServerInstance
().
getOrCreateChatData
(
entity
.
getUuidAsString
());
if
(
chatData
.
characterSheet
.
isEmpty
())
{
if
(
chatData
.
characterSheet
.
isEmpty
())
{
...
@@ -270,7 +270,7 @@ public class ServerPackets {
...
@@ -270,7 +270,7 @@ public class ServerPackets {
public
static
void
BroadcastPacketMessage
(
ChatDataManager
.
EntityChatData
chatData
)
{
public
static
void
BroadcastPacketMessage
(
ChatDataManager
.
EntityChatData
chatData
)
{
for
(
ServerWorld
world
:
serverInstance
.
getWorlds
())
{
for
(
ServerWorld
world
:
serverInstance
.
getWorlds
())
{
UUID
entityId
=
UUID
.
fromString
(
chatData
.
entityId
);
UUID
entityId
=
UUID
.
fromString
(
chatData
.
entityId
);
MobEntity
entity
=
ServerEntityFinder
.
getEntityByUUID
(
world
,
entityId
);
MobEntity
entity
=
(
MobEntity
)
ServerEntityFinder
.
getEntityByUUID
(
world
,
entityId
);
if
(
entity
!=
null
)
{
if
(
entity
!=
null
)
{
// Set custom name (if null)
// Set custom name (if null)
String
characterName
=
chatData
.
getCharacterProp
(
"name"
);
String
characterName
=
chatData
.
getCharacterProp
(
"name"
);
...
...
src/main/java/com/owlmaddie/utils/ServerEntityFinder.java
View file @
13979b85
package
com
.
owlmaddie
.
utils
;
package
com
.
owlmaddie
.
utils
;
import
net.minecraft.entity.Entity
;
import
net.minecraft.entity.Entity
;
import
net.minecraft.entity.
mob.Mob
Entity
;
import
net.minecraft.entity.
Living
Entity
;
import
net.minecraft.server.world.ServerWorld
;
import
net.minecraft.server.world.ServerWorld
;
import
java.util.UUID
;
import
java.util.UUID
;
/**
/**
* The {@code ServerEntityFinder} class is used to find a specific
Mob
Entity by UUID, since
* The {@code ServerEntityFinder} class is used to find a specific
Living
Entity by UUID, since
* there is not a built-in method for this.
* there is not a built-in method for this.
*/
*/
public
class
ServerEntityFinder
{
public
class
ServerEntityFinder
{
public
static
Mob
Entity
getEntityByUUID
(
ServerWorld
world
,
UUID
uuid
)
{
public
static
Living
Entity
getEntityByUUID
(
ServerWorld
world
,
UUID
uuid
)
{
for
(
Entity
entity
:
world
.
iterateEntities
())
{
for
(
Entity
entity
:
world
.
iterateEntities
())
{
if
(
entity
.
getUuid
().
equals
(
uuid
)
&&
entity
instanceof
Mob
Entity
)
{
if
(
entity
.
getUuid
().
equals
(
uuid
)
&&
entity
instanceof
Living
Entity
)
{
return
(
MobEntity
)
entity
;
return
(
LivingEntity
)
entity
;
}
}
}
}
return
null
;
// Entity not found
return
null
;
// Entity not found
...
...
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