Skip to content

Commit 2c1c373

Browse files
committed
Fixed Fabric BUT MULTIPLAYER PACKETS ARE BROKEN
1 parent 78b8f06 commit 2c1c373

13 files changed

Lines changed: 65 additions & 53 deletions

File tree

changelog.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@
22

33
## Changed
44

5-
* Massive cleanup in the way we register Codecs and Data ComponentTypes.
5+
* Massive cleanup in the way we register Codecs and Data ComponentTypes.
6+
7+
## Bug Fixes
8+
9+
* Fixed a critical issue where Fabric Server where enable to be started due to trying to load Client sided Code on the
10+
Server.

common/src/main/java/software/bluelib/api/net/NetworkPacket.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
package software.bluelib.api.net;
99

1010
import java.util.function.Predicate;
11+
1112
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
1213
import net.minecraft.resources.ResourceKey;
1314
import net.minecraft.resources.ResourceLocation;
15+
import net.minecraft.server.MinecraftServer;
1416
import net.minecraft.server.level.ServerPlayer;
1517
import net.minecraft.world.level.Level;
1618
import org.jetbrains.annotations.NotNull;
@@ -19,7 +21,7 @@
1921
import software.bluelib.api.utils.logging.BaseLogger;
2022
import software.bluelib.internal.BlueTranslation;
2123

22-
@SuppressWarnings({ "unused" })
24+
@SuppressWarnings({"unused"})
2325
public interface NetworkPacket<T extends NetworkPacket<T>> extends CustomPacketPayload, Encodable {
2426

2527
@NotNull
@@ -35,22 +37,16 @@ default void sendToPlayers(@NotNull Iterable<ServerPlayer> pPlayers) {
3537
}
3638
}
3739

