ItemBasedSteering .java

net.minecraft.world.entity.ItemBasedSteering (class): members: boostTimeAccessor, MAX_BOOST_TIME, MIN_BOOST_TIME, boostFactor, boostTime, tickBoost, boost.

net.minecraft.world.entityclass51 linescommon1.4 KB

API Surface (4)

void onSynced()
boolean boost(final RandomSource random)
void tickBoost()
float boostFactor()

Fields & Constants (6)

MIN_BOOST_TIME
MAX_BOOST_TIME
entityData
boostTimeAccessor
boosting
boostTime

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

ItemBasedSteering.java51 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity;
2
3
import net.minecraft.network.syncher.EntityDataAccessor;
4
import net.minecraft.network.syncher.SynchedEntityData;
5
import net.minecraft.util.Mth;
6
import net.minecraft.util.RandomSource;
7
8
public class ItemBasedSteering {
9
	private static final int MIN_BOOST_TIME = 140;
10
	private static final int MAX_BOOST_TIME = 700;
11
	private final SynchedEntityData entityData;
12
	private final EntityDataAccessor<Integer> boostTimeAccessor;
13
	private boolean boosting;
14
	private int boostTime;
15
16
	public ItemBasedSteering(final SynchedEntityData entityData, final EntityDataAccessor<Integer> boostTimeAccessor) {
17
		this.entityData = entityData;
18
		this.boostTimeAccessor = boostTimeAccessor;
19
	}
20
21
	public void onSynced() {
22
		this.boosting = true;
23
		this.boostTime = 0;
24
	}
25
26
	public boolean boost(final RandomSource random) {
27
		if (this.boosting) {
28
			return false;
29
		}
30
31
		this.boosting = true;
32
		this.boostTime = 0;
33
		this.entityData.set(this.boostTimeAccessor, random.nextInt(841) + 140);
34
		return true;
35
	}
36
37
	public void tickBoost() {
38
		if (this.boosting && this.boostTime++ > this.boostTimeTotal()) {
39
			this.boosting = false;
40
		}
41
	}
42
43
	public float boostFactor() {
44
		return this.boosting ? 1.0F + 1.15F * Mth.sin((float)this.boostTime / this.boostTimeTotal() * (float) Math.PI) : 1.0F;
45
	}
46
47
	private int boostTimeTotal() {
48
		return this.entityData.get(this.boostTimeAccessor);
49
	}
50
}
51

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