VibrationInfo .java

net.minecraft.world.level.gameevent.vibrations.VibrationInfo (record, 56 lines): members: gameEvent, distance, uuid, projectileOwnerUuid, entity, pos.

net.minecraft.world.level.gameevent.vibrationsrecord56 linescommon2.5 KB

API Surface (3)

record VibrationInfo(Holder<GameEvent> gameEvent, float distance, Vec3 pos, @Nullable UUID uuid, @Nullable UUID projectileOwnerUuid, @Nullable Entity entity)
Optional<Entity> getEntity(final ServerLevel level)
Optional<Entity> getProjectileOwner(final ServerLevel level)

Fields & Constants (2)

CODEC
uuid

String literals (4)

"game_event"
"distance"
"source"
"projectile_owner"

Code Graph: Dependencies (7)

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

Full Source

VibrationInfo.java56 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.gameevent.vibrations;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.codecs.RecordCodecBuilder;
5
import java.util.Optional;
6
import java.util.UUID;
7
import net.minecraft.core.Holder;
8
import net.minecraft.core.UUIDUtil;
9
import net.minecraft.server.level.ServerLevel;
10
import net.minecraft.world.entity.Entity;
11
import net.minecraft.world.entity.projectile.Projectile;
12
import net.minecraft.world.level.gameevent.GameEvent;
13
import net.minecraft.world.phys.Vec3;
14
import org.jspecify.annotations.Nullable;
15
16
public record VibrationInfo(
17
	Holder<GameEvent> gameEvent, float distance, Vec3 pos, @Nullable UUID uuid, @Nullable UUID projectileOwnerUuid, @Nullable Entity entity
18
) {
19
	public static final Codec<VibrationInfo> CODEC = RecordCodecBuilder.create(
20
		i -> i.group(
21
				GameEvent.CODEC.fieldOf("game_event").forGetter(VibrationInfo::gameEvent),
22
				Codec.floatRange(0.0F, Float.MAX_VALUE).fieldOf("distance").forGetter(VibrationInfo::distance),
23
				Vec3.CODEC.fieldOf("pos").forGetter(VibrationInfo::pos),
24
				UUIDUtil.CODEC.lenientOptionalFieldOf("source").forGetter(o -> Optional.ofNullable(o.uuid())),
25
				UUIDUtil.CODEC.lenientOptionalFieldOf("projectile_owner").forGetter(o -> Optional.ofNullable(o.projectileOwnerUuid()))
26
			)
27
			.apply(i, (event, distance, pos, source, projectileOwner) -> new VibrationInfo(event, distance, pos, source.orElse(null), projectileOwner.orElse(null)))
28
	);
29
30
	public VibrationInfo(
31
		final Holder<GameEvent> gameEvent, final float distance, final Vec3 pos, final @Nullable UUID uuid, final @Nullable UUID projectileOwnerUuid
32
	) {
33
		this(gameEvent, distance, pos, uuid, projectileOwnerUuid, null);
34
	}
35
36
	public VibrationInfo(final Holder<GameEvent> gameEvent, final float distance, final Vec3 pos, final @Nullable Entity entity) {
37
		this(gameEvent, distance, pos, entity == null ? null : entity.getUUID(), getProjectileOwner(entity), entity);
38
	}
39
40
	private static @Nullable UUID getProjectileOwner(final @Nullable Entity entity) {
41
		return entity instanceof Projectile projectile && projectile.getOwner() != null ? projectile.getOwner().getUUID() : null;
42
	}
43
44
	public Optional<Entity> getEntity(final ServerLevel level) {
45
		return Optional.ofNullable(this.entity).or(() -> Optional.ofNullable(this.uuid).map(level::getEntity));
46
	}
47
48
	public Optional<Entity> getProjectileOwner(final ServerLevel level) {
49
		return this.getEntity(level)
50
			.filter(e -> e instanceof Projectile)
51
			.map(e -> (Projectile)e)
52
			.map(Projectile::getOwner)
53
			.or(() -> Optional.ofNullable(this.projectileOwnerUuid).map(level::getEntity));
54
	}
55
}
56

Decompiled Minecraft 26.3 source of VibrationInfo (net/minecraft/world/level/gameevent/vibrations/VibrationInfo.java) with Mojang official mappings, stored verbatim on the site.