AbstractMinecart .java

net.minecraft.world.entity.vehicle.minecart.AbstractMinecart (class): members: getCurrentBlockPosOrRailBelow, DATA_ID_CUSTOM_DISPLAY_BLOCK, exits, EXITS.

net.minecraft.world.entity.vehicle.minecartclass617 linescommonextends VehicleEntity19.6 KB

API Surface (54)

void setInitialPos(final double x, final double y, final double z)
MinecartBehavior getBehavior()
Entity.MovementEmission getMovementEmission()
void defineSynchedData(final SynchedEntityData.Builder entityData)
boolean canCollideWith(final Entity entity)
boolean isPushable()
Vec3 getRelativePortalPosition(final Direction.Axis axis, final BlockUtil.FoundRectangle portalArea)
Vec3 getPassengerAttachmentPoint(final Entity passenger, final EntityDimensions dimensions, final float scale)
Vec3 getDismountLocationForPassenger(final LivingEntity passenger)
float getBlockSpeedFactor()
void animateHurt(final float yaw)
boolean isPickable()
Pair<Vec3i, Vec3i> exits(final RailShape shape)
Direction getMotionDirection()
double getDefaultGravity()
void tick()
boolean isFirstTick()
BlockPos getCurrentBlockPosOrRailBelow()
double getMaxSpeed(final ServerLevel level)
void activateMinecart(final ServerLevel level, final int xt, final int yt, final int zt, final boolean state)
void lerpPositionAndRotationStep(final int stepsToTarget, final double targetX, final double targetY, final double targetZ, final double targetYRot, final double targetXRot)
void applyGravity()
void reapplyPosition()
boolean updateFluidInteraction()
Vec3 getKnownMovement()
InterpolationHandler createInterpolationHandler()
void onInterpolationStart(final InterpolationHandler interpolation)
void recreateFromPacket(final ClientboundAddEntityPacket packet)
void lerpMotion(final Vec3 movement)
void moveAlongTrack(final ServerLevel level)
void comeOffTrack(final ServerLevel level)
float getAirDrag()
double makeStepAlongTrack(final BlockPos pos, final RailShape shape, final double movementLeft)
void move(final MoverType moverType, final Vec3 delta)
void applyEffectsFromBlocks()
boolean isOnRails()
void setOnRails(final boolean onRails)
boolean isFlipped()
void setFlipped(final boolean flipped)
Vec3 getRedstoneDirection(final BlockPos pos)
boolean isRedstoneConductor(final BlockPos pos)
Vec3 applyNaturalSlowdown(final Vec3 movement)
void readAdditionalSaveData(final ValueInput input)
void addAdditionalSaveData(final ValueOutput output)
void push(final Entity entity)
BlockState getDisplayBlockState()
BlockState getDefaultDisplayBlockState()
int getDisplayOffset()
int getDefaultDisplayOffset()
void setCustomDisplayBlockState(final Optional<BlockState> state)
void setDisplayOffset(final int offset)
boolean useExperimentalMovement(final Level level)
boolean isRideable()
boolean isFurnace()

Fields & Constants (18)

LOWERED_PASSENGER_ATTACHMENT
DATA_ID_CUSTOM_DISPLAY_BLOCK
DATA_ID_DISPLAY_OFFSET
POSE_DISMOUNT_HEIGHTS
WATER_SLOWDOWN_FACTOR
DEFAULT_FLIPPED_ROTATION
EXITS
onRails
flipped
behavior
level
x
y
z
type
reason
itemStack
targetYRot

String literals (4)

"DisplayState"
"DisplayOffset"
"FlippedRotation"
"HasTicked"

Full Source

