ThrowableProjectile .java

net.minecraft.world.entity.projectile.ThrowableProjectile (class): members: MIN_CAMERA_DISTANCE_SQUARED, canUsePortal, getAirDrag, getDefaultGravity, tick.

net.minecraft.world.entity.projectileclass105 linescommonextends Projectile2.8 KB

API Surface (5)

boolean shouldRenderAtSqrDistance(final double distance)
boolean canUsePortal(final boolean ignorePassenger)
void tick()
float getAirDrag()
double getDefaultGravity()

Fields & Constants (1)

MIN_CAMERA_DISTANCE_SQUARED

Full Source

ThrowableProjectile.java105 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.projectile;
2
3
import net.minecraft.core.particles.ParticleTypes;
4
import net.minecraft.world.entity.EntityType;
5
import net.minecraft.world.entity.InsideBlockEffectApplier;
6
import net.minecraft.world.level.Level;
7
import net.minecraft.world.level.block.Blocks;
8
import net.minecraft.world.phys.HitResult;
9
import net.minecraft.world.phys.Vec3;
10
11
public abstract class ThrowableProjectile extends Projectile {
12
	private static final float MIN_CAMERA_DISTANCE_SQUARED = 12.25F;
13
14
	protected ThrowableProjectile(final EntityType<? extends ThrowableProjectile> type, final Level level) {
15
		super(type, level);
16
	}
17
18
	protected ThrowableProjectile(final EntityType<? extends ThrowableProjectile> type, final double x, final double y, final double z, final Level level) {
19
		this(type, level);
20
		this.setPos(x, y, z);
21
	}
22
23
	@Override
24
	public boolean shouldRenderAtSqrDistance(final double distance) {
25
		if (this.tickCount < 2 && distance < 12.25) {
26
			return false;
27
		}
28
29
		double size = this.getBoundingBox().getSize() * 4.0;
30
		if (Double.isNaN(size)) {
31
			size = 4.0;
32
		}
33
34
		size *= 64.0;
35
		return distance < size * size;
36
	}
37
38
	@Override
39
	public boolean canUsePortal(final boolean ignorePassenger) {
40
		return true;
41
	}
42
43
	@Override
44
	public void tick() {
45
		this.handleFirstTickBubbleColumn();
46
		this.applyGravity();
47
		this.applyInertia();
48
		HitResult result = ProjectileUtil.getHitResultOnMoveVector(this, this::canHitEntity);
49
		Vec3 newPosition;
50
		if (result.getType() != HitResult.Type.MISS) {
51
			newPosition = result.getLocation();
52
		} else {
53
			newPosition = this.position().add(this.getDeltaMovement());
54
		}
55
56
		this.setPos(newPosition);
57
		this.updateRotation();
58
		this.applyEffectsFromBlocks();
59
		super.tick();
60
		if (result.getType() != HitResult.Type.MISS && this.isAlive()) {
61
			this.hitTargetOrDeflectSelf(result);
62
		}
63
	}
64
65
	private void applyInertia() {
66
		Vec3 movement = this.getDeltaMovement();
67
		Vec3 position = this.position();
68
		float inertia;
69
		if (this.isInWater()) {
70
			for (int i = 0; i < 4; i++) {
71
				float s = 0.25F;
72
				this.level()
73
					.addParticle(
74
						ParticleTypes.BUBBLE, position.x - movement.x * 0.25, position.y - movement.y * 0.25, position.z - movement.z * 0.25, movement.x, movement.y, movement.z
75
					);
76
			}
77
78
			inertia = 0.8F;
79
		} else {
80
			inertia = this.getAirDrag();
81
		}
82
83
		this.setDeltaMovement(movement.scale(inertia));
84
	}
85
86
	@Override
87
	protected float getAirDrag() {
88
		return 0.99F;
89
	}
90
91
	private void handleFirstTickBubbleColumn() {
92
		if (this.firstTick) {
93
			this.level()
94
				.findBlocksIn(this.getBoundingBox())
95
				.filterState(state -> state.is(Blocks.BUBBLE_COLUMN))
96
				.forEach((pos, state) -> state.entityInside(this.level(), pos, this, InsideBlockEffectApplier.NOOP, true));
97
		}
98
	}
99
100
	@Override
101
	protected double getDefaultGravity() {
102
		return 0.03;
103
	}
104
}
105

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