mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Mobs with feather falling 4 boots can now walk and pathfind on clouds
This commit is contained in:
parent
122781ea43
commit
0a44fb066d
9 changed files with 57 additions and 8 deletions
|
@ -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;
|
||||
|
@ -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<Pony> getClientPony() {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
"MixinWorld",
|
||||
"PointOfInterestTypesAccessor",
|
||||
"server.MixinEntityTrackerEntry",
|
||||
"server.MixinPathNodeMaker",
|
||||
"server.MixinPlayerManager",
|
||||
"server.MixinServerPlayerEntity",
|
||||
"server.MixinServerPlayNetworkHandler",
|
||||
|
|
Loading…
Reference in a new issue