From 1d7200279c163c50f84dff1881804ff025c6907f Mon Sep 17 00:00:00 2001 From: D1p4k <82884007+D1p4k@users.noreply.github.com> Date: Tue, 5 Dec 2023 21:47:57 +0100 Subject: [PATCH 01/10] Next Beta --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 3a460fe..4b391ca 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ minecraft_version=1.20.3 yarn_mappings=1.20.3+build.1 loader_version=0.15.0 # Mod Properties -mod_version=4.0.0-beta.1 +mod_version=4.0.0-beta.2 maven_group=dev.louis archives_base_name=Nebula # Dependencies From b26cd9052a83aefe41b98100d145a1c8a18ed36b Mon Sep 17 00:00:00 2001 From: D1p4k <82884007+D1p4k@users.noreply.github.com> Date: Tue, 5 Dec 2023 21:48:22 +0100 Subject: [PATCH 02/10] Add /nebula learnSpell --- src/main/java/dev/louis/nebula/command/NebulaCommand.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/louis/nebula/command/NebulaCommand.java b/src/main/java/dev/louis/nebula/command/NebulaCommand.java index 9cd4ad3..56a0afa 100644 --- a/src/main/java/dev/louis/nebula/command/NebulaCommand.java +++ b/src/main/java/dev/louis/nebula/command/NebulaCommand.java @@ -35,9 +35,9 @@ private static void register(CommandDispatcher dispatcher, command.then(getManaCommand); command.then(setManaCommand); - + var learnSpellCommand = literal("learnSpell"); Nebula.SPELL_REGISTRY.forEach(spellType -> { - command.then(CommandManager.literal(spellType.getId().toString()).executes(context -> { + learnSpellCommand.then(CommandManager.literal(spellType.getId().toString()).executes(context -> { if(context.getSource().isExecutedByPlayer()) { context.getSource().getPlayer().getSpellManager().learnSpell(spellType); } @@ -45,6 +45,7 @@ private static void register(CommandDispatcher dispatcher, })); }); + command.then(learnSpellCommand); dispatcher.register(command); } From 71d821f55aedd619ef24955b8f11cf54c0f29cb6 Mon Sep 17 00:00:00 2001 From: D1p4k <82884007+D1p4k@users.noreply.github.com> Date: Fri, 8 Dec 2023 21:03:34 +0100 Subject: [PATCH 03/10] Fix Stuff --- src/main/java/dev/louis/nebula/Nebula.java | 1 + .../nebula/mana/manager/ManaManager.java | 4 ++ .../mana/manager/NebulaManaManager.java | 22 +++++-- .../dev/louis/nebula/mixin/PlayerMixin.java | 6 +- .../nebula/mixin/ServerPlayerEntityMixin.java | 10 +++ .../java/dev/louis/nebula/spell/Spell.java | 5 ++ .../spell/manager/NebulaSpellManager.java | 19 +++--- .../nebula/spell/manager/SpellManager.java | 61 +++++++++++++++++++ 8 files changed, 110 insertions(+), 18 deletions(-) diff --git a/src/main/java/dev/louis/nebula/Nebula.java b/src/main/java/dev/louis/nebula/Nebula.java index e713fa5..0feedf4 100644 --- a/src/main/java/dev/louis/nebula/Nebula.java +++ b/src/main/java/dev/louis/nebula/Nebula.java @@ -27,6 +27,7 @@ public void onInitialize() { NebulaManager.INSTANCE.init(); NebulaCommand.init(); LOGGER.info("Nebula has initialized."); + } public void registerPacketReceivers() { diff --git a/src/main/java/dev/louis/nebula/mana/manager/ManaManager.java b/src/main/java/dev/louis/nebula/mana/manager/ManaManager.java index 8586a20..2228e10 100644 --- a/src/main/java/dev/louis/nebula/mana/manager/ManaManager.java +++ b/src/main/java/dev/louis/nebula/mana/manager/ManaManager.java @@ -24,6 +24,10 @@ public interface ManaManager { int getMaxMana(); + boolean hasEnoughMana(int mana); + + boolean hasEnoughMana(SpellType spellType); + boolean sendSync(); boolean receiveSync(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender); diff --git a/src/main/java/dev/louis/nebula/mana/manager/NebulaManaManager.java b/src/main/java/dev/louis/nebula/mana/manager/NebulaManaManager.java index 2410587..1d44068 100644 --- a/src/main/java/dev/louis/nebula/mana/manager/NebulaManaManager.java +++ b/src/main/java/dev/louis/nebula/mana/manager/NebulaManaManager.java @@ -33,20 +33,20 @@ public int getMana() { } public void setMana(int mana, boolean syncToClient) { - this.mana = Math.max(Math.min(mana, getMaxMana()), 0); - if(syncToClient) sendSync(); + this.mana = Math.max(Math.min(mana, this.getMaxMana()), 0); + if(syncToClient) this.sendSync(); } public void setMana(int mana) { - setMana(mana, true); + this.setMana(mana, true); } public void addMana(int mana) { - setMana(getMana() + mana); + this.setMana(this.getMana() + mana); } public void drainMana(int mana) { - setMana(getMana() - mana); + this.setMana(this.getMana() - mana); } public void drainMana(SpellType spellType) { @@ -57,11 +57,21 @@ public int getMaxMana() { return 20; } + @Override + public boolean hasEnoughMana(int mana) { + return this.getMana() >= mana; + } + + @Override + public boolean hasEnoughMana(SpellType spellType) { + return this.hasEnoughMana(spellType.getManaCost()); + } + @Override public boolean sendSync() { if (this.player instanceof ServerPlayerEntity serverPlayerEntity) { if (serverPlayerEntity.networkHandler != null) { - int syncMana = this.player.getManaManager().getMana(); + int syncMana = this.getMana(); if (syncMana == this.lastSyncedMana) return true; this.lastSyncedMana = syncMana; ServerPlayNetworking.send( diff --git a/src/main/java/dev/louis/nebula/mixin/PlayerMixin.java b/src/main/java/dev/louis/nebula/mixin/PlayerMixin.java index dc35794..c1ae5e1 100644 --- a/src/main/java/dev/louis/nebula/mixin/PlayerMixin.java +++ b/src/main/java/dev/louis/nebula/mixin/PlayerMixin.java @@ -10,12 +10,16 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.NbtCompound; import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Debug; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +@Debug( + export = true +) @Mixin(PlayerEntity.class) public abstract class PlayerMixin extends LivingEntity implements NebulaPlayer { protected PlayerMixin(EntityType entityType, World world) { @@ -45,7 +49,7 @@ public void tickManaAndSpellManager(CallbackInfo ci) { this.spellManager.tick(); } - @Inject(method = "onDeath", at = @At("HEAD")) + @Inject(method = "onDeath", at = @At("RETURN")) public void informManaAndSpellManagerOfDeath(DamageSource damageSource, CallbackInfo ci) { this.manaManager.onDeath(damageSource); this.spellManager.onDeath(damageSource); diff --git a/src/main/java/dev/louis/nebula/mixin/ServerPlayerEntityMixin.java b/src/main/java/dev/louis/nebula/mixin/ServerPlayerEntityMixin.java index 8294f67..6f3dd2b 100644 --- a/src/main/java/dev/louis/nebula/mixin/ServerPlayerEntityMixin.java +++ b/src/main/java/dev/louis/nebula/mixin/ServerPlayerEntityMixin.java @@ -2,6 +2,7 @@ import com.mojang.authlib.GameProfile; import dev.louis.nebula.Nebula; +import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.math.BlockPos; @@ -31,4 +32,13 @@ public void syncManaAndSpellsOnSpawn(CallbackInfo ci) { boolean hasManaSynced = this.getManaManager().sendSync(); if(!hasManaSynced) Nebula.LOGGER.info("Mana could not be synced!"); } + + @Inject( + method = "onDeath", + at = @At("RETURN") + ) + public void informManaAndSpellManagerOfDeath(DamageSource damageSource, CallbackInfo ci) { + this.getManaManager().onDeath(damageSource); + this.getSpellManager().onDeath(damageSource); + } } diff --git a/src/main/java/dev/louis/nebula/spell/Spell.java b/src/main/java/dev/louis/nebula/spell/Spell.java index 97c0491..e49c5ed 100644 --- a/src/main/java/dev/louis/nebula/spell/Spell.java +++ b/src/main/java/dev/louis/nebula/spell/Spell.java @@ -1,5 +1,6 @@ package dev.louis.nebula.spell; +import dev.louis.nebula.spell.manager.SpellManager; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.PacketByteBuf; import net.minecraft.util.Identifier; @@ -14,6 +15,10 @@ public Spell(SpellType spellType, PlayerEntity caster) { this.caster = caster; } + /** + * This should not be called manually. + * Use * {@link SpellManager#cast(Spell)} or {@link SpellManager#cast(SpellType)} + */ public abstract void cast(); public Identifier getID() { diff --git a/src/main/java/dev/louis/nebula/spell/manager/NebulaSpellManager.java b/src/main/java/dev/louis/nebula/spell/manager/NebulaSpellManager.java index a2d3a43..4a3b1b5 100644 --- a/src/main/java/dev/louis/nebula/spell/manager/NebulaSpellManager.java +++ b/src/main/java/dev/louis/nebula/spell/manager/NebulaSpellManager.java @@ -30,9 +30,9 @@ public class NebulaSpellManager implements SpellManager { private static final String SPELL_NBT_KEY = "Spell"; private static final String SPELLS_NBT_KEY = "Spells"; + private final Set tickingSpells = new HashSet<>(); + private final Set> castableSpells = new HashSet<>(); private PlayerEntity player; - private Set tickingSpells = new HashSet<>(); - private Set> castableSpells = new HashSet<>(); public NebulaSpellManager(PlayerEntity player) { this.player = player; @@ -71,22 +71,17 @@ public boolean isSpellTicking(TickingSpell tickingSpell) { @Override public boolean learnSpell(SpellType spellType) { this.castableSpells.add(spellType); - sendSync(); + this.sendSync(); return true; } @Override public boolean forgetSpell(SpellType spellType) { this.castableSpells.remove(spellType); - sendSync(); + this.sendSync(); return true; } - private void setCastableSpells(Set> castableSpells) { - this.castableSpells = castableSpells; - sendSync(); - } - private Set> getCastableSpells() { return castableSpells; } @@ -96,12 +91,12 @@ private void updateCastableSpell(Map, Boolean> castableSpells) { if (knows) this.castableSpells.add(spellType); else this.castableSpells.remove(spellType); }); - sendSync(); + this.sendSync(); } @Override public void cast(SpellType spellType) { - cast(spellType.create(this.player)); + this.cast(spellType.create(this.player)); } @Override @@ -122,6 +117,8 @@ public void onDeath(DamageSource damageSource) { if(this.isServer()) { this.tickingSpells.forEach((tickingSpell -> tickingSpell.stop(true))); } + this.castableSpells.clear(); + this.tickingSpells.clear(); } public boolean isCastable(SpellType spellType) { diff --git a/src/main/java/dev/louis/nebula/spell/manager/SpellManager.java b/src/main/java/dev/louis/nebula/spell/manager/SpellManager.java index 5f222a8..901bdbe 100644 --- a/src/main/java/dev/louis/nebula/spell/manager/SpellManager.java +++ b/src/main/java/dev/louis/nebula/spell/manager/SpellManager.java @@ -14,30 +14,91 @@ public interface SpellManager { void tick(); + /** + * This shouldn't be called directly, it is called by {@link TickingSpell#cast()} + * @param tickingSpell The TickingSpell which should start ticking. + * @return If the TickingSpell was successfully added. + */ boolean startTickingSpell(TickingSpell tickingSpell); + /** + * Stops the TickingSpell from ticking. + * {@link TickingSpell#stop()} will be called when this is called. + * @param tickingSpell The TickingSpell which should be stopped. + * @return If the TickingSpell was successfully stopped. + */ boolean stopTickingSpell(TickingSpell tickingSpell); + /** + * Checks if a TickingSpell of the specified SpellType is currently ticking. + * @param spellType The SpellType which should be checked. + * @return If a TickingSpell with the specified SpellType is currently ticking. + */ boolean isSpellTypeTicking(SpellType spellType); + /** + * Checks if a TickingSpell is currently ticking. + * @param tickingSpell The TickingSpell which should be checked. + * @return If the TickingSpell is currently ticking. + */ boolean isSpellTicking(TickingSpell tickingSpell); + /** + * Learns the specified SpellType. + * @param spellType The SpellType which should be learned. + * @return If the SpellType was successfully learned. Returns false if the SpellType is already learned or the learning failed. + */ boolean learnSpell(SpellType spellType); + /** + * Forgets the specified SpellType. + * @param spellType The SpellType which should be forgotten. + * @return If the SpellType was successfully forgotten. Returns false if the SpellType was not learned or the forgetting failed. + */ boolean forgetSpell(SpellType spellType); + /** + * Casts a Spell of the specified SpellType. The Spell may not cast if it is not castable, cancelled by {@link dev.louis.nebula.event.SpellCastCallback} or other reasons. + * @param spellType The SpellType which should be cast. + */ void cast(SpellType spellType); + /** + * Casts a Spell. The Spell may not cast if it is not castable, cancelled by {@link dev.louis.nebula.event.SpellCastCallback} or other reasons. + * @param spell The Spell which should be casted. + */ void cast(Spell spell); + /** + * This is called when the Caster dies. + * @param damageSource The DamageSource of the death. + */ void onDeath(DamageSource damageSource); + /** + * Checks if the specified SpellType is castable. + * @param spellType The SpellType which should be checked. + * @return If the SpellType is castable. + */ boolean isCastable(SpellType spellType); + /** + * Checks if the specified has been learned. + * @param spellType The SpellType which should be checked. + * @return If the SpellType has been learned. + */ boolean hasLearned(SpellType spellType); + /** + * Sends the SpellManager's state to the client. + * @return If the state was successfully sent. + */ boolean sendSync(); + /** + * Receives the SpellManager's state for the client. This shall never be called by the server. + * @return If the state was successfully received. + */ boolean receiveSync(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender); NbtCompound writeNbt(NbtCompound nbt); From 77d48f34ceb2eb760ca8a112dee46697e2b3c872 Mon Sep 17 00:00:00 2001 From: D1p4k <82884007+D1p4k@users.noreply.github.com> Date: Fri, 8 Dec 2023 23:51:34 +0100 Subject: [PATCH 04/10] Java Doc, Client Player now copies SpellManager and ManaManager. Create NebulaPlayer#createManagersIfNecessary. To reduce code duplicate. Double the amount of Mixins :) --- .../dev/louis/nebula/api/NebulaPlayer.java | 4 +++ .../mixin/ClientPlayNetworkHandlerMixin.java | 28 +++++++++++++++++++ .../nebula/mixin/ClientPlayerEntityMixin.java | 25 +++++++++++++++++ .../dev/louis/nebula/mixin/PlayerMixin.java | 11 ++++++-- .../nebula/mixin/ServerPlayerEntityMixin.java | 2 ++ .../dev/louis/nebula/spell/TickingSpell.java | 6 ++++ .../nebula/spell/manager/SpellManager.java | 14 ++++++++++ src/main/resources/Nebula.mixins.json | 2 ++ 8 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 src/main/java/dev/louis/nebula/mixin/ClientPlayNetworkHandlerMixin.java create mode 100644 src/main/java/dev/louis/nebula/mixin/ClientPlayerEntityMixin.java diff --git a/src/main/java/dev/louis/nebula/api/NebulaPlayer.java b/src/main/java/dev/louis/nebula/api/NebulaPlayer.java index 96cb644..a827656 100644 --- a/src/main/java/dev/louis/nebula/api/NebulaPlayer.java +++ b/src/main/java/dev/louis/nebula/api/NebulaPlayer.java @@ -19,4 +19,8 @@ default SpellManager getSpellManager() { default SpellManager setSpellManager(SpellManager spellManager) { throw new UnsupportedOperationException("Injected Interface method was not overridden!"); } + + default void createManagersIfNecessary() { + throw new UnsupportedOperationException("Injected Interface method was not overridden!"); + }; } diff --git a/src/main/java/dev/louis/nebula/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/dev/louis/nebula/mixin/ClientPlayNetworkHandlerMixin.java new file mode 100644 index 0000000..d1d7454 --- /dev/null +++ b/src/main/java/dev/louis/nebula/mixin/ClientPlayNetworkHandlerMixin.java @@ -0,0 +1,28 @@ +package dev.louis.nebula.mixin; + +import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.client.network.ClientPlayerEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ClientPlayNetworkHandler.class) +public class ClientPlayNetworkHandlerMixin { + @Inject( + method = "onPlayerRespawn", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/network/ClientPlayerEntity;init()V" + ) + ) + public void transportManager( + CallbackInfo ci, + @Local(ordinal = 0) ClientPlayerEntity oldClientPlayer, + @Local(ordinal = 1) ClientPlayerEntity newClientPlayer + ) { + newClientPlayer.setSpellManager(oldClientPlayer.getSpellManager().setPlayer(newClientPlayer)); + newClientPlayer.setManaManager(oldClientPlayer.getManaManager().setPlayer(newClientPlayer)); + } +} diff --git a/src/main/java/dev/louis/nebula/mixin/ClientPlayerEntityMixin.java b/src/main/java/dev/louis/nebula/mixin/ClientPlayerEntityMixin.java new file mode 100644 index 0000000..a92ceb6 --- /dev/null +++ b/src/main/java/dev/louis/nebula/mixin/ClientPlayerEntityMixin.java @@ -0,0 +1,25 @@ +package dev.louis.nebula.mixin; + +import com.mojang.authlib.GameProfile; +import net.minecraft.client.network.AbstractClientPlayerEntity; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.world.ClientWorld; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ClientPlayerEntity.class) +public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity { + public ClientPlayerEntityMixin(ClientWorld world, GameProfile profile) { + super(world, profile); + } + + @Inject( + method = "init", + at = @At("RETURN") + ) + public void init(CallbackInfo ci) { + this.createManagersIfNecessary(); + } +} diff --git a/src/main/java/dev/louis/nebula/mixin/PlayerMixin.java b/src/main/java/dev/louis/nebula/mixin/PlayerMixin.java index c1ae5e1..ad05e67 100644 --- a/src/main/java/dev/louis/nebula/mixin/PlayerMixin.java +++ b/src/main/java/dev/louis/nebula/mixin/PlayerMixin.java @@ -27,9 +27,9 @@ protected PlayerMixin(EntityType entityType, World world } @Unique - private ManaManager manaManager = NebulaManager.createManaManager((PlayerEntity) (Object) this); + private ManaManager manaManager; @Unique - private SpellManager spellManager = NebulaManager.createSpellManager((PlayerEntity) (Object) this); + private SpellManager spellManager; @Inject(method = "writeCustomDataToNbt", at = @At("RETURN")) public void writeManaAndSpellToNbt(NbtCompound nbt, CallbackInfo ci) { @@ -39,6 +39,7 @@ public void writeManaAndSpellToNbt(NbtCompound nbt, CallbackInfo ci) { @Inject(method = "readCustomDataFromNbt",at = @At("RETURN")) public void readManaAndSpellToNbt(NbtCompound nbt, CallbackInfo ci) { + this.createManagersIfNecessary(); this.manaManager.readNbt(nbt); this.spellManager.readNbt(nbt); } @@ -74,4 +75,10 @@ public SpellManager getSpellManager() { public SpellManager setSpellManager(SpellManager spellManager) { return this.spellManager = spellManager; } + + @Override + public void createManagersIfNecessary() { + if (this.manaManager == null) this.setManaManager(NebulaManager.createManaManager((PlayerEntity) (Object) this)); + if (this.spellManager == null) this.setSpellManager(NebulaManager.createSpellManager((PlayerEntity) (Object) this)); + } } diff --git a/src/main/java/dev/louis/nebula/mixin/ServerPlayerEntityMixin.java b/src/main/java/dev/louis/nebula/mixin/ServerPlayerEntityMixin.java index 6f3dd2b..1a283b7 100644 --- a/src/main/java/dev/louis/nebula/mixin/ServerPlayerEntityMixin.java +++ b/src/main/java/dev/louis/nebula/mixin/ServerPlayerEntityMixin.java @@ -26,6 +26,8 @@ public void copyNebulaStuffFrom(ServerPlayerEntity oldPlayer, boolean alive, Cal @Inject(method = "onSpawn", at = @At("RETURN")) public void syncManaAndSpellsOnSpawn(CallbackInfo ci) { + this.createManagersIfNecessary(); + boolean haveSpellsSynced = this.getSpellManager().sendSync(); if(!haveSpellsSynced) Nebula.LOGGER.info("Spells could not be synced!"); diff --git a/src/main/java/dev/louis/nebula/spell/TickingSpell.java b/src/main/java/dev/louis/nebula/spell/TickingSpell.java index a868122..1514350 100644 --- a/src/main/java/dev/louis/nebula/spell/TickingSpell.java +++ b/src/main/java/dev/louis/nebula/spell/TickingSpell.java @@ -22,6 +22,12 @@ public void tick() { spellAge++; } + /** + * This method stops the spell! + * The Spell will no longer be ticked. + * When overriding this method, make sure to call super.stop(). + * @param fromDeath If the cause of stopping was the death of the Caster. + */ public void stop(boolean fromDeath) { shouldContinue = false; } diff --git a/src/main/java/dev/louis/nebula/spell/manager/SpellManager.java b/src/main/java/dev/louis/nebula/spell/manager/SpellManager.java index 901bdbe..819ca58 100644 --- a/src/main/java/dev/louis/nebula/spell/manager/SpellManager.java +++ b/src/main/java/dev/louis/nebula/spell/manager/SpellManager.java @@ -101,10 +101,24 @@ public interface SpellManager { */ boolean receiveSync(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender); + /** + * Writes the NBT data of the SpellManager. + * @param nbt The nbt data that shall be written to. + * @return The nbt data that has been written to. + */ NbtCompound writeNbt(NbtCompound nbt); + /** + * Reads the NBT data of the SpellManager. + * @param nbt The nbt data that shall be read. + */ void readNbt(NbtCompound nbt); + /** + * Sets the PlayerEntity of the SpellManager. + * @param player The new PlayerEntity of the SpellManager. + * @return The SpellManager with the new PlayerEntity. + */ SpellManager setPlayer(PlayerEntity player); @FunctionalInterface diff --git a/src/main/resources/Nebula.mixins.json b/src/main/resources/Nebula.mixins.json index d198d6e..7f94cac 100644 --- a/src/main/resources/Nebula.mixins.json +++ b/src/main/resources/Nebula.mixins.json @@ -8,6 +8,8 @@ "ServerPlayerEntityMixin" ], "client": [ + "ClientPlayerEntityMixin", + "ClientPlayNetworkHandlerMixin" ], "injectors": { "defaultRequire": 1 From 371f8d9578f221848eb77fce28c2e3cf1885de17 Mon Sep 17 00:00:00 2001 From: D1p4k <82884007+D1p4k@users.noreply.github.com> Date: Fri, 8 Dec 2023 23:52:22 +0100 Subject: [PATCH 05/10] Make Logger startup better. --- src/main/java/dev/louis/nebula/Nebula.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dev/louis/nebula/Nebula.java b/src/main/java/dev/louis/nebula/Nebula.java index 0feedf4..6a67d38 100644 --- a/src/main/java/dev/louis/nebula/Nebula.java +++ b/src/main/java/dev/louis/nebula/Nebula.java @@ -26,7 +26,7 @@ public void onInitialize() { this.registerPacketReceivers(); NebulaManager.INSTANCE.init(); NebulaCommand.init(); - LOGGER.info("Nebula has initialized."); + LOGGER.info("Nebula has been initialized."); } From 1d85ee99196aea60e3ea636c96ca6273ea5672c3 Mon Sep 17 00:00:00 2001 From: D1p4k <82884007+D1p4k@users.noreply.github.com> Date: Sat, 9 Dec 2023 00:08:13 +0100 Subject: [PATCH 06/10] Javadoc-ify splendid --- .../nebula/mana/manager/ManaManager.java | 60 +++++++++++++++++++ .../mana/manager/NebulaManaManager.java | 24 +++----- .../nebula/spell/manager/SpellManager.java | 6 +- 3 files changed, 72 insertions(+), 18 deletions(-) diff --git a/src/main/java/dev/louis/nebula/mana/manager/ManaManager.java b/src/main/java/dev/louis/nebula/mana/manager/ManaManager.java index 2228e10..fa46e80 100644 --- a/src/main/java/dev/louis/nebula/mana/manager/ManaManager.java +++ b/src/main/java/dev/louis/nebula/mana/manager/ManaManager.java @@ -10,34 +10,94 @@ import net.minecraft.network.PacketByteBuf; public interface ManaManager { + /** + * This is called every tick the player is ticked. + * This should not be called manually. + */ void tick(); + /** + * Sets the amount of mana. + * @param mana The amount of mana to set. + */ void setMana(int mana); + /** + * @return The current amount of mana. + */ int getMana(); + /** + * Adds the specified amount of mana. + * @param mana The amount of mana to add. + */ void addMana(int mana); + /** + * Drains the specified amount of mana. + * @param mana The amount of mana to drain. + */ void drainMana(int mana); + /** + * Drains amount of mana from {@link SpellType#getManaCost()} + * @param spellType The SpellType where the amount of mana to drain is got from. + */ void drainMana(SpellType spellType); + /** + * @return The maximum amount of mana that can be stored. + */ int getMaxMana(); + /** + * @param mana The man amount that should be checked. + * @return If enough mana is available. + */ boolean hasEnoughMana(int mana); + /** + * @param spellType The SpellType which should be checked. + * @return If enough mana is available for the specified SpellType. + */ boolean hasEnoughMana(SpellType spellType); + /** + * Sends the ManaManager's state to the client. + * @return If the state was successfully send. + */ boolean sendSync(); + /** + * Receives the ManaManager's state for the client. This shall never be called by the server. + * @return If the state was successfully received. + */ boolean receiveSync(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender); + /** + * Writes the Nbt data of the SpellManager. + * @param nbt The Nbt data that shall be written to. + * @return The Nbt data that has been written to. + */ void writeNbt(NbtCompound nbt); + /** + * Reads the Nbt data of the ManaManager. + * @param nbt The Nbt data that shall be read. + */ void readNbt(NbtCompound nbt); + /** + * This is called when the Player dies. + * @param damageSource The DamageSource of the death. + */ void onDeath(DamageSource damageSource); + /** + * Sets the PlayerEntity of the ManaManager. + * @param player The new PlayerEntity of the ManaManager. + * @return The ManaManager with the new PlayerEntity. + */ ManaManager setPlayer(PlayerEntity player); @FunctionalInterface diff --git a/src/main/java/dev/louis/nebula/mana/manager/NebulaManaManager.java b/src/main/java/dev/louis/nebula/mana/manager/NebulaManaManager.java index 1d44068..fc96e5e 100644 --- a/src/main/java/dev/louis/nebula/mana/manager/NebulaManaManager.java +++ b/src/main/java/dev/louis/nebula/mana/manager/NebulaManaManager.java @@ -69,20 +69,15 @@ public boolean hasEnoughMana(SpellType spellType) { @Override public boolean sendSync() { - if (this.player instanceof ServerPlayerEntity serverPlayerEntity) { - if (serverPlayerEntity.networkHandler != null) { - int syncMana = this.getMana(); - if (syncMana == this.lastSyncedMana) return true; - this.lastSyncedMana = syncMana; - ServerPlayNetworking.send( - serverPlayerEntity, - new SynchronizeManaAmountS2CPacket(syncMana) - ); - return true; - } else { - Nebula.LOGGER.error("sendSync was called to early for " + serverPlayerEntity.getGameProfile().getName()); - return false; - } + if (this.player instanceof ServerPlayerEntity serverPlayerEntity && serverPlayerEntity.networkHandler != null) { + int syncMana = this.getMana(); + if (syncMana == this.lastSyncedMana) return true; + this.lastSyncedMana = syncMana; + ServerPlayNetworking.send( + serverPlayerEntity, + new SynchronizeManaAmountS2CPacket(syncMana) + ); + return true; } return false; } @@ -101,7 +96,6 @@ public boolean receiveSync(MinecraftClient client, ClientPlayNetworkHandler hand @Override public void writeNbt(NbtCompound nbt) { NbtCompound nebulaNbt = nbt.getCompound(Nebula.MOD_ID); - nebulaNbt.putInt(MANA_NBT_KEY, this.getMana()); nbt.put(Nebula.MOD_ID, nebulaNbt); } diff --git a/src/main/java/dev/louis/nebula/spell/manager/SpellManager.java b/src/main/java/dev/louis/nebula/spell/manager/SpellManager.java index 819ca58..5eb5490 100644 --- a/src/main/java/dev/louis/nebula/spell/manager/SpellManager.java +++ b/src/main/java/dev/louis/nebula/spell/manager/SpellManager.java @@ -91,7 +91,7 @@ public interface SpellManager { /** * Sends the SpellManager's state to the client. - * @return If the state was successfully sent. + * @return If the state was successfully send. */ boolean sendSync(); @@ -102,14 +102,14 @@ public interface SpellManager { boolean receiveSync(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender); /** - * Writes the NBT data of the SpellManager. + * Writes the Nbt data of the SpellManager. * @param nbt The nbt data that shall be written to. * @return The nbt data that has been written to. */ NbtCompound writeNbt(NbtCompound nbt); /** - * Reads the NBT data of the SpellManager. + * Reads the Nbt data of the SpellManager. * @param nbt The nbt data that shall be read. */ void readNbt(NbtCompound nbt); From cdd0aa3434cd7f88d3b27ff3fdde9c9701d5ac1c Mon Sep 17 00:00:00 2001 From: D1p4k <82884007+D1p4k@users.noreply.github.com> Date: Sat, 9 Dec 2023 23:53:26 +0100 Subject: [PATCH 07/10] Attempt at refactoring the NebulaManager and make it use entrypoints to make unhandled Mod Collisions impossible. --- gradle.properties | 8 +- src/main/java/dev/louis/nebula/Nebula.java | 9 +- .../java/dev/louis/nebula/NebulaManager.java | 139 ++++++++++++------ .../RegisterManaManagerEntrypoint.java | 11 ++ .../RegisterSpellManagerEntrypoint.java | 11 ++ .../ManaManagerRegistrableView.java | 7 + .../SpellManagerRegistrableView.java | 7 + 7 files changed, 139 insertions(+), 53 deletions(-) create mode 100644 src/main/java/dev/louis/nebula/api/manager/entrypoint/RegisterManaManagerEntrypoint.java create mode 100644 src/main/java/dev/louis/nebula/api/manager/entrypoint/RegisterSpellManagerEntrypoint.java create mode 100644 src/main/java/dev/louis/nebula/api/manager/registerable/ManaManagerRegistrableView.java create mode 100644 src/main/java/dev/louis/nebula/api/manager/registerable/SpellManagerRegistrableView.java diff --git a/gradle.properties b/gradle.properties index 4b391ca..5228f3b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,13 +2,13 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://modmuss50.me/fabric.html -minecraft_version=1.20.3 -yarn_mappings=1.20.3+build.1 -loader_version=0.15.0 +minecraft_version=1.20.4 +yarn_mappings=1.20.4+build.1 +loader_version=0.15.1 # Mod Properties mod_version=4.0.0-beta.2 maven_group=dev.louis archives_base_name=Nebula # Dependencies # check this on https://modmuss50.me/fabric.html -fabric_version=0.91.1+1.20.3 +fabric_version=0.91.2+1.20.4 diff --git a/src/main/java/dev/louis/nebula/Nebula.java b/src/main/java/dev/louis/nebula/Nebula.java index 6a67d38..8d50da1 100644 --- a/src/main/java/dev/louis/nebula/Nebula.java +++ b/src/main/java/dev/louis/nebula/Nebula.java @@ -1,6 +1,7 @@ package dev.louis.nebula; import com.mojang.logging.LogUtils; +import dev.louis.nebula.api.manager.registerable.SpellManagerRegistrableView; import dev.louis.nebula.command.NebulaCommand; import dev.louis.nebula.networking.SpellCastC2SPacket; import dev.louis.nebula.spell.SpellType; @@ -23,9 +24,9 @@ public class Nebula implements ModInitializer { @Override public void onInitialize() { SpellType.init(); - this.registerPacketReceivers(); - NebulaManager.INSTANCE.init(); + NebulaManager.init(); NebulaCommand.init(); + this.registerPacketReceivers(); LOGGER.info("Nebula has been initialized."); } @@ -33,5 +34,9 @@ public void onInitialize() { public void registerPacketReceivers() { ServerPlayNetworking.registerGlobalReceiver(SpellCastC2SPacket.getId(), SpellCastC2SPacket::receive); } + + void registerSpell(SpellManagerRegistrableView spellManagerRegistrableView) { + + } } diff --git a/src/main/java/dev/louis/nebula/NebulaManager.java b/src/main/java/dev/louis/nebula/NebulaManager.java index 5f58886..ac33388 100644 --- a/src/main/java/dev/louis/nebula/NebulaManager.java +++ b/src/main/java/dev/louis/nebula/NebulaManager.java @@ -1,69 +1,114 @@ package dev.louis.nebula; +import dev.louis.nebula.api.manager.entrypoint.RegisterManaManagerEntrypoint; +import dev.louis.nebula.api.manager.entrypoint.RegisterSpellManagerEntrypoint; +import dev.louis.nebula.api.manager.registerable.ManaManagerRegistrableView; +import dev.louis.nebula.api.manager.registerable.SpellManagerRegistrableView; import dev.louis.nebula.mana.manager.ManaManager; import dev.louis.nebula.mana.manager.NebulaManaManager; import dev.louis.nebula.spell.manager.NebulaSpellManager; import dev.louis.nebula.spell.manager.SpellManager; import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.metadata.ModMetadata; +import net.fabricmc.loader.api.ModContainer; +import net.fabricmc.loader.api.entrypoint.EntrypointContainer; import net.minecraft.entity.player.PlayerEntity; -public class NebulaManager { - private static final String JSON_KEY_CONTAINS_MANA_MANAGER = "nebula:contains_mana_manager"; - private static final String JSON_KEY_CONTAINS_SPELL_MANAGER = "nebula:contains_spell_manager"; - public static final NebulaManager INSTANCE = new NebulaManager(); - private NebulaManager(){} - - private ManaManager.Factory manaManagerFactory; - private SpellManager.Factory spellManagerFactory; - private boolean loadManaManager = true; - private boolean loadSpellManager = true; - public void init() { - load(); - if(loadManaManager)registerManaManagerFactory(NebulaManaManager::new); - if(loadSpellManager)registerSpellManagerFactory(NebulaSpellManager::new); - } - private void load() { - FabricLoader.getInstance().getAllMods().forEach(mod -> { - final ModMetadata metadata = mod.getMetadata(); - if(metadata.getId().equals(Nebula.MOD_ID))return; - var loadManaManager = metadata.getCustomValue(JSON_KEY_CONTAINS_MANA_MANAGER); - if (loadManaManager != null && loadManaManager.getAsBoolean()) this.loadManaManager = false; - var loadSpellManager = metadata.getCustomValue(JSON_KEY_CONTAINS_SPELL_MANAGER); - if (loadSpellManager != null && loadSpellManager.getAsBoolean()) this.loadSpellManager = false; - }); - } +import java.util.List; - public void registerManaManagerFactory(ManaManager.Factory manaManager) { - if (manaManager == null) { - throw new NullPointerException("Attempt to register a NULL ManaManager"); - } - if (this.manaManagerFactory != null) { - throw new UnsupportedOperationException("A second ManaManager attempted to register. Multiple ManaManagers are not supported."); - } - this.manaManagerFactory = manaManager; - } +public class NebulaManager implements ManaManagerRegistrableView, SpellManagerRegistrableView { + private static ModContainer manaManagerMod; + private static ManaManager.Factory manaManagerFactory; + private static ModContainer spellManagerMod; + private static SpellManager.Factory spellManagerFactory; + private static boolean isLocked = false; - public void registerSpellManagerFactory(SpellManager.Factory spellKnowledgeManager) { - if (spellKnowledgeManager == null) { - throw new NullPointerException("Attempt to register a NULL SpellManager"); - } - if (this.spellManagerFactory != null) { - throw new UnsupportedOperationException("A SpellManager plug-in attempted to register. Multiple SpellManagers are not supported."); - } - this.spellManagerFactory = spellKnowledgeManager; + private NebulaManager() {} + + public static void init() { + if(NebulaManager.isLocked) throw new IllegalStateException("Registration of Managers is locked!"); + NebulaManager nebulaManager = new NebulaManager(); + nebulaManager.runEntrypointsOrThrow(); + nebulaManager.lock(); } - public ManaManager.Factory getManaManagerFactory() { + public static ManaManager.Factory getManaManagerFactory() { return manaManagerFactory; } - public SpellManager.Factory getSpellManagerFactory() { + + public static SpellManager.Factory getSpellManagerFactory() { return spellManagerFactory; } + public static ManaManager createManaManager(PlayerEntity player) { - return INSTANCE.getManaManagerFactory().createPlayerManaManager(player); + return getManaManagerFactory().createPlayerManaManager(player); } + public static SpellManager createSpellManager(PlayerEntity player) { - return INSTANCE.getSpellManagerFactory().createSpellKnowledgeManager(player); + return getSpellManagerFactory().createSpellKnowledgeManager(player); + } + + public void lock() { + if(spellManagerFactory == null) spellManagerFactory = NebulaSpellManager::new; + if(manaManagerFactory == null) manaManagerFactory = NebulaManaManager::new; + isLocked = true; + } + + @Override + public void registerManaManagerFactory(ManaManager.Factory manaManagerFactory) { + NebulaManager.manaManagerFactory = manaManagerFactory; + } + + @Override + public void registerSpellManagerFactory(SpellManager.Factory spellManagerFactory) { + NebulaManager.spellManagerFactory = spellManagerFactory; + } + + /** + * Throws an exception if multiple mods want to override the ManaManager or SpellManager. + */ + private void runEntrypointsOrThrow() { + var manaManagerEntrypoints = FabricLoader.getInstance().getEntrypointContainers("registerManaManager", RegisterManaManagerEntrypoint.class) + .stream().filter(container -> container.getEntrypoint().shouldRegister()).toList(); + + var spellManagerEntrypoints = FabricLoader.getInstance().getEntrypointContainers("registerSpellManager", RegisterSpellManagerEntrypoint.class) + .stream().filter(container -> container.getEntrypoint().shouldRegister()).toList(); + + var manaManagerMods = manaManagerEntrypoints.stream().map(EntrypointContainer::getProvider).toList(); + var spellManagerMods = spellManagerEntrypoints.stream().map(EntrypointContainer::getProvider).toList(); + + if(manaManagerEntrypoints.size() > 1 && spellManagerEntrypoints.size() > 1) { + throw new IllegalStateException("Multiple Mods want to override the ManaManager and SpellManager!\n " + + "Mods overriding ManaManager: " + manaManagerMods + ",\n" + + "Mods overriding SpellManager: " + spellManagerMods); + } + + if(manaManagerEntrypoints.size() > 1) { + throw new IllegalStateException("Multiple Mods want to override the ManaManager! Mods: " + manaManagerMods); + } + + if(spellManagerEntrypoints.size() > 1) { + throw new IllegalStateException("Multiple Mods want to override the SpellManager! Mods: " + spellManagerMods); + } + + runEntryPoints(getFirstOrNull(manaManagerEntrypoints), getFirstOrNull(spellManagerEntrypoints)); + } + + private void runEntryPoints( + EntrypointContainer manaManagerEntrypointEntrypointContainer, + EntrypointContainer spellManagerEntrypointEntrypointContainer + ) { + if(manaManagerEntrypointEntrypointContainer != null) { + manaManagerEntrypointEntrypointContainer.getEntrypoint().registerSpell(this); + NebulaManager.manaManagerMod = manaManagerEntrypointEntrypointContainer.getProvider(); + } + + if(spellManagerEntrypointEntrypointContainer != null) { + spellManagerEntrypointEntrypointContainer.getEntrypoint().registerSpell(this); + NebulaManager.spellManagerMod = spellManagerEntrypointEntrypointContainer.getProvider(); + } + } + + private static T getFirstOrNull(List list) { + return list.isEmpty() ? null : list.get(0); } } diff --git a/src/main/java/dev/louis/nebula/api/manager/entrypoint/RegisterManaManagerEntrypoint.java b/src/main/java/dev/louis/nebula/api/manager/entrypoint/RegisterManaManagerEntrypoint.java new file mode 100644 index 0000000..84703d8 --- /dev/null +++ b/src/main/java/dev/louis/nebula/api/manager/entrypoint/RegisterManaManagerEntrypoint.java @@ -0,0 +1,11 @@ +package dev.louis.nebula.api.manager.entrypoint; + +import dev.louis.nebula.api.manager.registerable.SpellManagerRegistrableView; + +public interface RegisterManaManagerEntrypoint { + void registerSpell(SpellManagerRegistrableView spellManagerRegistrableView); + + default boolean shouldRegister() { + return true; + }; +} diff --git a/src/main/java/dev/louis/nebula/api/manager/entrypoint/RegisterSpellManagerEntrypoint.java b/src/main/java/dev/louis/nebula/api/manager/entrypoint/RegisterSpellManagerEntrypoint.java new file mode 100644 index 0000000..576ec24 --- /dev/null +++ b/src/main/java/dev/louis/nebula/api/manager/entrypoint/RegisterSpellManagerEntrypoint.java @@ -0,0 +1,11 @@ +package dev.louis.nebula.api.manager.entrypoint; + +import dev.louis.nebula.api.manager.registerable.SpellManagerRegistrableView; + +public interface RegisterSpellManagerEntrypoint { + void registerSpell(SpellManagerRegistrableView spellManagerRegistrableView); + + default boolean shouldRegister() { + return true; + }; +} diff --git a/src/main/java/dev/louis/nebula/api/manager/registerable/ManaManagerRegistrableView.java b/src/main/java/dev/louis/nebula/api/manager/registerable/ManaManagerRegistrableView.java new file mode 100644 index 0000000..a510bd6 --- /dev/null +++ b/src/main/java/dev/louis/nebula/api/manager/registerable/ManaManagerRegistrableView.java @@ -0,0 +1,7 @@ +package dev.louis.nebula.api.manager.registerable; + +import dev.louis.nebula.mana.manager.ManaManager; + +public interface ManaManagerRegistrableView { + void registerManaManagerFactory(ManaManager.Factory manaManagerFactory); +} \ No newline at end of file diff --git a/src/main/java/dev/louis/nebula/api/manager/registerable/SpellManagerRegistrableView.java b/src/main/java/dev/louis/nebula/api/manager/registerable/SpellManagerRegistrableView.java new file mode 100644 index 0000000..2f618a7 --- /dev/null +++ b/src/main/java/dev/louis/nebula/api/manager/registerable/SpellManagerRegistrableView.java @@ -0,0 +1,7 @@ +package dev.louis.nebula.api.manager.registerable; + +import dev.louis.nebula.spell.manager.SpellManager; + +public interface SpellManagerRegistrableView { + void registerSpellManagerFactory(SpellManager.Factory manaManagerFactory); +} \ No newline at end of file From 05e09d0c4ffecd28b47e56201cdd9543bd70d992 Mon Sep 17 00:00:00 2001 From: D1p4k <82884007+D1p4k@users.noreply.github.com> Date: Sun, 10 Dec 2023 00:29:46 +0100 Subject: [PATCH 08/10] Improving Stuff --- .../java/dev/louis/nebula/NebulaManager.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/louis/nebula/NebulaManager.java b/src/main/java/dev/louis/nebula/NebulaManager.java index ac33388..f704179 100644 --- a/src/main/java/dev/louis/nebula/NebulaManager.java +++ b/src/main/java/dev/louis/nebula/NebulaManager.java @@ -29,6 +29,7 @@ public static void init() { NebulaManager nebulaManager = new NebulaManager(); nebulaManager.runEntrypointsOrThrow(); nebulaManager.lock(); + nebulaManager.printInfo(); } public static ManaManager.Factory getManaManagerFactory() { @@ -48,8 +49,14 @@ public static SpellManager createSpellManager(PlayerEntity player) { } public void lock() { - if(spellManagerFactory == null) spellManagerFactory = NebulaSpellManager::new; - if(manaManagerFactory == null) manaManagerFactory = NebulaManaManager::new; + if(spellManagerFactory == null) { + spellManagerFactory = NebulaSpellManager::new; + spellManagerMod = FabricLoader.getInstance().getModContainer(Nebula.MOD_ID).orElseThrow(); + } + if(manaManagerFactory == null) { + manaManagerFactory = NebulaManaManager::new; + manaManagerMod = FabricLoader.getInstance().getModContainer(Nebula.MOD_ID).orElseThrow(); + } isLocked = true; } @@ -108,6 +115,11 @@ private void runEntryPoints( } } + private void printInfo() { + Nebula.LOGGER.info("ManaManager is registered by: " + NebulaManager.manaManagerMod.getMetadata().getName()); + Nebula.LOGGER.info("SpellManager is registered by: " + NebulaManager.spellManagerMod.getMetadata().getName()); + } + private static T getFirstOrNull(List list) { return list.isEmpty() ? null : list.get(0); } From f4c80a63c3ef491c28da13675b5c3ce8cc27f244 Mon Sep 17 00:00:00 2001 From: D1p4k <82884007+D1p4k@users.noreply.github.com> Date: Sun, 10 Dec 2023 00:30:10 +0100 Subject: [PATCH 09/10] Remove weird method? --- src/main/java/dev/louis/nebula/Nebula.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/dev/louis/nebula/Nebula.java b/src/main/java/dev/louis/nebula/Nebula.java index 8d50da1..f3b7f52 100644 --- a/src/main/java/dev/louis/nebula/Nebula.java +++ b/src/main/java/dev/louis/nebula/Nebula.java @@ -1,7 +1,6 @@ package dev.louis.nebula; import com.mojang.logging.LogUtils; -import dev.louis.nebula.api.manager.registerable.SpellManagerRegistrableView; import dev.louis.nebula.command.NebulaCommand; import dev.louis.nebula.networking.SpellCastC2SPacket; import dev.louis.nebula.spell.SpellType; @@ -34,9 +33,5 @@ public void onInitialize() { public void registerPacketReceivers() { ServerPlayNetworking.registerGlobalReceiver(SpellCastC2SPacket.getId(), SpellCastC2SPacket::receive); } - - void registerSpell(SpellManagerRegistrableView spellManagerRegistrableView) { - - } } From 3461335e4bd7fb4734e1fea7c413821f828ffce2 Mon Sep 17 00:00:00 2001 From: D1p4k <82884007+D1p4k@users.noreply.github.com> Date: Sun, 10 Dec 2023 00:37:45 +0100 Subject: [PATCH 10/10] Code cleanup --- src/main/java/dev/louis/nebula/Nebula.java | 1 - .../dev/louis/nebula/mana/manager/NebulaManaManager.java | 1 - .../louis/nebula/spell/manager/NebulaSpellManager.java | 9 --------- 3 files changed, 11 deletions(-) diff --git a/src/main/java/dev/louis/nebula/Nebula.java b/src/main/java/dev/louis/nebula/Nebula.java index f3b7f52..699101d 100644 --- a/src/main/java/dev/louis/nebula/Nebula.java +++ b/src/main/java/dev/louis/nebula/Nebula.java @@ -27,7 +27,6 @@ public void onInitialize() { NebulaCommand.init(); this.registerPacketReceivers(); LOGGER.info("Nebula has been initialized."); - } public void registerPacketReceivers() { diff --git a/src/main/java/dev/louis/nebula/mana/manager/NebulaManaManager.java b/src/main/java/dev/louis/nebula/mana/manager/NebulaManaManager.java index fc96e5e..262e731 100644 --- a/src/main/java/dev/louis/nebula/mana/manager/NebulaManaManager.java +++ b/src/main/java/dev/louis/nebula/mana/manager/NebulaManaManager.java @@ -15,7 +15,6 @@ public class NebulaManaManager implements ManaManager { private static final String MANA_NBT_KEY = "Mana"; - private PlayerEntity player; private int mana = 0; private int lastSyncedMana = -1; diff --git a/src/main/java/dev/louis/nebula/spell/manager/NebulaSpellManager.java b/src/main/java/dev/louis/nebula/spell/manager/NebulaSpellManager.java index 4a3b1b5..9c67ebc 100644 --- a/src/main/java/dev/louis/nebula/spell/manager/NebulaSpellManager.java +++ b/src/main/java/dev/louis/nebula/spell/manager/NebulaSpellManager.java @@ -188,13 +188,4 @@ public SpellManager setPlayer(PlayerEntity player) { public boolean isServer() { return !player.getWorld().isClient(); } - - /** - * It is safe to do this here because if code runs inside this Spell manager the Spell manager should be this one. - * @param player The Player you want the Spell Manager from. - * @return The NebulaSpellManager of that Player. - */ - private NebulaSpellManager getNebulaSpellmanager(PlayerEntity player) { - return (NebulaSpellManager) player.getSpellManager(); - } }