38-
default void sendToAllPlayers() {
39-
NetworkRegistry.sendToAllPlayers(this);
40+
default void sendToAllPlayers(@NotNull MinecraftServer pServer) {
41+
NetworkRegistry.sendToAllPlayers(pServer, this);
4042
}
4143

4244
default void sendToServer() {
4345
NetworkRegistry.sendToServer(this);
4446
}
4547

46-
default void sendToPlayersAround(@NotNull Double pX, @NotNull Double pY, @NotNull Double pZ, @NotNull Double pDistance, @NotNull ResourceKey<Level> pWorldKey, @NotNull Predicate<ServerPlayer> pExclusionCondition) {
47-
var server = BlueLibConstants.PlatformHelper.PLATFORM.getServer();
48-
if (server == null) {
49-
BaseLogger.log(true, BaseLogLevel.ERROR, BlueTranslation.translate("server.null"));
50-
return;
51-
}
52-
53-
for (ServerPlayer player : server.getPlayerList().getPlayers()) {
48+
default void sendToPlayersAround(@NotNull MinecraftServer pServer, @NotNull Double pX, @NotNull Double pY, @NotNull Double pZ, @NotNull Double pDistance, @NotNull ResourceKey<Level> pWorldKey, @NotNull Predicate<ServerPlayer> pExclusionCondition) {
49+
for (ServerPlayer player : pServer.getPlayerList().getPlayers()) {
5450
if (pExclusionCondition.test(player)) continue;
5551
if (!player.level().dimension().equals(pWorldKey)) continue;
5652

@@ -63,8 +59,8 @@ default void sendToPlayersAround(@NotNull Double pX, @NotNull Double pY, @NotNul
6359
}
6460
}
6561

66-
default void sendToPlayersAround(@NotNull Double pX, @NotNull Double pY, @NotNull Double pZ, @NotNull Double pDistance, @NotNull ResourceKey<Level> pWorldKey) {
67-
sendToPlayersAround(pX, pY, pZ, pDistance, pWorldKey, player -> false);
62+
default void sendToPlayersAround(@NotNull MinecraftServer pServer, @NotNull Double pX, @NotNull Double pY, @NotNull Double pZ, @NotNull Double pDistance, @NotNull ResourceKey<Level> pWorldKey) {
63+
sendToPlayersAround(pServer, pX, pY, pZ, pDistance, pWorldKey, player -> false);
6864
}
6965

7066
@Override

common/src/main/java/software/bluelib/api/net/NetworkRegistry.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import java.util.ArrayList;
1111
import java.util.List;
12+
13+
import net.minecraft.client.Minecraft;
1214
import net.minecraft.core.BlockPos;
1315
import net.minecraft.server.MinecraftServer;
1416
import net.minecraft.server.level.ServerLevel;
@@ -22,7 +24,7 @@
2224
import software.bluelib.internal.BlueTranslation;
2325
import software.bluelib.net.PacketRegisterInfo;
2426

25-
@SuppressWarnings({ "unused" })
27+
@SuppressWarnings({"unused"})
2628
public class NetworkRegistry {
2729

2830
public static void sendPacket(@NotNull ServerPlayer pPlayer, @NotNull NetworkPacket<?> pPacket) {
@@ -37,13 +39,8 @@ public static void sendPacketToPlayer(@NotNull ServerPlayer pPlayer, @NotNull Ne
3739
BlueLibConstants.PlatformHelper.REGISTRY.getNetwork().sendPacketToPlayer(pPlayer, pPacket);
3840
}
3941

40-
public static void sendToAllPlayers(@NotNull NetworkPacket<?> pPacket) {
41-
MinecraftServer server = BlueLibConstants.PlatformHelper.PLATFORM.getServer();
42-
if (server == null) {
43-
BaseLogger.log(true, BaseLogLevel.ERROR, BlueTranslation.translate("server.null"));
44-
return;
45-
}
46-
sendPacketToPlayers(server.getPlayerList().getPlayers(), pPacket);
42+
public static void sendToAllPlayers(@NotNull MinecraftServer pServer, @NotNull NetworkPacket<?> pPacket) {
43+
sendPacketToPlayers(pServer.getPlayerList().getPlayers(), pPacket);
4744
}
4845

4946
public static void sendPacketToPlayers(@NotNull Iterable<ServerPlayer> pPlayers, @NotNull NetworkPacket<?> pPacket) {

common/src/main/java/software/bluelib/commands/OpenLoggerScreenCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ private static int openLogScreen(@NotNull CommandContext<CommandSourceStack> pCo
3131
pContext.getSource().sendFailure(BlueTranslation.translate("command.logger.no_player"));
3232
return 0;
3333
}
34+
NetworkRegistry.sendPacketToPlayer(player, new OpenLoggerPacket());
3435
if (player.hasPermissions(3)) {
3536
NetworkRegistry.sendPacketToPlayer(player, new OpenLoggerPacket());
3637
} else {

common/src/main/java/software/bluelib/config/LoggerConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ public class LoggerConfig {
1515
public static boolean isBlueLibLoggingEnabled = false;
1616
public static boolean isLoggingEnabled = false;
1717
@ApiStatus.Internal
18-
public static final boolean isExampleEnabled = false;
18+
public static final boolean isExampleEnabled = true;
1919
}

common/src/main/java/software/bluelib/platform/IPlatformHelper.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,4 @@ default String getEnvironmentName() {
4848

4949
@NotNull
5050
ModAPI getAPI();
51-
52-
@Nullable
53-
MinecraftServer getServer();
5451
}

fabric/src/main/java/software/bluelib/platform/FabricPlatformClientHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
import net.fabricmc.api.EnvType;
1111
import net.fabricmc.api.Environment;
12+
import net.minecraft.client.Minecraft;
1213
import net.minecraft.client.model.HumanoidModel;
14+
import net.minecraft.server.MinecraftServer;
1315
import net.minecraft.world.entity.EquipmentSlot;
1416
import net.minecraft.world.entity.LivingEntity;
1517
import net.minecraft.world.item.ItemStack;

fabric/src/main/java/software/bluelib/platform/FabricPlatformHelper.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.Optional;
1414
import java.util.Set;
1515
import java.util.stream.Collectors;
16+
1617
import net.fabricmc.api.EnvType;
1718
import net.fabricmc.loader.api.FabricLoader;
1819
import net.fabricmc.loader.api.ModContainer;
@@ -27,6 +28,9 @@
2728

2829
public class FabricPlatformHelper implements IPlatformHelper {
2930

31+
public FabricPlatformHelper() {
32+
}
33+
3034
@Override
3135
public @NotNull String getPlatformName() {
3236
return "Fabric";
@@ -85,9 +89,4 @@ public boolean isPhysicalClient() {
8589
public @NotNull ModAPI getAPI() {
8690
return ModAPI.FABRIC;
8791
}
88-
89-
@Override
90-
public @Nullable MinecraftServer getServer() {
91-
return this.getEnvironment() == Environment.CLIENT ? Minecraft.getInstance().getSingleplayerServer() : BlueLibConstants.server;
92-
}
9392
}

fabric/src/main/resources/bluelib.fabric.mixins.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@
33
"minVersion": "0.8",
44
"package": "software.bluelib.mixin",
55
"refmap": "${mod_id}.refmap.json",
6-
"mixins": [],
6+
"mixins": [
7+
"common.brewing.BrewingStandBlockEntityMixin",
8+
"common.brewing.BrewingStandMenuMixin",
9+
"common.brewing.IngredientSlotMixin",
10+
"common.brewing.PotionSlotMixin",
11+
"common.loader.AbstractContainerMenuMixin",
12+
"common.loader.ItemStackMixin",
13+
"common.variant.LivingEntityMixin"
14+
],
715
"client": [
8-
"client.HumanoidArmorLayerMixin"
16+
"client.HumanoidArmorLayerMixin",
17+
"client.BlockEntityWithoutLevelRendererMixin",
18+
"client.LevelRendererMixin",
19+
"client.TextureManagerMixin",
20+
"client.VersionWarningMixin"
921
],
1022
"server": [],
1123
"injectors": {

neoforge/src/main/java/software/bluelib/BlueLib.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,18 @@
2828
public class BlueLib {
2929

3030
public BlueLib(@NotNull IEventBus pModEventBus, @NotNull ModContainer pModContainer) {
31+
pModEventBus.addListener(EventPriority.HIGHEST, NeoForgeNetworkManager::registerMessages);
32+
3133
NeoForgeRegistryHelper.register(pModEventBus);
3234

35+
setupEventListeners(pModEventBus);
36+
3337
BlueLibCommon.doRegistration();
3438

3539
if (FMLEnvironment.dist == Dist.CLIENT)
3640
BlueLibClient.init(pModContainer);
3741

3842
registerConfigs(pModContainer);
39-
setupEventListeners(pModEventBus);
4043

4144
NeoForgeReloadHandler.registerProvider(new VariantProvider());
4245
}
@@ -48,7 +51,6 @@ private void registerConfigs(@NotNull ModContainer pModContainer) {
4851

4952
private void setupEventListeners(@NotNull IEventBus pModEventBus) {
5053
pModEventBus.register(this);
51-
pModEventBus.addListener(NeoForgeNetworkManager::registerMessages);
5254
}
5355

5456
@SubscribeEvent(priority = EventPriority.LOWEST)

0 commit comments

Comments
 (0)