Added a c:has_no_atmosphere dimension_type tag to disable pegasus flight when in spaaaaaaace #120

This commit is contained in:
Sollace 2023-06-06 21:44:49 +01:00
parent 42f186c0a5
commit 6c1c3e17d2
5 changed files with 26 additions and 3 deletions

View file

@ -9,6 +9,8 @@ import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.item.Item;
import net.minecraft.registry.*;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;
import net.minecraft.world.dimension.DimensionType;
public interface UTags {
TagKey<Item> APPLES = item("apples");
@ -42,6 +44,8 @@ public interface UTags {
TagKey<DamageType> BREAKS_SUNGLASSES = damage("breaks_sunglasses");
TagKey<DimensionType> HAS_NO_ATMOSPHERE = dimension("has_no_atmosphere");
static TagKey<Item> item(String name) {
return TagKey.of(RegistryKeys.ITEM, Unicopia.id(name));
}
@ -62,6 +66,10 @@ public interface UTags {
return TagKey.of(RegistryKeys.DAMAGE_TYPE, Unicopia.id(name));
}
static TagKey<DimensionType> dimension(String name) {
return TagKey.of(RegistryKeys.DIMENSION_TYPE, new Identifier("c", name));
}
static void bootstrap() {
Toxics.bootstrap();
}

View file

@ -30,7 +30,7 @@ public class PegasusFlightToggleAbility implements Ability<Hit> {
@Nullable
@Override
public Hit tryActivate(Pony player) {
return player.asEntity().isCreative() ? null : Hit.INSTANCE;
return player.asEntity().isCreative() || player.getPhysics().getFlightType().isGrounded() ? null : Hit.INSTANCE;
}
@Override
@ -54,7 +54,7 @@ public class PegasusFlightToggleAbility implements Ability<Hit> {
@Override
public void apply(Pony player, Hit data) {
if (player.asEntity().isCreative()) {
if (tryActivate(player) == null) {
return;
}

View file

@ -35,10 +35,11 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.math.*;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.event.GameEvent;
public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickable, Motion, NbtSerialisable {
@ -154,6 +155,11 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
}
public FlightType getFlightType() {
DimensionType dimension = entity.getWorld().getDimension();
if (RegistryUtils.isIn(entity.getWorld(), dimension, RegistryKeys.DIMENSION_TYPE, UTags.HAS_NO_ATMOSPHERE)) {
return FlightType.NONE;
}
if (UItems.PEGASUS_AMULET.isApplicable(entity)) {
return FlightType.ARTIFICIAL;

View file

@ -49,4 +49,8 @@ public interface RegistryUtils {
.filter(filter)
.toList(), world.random);
}
static <T> boolean isIn(World world, T obj, RegistryKey<? extends Registry<T>> registry, TagKey<T> tag) {
return world.getRegistryManager().get(registry).getEntry(obj).isIn(tag);
}
}

View file

@ -0,0 +1,5 @@
{
"replace": false,
"values": [
]
}