Skip to content

Commit

Permalink
5.2.0 :) (#35)
Browse files Browse the repository at this point in the history
* Nebula V5

* Updating 5.2 :)
I broke Spell/ManaManager overwrite again whooops!

* remove unused field
  • Loading branch information
Dev0Louis authored Feb 5, 2024
1 parent c602d8d commit 80a5ea7
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 82 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.1.0
mod_version=5.2.0
maven_group=dev.louis
archives_base_name=Nebula
# Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nebulo/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
],
"depends": {
"fabricloader": ">=0.15.3",
"nebula": ">=5.0.0-",
"nebula": ">=5.2.0-",
"fabric": "*",
"minecraft": "${supported_version}"
}
Expand Down
63 changes: 26 additions & 37 deletions src/main/java/dev/louis/nebula/NebulaManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Identifier> manaPacketRegisterer;

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

private NebulaManager() {}

Expand Down Expand Up @@ -65,46 +65,31 @@ 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();
}
isLocked = true;
}

@Override
public void registerManaManager(
ManaManager.Factory<?> manaManagerFactory,
Identifier manaPacketId,
Consumer<Identifier> 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<Identifier> spellPacketRegisterer
) {
public void registerSpellManager(SpellManager.Factory<?> spellManagerFactory) {
NebulaManager.spellManagerFactory = spellManagerFactory;
NebulaManager.spellPacketId = spellPacketId;
NebulaManager.spellPacketRegisterer = spellPacketRegisterer;
}

/**
Expand Down Expand Up @@ -137,18 +122,23 @@ private void runEntrypointsOrThrow() {
runEntryPoints(getFirstOrNull(manaManagerEntrypoints), getFirstOrNull(spellManagerEntrypoints));
}


private void runEntryPoints(
EntrypointContainer<RegisterManaManagerEntrypoint> manaManagerEntrypointEntrypointContainer,
EntrypointContainer<RegisterSpellManagerEntrypoint> 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);
}
}

Expand All @@ -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();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Identifier> manaPacketRegisterer
);
void registerManaManager(ManaManager.Factory<?> manaManagerFactory);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Identifier> spellPacketRegisterer
);
void registerSpellManager(SpellManager.Factory<?> spellManagerFactory);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 80a5ea7

Please sign in to comment.