Skip to content

Commit

Permalink
V6 finished?
Browse files Browse the repository at this point in the history
Gonna let someone else have an Eye on it before publishing.
  • Loading branch information
Dev0Louis committed Mar 18, 2024
1 parent 8ca5988 commit 80aba2c
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 48 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.7
# Mod Properties
mod_version=6.0.0-beta.1
mod_version=6.0.0
maven_group=dev.louis
archives_base_name=Nebula
# Dependencies
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")
67 changes: 24 additions & 43 deletions src/main/java/dev/louis/nebula/api/spell/SpellType.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ public class SpellType<T extends Spell> {

private final SpellFactory<T> spellFactory;
private final int manaCost;
private final boolean allowsMultipleCasts;
private final boolean needLearning;
private final Castability castability;
private final boolean allowsParallelCasts;
private final boolean needsLearning;

@ApiStatus.Internal
public SpellType(SpellFactory<T> spellFactory, int manaCost, boolean allowsMultipleCasts, boolean needLearning, Castability castability) {
public SpellType(SpellFactory<T> spellFactory, int manaCost, boolean allowsParallelCasts, boolean needsLearning) {
this.spellFactory = spellFactory;
this.manaCost = manaCost;
this.allowsMultipleCasts = allowsMultipleCasts;
this.needLearning = needLearning;
this.castability = castability;
this.allowsParallelCasts = allowsParallelCasts;
this.needsLearning = needsLearning;
}

@ApiStatus.Internal
Expand All @@ -53,15 +51,24 @@ public Identifier getId() {
* This should be used to check if the player can cast the spell.
*/
public boolean isCastable(PlayerEntity player) {
return castability.isCastable(this, player);
return player.getSpellManager().isCastable(this);
}

public boolean allowsMultipleCasts() {
return allowsMultipleCasts;
/**
* Utility method for checking if the spell has been learned by the given player.
* @param player Player to check.
* @return If the spell has been learned.
*/
public boolean isLearnedBy(PlayerEntity player) {
return player.getSpellManager().hasLearned(this);
}

public boolean allowsParallelCasts() {
return allowsParallelCasts;
}

public boolean needsLearning() {
return needLearning;
return needsLearning;
}

public int getManaCost() {
Expand All @@ -77,18 +84,16 @@ public String toString() {
return "SpellType{" +
"spellFactory=" + spellFactory +
", manaCost=" + manaCost +
", allowsMultipleCasts=" + allowsMultipleCasts +
", needLearning=" + needLearning +
", castability=" + castability +
", allowsParallelCasts=" + allowsParallelCasts +
", needLearning=" + needsLearning +
'}';
}

public static class Builder<T extends Spell> {
private final SpellFactory<T> factory;
private final int manaCost;
private boolean allowsMultipleCasts;
private boolean allowParallelCast;
private boolean needsLearning = true;
private Castability castability = Castability.DEFAULT;

private Builder(SpellFactory<T> factory, int manaCost) {
this.factory = factory;
Expand All @@ -104,7 +109,7 @@ public static <T extends Spell> Builder<T> create(SpellFactory<T> factory, int m
* That means that a spell could be cast while it is already ticking
*/
public Builder<T> parallelCast() {
this.allowsMultipleCasts = true;
this.allowParallelCast = true;
return this;
}

Expand All @@ -116,42 +121,18 @@ public Builder<T> needsLearning(boolean needsLearning) {
return this;
}

public Builder<T> castability(Castability castability) {
this.castability = castability;
return this;
}

public SpellType<T> build() {
return new SpellType<>(
this.factory,
this.manaCost,
this.allowsMultipleCasts,
this.needsLearning,
this.castability
this.allowParallelCast,
this.needsLearning
);
}
}

@FunctionalInterface
public interface SpellFactory<T extends Spell> {

T create(SpellType<T> spellType, PlayerEntity caster);
}

@FunctionalInterface
public interface Castability {
Castability ALWAYS = (spellType, player) -> true;
Castability DEFAULT = (spellType, player) -> player.getSpellManager().isCastable(spellType);
Castability NEVER = (spellType, player) -> false;

boolean isCastable(SpellType<?> spellType, PlayerEntity player);

default Castability and(Castability other) {
return (spellType, player) -> this.isCastable(spellType, player) && other.isCastable(spellType, player);
}

default Castability or(Castability other) {
return (spellType, player) -> this.isCastable(spellType, player) || other.isCastable(spellType, player);
}
}
}
1 change: 1 addition & 0 deletions src/main/java/dev/louis/nebula/command/NebulaCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ private static int getMana(ServerCommandSource source, Collection<ServerPlayerEn

private static int learnSpell(ServerCommandSource source, SpellType<?> spellType) {
if(source.getPlayer() != null) {
source.getPlayer().getSpellManager().learnSpell(spellType);
source.sendMessage(Text.of("Learned spell " + spellType.getId()));
}
return 1;
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/dev/louis/nebula/manager/NebulaManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ private void printInfo() {
Nebula.LOGGER.info("SpellManager is registered by: " + NebulaManager.spellManagerMod.getMetadata().getName());
}

public static ModContainer getManaManagerMod() {
return manaManagerMod;
}

public static ModContainer getSpellManagerMod() {
return spellManagerMod;
}

private static <T> T getFirstOrNull(List<T> list) {
return list.isEmpty() ? null : list.get(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public boolean cast(Spell spell) {
if (this.isServer()) {
spell.applyCost();
spell.cast();
if (spell.getDuration() > 0) this.activeSpells.add(spell);
this.activeSpells.add(spell);
} else {
ClientPlayNetworking.send(new SpellCastC2SPacket(spell.getType()));
}
Expand All @@ -108,7 +108,7 @@ public void onDeath(DamageSource damageSource) {

@Override
public boolean isCastable(SpellType<?> spellType) {
return this.player.isAlive() && player.getManaManager().hasEnoughMana(spellType) && (!spellType.needsLearning() || this.hasLearned(spellType)) && (spellType.allowsMultipleCasts() || !player.getSpellManager().isSpellTypeActive(spellType));
return this.player.isAlive() && player.getManaManager().hasEnoughMana(spellType) && (!spellType.needsLearning() || this.hasLearned(spellType)) && (spellType.allowsParallelCasts() || !player.getSpellManager().isSpellTypeActive(spellType));
}

public void markDirty() {
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/dev/louis/nebula/mixin/DebugHudMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dev.louis.nebula.mixin;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import dev.louis.nebula.manager.NebulaManager;
import net.minecraft.client.gui.hud.DebugHud;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

import java.util.List;

@Mixin(DebugHud.class)
public class DebugHudMixin {

@ModifyReturnValue(
at = @At("RETURN"),
method = "getLeftText"
)
protected List<String> getLeftText(List<String> original) {
original.add("[Nebula] Mana Manager Mod: " + NebulaManager.getManaManagerMod().getMetadata().getName());
original.add("[Nebula] Spell Manager Mod: " + NebulaManager.getSpellManagerMod().getMetadata().getName());
return original;
}
}
3 changes: 2 additions & 1 deletion src/main/resources/Nebula.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"client": [
"ClientPlayerEntityAccessor",
"ClientPlayerEntityMixin",
"ClientPlayNetworkHandlerMixin"
"ClientPlayNetworkHandlerMixin",
"DebugHudMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 80aba2c

Please sign in to comment.