diff --git a/gradle.properties b/gradle.properties index d2b250c..1792643 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ supported_version=>=1.20.2 yarn_mappings=1.20.4+build.3 loader_version=0.15.6 # Mod Properties -mod_version=5.1.0 +mod_version=5.2.0 maven_group=dev.louis archives_base_name=Nebula # Dependencies diff --git a/nebulo/src/main/java/dev/louis/nebulo/manager/ManagerRegisterer.java b/nebulo/src/main/java/dev/louis/nebulo/manager/ManagerRegisterer.java index 901efa7..45662fe 100644 --- a/nebulo/src/main/java/dev/louis/nebulo/manager/ManagerRegisterer.java +++ b/nebulo/src/main/java/dev/louis/nebulo/manager/ManagerRegisterer.java @@ -14,21 +14,23 @@ public class ManagerRegisterer implements RegisterManaManagerEntrypoint, RegisterSpellManagerEntrypoint { @Override - public void registerSpell(ManaManagerRegistrableView manaManagerRegistrableView) { - manaManagerRegistrableView.registerManaManager( - NebuloManaManager::new, - SyncManaS2CPacket.ID, - (packetId) -> ClientPlayNetworking.registerGlobalReceiver(packetId, NebulaManaManager::receiveSync) - ); + public void registerManaManager(ManaManagerRegistrableView manaManagerRegistrableView) { + manaManagerRegistrableView.registerManaManager(NebuloManaManager::new); } @Override - public void registerSpell(SpellManagerRegistrableView spellManagerRegistrableView) { - spellManagerRegistrableView.registerSpellManager( - NebuloSpellManager::new, - UpdateSpellCastabilityS2CPacket.ID, - (packetId) -> ClientPlayNetworking.registerGlobalReceiver(packetId, NebulaSpellManager::receiveSync) - ); + public void registerManaPacketReceiver() { + ClientPlayNetworking.registerGlobalReceiver(SyncManaS2CPacket.TYPE, NebulaManaManager::receiveSync); + } + + @Override + public void registerSpellManager(SpellManagerRegistrableView spellManagerRegistrableView) { + spellManagerRegistrableView.registerSpellManager(NebuloSpellManager::new); + } + + @Override + public void registerSpellPacketReceiver() { + ClientPlayNetworking.registerGlobalReceiver(UpdateSpellCastabilityS2CPacket.TYPE, NebulaSpellManager::receiveSync); } @Override diff --git a/nebulo/src/main/resources/fabric.mod.json b/nebulo/src/main/resources/fabric.mod.json index c5d3eae..3c595a3 100644 --- a/nebulo/src/main/resources/fabric.mod.json +++ b/nebulo/src/main/resources/fabric.mod.json @@ -29,7 +29,7 @@ ], "depends": { "fabricloader": ">=0.15.3", - "nebula": ">=5.0.0-", + "nebula": ">=5.2.0-", "fabric": "*", "minecraft": "${supported_version}" } diff --git a/src/main/java/dev/louis/nebula/NebulaManager.java b/src/main/java/dev/louis/nebula/NebulaManager.java index e23fbb7..4661c93 100644 --- a/src/main/java/dev/louis/nebula/NebulaManager.java +++ b/src/main/java/dev/louis/nebula/NebulaManager.java @@ -17,25 +17,25 @@ import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.entrypoint.EntrypointContainer; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.Identifier; import org.jetbrains.annotations.ApiStatus; import java.util.List; -import java.util.function.Consumer; @ApiStatus.Internal public class NebulaManager implements ManaManagerRegistrableView, SpellManagerRegistrableView { + private static boolean isLocked = false; + + private static RegisterManaManagerEntrypoint manaManagerEntrypoint; private static ModContainer manaManagerMod; private static ManaManager.Factory manaManagerFactory; + private static Runnable manaPacketRegisterer = () -> manaManagerEntrypoint.registerManaPacketReceiver(); + + private static RegisterSpellManagerEntrypoint spellManagerEntrypoint; private static ModContainer spellManagerMod; private static SpellManager.Factory spellManagerFactory; - private static boolean isLocked = false; + private static Runnable spellPacketRegisterer = () -> spellManagerEntrypoint.registerSpellPacketReceiver(); - private static Identifier manaPacketId; - private static Consumer manaPacketRegisterer; - private static Identifier spellPacketId; - private static Consumer spellPacketRegisterer; private NebulaManager() {} @@ -65,20 +65,16 @@ public static SpellManager createSpellManager(PlayerEntity player) { public void lock() { if(spellManagerFactory == null) { - registerSpellManager( - NebulaSpellManager::new, - UpdateSpellCastabilityS2CPacket.ID, - (packetId) -> ClientPlayNetworking.registerGlobalReceiver(packetId, NebulaSpellManager::receiveSync) - ); + registerSpellManager(NebulaSpellManager::new); spellManagerMod = FabricLoader.getInstance().getModContainer(Nebula.MOD_ID).orElseThrow(); + spellPacketRegisterer = () -> + ClientPlayNetworking.registerGlobalReceiver(SyncManaS2CPacket.TYPE, NebulaManaManager::receiveSync); } if(manaManagerFactory == null) { - registerManaManager( - NebulaManaManager::new, - SyncManaS2CPacket.ID, - (packetId) -> ClientPlayNetworking.registerGlobalReceiver(packetId, NebulaManaManager::receiveSync) - ); + registerManaManager(NebulaManaManager::new); + manaPacketRegisterer = () -> + ClientPlayNetworking.registerGlobalReceiver(UpdateSpellCastabilityS2CPacket.TYPE, NebulaSpellManager::receiveSync); manaManagerMod = FabricLoader.getInstance().getModContainer(Nebula.MOD_ID).orElseThrow(); } @@ -86,25 +82,14 @@ public void lock() { } @Override - public void registerManaManager( - ManaManager.Factory manaManagerFactory, - Identifier manaPacketId, - Consumer manaPacketRegisterer - ) { + public void registerManaManager(ManaManager.Factory manaManagerFactory) { NebulaManager.manaManagerFactory = manaManagerFactory; - NebulaManager.manaPacketId = manaPacketId; - NebulaManager.manaPacketRegisterer = manaPacketRegisterer; } + @Override - public void registerSpellManager( - SpellManager.Factory spellManagerFactory, - Identifier spellPacketId, - Consumer spellPacketRegisterer - ) { + public void registerSpellManager(SpellManager.Factory spellManagerFactory) { NebulaManager.spellManagerFactory = spellManagerFactory; - NebulaManager.spellPacketId = spellPacketId; - NebulaManager.spellPacketRegisterer = spellPacketRegisterer; } /** @@ -137,18 +122,23 @@ private void runEntrypointsOrThrow() { runEntryPoints(getFirstOrNull(manaManagerEntrypoints), getFirstOrNull(spellManagerEntrypoints)); } + private void runEntryPoints( EntrypointContainer manaManagerEntrypointEntrypointContainer, EntrypointContainer spellManagerEntrypointEntrypointContainer ) { if(manaManagerEntrypointEntrypointContainer != null) { - manaManagerEntrypointEntrypointContainer.getEntrypoint().registerSpell(this); + NebulaManager.manaManagerEntrypoint = manaManagerEntrypointEntrypointContainer.getEntrypoint(); NebulaManager.manaManagerMod = manaManagerEntrypointEntrypointContainer.getProvider(); + + NebulaManager.manaManagerEntrypoint.registerManaManager(this); } if(spellManagerEntrypointEntrypointContainer != null) { - spellManagerEntrypointEntrypointContainer.getEntrypoint().registerSpell(this); + NebulaManager.spellManagerEntrypoint = spellManagerEntrypointEntrypointContainer.getEntrypoint(); NebulaManager.spellManagerMod = spellManagerEntrypointEntrypointContainer.getProvider(); + + NebulaManager.spellManagerEntrypoint.registerSpellManager(this); } } @@ -166,9 +156,8 @@ public static void registerPacketReceivers() { if(!NebulaManager.isLocked) { throw new IllegalStateException("NebulaManager is not locked yet!"); } - NebulaManager.manaPacketRegisterer.accept(NebulaManager.manaPacketId); - Nebula.LOGGER.info("Registered ManaManager Packet Receiver with id: " + NebulaManager.manaPacketId); - NebulaManager.spellPacketRegisterer.accept(NebulaManager.spellPacketId); - Nebula.LOGGER.info("Registered SpellManager Packet Receiver with id: " + NebulaManager.spellPacketId); + NebulaManager.manaPacketRegisterer.run(); + NebulaManager.spellPacketRegisterer.run(); + } } diff --git a/src/main/java/dev/louis/nebula/api/manager/mana/entrypoint/RegisterManaManagerEntrypoint.java b/src/main/java/dev/louis/nebula/api/manager/mana/entrypoint/RegisterManaManagerEntrypoint.java index a890f0b..46c2600 100644 --- a/src/main/java/dev/louis/nebula/api/manager/mana/entrypoint/RegisterManaManagerEntrypoint.java +++ b/src/main/java/dev/louis/nebula/api/manager/mana/entrypoint/RegisterManaManagerEntrypoint.java @@ -6,7 +6,9 @@ * The entrypoint for registering a custom mana manager. */ public interface RegisterManaManagerEntrypoint { - void registerSpell(ManaManagerRegistrableView manaManagerRegistrableView); + void registerManaManager(ManaManagerRegistrableView manaManagerRegistrableView); + + void registerManaPacketReceiver(); default boolean shouldRegister() { return true; diff --git a/src/main/java/dev/louis/nebula/api/manager/mana/registerable/ManaManagerRegistrableView.java b/src/main/java/dev/louis/nebula/api/manager/mana/registerable/ManaManagerRegistrableView.java index 5f7f85d..47f2140 100644 --- a/src/main/java/dev/louis/nebula/api/manager/mana/registerable/ManaManagerRegistrableView.java +++ b/src/main/java/dev/louis/nebula/api/manager/mana/registerable/ManaManagerRegistrableView.java @@ -1,14 +1,7 @@ package dev.louis.nebula.api.manager.mana.registerable; import dev.louis.nebula.api.manager.mana.ManaManager; -import net.minecraft.util.Identifier; - -import java.util.function.Consumer; public interface ManaManagerRegistrableView { - void registerManaManager( - ManaManager.Factory manaManagerFactory, - Identifier manaPacketId, - Consumer manaPacketRegisterer - ); + void registerManaManager(ManaManager.Factory manaManagerFactory); } \ No newline at end of file diff --git a/src/main/java/dev/louis/nebula/api/manager/spell/entrypoint/RegisterSpellManagerEntrypoint.java b/src/main/java/dev/louis/nebula/api/manager/spell/entrypoint/RegisterSpellManagerEntrypoint.java index 4c48820..86947cb 100644 --- a/src/main/java/dev/louis/nebula/api/manager/spell/entrypoint/RegisterSpellManagerEntrypoint.java +++ b/src/main/java/dev/louis/nebula/api/manager/spell/entrypoint/RegisterSpellManagerEntrypoint.java @@ -6,7 +6,9 @@ * The entrypoint for registering a custom spell manager. */ public interface RegisterSpellManagerEntrypoint { - void registerSpell(SpellManagerRegistrableView spellManagerRegistrableView); + void registerSpellManager(SpellManagerRegistrableView spellManagerRegistrableView); + + void registerSpellPacketReceiver(); default boolean shouldRegister() { return true; diff --git a/src/main/java/dev/louis/nebula/api/manager/spell/registerable/SpellManagerRegistrableView.java b/src/main/java/dev/louis/nebula/api/manager/spell/registerable/SpellManagerRegistrableView.java index 4621209..5fbfbc0 100644 --- a/src/main/java/dev/louis/nebula/api/manager/spell/registerable/SpellManagerRegistrableView.java +++ b/src/main/java/dev/louis/nebula/api/manager/spell/registerable/SpellManagerRegistrableView.java @@ -1,14 +1,7 @@ package dev.louis.nebula.api.manager.spell.registerable; import dev.louis.nebula.api.manager.spell.SpellManager; -import net.minecraft.util.Identifier; - -import java.util.function.Consumer; public interface SpellManagerRegistrableView { - void registerSpellManager( - SpellManager.Factory manaManagerFactory, - Identifier spellPacketId, - Consumer spellPacketRegisterer - ); + void registerSpellManager(SpellManager.Factory spellManagerFactory); } \ No newline at end of file diff --git a/src/main/java/dev/louis/nebula/manager/mana/NebulaManaManager.java b/src/main/java/dev/louis/nebula/manager/mana/NebulaManaManager.java index be75e47..83bff36 100644 --- a/src/main/java/dev/louis/nebula/manager/mana/NebulaManaManager.java +++ b/src/main/java/dev/louis/nebula/manager/mana/NebulaManaManager.java @@ -3,15 +3,14 @@ import dev.louis.nebula.Nebula; import dev.louis.nebula.api.manager.mana.ManaManager; import dev.louis.nebula.api.spell.SpellType; +import dev.louis.nebula.mixin.ClientPlayerEntityAccessor; import dev.louis.nebula.networking.SyncManaS2CPacket; import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.NbtCompound; -import net.minecraft.network.PacketByteBuf; import net.minecraft.server.network.ServerPlayerEntity; /** @@ -97,9 +96,8 @@ public boolean sendSync() { return false; } - public static boolean receiveSync(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) { - var packet = SyncManaS2CPacket.read(buf); - client.executeSync(() -> client.player.getManaManager().setMana(packet.mana())); + public static boolean receiveSync(SyncManaS2CPacket packet, ClientPlayerEntity player, PacketSender responseSender) { + ((ClientPlayerEntityAccessor)player).getClient().executeSync(() -> player.getManaManager().setMana(packet.mana())); return true; } diff --git a/src/main/java/dev/louis/nebula/manager/spell/NebulaSpellManager.java b/src/main/java/dev/louis/nebula/manager/spell/NebulaSpellManager.java index 2b21cb8..6981437 100644 --- a/src/main/java/dev/louis/nebula/manager/spell/NebulaSpellManager.java +++ b/src/main/java/dev/louis/nebula/manager/spell/NebulaSpellManager.java @@ -5,18 +5,17 @@ import dev.louis.nebula.api.manager.spell.SpellManager; import dev.louis.nebula.api.spell.Spell; import dev.louis.nebula.api.spell.SpellType; +import dev.louis.nebula.mixin.ClientPlayerEntityAccessor; import dev.louis.nebula.networking.SpellCastC2SPacket; import dev.louis.nebula.networking.UpdateSpellCastabilityS2CPacket; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtList; -import net.minecraft.network.PacketByteBuf; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.ActionResult; import net.minecraft.util.Identifier; @@ -157,10 +156,9 @@ public boolean sendSync() { } - public static boolean receiveSync(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) { - UpdateSpellCastabilityS2CPacket packet = UpdateSpellCastabilityS2CPacket.read(buf); - MinecraftClient.getInstance().executeSync(() -> { - var spellManager = client.player.getSpellManager(); + public static boolean receiveSync(UpdateSpellCastabilityS2CPacket packet, ClientPlayerEntity player, PacketSender responseSender) { + ((ClientPlayerEntityAccessor)player).getClient().executeSync(() -> { + SpellManager spellManager = player.getSpellManager(); packet.spells().forEach((spellType, learned) -> { if (learned) spellManager.learnSpell(spellType); else spellManager.forgetSpell(spellType);