Skip to content

Commit

Permalink
Fix MC-257487
Browse files Browse the repository at this point in the history
  • Loading branch information
Rektroth committed Oct 12, 2023
1 parent 600df6a commit 1951253
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Patch for MC-257487
*
* Authored for CraftBukkit/Spigot by Jake Potrebic <[email protected]> on November 12, 2022.
* Ported to Fabric by Rektroth <[email protected]> on October 12, 2023.
*/

package io.github.rektroth.whiteout.mixin.entity.boss.dragon;

import net.minecraft.entity.boss.ServerBossBar;
import net.minecraft.entity.boss.dragon.EnderDragonFight;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(EnderDragonFight.class)
public interface EnderDragonFightAccessor {
@Accessor("bossBar")
public ServerBossBar getBossBar();

@Accessor("bossBar")
public void setBossBar(ServerBossBar bossBar);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Patch for MC-257487
*
* Authored for CraftBukkit/Spigot by Jake Potrebic <[email protected]> on November 12, 2022.
* Ported to Fabric by Rektroth <[email protected]> on October 12, 2023.
*/

package io.github.rektroth.whiteout.mixin.entity.boss.dragon;

import io.github.rektroth.whiteout.mixin.entity.boss.dragon.EnderDragonFightAccessor;
import net.minecraft.entity.boss.BossBar;
import net.minecraft.entity.boss.ServerBossBar;
import net.minecraft.entity.boss.dragon.EnderDragonEntity;
import net.minecraft.entity.boss.dragon.EnderDragonFight;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(EnderDragonFight.class)
public class EnderDragonFightMixin {
private static final Text DEFAULT_BOSS_EVENT_NAME = Text.translatable("entity.minecraft.ender_dragon");

@Inject(at = @At("HEAD"), method = "<init>")
private void fixBossBar() {
((EnderDragonFightAccessor)((EnderDragonFight)(Object)this)).setBossBar((ServerBossBar)(new ServerBossBar(DEFAULT_BOSS_EVENT_NAME, BossBar.Color.PINK, BossBar.Style.PROGRESS)).setDragonMusic(true).setThickenFog(true));
}

@Inject(at = @At("TAIL"), method = "updateFight(Lnet/minecraft/entity/boss/dragon/EnderDragonEntity;)V")
private void fixedCustomNameCheck(EnderDragonEntity dragon) {
ServerBossBar bossBar = ((EnderDragonFightAccessor)((EnderDragonFight)(Object)this)).getBossBar();

if (dragon.hasCustomName()) {
bossBar.setName(dragon.getDisplayName());
} else {
bossBar.setName(DEFAULT_BOSS_EVENT_NAME);
}

((EnderDragonFightAccessor)((EnderDragonFight)(Object)this)).setBossBar(bossBar);
}

@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/boss/dragon/EnderDragonEntity;hasCustomName()Z"), method = "updateFight(Lnet/minecraft/entity/boss/dragon/EnderDragonEntity;)V")
private boolean skipBadCustomNameCheck() {
return false;
}
}

0 comments on commit 1951253

Please sign in to comment.