AbstractMinecart.java617 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.vehicle.minecart;
2
3
import com.google.common.collect.ImmutableList;
4
import com.google.common.collect.ImmutableMap;
5
import com.google.common.collect.Maps;
6
import com.mojang.datafixers.util.Pair;
7
import java.util.Map;
8
import java.util.Optional;
9
import net.minecraft.core.BlockPos;
10
import net.minecraft.core.Direction;
11
import net.minecraft.core.Vec3i;
12
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
13
import net.minecraft.network.syncher.EntityDataAccessor;
14
import net.minecraft.network.syncher.EntityDataSerializers;
15
import net.minecraft.network.syncher.SynchedEntityData;
16
import net.minecraft.server.level.ServerLevel;
17
import net.minecraft.tags.BlockTags;
18
import net.minecraft.util.BlockUtil;
19
import net.minecraft.util.Mth;
20
import net.minecraft.util.Util;
21
import net.minecraft.world.entity.Entity;
22
import net.minecraft.world.entity.EntityDimensions;
23
import net.minecraft.world.entity.EntitySpawnReason;
24
import net.minecraft.world.entity.EntityType;
25
import net.minecraft.world.entity.InterpolationHandler;
26
import net.minecraft.world.entity.LinearInterpolationHandler;
27
import net.minecraft.world.entity.LivingEntity;
28
import net.minecraft.world.entity.MoverType;
29
import net.minecraft.world.entity.Pose;
30
import net.minecraft.world.entity.npc.villager.Villager;
31
import net.minecraft.world.entity.npc.wanderingtrader.WanderingTrader;
32
import net.minecraft.world.entity.player.Player;
33
import net.minecraft.world.entity.vehicle.DismountHelper;
34
import net.minecraft.world.entity.vehicle.VehicleEntity;
35
import net.minecraft.world.entity.vehicle.boat.AbstractBoat;
36
import net.minecraft.world.flag.FeatureFlags;
37
import net.minecraft.world.item.ItemStack;
38
import net.minecraft.world.level.Level;
39
import net.minecraft.world.level.block.BaseRailBlock;
40
import net.minecraft.world.level.block.Blocks;
41
import net.minecraft.world.level.block.PoweredRailBlock;
42
import net.minecraft.world.level.block.state.BlockState;
43
import net.minecraft.world.level.block.state.properties.RailShape;
44
import net.minecraft.world.level.storage.ValueInput;
45
import net.minecraft.world.level.storage.ValueOutput;
46
import net.minecraft.world.phys.AABB;
47
import net.minecraft.world.phys.Vec3;
48
import org.jspecify.annotations.Nullable;
49
50
public abstract class AbstractMinecart extends VehicleEntity {
51
	private static final Vec3 LOWERED_PASSENGER_ATTACHMENT = new Vec3(0.0, 0.0, 0.0);
52
	private static final EntityDataAccessor<Optional<BlockState>> DATA_ID_CUSTOM_DISPLAY_BLOCK = SynchedEntityData.defineId(
53
		AbstractMinecart.class, EntityDataSerializers.OPTIONAL_BLOCK_STATE
54
	);
55
	private static final EntityDataAccessor<Integer> DATA_ID_DISPLAY_OFFSET = SynchedEntityData.defineId(AbstractMinecart.class, EntityDataSerializers.INT);
56
	private static final ImmutableMap<Pose, ImmutableList<Integer>> POSE_DISMOUNT_HEIGHTS = ImmutableMap.of(
57
		Pose.STANDING, ImmutableList.of(0, 1, -1), Pose.CROUCHING, ImmutableList.of(0, 1, -1), Pose.SWIMMING, ImmutableList.of(0, 1)
58
	);
59
	protected static final float WATER_SLOWDOWN_FACTOR = 0.95F;
60
	private static final boolean DEFAULT_FLIPPED_ROTATION = false;
61
	private boolean onRails;
62
	private boolean flipped = false;
63
	private final MinecartBehavior behavior;
64
	private static final Map<RailShape, Pair<Vec3i, Vec3i>> EXITS = Maps.newEnumMap(
65
		Util.make(
66
			() -> {
67
				Vec3i xNeg = Direction.WEST.getUnitVec3i();
68
				Vec3i xPos = Direction.EAST.getUnitVec3i();
69
				Vec3i zNeg = Direction.NORTH.getUnitVec3i();
70
				Vec3i zPos = Direction.SOUTH.getUnitVec3i();
71
				Vec3i xNegBelow = xNeg.below();
72
				Vec3i xPosBelow = xPos.below();
73
				Vec3i zNegBelow = zNeg.below();
74
				Vec3i zPosBelow = zPos.below();
75
				return ImmutableMap.of(
76
					RailShape.NORTH_SOUTH,
77
					Pair.of(zNeg, zPos),
78
					RailShape.EAST_WEST,
79
					Pair.of(xNeg, xPos),
80
					RailShape.ASCENDING_EAST,
81
					Pair.of(xNegBelow, xPos),
82
					RailShape.ASCENDING_WEST,
83
					Pair.of(xNeg, xPosBelow),
84
					RailShape.ASCENDING_NORTH,
85
					Pair.of(zNeg, zPosBelow),
86
					RailShape.ASCENDING_SOUTH,
87
					Pair.of(zNegBelow, zPos),
88
					RailShape.SOUTH_EAST,
89
					Pair.of(zPos, xPos),
90
					RailShape.SOUTH_WEST,
91
					Pair.of(zPos, xNeg),
92
					RailShape.NORTH_WEST,
93
					Pair.of(zNeg, xNeg),
94
					RailShape.NORTH_EAST,
95
					Pair.of(zNeg, xPos)
96
				);
97
			}
98
		)
99
	);
100
101
	protected AbstractMinecart(final EntityType<?> type, final Level level) {
102
		super(type, level);
103
		this.blocksBuilding = true;
104
		if (useExperimentalMovement(level)) {
105
			this.behavior = new NewMinecartBehavior(this);
106
		} else {
107
			this.behavior = new OldMinecartBehavior(this);
108
		}
109
	}
110
111
	protected AbstractMinecart(final EntityType<?> type, final Level level, final double x, final double y, final double z) {
112
		this(type, level);
113
		this.setInitialPos(x, y, z);
114
	}
115
116
	public void setInitialPos(final double x, final double y, final double z) {
117
		this.setPos(x, y, z);
118
		this.xo = x;
119
		this.yo = y;
120
		this.zo = z;
121
	}
122
123
	public static <T extends AbstractMinecart> @Nullable T createMinecart(
124
		final Level level,
125
		final double x,
126
		final double y,
127
		final double z,
128
		final EntityType<T> type,
129
		final EntitySpawnReason reason,
130
		final ItemStack itemStack,
131
		final @Nullable Player player
132
	) {
133
		T entity = (T)type.create(level, reason);
134
		if (entity != null) {
135
			entity.setInitialPos(x, y, z);
136
			EntityType.createDefaultStackConfig(level, itemStack, player).apply(entity);
137
			if (entity.getBehavior() instanceof NewMinecartBehavior newMinecartBehavior) {
138
				BlockPos currentPos = entity.getCurrentBlockPosOrRailBelow();
139
				BlockState currentState = level.getBlockState(currentPos);
140
				newMinecartBehavior.adjustToRails(currentPos, currentState, true);
141
			}
142
		}
143
144
		return entity;
145
	}
146
147
	public MinecartBehavior getBehavior() {
148
		return this.behavior;
149
	}
150
151
	@Override
152
	protected Entity.MovementEmission getMovementEmission() {
153
		return Entity.MovementEmission.EVENTS;
154
	}
155
156
	@Override
157
	protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
158
		super.defineSynchedData(entityData);
159
		entityData.define(DATA_ID_CUSTOM_DISPLAY_BLOCK, Optional.empty());
160
		entityData.define(DATA_ID_DISPLAY_OFFSET, this.getDefaultDisplayOffset());
161
	}
