Skip to content

Commit

Permalink
fix NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
IAFEnvoy committed Jan 29, 2025
1 parent daf1d76 commit 562c1c8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@

@Environment(EnvType.CLIENT)
public class PowerHudRenderer {
private static final Identifier WIDGETS_TEXTURE = Identifier.of(Identifier.DEFAULT_NAMESPACE,"textures/gui/widgets.png");
private static final Identifier WIDGETS_TEXTURE = Identifier.of(Identifier.DEFAULT_NAMESPACE, "textures/gui/widgets.png");
private static final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;

public static void render(MinecraftClient client, DrawContext context) {
assert client.player != null;
if (client.player.isSpectator()) return;
if (client.player == null || client.player.isSpectator()) return;
SongPowerData data = SongPowerData.byPlayer(client.player);
if (!data.isEnabled()) return;
//Render Power Slot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.sound.AbstractSoundInstance;
import net.minecraft.client.sound.TickableSoundInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.LocalRandom;
Expand Down Expand Up @@ -46,8 +47,8 @@ public void tick() {
}

public static boolean farEnough(BlockPos pos) {
assert MinecraftClient.getInstance().player != null;
return MinecraftClient.getInstance().player.getBlockPos().getSquaredDistance(pos) > MAX_DISTANCE * MAX_DISTANCE;
PlayerEntity player = MinecraftClient.getInstance().player;
return player == null || player.getBlockPos().getSquaredDistance(pos) > MAX_DISTANCE * MAX_DISTANCE;
}

private static class SongCubeSoundInstance extends AbstractSoundInstance implements TickableSoundInstance {
Expand Down Expand Up @@ -85,7 +86,7 @@ public boolean isDone() {
@Override
public void tick() {
ClientPlayerEntity player = client.get().player;
assert player != null;
if (player == null) return;
double distance = Math.sqrt(player.squaredDistanceTo(this.x, this.y, this.z));
if (distance > MAX_DISTANCE) this.stop();
else this.volume = (float) (1 - 0.9 * distance / MAX_DISTANCE);
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ minecraft_version=1.20.1
enabled_platforms=fabric,forge
yarn_mappings=1.20.1+build.10
archives_base_name=SongsOfWar
mod_version=0.8.4
mod_version=0.8.5
maven_group=com.iafenvoy
architectury_version=9.2.14
fabric_loader_version=0.15.11
Expand Down

0 comments on commit 562c1c8

Please sign in to comment.