diff --git a/Common/src/main/java/dev/cammiescorner/icarus/api/IcarusPlayerValues.java b/Common/src/main/java/dev/cammiescorner/icarus/api/IcarusPlayerValues.java index 48ccd2a..133ff6e 100644 --- a/Common/src/main/java/dev/cammiescorner/icarus/api/IcarusPlayerValues.java +++ b/Common/src/main/java/dev/cammiescorner/icarus/api/IcarusPlayerValues.java @@ -1,9 +1,11 @@ package dev.cammiescorner.icarus.api; import dev.cammiescorner.icarus.IcarusConfig; -import dev.cammiescorner.icarus.init.IcarusDimensionTags; +import dev.cammiescorner.icarus.init.IcarusDimensionTypeTags; +import dev.cammiescorner.icarus.init.IcarusLevelTags; import net.minecraft.tags.TagKey; -import net.minecraft.world.level.Level; +import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.dimension.LevelStem; public interface IcarusPlayerValues { @@ -23,8 +25,12 @@ public interface IcarusPlayerValues { boolean maxHeightEnabled(); - default TagKey noFlyingAllowedInDimensions() { - return IcarusDimensionTags.NO_FLYING_ALLOWED; + default TagKey noFlyingAllowedInLevels() { + return IcarusLevelTags.NO_FLYING_ALLOWED; + } + + default TagKey noFlyingAllowedInDimensions() { + return IcarusDimensionTypeTags.NO_FLYING_ALLOWED; } default float requiredFoodAmount() { diff --git a/Common/src/main/java/dev/cammiescorner/icarus/init/IcarusDimensionTags.java b/Common/src/main/java/dev/cammiescorner/icarus/init/IcarusDimensionTypeTags.java similarity index 52% rename from Common/src/main/java/dev/cammiescorner/icarus/init/IcarusDimensionTags.java rename to Common/src/main/java/dev/cammiescorner/icarus/init/IcarusDimensionTypeTags.java index 5129bd2..4e3beca 100644 --- a/Common/src/main/java/dev/cammiescorner/icarus/init/IcarusDimensionTags.java +++ b/Common/src/main/java/dev/cammiescorner/icarus/init/IcarusDimensionTypeTags.java @@ -3,10 +3,9 @@ import dev.cammiescorner.icarus.Icarus; import net.minecraft.core.registries.Registries; import net.minecraft.tags.TagKey; -import net.minecraft.world.level.Level; import net.minecraft.world.level.dimension.DimensionType; -public class IcarusDimensionTags { +public class IcarusDimensionTypeTags { - public static final TagKey NO_FLYING_ALLOWED = TagKey.create(Registries.DIMENSION, Icarus.id("no_flying_allowed")); + public static final TagKey NO_FLYING_ALLOWED = TagKey.create(Registries.DIMENSION_TYPE, Icarus.id("no_flying_allowed")); } diff --git a/Common/src/main/java/dev/cammiescorner/icarus/init/IcarusLevelTags.java b/Common/src/main/java/dev/cammiescorner/icarus/init/IcarusLevelTags.java new file mode 100644 index 0000000..c780fea --- /dev/null +++ b/Common/src/main/java/dev/cammiescorner/icarus/init/IcarusLevelTags.java @@ -0,0 +1,11 @@ +package dev.cammiescorner.icarus.init; + +import dev.cammiescorner.icarus.Icarus; +import net.minecraft.core.registries.Registries; +import net.minecraft.tags.TagKey; +import net.minecraft.world.level.dimension.LevelStem; + +public class IcarusLevelTags { + + public static final TagKey NO_FLYING_ALLOWED = TagKey.create(Registries.LEVEL_STEM, Icarus.id("no_flying_allowed")); +} diff --git a/Common/src/main/java/dev/cammiescorner/icarus/util/IcarusHelper.java b/Common/src/main/java/dev/cammiescorner/icarus/util/IcarusHelper.java index 5419d48..828c627 100644 --- a/Common/src/main/java/dev/cammiescorner/icarus/util/IcarusHelper.java +++ b/Common/src/main/java/dev/cammiescorner/icarus/util/IcarusHelper.java @@ -3,6 +3,7 @@ import dev.cammiescorner.icarus.api.IcarusPlayerValues; import dev.cammiescorner.icarus.api.SlowFallingEntity; import dev.cammiescorner.icarus.client.IcarusClient; +import dev.cammiescorner.icarus.init.IcarusDimensionTypeTags; import dev.cammiescorner.icarus.init.IcarusItemTags; import dev.cammiescorner.icarus.init.IcarusStatusEffects; import dev.cammiescorner.icarus.item.WingItem; @@ -36,12 +37,20 @@ public class IcarusHelper { public static boolean onFallFlyingTick(LivingEntity entity, @Nullable ItemStack wings, boolean tick) { IcarusPlayerValues cfg = IcarusHelper.getConfigValues(entity); - if (!entity.level().isClientSide() && entity.level().registryAccess().registryOrThrow(Registries.DIMENSION).getHolderOrThrow(entity.level().dimension()).is(cfg.noFlyingAllowedInDimensions())) { - if (entity instanceof ServerPlayer player) { - stopFlying(player); - player.sendSystemMessage(Component.translatable("message.icarus.status.no_fly.dimension").withStyle(ChatFormatting.RED), true); + var level = entity.level(); + + if(!level.isClientSide()) { + // level stem -> the actual level instance + // dimension type -> all levels of a given type + // some level stems (namely, AE2's spatial storage dimension) may not be registered properly + // first check the dimension type, then check the level itself; if either one is in the no fly tag, cancel flying and send a message + if(level.dimensionTypeRegistration().is(IcarusDimensionTypeTags.NO_FLYING_ALLOWED) || level.registryAccess().registryOrThrow(Registries.LEVEL_STEM).getHolder(Registries.levelToLevelStem(level.dimension())).map(stemHolder -> stemHolder.is(cfg.noFlyingAllowedInLevels())).orElse(false)) { + if (entity instanceof ServerPlayer player) { + stopFlying(player); + player.sendSystemMessage(Component.translatable("message.icarus.status.no_fly.dimension").withStyle(ChatFormatting.RED), true); + } + return false; } - return false; } if (entity.hasEffect(IcarusStatusEffects.flightlessHolder())) { diff --git a/Common/src/main/java/dev/cammiescorner/icarus/util/ServerPlayerFallbackValues.java b/Common/src/main/java/dev/cammiescorner/icarus/util/ServerPlayerFallbackValues.java index 36dfb53..81fb943 100644 --- a/Common/src/main/java/dev/cammiescorner/icarus/util/ServerPlayerFallbackValues.java +++ b/Common/src/main/java/dev/cammiescorner/icarus/util/ServerPlayerFallbackValues.java @@ -2,9 +2,6 @@ import dev.cammiescorner.icarus.IcarusConfig; import dev.cammiescorner.icarus.api.IcarusPlayerValues; -import dev.cammiescorner.icarus.init.IcarusDimensionTags; -import net.minecraft.tags.TagKey; -import net.minecraft.world.level.Level; public class ServerPlayerFallbackValues implements IcarusPlayerValues { @@ -43,11 +40,6 @@ public boolean maxHeightEnabled() { return IcarusConfig.maxHeightEnabled; } - @Override - public TagKey noFlyingAllowedInDimensions() { - return IcarusDimensionTags.NO_FLYING_ALLOWED; - } - @Override public int maxHeightAboveWorld() { return IcarusConfig.maxHeightAboveWorld; diff --git a/Common/src/main/resources/data/icarus/tags/dimension_type/no_flying_allowed.json b/Common/src/main/resources/data/icarus/tags/dimension_type/no_flying_allowed.json new file mode 100644 index 0000000..d275da3 --- /dev/null +++ b/Common/src/main/resources/data/icarus/tags/dimension_type/no_flying_allowed.json @@ -0,0 +1,5 @@ +{ + "replace": false, + "values": [ + ] +}