162
163
	@Override
164
	public boolean canCollideWith(final Entity entity) {
165
		return AbstractBoat.canVehicleCollide(this, entity);
166
	}
167
168
	@Override
169
	public boolean isPushable() {
170
		return true;
171
	}
172
173
	@Override
174
	public Vec3 getRelativePortalPosition(final Direction.Axis axis, final BlockUtil.FoundRectangle portalArea) {
175
		return LivingEntity.resetForwardDirectionOfRelativePortalPosition(super.getRelativePortalPosition(axis, portalArea));
176
	}
177
178
	@Override
179
	protected Vec3 getPassengerAttachmentPoint(final Entity passenger, final EntityDimensions dimensions, final float scale) {
180
		boolean shouldLowerAttachmentPoint = passenger instanceof Villager || passenger instanceof WanderingTrader;
181
		return shouldLowerAttachmentPoint ? LOWERED_PASSENGER_ATTACHMENT : super.getPassengerAttachmentPoint(passenger, dimensions, scale);
182
	}
183
184
	@Override
185
	public Vec3 getDismountLocationForPassenger(final LivingEntity passenger) {
186
		Direction forward = this.getMotionDirection();
187
		if (forward.getAxis() == Direction.Axis.Y) {
188
			return super.getDismountLocationForPassenger(passenger);
189
		}
190
191
		int[][] offsets = DismountHelper.offsetsForDirection(forward);
192
		BlockPos vehicleBlockPos = this.blockPosition();
193
		BlockPos.MutableBlockPos targetBlockPos = new BlockPos.MutableBlockPos();
194
		ImmutableList<Pose> dismountPoses = passenger.getDismountPoses();
195
196
		for (Pose pose : dismountPoses) {
197
			EntityDimensions passengerDimensions = passenger.getDimensions(pose);
198
			float dismountAreaReach = Math.min(passengerDimensions.width(), 1.0F) / 2.0F;
199
200
			for (int offsetY : POSE_DISMOUNT_HEIGHTS.get(pose)) {
201
				for (int[] offsetXZ : offsets) {
202
					targetBlockPos.set(vehicleBlockPos.getX() + offsetXZ[0], vehicleBlockPos.getY() + offsetY, vehicleBlockPos.getZ() + offsetXZ[1]);
203
					double blockFloorHeight = this.level()
204
						.getBlockFloorHeight(
205
							DismountHelper.nonClimbableShape(this.level(), targetBlockPos), () -> DismountHelper.nonClimbableShape(this.level(), targetBlockPos.below())
206
						);
207
					if (DismountHelper.isBlockFloorValid(blockFloorHeight)) {
208
						AABB dismountCollisionBox = new AABB(-dismountAreaReach, 0.0, -dismountAreaReach, dismountAreaReach, passengerDimensions.height(), dismountAreaReach);
209
						Vec3 location = Vec3.upFromBottomCenterOf(targetBlockPos, blockFloorHeight);
210
						if (DismountHelper.canDismountTo(this.level(), passenger, dismountCollisionBox.move(location))) {
211
							passenger.setPose(pose);
212
							return location;
213
						}
214
					}
215
				}
216
			}
217
		}
218
219
		double vehicleTop = this.getBoundingBox().maxY;
220
		targetBlockPos.set(vehicleBlockPos.getX(), vehicleTop, vehicleBlockPos.getZ());
221
222
		for (Pose pose : dismountPoses) {
223
			double poseHeight = passenger.getDimensions(pose).height();
224
			int blockCoverageY = Mth.ceil(vehicleTop - targetBlockPos.getY() + poseHeight);
225
			double ceilingAboveVehicle = DismountHelper.findCeilingFrom(
226
				targetBlockPos, blockCoverageY, pos -> this.level().getBlockState(pos).getCollisionShape(this.level(), pos)
227
			);
228
			if (vehicleTop + poseHeight <= ceilingAboveVehicle) {
229
				passenger.setPose(pose);
230
				break;
231
			}
232
		}
233
234
		return super.getDismountLocationForPassenger(passenger);
235
	}
