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
485c80e8
Commit
485c80e8
authored
Nov 09, 2023
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support all 3 worlds when broadcasting messages to players for an entityId
parent
d3eed475
Pipeline
#11655
passed with stage
in 20 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
19 deletions
+22
-19
ModInit.java
src/main/java/com/owlmaddie/ModInit.java
+22
-19
No files found.
src/main/java/com/owlmaddie/ModInit.java
View file @
485c80e8
package
com
.
owlmaddie
;
import
io.netty.buffer.Unpooled
;
import
net.fabricmc.api.ModInitializer
;
import
net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents
;
import
net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking
;
import
net.minecraft.entity.Entity
;
import
net.minecraft.entity.LivingEntity
;
import
net.minecraft.entity.effect.StatusEffectInstance
;
import
net.minecraft.entity.effect.StatusEffects
;
import
net.minecraft.util.Identifier
;
import
net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents
;
import
net.minecraft.server.network.ServerPlayerEntity
;
import
net.minecraft.network.PacketByteBuf
;
import
net.minecraft.server.MinecraftServer
;
import
io.netty.buffer.Unpooled
;
import
net.minecraft.server.network.ServerPlayerEntity
;
import
net.minecraft.server.world.ServerWorld
;
import
net.minecraft.util.Identifier
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -89,21 +90,23 @@ public class ModInit implements ModInitializer {
// Send new message to all connected players
public
static
void
BroadcastPacketMessage
(
ChatDataManager
.
EntityChatData
chatData
)
{
// TODO: Fix static OVERWORLD reference
Entity
entity
=
serverInstance
.
getOverworld
().
getEntityById
(
chatData
.
entityId
);
if
(
entity
!=
null
)
{
PacketByteBuf
buffer
=
new
PacketByteBuf
(
Unpooled
.
buffer
());
// Write the entity's chat updated data
buffer
.
writeInt
(
entity
.
getId
());
buffer
.
writeString
(
chatData
.
currentMessage
);
buffer
.
writeInt
(
chatData
.
currentLineNumber
);
buffer
.
writeString
(
chatData
.
status
.
toString
());
// Iterate over all players and send the packet
for
(
ServerPlayerEntity
player
:
serverInstance
.
getPlayerManager
().
getPlayerList
())
{
LOGGER
.
info
(
"Server send message packet to player: "
+
player
.
getName
().
getString
());
ServerPlayNetworking
.
send
(
player
,
PACKET_S2C_MESSAGE
,
buffer
);
for
(
ServerWorld
world
:
serverInstance
.
getWorlds
())
{
Entity
entity
=
world
.
getEntityById
(
chatData
.
entityId
);
if
(
entity
!=
null
)
{
PacketByteBuf
buffer
=
new
PacketByteBuf
(
Unpooled
.
buffer
());
// Write the entity's chat updated data
buffer
.
writeInt
(
entity
.
getId
());
buffer
.
writeString
(
chatData
.
currentMessage
);
buffer
.
writeInt
(
chatData
.
currentLineNumber
);
buffer
.
writeString
(
chatData
.
status
.
toString
());
// Iterate over all players and send the packet
for
(
ServerPlayerEntity
player
:
serverInstance
.
getPlayerManager
().
getPlayerList
())
{
LOGGER
.
info
(
"Server send message packet to player: "
+
player
.
getName
().
getString
());
ServerPlayNetworking
.
send
(
player
,
PACKET_S2C_MESSAGE
,
buffer
);
}
break
;
}
}
}
...
...
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