From c602d8d8375720c2e7f4753dc1cbc2dd06daa3e3 Mon Sep 17 00:00:00 2001 From: Louis <82884007+Dev0Louis@users.noreply.github.com> Date: Mon, 29 Jan 2024 01:15:44 +0100 Subject: [PATCH] 5.1.0 :) (#34) * Nebula V5.1 * First Api Breakage! :) Becuase we need it --------- --- gradle.properties | 2 +- .../nebulo/manager/ManagerRegisterer.java | 15 ++++++- .../java/dev/louis/nebula/NebulaManager.java | 41 ++++++++++++------- .../ManaManagerRegistrableView.java | 7 ++-- .../SpellManagerRegistrableView.java | 7 ++-- 5 files changed, 49 insertions(+), 23 deletions(-) diff --git a/gradle.properties b/gradle.properties index 218bdad..d2b250c 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.0.0 +mod_version=5.1.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 900c56f..901efa7 100644 --- a/nebulo/src/main/java/dev/louis/nebulo/manager/ManagerRegisterer.java +++ b/nebulo/src/main/java/dev/louis/nebulo/manager/ManagerRegisterer.java @@ -4,20 +4,31 @@ import dev.louis.nebula.api.manager.mana.registerable.ManaManagerRegistrableView; import dev.louis.nebula.api.manager.spell.entrypoint.RegisterSpellManagerEntrypoint; import dev.louis.nebula.api.manager.spell.registerable.SpellManagerRegistrableView; +import dev.louis.nebula.manager.mana.NebulaManaManager; +import dev.louis.nebula.manager.spell.NebulaSpellManager; import dev.louis.nebula.networking.SyncManaS2CPacket; import dev.louis.nebula.networking.UpdateSpellCastabilityS2CPacket; import dev.louis.nebulo.manager.mana.NebuloManaManager; import dev.louis.nebulo.manager.spell.NebuloSpellManager; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; public class ManagerRegisterer implements RegisterManaManagerEntrypoint, RegisterSpellManagerEntrypoint { @Override public void registerSpell(ManaManagerRegistrableView manaManagerRegistrableView) { - manaManagerRegistrableView.registerManaManager(NebuloManaManager::new, SyncManaS2CPacket.ID, NebuloManaManager::receiveSync); + manaManagerRegistrableView.registerManaManager( + NebuloManaManager::new, + SyncManaS2CPacket.ID, + (packetId) -> ClientPlayNetworking.registerGlobalReceiver(packetId, NebulaManaManager::receiveSync) + ); } @Override public void registerSpell(SpellManagerRegistrableView spellManagerRegistrableView) { - spellManagerRegistrableView.registerSpellManager(NebuloSpellManager::new, UpdateSpellCastabilityS2CPacket.ID, NebuloSpellManager::receiveSync); + spellManagerRegistrableView.registerSpellManager( + NebuloSpellManager::new, + UpdateSpellCastabilityS2CPacket.ID, + (packetId) -> ClientPlayNetworking.registerGlobalReceiver(packetId, NebulaSpellManager::receiveSync) + ); } @Override diff --git a/src/main/java/dev/louis/nebula/NebulaManager.java b/src/main/java/dev/louis/nebula/NebulaManager.java index 25578d0..e23fbb7 100644 --- a/src/main/java/dev/louis/nebula/NebulaManager.java +++ b/src/main/java/dev/louis/nebula/NebulaManager.java @@ -21,6 +21,7 @@ import org.jetbrains.annotations.ApiStatus; import java.util.List; +import java.util.function.Consumer; @ApiStatus.Internal public class NebulaManager implements ManaManagerRegistrableView, SpellManagerRegistrableView { @@ -29,10 +30,12 @@ public class NebulaManager implements ManaManagerRegistrableView, SpellManagerRe private static ModContainer spellManagerMod; private static SpellManager.Factory spellManagerFactory; private static boolean isLocked = false; - private static ClientPlayNetworking.PlayChannelHandler spellPlayChannelHandler; - private static ClientPlayNetworking.PlayChannelHandler manaPlayChannelHandler; + private static Identifier manaPacketId; + private static Consumer manaPacketRegisterer; + private static Identifier spellPacketId; + private static Consumer spellPacketRegisterer; private NebulaManager() {} @@ -62,11 +65,21 @@ public static SpellManager createSpellManager(PlayerEntity player) { public void lock() { if(spellManagerFactory == null) { - registerSpellManager(NebulaSpellManager::new, UpdateSpellCastabilityS2CPacket.ID, NebulaSpellManager::receiveSync); + registerSpellManager( + NebulaSpellManager::new, + UpdateSpellCastabilityS2CPacket.ID, + (packetId) -> ClientPlayNetworking.registerGlobalReceiver(packetId, NebulaSpellManager::receiveSync) + ); + spellManagerMod = FabricLoader.getInstance().getModContainer(Nebula.MOD_ID).orElseThrow(); } if(manaManagerFactory == null) { - registerManaManager(NebulaManaManager::new, SyncManaS2CPacket.ID, NebulaManaManager::receiveSync); + registerManaManager( + NebulaManaManager::new, + SyncManaS2CPacket.ID, + (packetId) -> ClientPlayNetworking.registerGlobalReceiver(packetId, NebulaManaManager::receiveSync) + ); + manaManagerMod = FabricLoader.getInstance().getModContainer(Nebula.MOD_ID).orElseThrow(); } isLocked = true; @@ -75,23 +88,23 @@ public void lock() { @Override public void registerManaManager( ManaManager.Factory manaManagerFactory, - Identifier packetId, - ClientPlayNetworking.PlayChannelHandler manaChannelHandler + Identifier manaPacketId, + Consumer manaPacketRegisterer ) { NebulaManager.manaManagerFactory = manaManagerFactory; - NebulaManager.manaPacketId = packetId; - NebulaManager.manaPlayChannelHandler = manaChannelHandler; + NebulaManager.manaPacketId = manaPacketId; + NebulaManager.manaPacketRegisterer = manaPacketRegisterer; } @Override public void registerSpellManager( SpellManager.Factory spellManagerFactory, - Identifier packetId, - ClientPlayNetworking.PlayChannelHandler spellChannelHandler + Identifier spellPacketId, + Consumer spellPacketRegisterer ) { NebulaManager.spellManagerFactory = spellManagerFactory; - NebulaManager.spellPacketId = packetId; - NebulaManager.spellPlayChannelHandler = spellChannelHandler; + NebulaManager.spellPacketId = spellPacketId; + NebulaManager.spellPacketRegisterer = spellPacketRegisterer; } /** @@ -153,9 +166,9 @@ public static void registerPacketReceivers() { if(!NebulaManager.isLocked) { throw new IllegalStateException("NebulaManager is not locked yet!"); } - ClientPlayNetworking.registerGlobalReceiver(NebulaManager.manaPacketId, NebulaManager.manaPlayChannelHandler); + NebulaManager.manaPacketRegisterer.accept(NebulaManager.manaPacketId); Nebula.LOGGER.info("Registered ManaManager Packet Receiver with id: " + NebulaManager.manaPacketId); - ClientPlayNetworking.registerGlobalReceiver(NebulaManager.spellPacketId, NebulaManager.spellPlayChannelHandler); + NebulaManager.spellPacketRegisterer.accept(NebulaManager.spellPacketId); Nebula.LOGGER.info("Registered SpellManager Packet Receiver with id: " + NebulaManager.spellPacketId); } } 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 1b2be6a..5f7f85d 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,13 +1,14 @@ package dev.louis.nebula.api.manager.mana.registerable; import dev.louis.nebula.api.manager.mana.ManaManager; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.minecraft.util.Identifier; +import java.util.function.Consumer; + public interface ManaManagerRegistrableView { void registerManaManager( ManaManager.Factory manaManagerFactory, - Identifier packetId, - ClientPlayNetworking.PlayChannelHandler channelHandler + Identifier manaPacketId, + Consumer manaPacketRegisterer ); } \ No newline at end of file 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 4733d1b..4621209 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,13 +1,14 @@ package dev.louis.nebula.api.manager.spell.registerable; import dev.louis.nebula.api.manager.spell.SpellManager; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.minecraft.util.Identifier; +import java.util.function.Consumer; + public interface SpellManagerRegistrableView { void registerSpellManager( SpellManager.Factory manaManagerFactory, - Identifier packetId, - ClientPlayNetworking.PlayChannelHandler channelHandler + Identifier spellPacketId, + Consumer spellPacketRegisterer ); } \ No newline at end of file