236
237
	@Override
238
	protected float getBlockSpeedFactor() {
239
		BlockState blockState = this.level().getBlockState(this.blockPosition());
240
		return blockState.is(BlockTags.RAILS) ? 1.0F : super.getBlockSpeedFactor();
241
	}
242
243
	@Override
244
	public void animateHurt(final float yaw) {
245
		this.setHurtDir(-this.getHurtDir());
246
		this.setHurtTime(10);
247
		this.setDamage(this.getDamage() + this.getDamage() * 10.0F);
248
	}
249
250
	@Override
251
	public boolean isPickable() {
252
		return !this.isRemoved();
253
	}
254
255
	public static Pair<Vec3i, Vec3i> exits(final RailShape shape) {
256
		return EXITS.get(shape);
257
	}
258
259
	@Override
260
	public Direction getMotionDirection() {
261
		return this.behavior.getMotionDirection();
262
	}
263
264
	@Override
265
	protected double getDefaultGravity() {
266
		return this.isInWater() ? 0.005 : 0.04;
267
	}
268
269
	@Override
270
	public void tick() {
271
		if (this.getHurtTime() > 0) {
272
			this.setHurtTime(this.getHurtTime() - 1);
273
		}
274
275
		if (this.getDamage() > 0.0F) {
276
			this.setDamage(this.getDamage() - 1.0F);
277
		}
278
279
		this.checkBelowWorld();
280
		this.computeSpeed();
281
		this.handlePortal();
282
		this.behavior.tick();
283
		this.updateFluidInteraction();
284
		if (this.isInLava()) {
285
			this.lavaIgnite();
286
			this.lavaHurt();
287
			this.fallDistance *= 0.5;
288
		}
289
290
		this.firstTick = false;
291
	}
292
293
	public boolean isFirstTick() {
294
		return this.firstTick;
295
	}
