Skip to content

Commit

Permalink
Merge pull request #23 from Dev0Louis/dev
Browse files Browse the repository at this point in the history
Fix Crash
  • Loading branch information
Dev0Louis authored Dec 11, 2023
2 parents 322f081 + c2cf837 commit a322ad7
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.20.4
yarn_mappings=1.20.4+build.1
loader_version=0.15.1
# Mod Properties
mod_version=4.0.0
mod_version=4.0.1
maven_group=dev.louis
archives_base_name=Nebula
# Dependencies
Expand Down
84 changes: 84 additions & 0 deletions src/main/java/dev/louis/nebula/mana/manager/ManaManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.fabricmc.fabric.api.networking.v1.PacketSender;
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;
Expand Down Expand Up @@ -104,4 +105,87 @@ public interface ManaManager {
interface Factory<T extends ManaManager> {
T createPlayerManaManager(PlayerEntity player);
}

/**
* ManaManager indicating that no ManaManager has been constructed yet.
* Is also used for Player classes that never construct a ManaManager like {@link ClientPlayerEntity}.
* Calling methods is safe, but won't do anything.
*/
ManaManager EMPTY = new ManaManager() {

@Override
public void tick() {

}

@Override
public void setMana(int mana) {

}

@Override
public int getMana() {
return 0;
}

@Override
public void addMana(int mana) {

}

@Override
public void drainMana(int mana) {

}

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

}

@Override
public int getMaxMana() {
return 0;
}

@Override
public boolean hasEnoughMana(int mana) {
return false;
}

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

@Override
public boolean sendSync() {
return false;
}

@Override
public boolean receiveSync(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) {
return false;
}

@Override
public void writeNbt(NbtCompound nbt) {

}

@Override
public void readNbt(NbtCompound nbt) {

}

@Override
public void onDeath(DamageSource damageSource) {

}

@Override
public ManaManager setPlayer(PlayerEntity player) {
return this;
}
};
}
8 changes: 4 additions & 4 deletions src/main/java/dev/louis/nebula/mixin/PlayerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ protected PlayerMixin(EntityType<? extends LivingEntity> entityType, World world
}

@Unique
private ManaManager manaManager;
private ManaManager manaManager = ManaManager.EMPTY;
@Unique
private SpellManager spellManager;
private SpellManager spellManager = SpellManager.EMPTY;

@Inject(method = "writeCustomDataToNbt", at = @At("RETURN"))
public void writeManaAndSpellToNbt(NbtCompound nbt, CallbackInfo ci) {
Expand Down Expand Up @@ -78,7 +78,7 @@ public SpellManager setSpellManager(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));
if (this.manaManager == ManaManager.EMPTY) this.setManaManager(NebulaManager.createManaManager((PlayerEntity) (Object) this));
if (this.spellManager == SpellManager.EMPTY) this.setSpellManager(NebulaManager.createSpellManager((PlayerEntity) (Object) this));
}
}
93 changes: 93 additions & 0 deletions src/main/java/dev/louis/nebula/spell/manager/SpellManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.fabricmc.fabric.api.networking.v1.PacketSender;
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;
Expand Down Expand Up @@ -125,4 +126,96 @@ public interface SpellManager {
interface Factory<T extends SpellManager> {
T createSpellKnowledgeManager(PlayerEntity player);
}

/**
* SpellManager indicating that no ManaManager has been constructed yet.
* Is also used for Player classes that never construct a SpellManager like {@link ClientPlayerEntity}.
* Calling methods is safe, but won't do anything.
*/
SpellManager EMPTY = new SpellManager() {
@Override
public void tick() {

}

@Override
public boolean startTickingSpell(TickingSpell tickingSpell) {
return false;
}

@Override
public boolean stopTickingSpell(TickingSpell tickingSpell) {
return false;
}

@Override
public boolean isSpellTypeTicking(SpellType<? extends TickingSpell> spellType) {
return false;
}

@Override
public boolean isSpellTicking(TickingSpell tickingSpell) {
return false;
}

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

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

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

}

@Override
public void cast(Spell spell) {

}

@Override
public void onDeath(DamageSource damageSource) {

}

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

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

@Override
public boolean sendSync() {
return false;
}

@Override
public boolean receiveSync(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) {
return false;
}

@Override
public NbtCompound writeNbt(NbtCompound nbt) {
return null;
}

@Override
public void readNbt(NbtCompound nbt) {

}

@Override
public SpellManager setPlayer(PlayerEntity player) {
return null;
}
};
}

0 comments on commit a322ad7

Please sign in to comment.