diff --git a/common/src/main/java/net/satisfy/farm_and_charm/core/block/CattlegridBlock.java b/common/src/main/java/net/satisfy/farm_and_charm/core/block/CattlegridBlock.java index f4fd117f..6faaee27 100644 --- a/common/src/main/java/net/satisfy/farm_and_charm/core/block/CattlegridBlock.java +++ b/common/src/main/java/net/satisfy/farm_and_charm/core/block/CattlegridBlock.java @@ -20,6 +20,7 @@ import net.minecraft.world.level.pathfinder.PathComputationType; import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.EntityCollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; import net.satisfy.farm_and_charm.core.registry.TagRegistry; @@ -28,6 +29,15 @@ import java.util.List; public class CattlegridBlock extends Block { + private static final VoxelShape FLOOR_COLLISION = Shapes.block(); + private static final VoxelShape MOB_WALLS = Shapes.or( + Block.box(0.0, 16.0, 0.0, 16.0, 28.0, 2.0), + Block.box(0.0, 16.0, 14.0, 16.0, 28.0, 16.0), + Block.box(0.0, 16.0, 0.0, 2.0, 28.0, 16.0), + Block.box(14.0, 16.0, 0.0, 16.0, 28.0, 16.0) + ); + private static final VoxelShape MOB_COLLISION = Shapes.or(FLOOR_COLLISION, MOB_WALLS); + public CattlegridBlock(Properties properties) { super(properties); } @@ -54,8 +64,7 @@ public void stepOn(Level level, BlockPos pos, BlockState state, Entity entity) { return; } - if (entity instanceof Mob mob) { - mob.makeStuckInBlock(state, new Vec3(0.0, 1.0, 0.0)); + if (entity instanceof Mob) { return; } @@ -71,7 +80,16 @@ protected boolean isPathfindable(BlockState state, PathComputationType type) { @Override public @NotNull VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { - return Shapes.block(); + if (!(context instanceof EntityCollisionContext entityContext)) { + return MOB_COLLISION; + } + + Entity entity = entityContext.getEntity(); + if (!(entity instanceof Mob) || entity.getType().is(TagRegistry.CAN_WALK_OVER_CATTLEGRID)) { + return FLOOR_COLLISION; + } + + return MOB_COLLISION; } @Override @@ -86,4 +104,4 @@ public void appendHoverText(ItemStack itemStack, Item.TooltipContext tooltipCont tooltip.add(Component.translatable("tooltip.farm_and_charm.tooltip_information.hold", shiftKey).withStyle(Style.EMPTY.withColor(TextColor.fromRgb(earthyColor)))); } } -} \ No newline at end of file +}