296
297
	public BlockPos getCurrentBlockPosOrRailBelow() {
298
		int xt = Mth.floor(this.getX());
299
		int yt = Mth.floor(this.getY());
300
		int zt = Mth.floor(this.getZ());
301
		if (useExperimentalMovement(this.level())) {
302
			double y = this.getY() - 0.1 - 1.0E-5F;
303
			if (this.level().getBlockState(BlockPos.containing(xt, y, zt)).is(BlockTags.RAILS)) {
304
				yt = Mth.floor(y);
305
			}
306
		} else if (this.level().getBlockState(new BlockPos(xt, yt - 1, zt)).is(BlockTags.RAILS)) {
307
			yt--;
308
		}
309
310
		return new BlockPos(xt, yt, zt);
311
	}
312
313
	protected double getMaxSpeed(final ServerLevel level) {
314
		return this.behavior.getMaxSpeed(level);
315
	}
316
317
	public void activateMinecart(final ServerLevel level, final int xt, final int yt, final int zt, final boolean state) {
318
	}
319
320
	@Override
321
	public void lerpPositionAndRotationStep(
322
		final int stepsToTarget, final double targetX, final double targetY, final double targetZ, final double targetYRot, final double targetXRot
323
	) {
324
		super.lerpPositionAndRotationStep(stepsToTarget, targetX, targetY, targetZ, targetYRot, targetXRot);
325
	}
326
327
	@Override
328
	public void applyGravity() {
329
		super.applyGravity();
330
	}
331
332
	@Override
333
	public void reapplyPosition() {
334
		super.reapplyPosition();
335
	}
336
337
	@Override
338
	public boolean updateFluidInteraction() {
339
		return super.updateFluidInteraction();
340
	}
341
342
	@Override
343
	public Vec3 getKnownMovement() {
344
		return this.behavior.getKnownMovement(super.getKnownMovement());
345
	}
346
347
	@Override
348
	protected InterpolationHandler createInterpolationHandler() {
349
		return useExperimentalMovement(this.level()) ? InterpolationHandler.NO_OP : LinearInterpolationHandler.create(this);
350
	}
351
352
	@Override
353
	public void onInterpolationStart(final InterpolationHandler interpolation) {
354
		this.behavior.onInterpolationStart(interpolation);
355
	}
356
357
	@Override
358
	public void recreateFromPacket(final ClientboundAddEntityPacket packet) {
359
		super.recreateFromPacket(packet);
360
		this.behavior.lerpMotion(this.getDeltaMovement());
361
	}
362
363
	@Override
364
	public void lerpMotion(final Vec3 movement) {
365
		this.behavior.lerpMotion(movement);
366
	}
367
368
	protected void moveAlongTrack(final ServerLevel level) {
369
		this.behavior.moveAlongTrack(level);
370
	}
371
372
	protected void comeOffTrack(final ServerLevel level) {
373
		double maxSpeed = this.getMaxSpeed(level);
374
		Vec3 movement = this.getDeltaMovement();
375
		this.setDeltaMovement(Mth.clamp(movement.x, -maxSpeed, maxSpeed), movement.y, Mth.clamp(movement.z, -maxSpeed, maxSpeed));
376
		if (this.onGround()) {
377
			this.setDeltaMovement(this.getDeltaMovement().scale(0.5));
378
		}
379
380
		this.move(MoverType.SELF, this.getDeltaMovement());
381
		if (!this.onGround()) {
382
			this.setDeltaMovement(this.getDeltaMovement().scale(this.getAirDrag()));
383
		}
384
	}
385
386
	@Override
387
	protected float getAirDrag() {
388
		return 0.95F;
389
	}
390
391
	protected double makeStepAlongTrack(final BlockPos pos, final RailShape shape, final double movementLeft) {
392
		return this.behavior.stepAlongTrack(pos, shape, movementLeft);
393
	}
394
395
	@Override
396
	public void move(final MoverType moverType, final Vec3 delta) {
397
		if (useExperimentalMovement(this.level())) {
398
			Vec3 toPosition = this.position().add(delta);
399
			super.move(moverType, delta);
400
			boolean shouldContinue = this.behavior.pushAndPickupEntities();
401
			if (shouldContinue) {
402
				super.move(moverType, toPosition.subtract(this.position()));
403
			}
404
405
			if (moverType.equals(MoverType.PISTON)) {
406
				this.onRails = false;
407
			}
408
		} else {
409
			super.move(moverType, delta);
410
			this.applyEffectsFromBlocks();
411
		}
412
	}
