diff --git a/src/main/java/com/minelittlepony/unicopia/InteractionManager.java b/src/main/java/com/minelittlepony/unicopia/InteractionManager.java index 98763054..549e6c86 100644 --- a/src/main/java/com/minelittlepony/unicopia/InteractionManager.java +++ b/src/main/java/com/minelittlepony/unicopia/InteractionManager.java @@ -2,6 +2,7 @@ package com.minelittlepony.unicopia; import java.util.Map; import java.util.Optional; +import java.util.Stack; import java.util.UUID; import org.jetbrains.annotations.NotNull; @@ -37,7 +38,7 @@ public class InteractionManager { @Nullable private SyncedConfig config; - private EquineContext equineContext = EquineContext.ABSENT; + private final Stack equineContext = new Stack<>(); public static InteractionManager getInstance() { return INSTANCE; @@ -113,11 +114,21 @@ public class InteractionManager { } public void setEquineContext(EquineContext context) { - equineContext = context; + equineContext.push(context); + } + + public void clearEquineContext() { + if (!equineContext.isEmpty()) { + equineContext.pop(); + } } public EquineContext getEquineContext() { - return getClientPony().map(EquineContext.class::cast).orElse(equineContext); + return getClientPony().map(EquineContext.class::cast).orElseGet(this::getPathingEquineContext); + } + + public EquineContext getPathingEquineContext() { + return equineContext.isEmpty() ? EquineContext.ABSENT : equineContext.peek(); } public Optional getClientPony() { diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBedBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBedBlock.java index 2ce5bddd..c851aff4 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBedBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBedBlock.java @@ -92,6 +92,6 @@ public class CloudBedBlock extends FancyBedBlock implements CloudLike { @Override @Deprecated public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { - return true; + return baseState.canPathfindThrough(world, pos, type); } } diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBlock.java index 1cab503e..c1c74a05 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBlock.java @@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.block.cloud; import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.EquineContext; +import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.entity.player.Pony; import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec; @@ -187,7 +188,8 @@ public class CloudBlock extends Block implements CloudLike { @Override @Deprecated public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { - return true; + System.out.println(InteractionManager.getInstance().getPathingEquineContext().collidesWithClouds()); + return type != NavigationType.LAND || !InteractionManager.getInstance().getPathingEquineContext().collidesWithClouds(); } protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, EquineContext equineContext) { diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudChestBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudChestBlock.java index f0ee4149..ce7f0d4b 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudChestBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudChestBlock.java @@ -5,6 +5,7 @@ import java.util.Optional; import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.EquineContext; +import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.block.UBlockEntities; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; @@ -152,7 +153,7 @@ public class CloudChestBlock extends ChestBlock implements CloudLike { @Override @Deprecated public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { - return true; + return type != NavigationType.LAND || !InteractionManager.getInstance().getPathingEquineContext().collidesWithClouds(); } public static class TileData extends ChestBlockEntity { diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudDoorBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudDoorBlock.java index eb30c220..6ee33082 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudDoorBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudDoorBlock.java @@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.block.cloud; import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.EquineContext; +import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.Race; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; @@ -12,6 +13,7 @@ import net.minecraft.block.BlockState; import net.minecraft.block.DoorBlock; import net.minecraft.block.ShapeContext; import net.minecraft.entity.Entity; +import net.minecraft.entity.ai.pathing.NavigationType; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemPlacementContext; import net.minecraft.util.ActionResult; @@ -95,4 +97,10 @@ public class CloudDoorBlock extends DoorBlock implements CloudLike { entity.setVelocity(entity.getVelocity().multiply(0.5F, 1, 0.5F)); } } + + @Override + @Deprecated + public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { + return !InteractionManager.getInstance().getPathingEquineContext().collidesWithClouds() || super.canPathfindThrough(state, world, pos, type); + } } diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudStairsBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudStairsBlock.java index 743640b0..454e1fd1 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudStairsBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudStairsBlock.java @@ -109,6 +109,6 @@ public class CloudStairsBlock extends StairsBlock implements CloudLike { @Override @Deprecated public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { - return true; + return baseBlock.canPathfindThrough(state, world, pos, type); } } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/server/MixinPathNodeMaker.java b/src/main/java/com/minelittlepony/unicopia/mixin/server/MixinPathNodeMaker.java new file mode 100644 index 00000000..9e18310c --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/server/MixinPathNodeMaker.java @@ -0,0 +1,26 @@ +package com.minelittlepony.unicopia.mixin.server; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import com.minelittlepony.unicopia.EquineContext; +import com.minelittlepony.unicopia.InteractionManager; + +import net.minecraft.entity.ai.pathing.PathNodeMaker; +import net.minecraft.entity.mob.MobEntity; +import net.minecraft.world.chunk.ChunkCache; + +@Mixin(PathNodeMaker.class) +abstract class MixinPathNodeMaker { + @Inject(method = "init", at = @At("HEAD")) + private void onInit(ChunkCache cachedWorld, MobEntity entity, CallbackInfo info) { + InteractionManager.getInstance().setEquineContext(EquineContext.of(entity)); + } + + @Inject(method = "clear", at = @At("HEAD")) + private void onClear(CallbackInfo info) { + InteractionManager.getInstance().clearEquineContext(); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/server/MixinPlayerManager.java b/src/main/java/com/minelittlepony/unicopia/mixin/server/MixinPlayerManager.java index 0c845c1c..271bf40a 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/server/MixinPlayerManager.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/server/MixinPlayerManager.java @@ -44,6 +44,6 @@ abstract class MixinPlayerManager { @Inject(method = "respawnPlayer", at = @At("RETURN")) private void afterRespawnPlayer(ServerPlayerEntity player, boolean alive, CallbackInfoReturnable info) { - InteractionManager.getInstance().setEquineContext(EquineContext.ABSENT); + InteractionManager.getInstance().clearEquineContext(); } } diff --git a/src/main/resources/unicopia.mixin.json b/src/main/resources/unicopia.mixin.json index 62c6fa11..99bd3a70 100644 --- a/src/main/resources/unicopia.mixin.json +++ b/src/main/resources/unicopia.mixin.json @@ -55,6 +55,7 @@ "MixinWorld", "PointOfInterestTypesAccessor", "server.MixinEntityTrackerEntry", + "server.MixinPathNodeMaker", "server.MixinPlayerManager", "server.MixinServerPlayerEntity", "server.MixinServerPlayNetworkHandler",