Skip to content

Commit

Permalink
5.1.0 :) (#34)
Browse files Browse the repository at this point in the history
* Nebula V5.1

* First Api Breakage! :)
Becuase we need it

---------
  • Loading branch information
Dev0Louis authored Jan 29, 2024
1 parent 309fbc2 commit c602d8d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 23 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 27 additions & 14 deletions src/main/java/dev/louis/nebula/NebulaManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<Identifier> manaPacketRegisterer;

private static Identifier spellPacketId;
private static Consumer<Identifier> spellPacketRegisterer;

private NebulaManager() {}

Expand Down Expand Up @@ -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;
Expand All @@ -75,23 +88,23 @@ public void lock() {
@Override
public void registerManaManager(
ManaManager.Factory<?> manaManagerFactory,
Identifier packetId,
ClientPlayNetworking.PlayChannelHandler manaChannelHandler
Identifier manaPacketId,
Consumer<Identifier> 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<Identifier> spellPacketRegisterer
) {
NebulaManager.spellManagerFactory = spellManagerFactory;
NebulaManager.spellPacketId = packetId;
NebulaManager.spellPlayChannelHandler = spellChannelHandler;
NebulaManager.spellPacketId = spellPacketId;
NebulaManager.spellPacketRegisterer = spellPacketRegisterer;
}

/**
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<Identifier> manaPacketRegisterer
);
}
Original file line number Diff line number Diff line change
@@ -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<Identifier> spellPacketRegisterer
);
}

0 comments on commit c602d8d

Please sign in to comment.