413
414
	@Override
415
	public void applyEffectsFromBlocks() {
416
		if (useExperimentalMovement(this.level())) {
417
			super.applyEffectsFromBlocks();
418
		} else {
419
			this.applyEffectsFromBlocks(this.position(), this.position());
420
			this.clearMovementThisTick();
421
		}
422
	}
423
424
	@Override
425
	public boolean isOnRails() {
426
		return this.onRails;
427
	}
428
429
	public void setOnRails(final boolean onRails) {
430
		this.onRails = onRails;
431
	}
432
433
	public boolean isFlipped() {
434
		return this.flipped;
435
	}
436
437
	public void setFlipped(final boolean flipped) {
438
		this.flipped = flipped;
439
	}
440
441
	public Vec3 getRedstoneDirection(final BlockPos pos) {
442
		BlockState state = this.level().getBlockState(pos);
443
		if (state.is(Blocks.POWERED_RAIL) && state.getValue(PoweredRailBlock.POWERED)) {
444
			RailShape shape = state.getValue(((BaseRailBlock)state.getBlock()).getShapeProperty());
445
			if (shape == RailShape.EAST_WEST) {
446
				if (this.isRedstoneConductor(pos.west())) {
447
					return new Vec3(1.0, 0.0, 0.0);
448
				}
449
450
				if (this.isRedstoneConductor(pos.east())) {
451
					return new Vec3(-1.0, 0.0, 0.0);
452
				}
453
			} else if (shape == RailShape.NORTH_SOUTH) {
454
				if (this.isRedstoneConductor(pos.north())) {
455
					return new Vec3(0.0, 0.0, 1.0);
456
				}
457
458
				if (this.isRedstoneConductor(pos.south())) {
459
					return new Vec3(0.0, 0.0, -1.0);
460
				}
461
			}
462
463
			return Vec3.ZERO;
464
		} else {
465
			return Vec3.ZERO;
466
		}
467
	}
468
469
	public boolean isRedstoneConductor(final BlockPos pos) {
470
		return this.level().getBlockState(pos).isRedstoneConductor(this.level(), pos);
471
	}
472
473
	protected Vec3 applyNaturalSlowdown(final Vec3 movement) {
474
		double slowdownFactor = this.behavior.getSlowdownFactor();
475
		Vec3 newMovement = movement.multiply(slowdownFactor, 0.0, slowdownFactor);
476
		if (this.isInWater()) {
477
			newMovement = newMovement.scale(0.95F);
478
		}
479
480
		return newMovement;
481
	}
482
483
	@Override
484
	protected void readAdditionalSaveData(final ValueInput input) {
485
		this.setCustomDisplayBlockState(input.read("DisplayState", BlockState.CODEC));
486
		this.setDisplayOffset(input.getIntOr("DisplayOffset", this.getDefaultDisplayOffset()));
487
		this.flipped = input.getBooleanOr("FlippedRotation", false);
488
		this.firstTick = input.getBooleanOr("HasTicked", false);
489
	}
490
491
	@Override
492
	protected void addAdditionalSaveData(final ValueOutput output) {
493
		this.getCustomDisplayBlockState().ifPresent(blockState -> output.store("DisplayState", BlockState.CODEC, blockState));
494
		int displayOffset = this.getDisplayOffset();
495
		if (displayOffset != this.getDefaultDisplayOffset()) {
496
			output.putInt("DisplayOffset", displayOffset);
497
		}
498
499
		output.putBoolean("FlippedRotation", this.flipped);
500
		output.putBoolean("HasTicked", this.firstTick);
501
	}
502
503
	@Override
504
	public void push(final Entity entity) {
505
		if (!this.level().isClientSide()) {
506
			if (!entity.noPhysics && !this.noPhysics) {
507
				if (!this.hasPassenger(entity)) {
508
					double xa = entity.getX() - this.getX();
509
					double za = entity.getZ() - this.getZ();
510
					double dd = xa * xa + za * za;
511
					if (dd >= 1.0E-4F) {
512
						dd = Math.sqrt(dd);
513
						xa /= dd;
514
						za /= dd;
515
						double pow = 1.0 / dd;
516
						if (pow > 1.0) {
517
							pow = 1.0;
518
						}
519
520
						xa *= pow;
521
						za *= pow;
522
						xa *= 0.1F;
523
						za *= 0.1F;
524
						xa *= 0.5;
525
						za *= 0.5;
526
						if (entity instanceof AbstractMinecart otherMinecart) {
527
							this.pushOtherMinecart(otherMinecart, xa, za);
528
						} else {
529
							this.push(-xa, 0.0, -za);
530
							entity.push(xa / 4.0, 0.0, za / 4.0);
531
						}
532
					}
533
				}
534
			}
535
		}
536
	}
