Skip to content

Commit

Permalink
Fixed forge networking issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Faboslav committed Dec 18, 2023
1 parent a7f2e8f commit 18fbc78
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,4 @@ public static <T extends Packet<T>> void sendToServer(Identifier channel, T pack
public static <T extends Packet<T>> void sendToPlayer(Identifier channel, T packet, PlayerEntity player) {
throw new NotImplementedException();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ private static void onSetup(FMLCommonSetupEvent event) {
}

private static void onDatapackSync(OnDatapackSyncEvent event) {
if (event.getPlayer() != null) {
DatapackSyncEvent.EVENT.invoke(new DatapackSyncEvent(event.getPlayer()));
} else {
event.getPlayerList().getPlayerList().forEach(player -> DatapackSyncEvent.EVENT.invoke(new DatapackSyncEvent(player)));
if (FMLEnvironment.dist.isDedicatedServer()) {
if (event.getPlayer() != null) {
DatapackSyncEvent.EVENT.invoke(new DatapackSyncEvent(event.getPlayer()));
} else {
event.getPlayerList().getPlayerList().forEach(player -> DatapackSyncEvent.EVENT.invoke(new DatapackSyncEvent(player)));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ public static <T extends Packet<T>> void registerS2CPacket(
}
channel.channel.registerMessage(++channel.packets, packetClass, handler::encode, handler::decode, (msg, ctx) -> {
NetworkEvent.Context context = ctx.get();
PlayerEntity player = null;
if (context.getSender() == null) {
player = PlayerProvider.getClientPlayer();
}

context.enqueueWork(() -> {
PlayerEntity player = null;
if (context.getSender() == null) {
player = PlayerProvider.getClientPlayer();
}

if (player != null) {
PlayerEntity finalPlayer = player;
handler.handle(msg).apply(finalPlayer, finalPlayer.getWorld());
}
});

if (player != null) {
PlayerEntity finalPlayer = player;
context.enqueueWork(() -> handler.handle(msg).apply(finalPlayer, finalPlayer.getWorld()));
}
context.setPacketHandled(true);
});
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.configureondemand=false
# Mod
mod_name=Friends&Foes
mod_id=friendsandfoes
mod_version=2.0.5
mod_version=2.0.6
mod_author=Faboslav
mod_description=Adds outvoted and forgotten mobs from the mob votes in a believable vanilla plus style.
maven_group=com.faboslav.friendsandfoes
Expand Down

0 comments on commit 18fbc78

Please sign in to comment.