From c31eba5f049646f5367961da371c53554ddfbbc7 Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 28 Dec 2021 02:58:07 +0200 Subject: [PATCH] Prevent transforming into paintings, item frames, or leash knots. Fixes #39 --- .../unicopia/ability/ChangelingDisguiseAbility.java | 3 ++- .../minelittlepony/unicopia/command/DisguiseCommand.java | 3 ++- .../unicopia/entity/behaviour/EntityAppearance.java | 3 ++- .../unicopia/entity/behaviour/EntityBehaviour.java | 8 +++++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java index 8941c9a1..b31700b6 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java @@ -14,6 +14,7 @@ import com.minelittlepony.unicopia.util.RayTraceHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.FallingBlockEntity; import net.minecraft.entity.LightningEntity; +import net.minecraft.entity.decoration.AbstractDecorationEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.sound.SoundCategory; @@ -43,7 +44,7 @@ public class ChangelingDisguiseAbility extends ChangelingFeedAbility { RayTraceHelper.Trace trace = RayTraceHelper.doTrace(player, 10, 1, EntityPredicates.EXCEPT_SPECTATOR.and(e -> !(e instanceof LightningEntity))); - Entity looked = trace.getEntity().map(e -> { + Entity looked = trace.getEntity().filter(e -> !(e instanceof AbstractDecorationEntity)).map(e -> { return e instanceof PlayerEntity ? Pony.of((PlayerEntity)e) .getSpellSlot() .get(SpellPredicate.IS_DISGUISE, true) diff --git a/src/main/java/com/minelittlepony/unicopia/command/DisguiseCommand.java b/src/main/java/com/minelittlepony/unicopia/command/DisguiseCommand.java index bf851faa..a75f2a38 100644 --- a/src/main/java/com/minelittlepony/unicopia/command/DisguiseCommand.java +++ b/src/main/java/com/minelittlepony/unicopia/command/DisguiseCommand.java @@ -20,6 +20,7 @@ import net.minecraft.command.argument.NbtCompoundArgumentType; import net.minecraft.command.suggestion.SuggestionProviders; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; +import net.minecraft.entity.decoration.AbstractDecorationEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.NbtCompound; import net.minecraft.server.command.CommandManager; @@ -77,7 +78,7 @@ public class DisguiseCommand { } static int disguise(ServerCommandSource source, PlayerEntity player, Entity entity) throws CommandSyntaxException { - if (entity == null) { + if (entity == null || entity instanceof AbstractDecorationEntity) { throw FAILED_EXCEPTION.create(); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityAppearance.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityAppearance.java index edee5a6d..aab516f1 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityAppearance.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityAppearance.java @@ -269,7 +269,8 @@ public class EntityAppearance implements NbtSerialisable, PlayerDimensions.Provi public boolean skipsUpdate() { return entity instanceof FallingBlockEntity || entity instanceof AbstractDecorationEntity - || entity instanceof PlayerEntity; + || entity instanceof PlayerEntity + || entity instanceof AbstractDecorationEntity; } public boolean isAxisAligned() { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java index 834577a7..7c38ede6 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java @@ -20,6 +20,7 @@ import net.minecraft.entity.FallingBlockEntity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.MovementType; import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.decoration.AbstractDecorationEntity; import net.minecraft.entity.mob.AbstractSkeletonEntity; import net.minecraft.entity.passive.LlamaEntity; import net.minecraft.entity.passive.SnowGolemEntity; @@ -112,7 +113,12 @@ public class EntityBehaviour { boolean clip = to.noClip; to.noClip = false; Vec3d vel = from.getRotationVec(1); - to.move(MovementType.SELF, vel); + + if (!(to instanceof AbstractDecorationEntity)) { + to.move(MovementType.SELF, vel); + } else { + to.setVelocity(Vec3d.ZERO); + } to.noClip = clip; } else { to.verticalCollision = from.verticalCollision;