Skip to content

Commit

Permalink
custom boss bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaupenjoe committed Dec 20, 2024
1 parent d0c2c94 commit 30c1452
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
import net.kaupenjoe.tutorialmod.item.ModItems;
import net.minecraft.Util;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerBossEvent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.BossEvent;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.*;
Expand All @@ -31,6 +35,9 @@ public class GeckoEntity extends Animal {
private static final EntityDataAccessor<Integer> VARIANT =
SynchedEntityData.defineId(GeckoEntity.class, EntityDataSerializers.INT);

private final ServerBossEvent bossEvent =
new ServerBossEvent(Component.literal("Our Mighty Gecko"), BossEvent.BossBarColor.GREEN, BossEvent.BossBarOverlay.NOTCHED_10);

public GeckoEntity(EntityType<? extends Animal> entityType, Level level) {
super(entityType, level);
}
Expand Down Expand Up @@ -147,4 +154,23 @@ protected SoundEvent getHurtSound(DamageSource damageSource) {
protected SoundEvent getDeathSound() {
return SoundEvents.BAT_DEATH;
}

/* BOSS BAR */
@Override
public void startSeenByPlayer(ServerPlayer serverPlayer) {
super.startSeenByPlayer(serverPlayer);
this.bossEvent.addPlayer(serverPlayer);
}

@Override
public void stopSeenByPlayer(ServerPlayer serverPlayer) {
super.stopSeenByPlayer(serverPlayer);
this.bossEvent.removePlayer(serverPlayer);
}

@Override
public void aiStep() {
super.aiStep();
this.bossEvent.setProgress(this.getHealth() / this.getMaxHealth());
}
}

0 comments on commit 30c1452

Please sign in to comment.