Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
#	nebulo/src/main/java/dev/louis/nebulo/manager/ManagerRegisterer.java
#	src/main/java/dev/louis/nebula/api/manager/mana/entrypoint/RegisterManaManagerEntrypoint.java
#	src/main/java/dev/louis/nebula/api/manager/spell/entrypoint/RegisterSpellManagerEntrypoint.java
#	src/main/java/dev/louis/nebula/manager/NebulaManager.java
  • Loading branch information
Dev0Louis committed Mar 18, 2024
2 parents 80a5ea7 + 80aba2c commit 52b9fe3
Show file tree
Hide file tree
Showing 21 changed files with 204 additions and 359 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ org.gradle.jvmargs=-Xmx1G
minecraft_version=1.20.4
supported_version=>=1.20.2
yarn_mappings=1.20.4+build.3
loader_version=0.15.6
loader_version=0.15.7
# Mod Properties
mod_version=5.2.0
mod_version=6.0.0
maven_group=dev.louis
archives_base_name=Nebula
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.95.0+1.20.4
fabric_version=0.96.4+1.20.4
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,20 @@
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 registerManaManager(ManaManagerRegistrableView manaManagerRegistrableView) {
manaManagerRegistrableView.registerManaManager(NebuloManaManager::new);
}

@Override
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
public boolean shouldRegister() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import dev.louis.nebula.api.spell.Spell;
import dev.louis.nebula.api.spell.SpellType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;

