EntityCollisionContext .java

net.minecraft.world.phys.shapes.EntityCollisionContext (class, 105 lines): members: entityBottom, descending, isPlacement, heldItem, isAbove, isDescending.

net.minecraft.world.phys.shapesclass105 linescommon3.1 KB

Implements

API Surface (8)

boolean isHoldingItem(final Item item)
boolean alwaysCollideWithFluid()
boolean canStandOnFluid(final FluidState fluidStateAbove, final FluidState fluid)
VoxelShape getCollisionShape(final BlockState state, final CollisionGetter collisionGetter, final BlockPos pos)
boolean isDescending()
boolean isAbove(final VoxelShape shape, final BlockPos pos, final boolean defaultValue)
boolean isPlacement()
boolean isAbove(final VoxelShape shape, final BlockPos pos, final boolean defaultValue)

Fields & Constants (6)

descending
entityBottom
placement
heldItem
alwaysCollideWithFluid
entity

Full Source

EntityCollisionContext.java105 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.phys.shapes;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.core.Direction;
5
import net.minecraft.world.entity.Entity;
6
import net.minecraft.world.entity.LivingEntity;
7
import net.minecraft.world.item.Item;
8
import net.minecraft.world.item.ItemStack;
9
import net.minecraft.world.level.CollisionGetter;
10
import net.minecraft.world.level.block.state.BlockState;
11
import net.minecraft.world.level.material.FluidState;
12
import org.jspecify.annotations.Nullable;
13
14
public class EntityCollisionContext implements CollisionContext {
15
	private final boolean descending;
16
	private final double entityBottom;
17
	private final boolean placement;
18
	private final ItemStack heldItem;
19
	private final boolean alwaysCollideWithFluid;
20
	private final @Nullable Entity entity;
21
22
	protected EntityCollisionContext(
23
		final boolean descending,
24
		final boolean placement,
25
		final double entityBottom,
26
		final ItemStack heldItem,
27
		final boolean alwaysCollideWithFluid,
28
		final @Nullable Entity entity
29
	) {
30
		this.descending = descending;
31
		this.placement = placement;
32
		this.entityBottom = entityBottom;
33
		this.heldItem = heldItem;
34
		this.alwaysCollideWithFluid = alwaysCollideWithFluid;
35
		this.entity = entity;
36
	}
37
38
	@Deprecated
39
	protected EntityCollisionContext(final Entity entity, final boolean alwaysCollideWithFluid, final boolean placement) {
40
		this(
41
			entity.isDescending(),
42
			placement,
43
			entity.getY(),
44
			entity instanceof LivingEntity livingEntity ? livingEntity.getMainHandItem() : ItemStack.EMPTY,
45
			alwaysCollideWithFluid,
46
			entity
47
		);
48
	}
49
50
	@Override
51
	public boolean isHoldingItem(final Item item) {
52
		return this.heldItem.is(item);
53
	}
54
55
	@Override
56
	public boolean alwaysCollideWithFluid() {
57
		return this.alwaysCollideWithFluid;
58
	}
59
60
	@Override
61
	public boolean canStandOnFluid(final FluidState fluidStateAbove, final FluidState fluid) {
62
		return !(this.entity instanceof LivingEntity livingEntity)
63
			? false
64
			: livingEntity.canStandOnFluid(fluid) && !fluidStateAbove.getType().isSame(fluid.getType());
65
	}
66
67
	@Override
68
	public VoxelShape getCollisionShape(final BlockState state, final CollisionGetter collisionGetter, final BlockPos pos) {
69
		return state.getCollisionShape(collisionGetter, pos, this);
70
	}
71
72
	@Override
73
	public boolean isDescending() {
74
		return this.descending;
75
	}
76
77
	@Override
78
	public boolean isAbove(final VoxelShape shape, final BlockPos pos, final boolean defaultValue) {
79
		return this.entityBottom > pos.getY() + shape.max(Direction.Axis.Y) - 1.0E-5F;
80
	}
81
82
	public @Nullable Entity getEntity() {
83
		return this.entity;
84
	}
85
86
	@Override
87
	public boolean isPlacement() {
88
		return this.placement;
89
	}
90
91
	protected static class Empty extends EntityCollisionContext {
92
		protected static final CollisionContext WITHOUT_FLUID_COLLISIONS = new EntityCollisionContext.Empty(false);
93
		protected static final CollisionContext WITH_FLUID_COLLISIONS = new EntityCollisionContext.Empty(true);
94
95
		public Empty(final boolean alwaysCollideWithFluid) {
96
			super(false, false, -Double.MAX_VALUE, ItemStack.EMPTY, alwaysCollideWithFluid, null);
97
		}
98
99
		@Override
100
		public boolean isAbove(final VoxelShape shape, final BlockPos pos, final boolean defaultValue) {
101
			return defaultValue;
102
		}
103
	}
104
}
105

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