537
538
	private void pushOtherMinecart(final AbstractMinecart otherMinecart, final double xa, final double za) {
539
		double xo;
540
		double zo;
541
		if (useExperimentalMovement(this.level())) {
542
			xo = this.getDeltaMovement().x;
543
			zo = this.getDeltaMovement().z;
544
		} else {
545
			xo = otherMinecart.getX() - this.getX();
546
			zo = otherMinecart.getZ() - this.getZ();
547
		}
548
549
		Vec3 dir = new Vec3(xo, 0.0, zo).normalize();
550
		Vec3 facing = new Vec3(Mth.cos(this.getYRot() * (float) (Math.PI / 180.0)), 0.0, Mth.sin(this.getYRot() * (float) (Math.PI / 180.0))).normalize();
551
		double dot = Math.abs(dir.dot(facing));
552
		if (!(dot < 0.8F) || useExperimentalMovement(this.level())) {
553
			Vec3 movement = this.getDeltaMovement();
554
			Vec3 entityMovement = otherMinecart.getDeltaMovement();
555
			if (otherMinecart.isFurnace() && !this.isFurnace()) {
556
				this.setDeltaMovement(movement.multiply(0.2, 1.0, 0.2));
557
				this.push(entityMovement.x - xa, 0.0, entityMovement.z - za);
558
				otherMinecart.setDeltaMovement(entityMovement.multiply(0.95, 1.0, 0.95));
559
			} else if (!otherMinecart.isFurnace() && this.isFurnace()) {
560
				otherMinecart.setDeltaMovement(entityMovement.multiply(0.2, 1.0, 0.2));
561
				otherMinecart.push(movement.x + xa, 0.0, movement.z + za);
562
				this.setDeltaMovement(movement.multiply(0.95, 1.0, 0.95));
563
			} else {
564
				double xdd = (entityMovement.x + movement.x) / 2.0;
565
				double zdd = (entityMovement.z + movement.z) / 2.0;
566
				this.setDeltaMovement(movement.multiply(0.2, 1.0, 0.2));
567
				this.push(xdd - xa, 0.0, zdd - za);
568
				otherMinecart.setDeltaMovement(entityMovement.multiply(0.2, 1.0, 0.2));
569
				otherMinecart.push(xdd + xa, 0.0, zdd + za);
570
			}
571
		}
572
	}
573
574
	public BlockState getDisplayBlockState() {
575
		return this.getCustomDisplayBlockState().orElseGet(this::getDefaultDisplayBlockState);
576
	}
577
578
	private Optional<BlockState> getCustomDisplayBlockState() {
579
		return this.getEntityData().get(DATA_ID_CUSTOM_DISPLAY_BLOCK);
580
	}
581
582
	public BlockState getDefaultDisplayBlockState() {
583
		return Blocks.AIR.defaultBlockState();
584
	}
585
586
	public int getDisplayOffset() {
587
		return this.getEntityData().get(DATA_ID_DISPLAY_OFFSET);
588
	}
589
590
	public int getDefaultDisplayOffset() {
591
		return 6;
592
	}
593
594
	public void setCustomDisplayBlockState(final Optional<BlockState> state) {
595
		this.getEntityData().set(DATA_ID_CUSTOM_DISPLAY_BLOCK, state);
596
	}
597
598
	public void setDisplayOffset(final int offset) {
599
		this.getEntityData().set(DATA_ID_DISPLAY_OFFSET, offset);
600
	}
601
602
	public static boolean useExperimentalMovement(final Level level) {
603
		return level.enabledFeatures().contains(FeatureFlags.MINECART_IMPROVEMENTS);
604
	}
605
606
	@Override
607
	public abstract ItemStack getPickResult();
608
609
	public boolean isRideable() {
610
		return false;
611
	}
612
613
	public boolean isFurnace() {
614
		return false;
615
	}
616
}
617

Decompiled Minecraft 26.3 source of AbstractMinecart (net/minecraft/world/entity/vehicle/minecart/AbstractMinecart.java) with Mojang official mappings, stored verbatim on the site.