Skip to content

Commit

Permalink
Merge pull request #32 from Dev0Louis/dev
Browse files Browse the repository at this point in the history
Beta 2 V5
  • Loading branch information
Dev0Louis authored Jan 23, 2024
2 parents 77b58ac + 62f9573 commit 8f353ce
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 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-beta.1
mod_version=5.0.0-beta.2
maven_group=dev.louis
archives_base_name=Nebula
# Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public interface ManaManagerRegistrableView {
void registerManaManager(
ManaManager.Factory<?> manaManagerFactory,
Identifier packetId,
ClientPlayNetworking.PlayChannelHandler playChannelHandler
ClientPlayNetworking.PlayChannelHandler channelHandler
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public interface SpellManagerRegistrableView {
void registerSpellManager(
SpellManager.Factory<?> manaManagerFactory,
Identifier packetId,
ClientPlayNetworking.PlayChannelHandler playChannelHandler
ClientPlayNetworking.PlayChannelHandler channelHandler
);
}
5 changes: 3 additions & 2 deletions src/main/java/dev/louis/nebula/api/spell/Spell.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ public final void stop() {

/**
* If true {@link Spell#applyCost()} and {@link Spell#cast()} will be called in that order. <br>
* If false nothing will be called.
* If false nothing will be called. <br>
* {@link SpellType.Builder#castability(SpellType.Castability)} instead if possible.
*/
public final boolean isCastable() {
public boolean isCastable() {
return this.getType().isCastable(this.caster);
}

Expand Down
42 changes: 27 additions & 15 deletions src/main/java/dev/louis/nebula/api/spell/SpellType.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public class SpellType<T extends Spell> {
private final int manaCost;
private final boolean allowsMultipleCasts;
private final boolean needLearning;
private final SpellCastingValidator castabilityFunction;
private final Castability castability;

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

public static void init() {
Expand All @@ -48,8 +48,11 @@ public Identifier getId() {
return REGISTRY.getId(this);
}

/**
* This should be used to check if the player can cast the spell.
*/
public boolean isCastable(PlayerEntity player) {
return castabilityFunction.isCastable(this, player);
return castability.isCastable(this, player);
}

public boolean allowsMultipleCasts() {
Expand Down Expand Up @@ -82,7 +85,7 @@ public static class Builder<T extends Spell> {
private final int manaCost;
private boolean allowsMultipleCasts;
private boolean needsLearning = true;
private SpellCastingValidator castabilityFunction = SpellCastingValidator.DEFAULT;
private Castability castability = Castability.DEFAULT;

private Builder(SpellFactory<T> factory, int manaCost) {
this.factory = factory;
Expand All @@ -97,23 +100,32 @@ public static <T extends Spell> Builder<T> create(SpellFactory<T> factory, int m
* Allows players to cast a spell multiple times at the same time. <br>
* That means that a spell could be cast while it is already ticking
*/
public Builder<T> allowMultipleCasts() {
public Builder<T> parallelCast() {
this.allowsMultipleCasts = true;
return this;
}

/**
* Set if the spell needs to be learned before it can be cast.
*/
public Builder<T> needsLearning(boolean needsLearning) {
this.needsLearning = needsLearning;
return this;
}

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

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

Expand All @@ -123,18 +135,18 @@ public interface SpellFactory<T extends Spell> {
}

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

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

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

default SpellCastingValidator or(SpellCastingValidator other) {
default Castability or(Castability other) {
return (spellType, player) -> this.isCastable(spellType, player) || other.isCastable(spellType, player);
}
}
Expand Down

0 comments on commit 8f353ce

Please sign in to comment.