Skip to content

Commit

Permalink
fix crash when flying in AE2 spatial dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed Sep 21, 2024
1 parent fd5a4ae commit 17b23f7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -23,8 +25,12 @@ public interface IcarusPlayerValues {

boolean maxHeightEnabled();

default TagKey<Level> noFlyingAllowedInDimensions() {
return IcarusDimensionTags.NO_FLYING_ALLOWED;
default TagKey<LevelStem> noFlyingAllowedInLevels() {
return IcarusLevelTags.NO_FLYING_ALLOWED;
}

default TagKey<DimensionType> noFlyingAllowedInDimensions() {
return IcarusDimensionTypeTags.NO_FLYING_ALLOWED;
}

default float requiredFoodAmount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Level> NO_FLYING_ALLOWED = TagKey.create(Registries.DIMENSION, Icarus.id("no_flying_allowed"));
public static final TagKey<DimensionType> NO_FLYING_ALLOWED = TagKey.create(Registries.DIMENSION_TYPE, Icarus.id("no_flying_allowed"));
}
Original file line number Diff line number Diff line change
@@ -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<LevelStem> NO_FLYING_ALLOWED = TagKey.create(Registries.LEVEL_STEM, Icarus.id("no_flying_allowed"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -43,11 +40,6 @@ public boolean maxHeightEnabled() {
return IcarusConfig.maxHeightEnabled;
}

@Override
public TagKey<Level> noFlyingAllowedInDimensions() {
return IcarusDimensionTags.NO_FLYING_ALLOWED;
}

@Override
public int maxHeightAboveWorld() {
return IcarusConfig.maxHeightAboveWorld;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"replace": false,
"values": [
]
}

0 comments on commit 17b23f7

Please sign in to comment.