Skip to content

Commit

Permalink
support additional enderdragon phases added by mods fixing #3714 (#3737)
Browse files Browse the repository at this point in the history
  • Loading branch information
vectrixdevelops authored Aug 16, 2022
1 parent be368a0 commit a313aa2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.common.accessor.world.entity.boss.enderdragon.phases;

import net.minecraft.world.entity.boss.enderdragon.phases.EnderDragonPhase;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.common.UntransformedAccessorError;

@Mixin(EnderDragonPhase.class)
public interface EnderDragonPhaseAccessor {

@Accessor("phases") static EnderDragonPhase<?>[] accessor$PHASES() {
throw new UntransformedAccessorError();
}

@Accessor("name") String accessor$name();

}
1 change: 1 addition & 0 deletions src/accessors/resources/mixins.sponge.accessors.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"world.entity.animal.horse.HorseAccessor",
"world.entity.animal.horse.LlamaAccessor",
"world.entity.animal.horse.TraderLlamaAccessor",
"world.entity.boss.enderdragon.phases.EnderDragonPhaseAccessor",
"world.entity.boss.wither.WitherBossAccessor",
"world.entity.decoration.ArmorStandAccessor",
"world.entity.decoration.HangingEntityAccessor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import org.spongepowered.api.scoreboard.criteria.Criterion;
import org.spongepowered.common.accessor.advancements.CriteriaTriggersAccessor;
import org.spongepowered.common.accessor.world.entity.animal.MushroomCow_MushroomTypeAccessor;
import org.spongepowered.common.accessor.world.entity.boss.enderdragon.phases.EnderDragonPhaseAccessor;
import org.spongepowered.common.accessor.world.item.ArmorMaterialsAccessor;
import org.spongepowered.common.accessor.world.level.GameRulesAccessor;
import org.spongepowered.common.accessor.world.level.block.entity.BannerPatternAccessor;
Expand Down Expand Up @@ -114,7 +115,7 @@ private VanillaRegistryLoader(final SpongeRegistryHolder holder) {

private void loadInstanceRegistries() {
this.holder.createRegistry(RegistryTypes.CRITERION, VanillaRegistryLoader.criterion());
this.manualName(RegistryTypes.DRAGON_PHASE_TYPE, EnderDragonPhase.getCount(), map -> {
this.manualOrAutomaticName(RegistryTypes.DRAGON_PHASE_TYPE, EnderDragonPhaseAccessor.accessor$PHASES(), map -> {
map.put(EnderDragonPhase.HOLDING_PATTERN, "holding_pattern");
map.put(EnderDragonPhase.STRAFE_PLAYER, "strafe_player");
map.put(EnderDragonPhase.LANDING_APPROACH, "landing_approach");
Expand All @@ -126,7 +127,7 @@ private void loadInstanceRegistries() {
map.put(EnderDragonPhase.CHARGING_PLAYER, "charging_player");
map.put(EnderDragonPhase.DYING, "dying");
map.put(EnderDragonPhase.HOVERING, "hover");
});
}, phase -> CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, ((EnderDragonPhaseAccessor) phase).accessor$name()));
this.holder.createRegistry(RegistryTypes.FIREWORK_SHAPE, VanillaRegistryLoader.fireworkShape());
this.holder.createRegistry(RegistryTypes.TRIGGER, VanillaRegistryLoader.trigger(), true,
(k, trigger) -> CriteriaTriggersAccessor.invoker$register((CriterionTrigger<?>) trigger));
Expand Down Expand Up @@ -318,9 +319,12 @@ private <A, I extends Enum<I>> Registry<A> manualName(final RegistryType<A> type
}

@SuppressWarnings("UnusedReturnValue")
private <A, I> Registry<A> manualName(final RegistryType<A> type, final int values, final Consumer<Manual<A, I>> byName) {
final Map<I, String> map = new HashMap<>(values);
private <A, I> Registry<A> manualOrAutomaticName(final RegistryType<A> type, final I[] values, final Consumer<Manual<A, I>> byName, final Function<I, String> autoName) {
final Map<I, String> map = new HashMap<>(values.length);
byName.accept(map::put);
for (final I value : values) {
map.computeIfAbsent(value, autoName);
}
return this.naming(type, values, map);
}

Expand All @@ -334,7 +338,7 @@ private <A, I extends Enum<I>> Registry<A> naming(final RegistryType<A> type, fi
}

@SuppressWarnings("UnusedReturnValue")
private <A, I extends Enum<I>> Registry<A> naming(final RegistryType<A> type, final I[] values, final Map<I, String> byName) {
private <A, I> Registry<A> naming(final RegistryType<A> type, final I[] values, final Map<I, String> byName) {
return this.naming(type, values.length, byName);
}

Expand Down

0 comments on commit a313aa2

Please sign in to comment.