Skip to content

Commit 0574fc2

Browse files
committed
fix EnderDragon#bossBar()
1 parent d2eb9d2 commit 0574fc2

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* This file is part of Sponge, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.common.accessor.world.level.dimension.end;
26+
27+
import net.minecraft.server.level.ServerBossEvent;
28+
import net.minecraft.world.level.dimension.end.EndDragonFight;
29+
import org.spongepowered.asm.mixin.Mixin;
30+
import org.spongepowered.asm.mixin.gen.Accessor;
31+
32+
@Mixin(EndDragonFight.class)
33+
public interface EndDragonFightAccessor {
34+
35+
@Accessor("dragonEvent") ServerBossEvent accessor$dragonEvent();
36+
}

src/accessors/resources/mixins.sponge.accessors.json

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@
194194
"world.level.chunk.storage.RegionFileAccessor",
195195
"world.level.chunk.storage.SimpleRegionStorageAccessor",
196196
"world.level.dimension.DimensionTypeAccessor",
197+
"world.level.dimension.end.EndDragonFightAccessor",
197198
"world.level.entity.EntityTickListAccessor",
198199
"world.level.entity.PersistentEntitySectionManagerAccessor",
199200
"world.level.levelgen.NoiseSettingsAccessor",

src/main/java/org/spongepowered/common/data/provider/entity/EnderDragonData.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@
2525
package org.spongepowered.common.data.provider.entity;
2626

2727
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
28+
import net.minecraft.world.level.dimension.end.EndDragonFight;
29+
import org.checkerframework.checker.nullness.qual.Nullable;
2830
import org.spongepowered.api.data.Keys;
2931
import org.spongepowered.api.entity.explosive.EndCrystal;
32+
import org.spongepowered.common.accessor.world.level.dimension.end.EndDragonFightAccessor;
33+
import org.spongepowered.common.adventure.SpongeAdventure;
3034
import org.spongepowered.common.data.provider.DataProviderRegistrator;
3135

3236
public final class EnderDragonData {
@@ -40,7 +44,16 @@ public static void register(final DataProviderRegistrator registrator) {
4044
.asMutable(EnderDragon.class)
4145
.create(Keys.HEALING_CRYSTAL)
4246
.get(h -> (EndCrystal) h.nearestCrystal)
43-
.set((h, v) -> h.nearestCrystal = (net.minecraft.world.entity.boss.enderdragon.EndCrystal) v);
47+
.set((h, v) -> h.nearestCrystal = (net.minecraft.world.entity.boss.enderdragon.EndCrystal) v)
48+
.create(Keys.BOSS_BAR)
49+
.get(h -> {
50+
final @Nullable EndDragonFight fight = h.getDragonFight();
51+
if (fight != null) {
52+
return SpongeAdventure.asAdventure(((EndDragonFightAccessor) fight).accessor$dragonEvent());
53+
} else {
54+
return null;
55+
}
56+
});
4457
}
4558
// @formatter:on
4659
}

0 commit comments

Comments
 (0)