MinecartCollisionContext .java

net.minecraft.world.phys.shapes.MinecartCollisionContext (class): members: ingoreBelow, slopeIgnore, getCollisionShape. imports: BaseRailBlock, RailShape.

net.minecraft.world.phys.shapesclass44 linescommonextends EntityCollisionContext1.7 KB

API Surface (1)

VoxelShape getCollisionShape(final BlockState state, final CollisionGetter collisionGetter, final BlockPos pos)

Fields & Constants (2)

ingoreBelow
slopeIgnore

Full Source

MinecartCollisionContext.java44 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.phys.shapes;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.world.entity.vehicle.minecart.AbstractMinecart;
5
import net.minecraft.world.level.CollisionGetter;
6
import net.minecraft.world.level.block.BaseRailBlock;
7
import net.minecraft.world.level.block.state.BlockState;
8
import net.minecraft.world.level.block.state.properties.RailShape;
9
import org.jspecify.annotations.Nullable;
10
11
public class MinecartCollisionContext extends EntityCollisionContext {
12
	private @Nullable BlockPos ingoreBelow;
13
	private @Nullable BlockPos slopeIgnore;
14
15
	protected MinecartCollisionContext(final AbstractMinecart entity, final boolean alwaysStandOnFluid) {
16
		super(entity, alwaysStandOnFluid, false);
17
		this.setupContext(entity);
18
	}
19
20
	private void setupContext(final AbstractMinecart entity) {
21
		BlockPos currentRailPos = entity.getCurrentBlockPosOrRailBelow();
22
		BlockState currentState = entity.level().getBlockState(currentRailPos);
23
		boolean onRails = BaseRailBlock.isRail(currentState);
24
		if (onRails) {
25
			this.ingoreBelow = currentRailPos.below();
26
			RailShape shape = currentState.getValue(((BaseRailBlock)currentState.getBlock()).getShapeProperty());
27
			if (shape.isSlope()) {
28
				this.slopeIgnore = switch (shape) {
29
					case ASCENDING_EAST -> currentRailPos.east();
30
					case ASCENDING_WEST -> currentRailPos.west();
31
					case ASCENDING_NORTH -> currentRailPos.north();
32
					case ASCENDING_SOUTH -> currentRailPos.south();
33
					default -> null;
34
				};
35
			}
36
		}
37
	}
38
39
	@Override
40
	public VoxelShape getCollisionShape(final BlockState state, final CollisionGetter collisionGetter, final BlockPos pos) {
41
		return !pos.equals(this.ingoreBelow) && !pos.equals(this.slopeIgnore) ? super.getCollisionShape(state, collisionGetter, pos) : Shapes.empty();
42
	}
43
}
44

Decompiled Minecraft 26.3 source of MinecartCollisionContext (net/minecraft/world/phys/shapes/MinecartCollisionContext.java) with Mojang official mappings, stored verbatim on the site.