public class CloudJumpSpell extends Spell {
public CloudJumpSpell(SpellType<?> spellType) {
super(spellType);
public CloudJumpSpell(SpellType<?> spellType, PlayerEntity player) {
super(spellType, player);
}

@Override
Expand Down Expand Up @@ -48,7 +49,7 @@ public int getDuration() {
}

@Override
public void onEnd() {
public void finish() {
if(!this.getCaster().getWorld().isClient()) {
var serverPlayer = (ServerPlayerEntity) this.getCaster();
serverPlayer.playSound(SoundEvents.ENTITY_CAMEL_DASH, SoundCategory.PLAYERS, 2f, -1f);
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ pluginManagement {
}
}

include(":nebulo")
//include(":nebulo")
1 change: 1 addition & 0 deletions src/main/java/dev/louis/nebula/Nebula.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.logging.LogUtils;
import dev.louis.nebula.api.spell.SpellType;
import dev.louis.nebula.command.NebulaCommand;
import dev.louis.nebula.manager.NebulaManager;
import dev.louis.nebula.networking.SpellCastC2SPacket;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/dev/louis/nebula/NebulaClient.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package dev.louis.nebula;

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 net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;

public class NebulaClient implements ClientModInitializer {

@Override
public void onInitializeClient() {
NebulaManager.registerPacketReceivers();
registerPacketReceivers();
}

public void registerPacketReceivers() {
ClientPlayNetworking.registerGlobalReceiver(UpdateSpellCastabilityS2CPacket.TYPE, NebulaSpellManager::receiveSync);
ClientPlayNetworking.registerGlobalReceiver(SyncManaS2CPacket.TYPE, NebulaManaManager::receiveSync);
}
}
17 changes: 17 additions & 0 deletions src/main/java/dev/louis/nebula/api/NebulaPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.louis.nebula.api.manager.mana.ManaManager;
import dev.louis.nebula.api.manager.spell.SpellManager;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;

/**
* This interface will be injected into {@link PlayerEntity}.
Expand All @@ -25,6 +26,22 @@ default SpellManager setSpellManager(SpellManager spellManager) {
throw new UnsupportedOperationException("Injected Interface method was not overridden!");
}

static ManaManager getManaManager(ServerPlayerEntity serverPlayer) {
return serverPlayer.getManaManager();
}

static ManaManager setManaManager(ServerPlayerEntity serverPlayer, ManaManager manaManager) {
return serverPlayer.setManaManager(manaManager);
}

static SpellManager getSpellManager(ServerPlayerEntity serverPlayer) {
return serverPlayer.getSpellManager();
}

static SpellManager setSpellManager(ServerPlayerEntity serverPlayer, SpellManager spellManager) {
return serverPlayer.setSpellManager(spellManager);
}

/**
* This creates the ManaManager and the SpellManager if they are not already created.
* This should not be called manually, unless you know what you are doing.
Expand Down
15 changes: 2 additions & 13 deletions src/main/java/dev/louis/nebula/api/manager/mana/ManaManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ public interface ManaManager {
*/
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.
*/
Expand All @@ -57,7 +51,7 @@ public interface ManaManager {
* @param spellType The SpellType which should be checked.
* @return If enough mana is available for the specified SpellType.
*/
boolean isCastable(SpellType<?> spellType);
boolean hasEnoughMana(SpellType<?> spellType);

/**
* Sends the ManaManager's state to the client.
Expand Down Expand Up @@ -132,11 +126,6 @@ public void drainMana(int mana) {

}

@Override
public void drainMana(SpellType<?> spellType) {

}

@Override
public int getMaxMana() {
return 0;
Expand All @@ -148,7 +137,7 @@ public boolean hasEnoughMana(int mana) {
}

@Override
public boolean isCastable(SpellType<?> spellType) {
public boolean hasEnoughMana(SpellType<?> spellType) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
public interface RegisterManaManagerEntrypoint {
void registerManaManager(ManaManagerRegistrableView manaManagerRegistrableView);

void registerManaPacketReceiver();

default boolean shouldRegister() {
return true;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
public interface RegisterSpellManagerEntrypoint {
void registerSpellManager(SpellManagerRegistrableView spellManagerRegistrableView);

void registerSpellPacketReceiver();

default boolean shouldRegister() {
return true;
};
Expand Down
93 changes: 15 additions & 78 deletions src/main/java/dev/louis/nebula/api/spell/Spell.java
Original file line number Diff line number Diff line change
@@ -1,48 +1,26 @@
package dev.louis.nebula.api.spell;

import dev.louis.nebula.api.manager.spell.SpellManager;
import net.minecraft.entity.data.TrackedDataHandler;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;

import java.util.Optional;

/**
* This class represents an attempt to cast a spell. It holds a reference to the caster of the Spell.
*
*/
public abstract class Spell {
public static final TrackedDataHandler<Optional<Spell>> OPTIONAL_SPELL = new TrackedDataHandler.ImmutableHandler<>() {
public void write(PacketByteBuf buf, Optional<Spell> optionalSpell) {
buf.writeBoolean(optionalSpell.isPresent());
optionalSpell.ifPresent(spell -> {
buf.writeRegistryValue(SpellType.REGISTRY, spell.getType());
spell.writeBuf(buf);
});
}

public Optional<Spell> read(PacketByteBuf buf) {
if(!buf.readBoolean()) return Optional.empty();
SpellType<?> spellType = buf.readRegistryValue(SpellType.REGISTRY);
if(spellType == null) throw new IllegalStateException("Spell type not found in registry");
var spell = spellType.create();
spell.readBuf(buf);
return Optional.of(spell);
}
};
private static final int DEFAULT_SPELL_AGE = 3 * 20;

private final SpellType<?> spellType;
private PlayerEntity caster;

protected int spellAge = 0;
private static final int DEFAULT_SPELL_AGE = 0;

protected final SpellType<?> spellType;
protected final PlayerEntity caster;

protected boolean wasInterrupted;
protected boolean hasEnded;
protected boolean stopped;

public Spell(SpellType<?> spellType) {
public int age = 0;

public Spell(SpellType<?> spellType, PlayerEntity caster) {
this.spellType = spellType;
this.caster = caster;
}

/**
Expand All @@ -59,18 +37,9 @@ public void applyCost() {
this.getCaster().getManaManager().drainMana(getType().getManaCost());
}

public final void baseTick() {
spellAge++;
this.tick();
}

public void tick() {
}

public Identifier getId() {
return this.getType().getId();
}

public PlayerEntity getCaster() {
return this.caster;
}
Expand All @@ -79,10 +48,6 @@ public SpellType<? extends Spell> getType() {
return this.spellType;
}

public int getAge() {
return this.spellAge;
}

public int getDuration() {
return DEFAULT_SPELL_AGE;
}
Expand All @@ -92,27 +57,22 @@ public int getDuration() {
* After this method is called {@link Spell#tick()} will not be called anymore.<br>
* Use this to finish all remaining logic of the spell.
*/
public void onEnd() {
this.hasEnded = true;
}

public void setCaster(PlayerEntity caster) {
this.caster = caster;
public void finish() {
}

/**
* Used to check if the spell should be stopped. <br>
* It is important to check super or check if the spell was interrupted {@link Spell#wasInterrupted()}. <br>
*/
public boolean shouldStop() {
return this.stopped || this.spellAge > this.getDuration();
return this.stopped || this.age > this.getDuration();
}

/**
* Interrupts the spell.<br>
* This method is final as no Spell is immune to being interrupted<br>
* <br>
* If you want to show to the player that the spell was interrupted check {@link Spell#wasInterrupted()} in {@link Spell#onEnd()} as it is called after this.
* If you want to show to the player that the spell was interrupted check {@link Spell#wasInterrupted()} in {@link Spell#finish()} as it is called after this.
*/
public final void interrupt() {
this.wasInterrupted = true;
Expand All @@ -121,11 +81,11 @@ public final void interrupt() {

/**
* Stop the spell.<br>
* This method is final as post-spell action shall be handled in {@link Spell#onEnd()}<br>
* This method is final as post-spell action shall be handled in {@link Spell#finish()}<br>
* <br>
* Unlike {@link Spell#interrupt()} if you call this method it is expected that the spell has finished execution.<br>
*/
public final void stop() {
protected final void stop() {
this.stopped = true;
}

Expand All @@ -146,35 +106,12 @@ public boolean wasInterrupted() {
return this.wasInterrupted;
}

public boolean hasEnded() {
return this.hasEnded;
}

/**
* Read additional casting data about the spell from the buf.
* @param buf The buf to be read from.
* @return The buf after being read from.
*/
public PacketByteBuf readBuf(PacketByteBuf buf) {
return buf;
}

/**
* Write additional casting data about the spell to the buf.
* @param buf The buf to be written to.
* @return The buf after being written to.
*/
public PacketByteBuf writeBuf(PacketByteBuf buf) {
return buf;
}


@Override
public String toString() {
return this.getClass().getSimpleName() +
"[spellType=" + this.spellType +
", caster=" + this.caster +
", spellAge=" + this.spellAge +
", spellAge=" + this.age +
", wasInterrupted=" + this.wasInterrupted + "]";
}
}
Loading

0 comments on commit 52b9fe3

Please sign in to comment.