Waypoint .java

net.minecraft.world.waypoints.Waypoint (interface): members: WAYPOINT_TRANSMIT_RANGE_HIDE_MODIFIER, addHideAttribute, Icon. strings: "style", "color".

net.minecraft.world.waypointsinterface85 linescommon3.3 KB

API Surface (3)

boolean hasData()
Waypoint.Icon cloneAndAssignStyle(final LivingEntity livingEntity)
void copyFrom(final Waypoint.Icon other)

Fields & Constants (1)

WAYPOINT_TRANSMIT_RANGE_HIDE_MODIFIER

String literals (3)

"waypoint_transmit_range_hide"
"style"
"color"

Full Source

Waypoint.java85 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.waypoints;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.codecs.RecordCodecBuilder;
5
import io.netty.buffer.ByteBuf;
6
import java.util.Optional;
7
import net.minecraft.core.component.DataComponents;
8
import net.minecraft.network.codec.ByteBufCodecs;
9
import net.minecraft.network.codec.StreamCodec;
10
import net.minecraft.resources.Identifier;
11
import net.minecraft.resources.ResourceKey;
12
import net.minecraft.util.ExtraCodecs;
13
import net.minecraft.world.entity.EquipmentSlotGroup;
14
import net.minecraft.world.entity.LivingEntity;
15
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
16
import net.minecraft.world.entity.ai.attributes.Attributes;
17
import net.minecraft.world.item.Item;
18
import net.minecraft.world.item.component.ItemAttributeModifiers;
19
import net.minecraft.world.scores.TeamColor;
20
21
public interface Waypoint {
22
	AttributeModifier WAYPOINT_TRANSMIT_RANGE_HIDE_MODIFIER = new AttributeModifier(
23
		Identifier.withDefaultNamespace("waypoint_transmit_range_hide"), -1.0, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL
24
	);
25
26
	static Item.Properties addHideAttribute(final Item.Properties properties) {
27
		return properties.component(
28
			DataComponents.ATTRIBUTE_MODIFIERS,
29
			ItemAttributeModifiers.builder()
30
				.add(Attributes.WAYPOINT_TRANSMIT_RANGE, WAYPOINT_TRANSMIT_RANGE_HIDE_MODIFIER, EquipmentSlotGroup.HEAD, ItemAttributeModifiers.Display.hidden())
31
				.build()
32
		);
33
	}
34
35
	class Icon {
36
		public static final Codec<Waypoint.Icon> CODEC = RecordCodecBuilder.create(
37
			i -> i.group(
38
					ResourceKey.codec(WaypointStyleAssets.ROOT_ID).fieldOf("style").forGetter(icon -> icon.style),
39
					ExtraCodecs.RGB_COLOR_CODEC.optionalFieldOf("color").forGetter(icon -> icon.color)
40
				)
41
				.apply(i, Waypoint.Icon::new)
42
		);
43
		public static final StreamCodec<ByteBuf, Waypoint.Icon> STREAM_CODEC = StreamCodec.composite(
44
			ResourceKey.streamCodec(WaypointStyleAssets.ROOT_ID),
45
			icon -> icon.style,
46
			ByteBufCodecs.optional(ByteBufCodecs.RGB_COLOR),
47
			icon -> icon.color,
48
			Waypoint.Icon::new
49
		);
50
		public static final Waypoint.Icon NULL = new Waypoint.Icon();
51
		public ResourceKey<WaypointStyleAsset> style = WaypointStyleAssets.DEFAULT;
52
		public Optional<Integer> color = Optional.empty();
53
54
		public Icon() {
55
		}
56
57
		private Icon(final ResourceKey<WaypointStyleAsset> style, final Optional<Integer> color) {
58
			this.style = style;
59
			this.color = color;
60
		}
61
62
		public boolean hasData() {
63
			return this.style != WaypointStyleAssets.DEFAULT || this.color.isPresent();
64
		}
65
66
		public Waypoint.Icon cloneAndAssignStyle(final LivingEntity livingEntity) {
67
			ResourceKey<WaypointStyleAsset> overrideStyle = this.getOverrideStyle();
68
			Optional<Integer> colorOverride = this.color
69
				.or(
70
					() -> Optional.ofNullable(livingEntity.getTeam()).flatMap(t -> t.getColor()).map(teamColor -> teamColor == TeamColor.BLACK ? -13619152 : teamColor.rgb())
71
				);
72
			return overrideStyle == this.style && colorOverride.isEmpty() ? this : new Waypoint.Icon(overrideStyle, colorOverride);
73
		}
74
75
		public void copyFrom(final Waypoint.Icon other) {
76
			this.color = other.color;
77
			this.style = other.style;
78
		}
79
80
		private ResourceKey<WaypointStyleAsset> getOverrideStyle() {
81
			return this.style != WaypointStyleAssets.DEFAULT ? this.style : WaypointStyleAssets.DEFAULT;
82
		}
83
	}
84
}
85

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