Mobs with feather falling 4 boots can now walk and pathfind on clouds

This commit is contained in:
Sollace 2024-09-25 20:34:53 +01:00
parent 4cfb8d835f
commit 4f4ac3f809
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
9 changed files with 57 additions and 8 deletions

View file

@ -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> equineContext = new Stack<>();
public static InteractionManager getInstance() {
return INSTANCE;
@ -109,11 +110,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<Pony> getClientPony() {

View file

@ -75,6 +75,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);
}
}

View file

@ -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 net.minecraft.block.Block;
@ -173,7 +174,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) {

View file

@ -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 net.minecraft.block.BlockState;
import net.minecraft.block.ChestBlock;
@ -139,7 +140,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 {

View file

@ -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 net.minecraft.block.BlockSetType;
@ -10,6 +11,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;
@ -84,4 +86,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);
}
}

View file

@ -97,6 +97,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);
}
}

View file

@ -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();
}
}

View file

@ -44,6 +44,6 @@ abstract class MixinPlayerManager {
@Inject(method = "respawnPlayer", at = @At("RETURN"))
private void afterRespawnPlayer(ServerPlayerEntity player, boolean alive, CallbackInfoReturnable<ServerPlayerEntity> info) {
InteractionManager.getInstance().setEquineContext(EquineContext.ABSENT);
InteractionManager.getInstance().clearEquineContext();
}
}

View file

@ -54,6 +54,7 @@
"MixinWorld",
"PointOfInterestTypesAccessor",
"server.MixinEntityTrackerEntry",
"server.MixinPathNodeMaker",
"server.MixinPlayerManager",
"server.MixinServerPlayerEntity",
"server.MixinServerPlayNetworkHandler",