SulfurCubeArchetype .java

net.minecraft.world.entity.SulfurCubeArchetype (record, 127 lines): members: items, attributeModifiers, buoyant, explosion, contactDamage, soundSettings.

net.minecraft.world.entityrecord127 linescommon6.3 KB

API Surface (8)

record SulfurCubeArchetype(HolderSet<Item> items, List<SulfurCubeArchetype.AttributeEntry> attributeModifiers, boolean buoyant, Optional<SulfurCubeArchetype.ExplosionData> explosion, Optional<SulfurCubeArchetype.ContactDamage> contactDamage, SulfurCubeArchetype.KnockbackModifiers knockbackModifiers, SulfurCubeArchetype.SoundSettings soundSettings)
record AttributeEntry(Holder<Attribute> attribute, AttributeModifier modifier)
SulfurCubeArchetype.AttributeEntry add(final Holder<Attribute> attribute, final double amount, final ResourceKey<SulfurCubeArchetype> archetype)
SulfurCubeArchetype.AttributeEntry multiply(final Holder<Attribute> attribute, final double amount, final ResourceKey<SulfurCubeArchetype> archetype)
record ContactDamage(Holder<DamageType> damageType, FloatProvider amount, boolean attributeToSource)
record ExplosionData(int power, boolean causesFire, int fuse)
record KnockbackModifiers(float horizontalPower, float verticalPower)
record SoundSettings(Holder<SoundEvent> hitSound, Holder<SoundEvent> pushSound, float pushSoundImpulseThreshold, float pushSoundCooldown)

Fields & Constants (3)

DIRECT_CODEC
DEFAULT_KNOCKBACK_MODIFIERS
DEFAULT_SOUND_SETTINGS

String literals (22)

"items"
"attribute_modifiers"
"buoyant"
"explosion"
"contact_damage"
"knockback_modifiers"
"sound_settings"
"attribute"
"_add_"
"_mul_"
"damage_type"
"amount"
"attribute_to_source"
"power"
"causes_fire"
"fuse"
"horizontal_power"
"vertical_power"
"hit_sound"
"push_sound"
"push_sound_impulse_threshold"
"push_sound_cooldown"

Full Source

SulfurCubeArchetype.java127 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.codecs.RecordCodecBuilder;
5
import java.util.List;
6
import java.util.Optional;
7
import net.minecraft.core.Holder;
8
import net.minecraft.core.HolderSet;
9
import net.minecraft.core.registries.Registries;
10
import net.minecraft.core.registries.codec.RegistryCodecs;
11
import net.minecraft.resources.Identifier;
12
import net.minecraft.resources.ResourceKey;
13
import net.minecraft.sounds.SoundEvent;
14
import net.minecraft.sounds.SoundEvents;
15
import net.minecraft.util.ExtraCodecs;
16
import net.minecraft.util.valueproviders.FloatProvider;
17
import net.minecraft.util.valueproviders.FloatProviders;
18
import net.minecraft.world.damagesource.DamageType;
19
import net.minecraft.world.entity.ai.attributes.Attribute;
20
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
21
import net.minecraft.world.item.Item;
22
23
public record SulfurCubeArchetype(
24
	HolderSet<Item> items,
25
	List<SulfurCubeArchetype.AttributeEntry> attributeModifiers,
26
	boolean buoyant,
27
	Optional<SulfurCubeArchetype.ExplosionData> explosion,
28
	Optional<SulfurCubeArchetype.ContactDamage> contactDamage,
29
	SulfurCubeArchetype.KnockbackModifiers knockbackModifiers,
30
	SulfurCubeArchetype.SoundSettings soundSettings
31
) {
32
	public static final Codec<SulfurCubeArchetype> DIRECT_CODEC = RecordCodecBuilder.create(
33
		i -> i.group(
34
				RegistryCodecs.holderSet(Registries.ITEM).fieldOf("items").forGetter(SulfurCubeArchetype::items),
35
				SulfurCubeArchetype.AttributeEntry.CODEC.listOf().fieldOf("attribute_modifiers").forGetter(SulfurCubeArchetype::attributeModifiers),
36
				Codec.BOOL.optionalFieldOf("buoyant", false).forGetter(SulfurCubeArchetype::buoyant),
37
				SulfurCubeArchetype.ExplosionData.CODEC.optionalFieldOf("explosion").forGetter(SulfurCubeArchetype::explosion),
38
				SulfurCubeArchetype.ContactDamage.CODEC.optionalFieldOf("contact_damage").forGetter(SulfurCubeArchetype::contactDamage),
39
				SulfurCubeArchetype.KnockbackModifiers.CODEC.fieldOf("knockback_modifiers").forGetter(SulfurCubeArchetype::knockbackModifiers),
40
				SulfurCubeArchetype.SoundSettings.CODEC.fieldOf("sound_settings").forGetter(SulfurCubeArchetype::soundSettings)
41
			)
42
			.apply(i, SulfurCubeArchetype::new)
43
	);
44
	public static SulfurCubeArchetype.KnockbackModifiers DEFAULT_KNOCKBACK_MODIFIERS = new SulfurCubeArchetype.KnockbackModifiers(0.33F, 0.06F);
45
	public static SulfurCubeArchetype.SoundSettings DEFAULT_SOUND_SETTINGS = new SulfurCubeArchetype.SoundSettings(
46
		SoundEvents.SULFUR_CUBE_REGULAR_HIT, SoundEvents.SULFUR_CUBE_REGULAR_PUSH, 0.2F, 0.5F
47
	);
48
49
	public record AttributeEntry(Holder<Attribute> attribute, AttributeModifier modifier) {
50
		public static final Codec<SulfurCubeArchetype.AttributeEntry> CODEC = RecordCodecBuilder.create(
51
			i -> i.group(
52
					Attribute.CODEC.fieldOf("attribute").forGetter(SulfurCubeArchetype.AttributeEntry::attribute),
53
					AttributeModifier.MAP_CODEC.forGetter(SulfurCubeArchetype.AttributeEntry::modifier)
54
				)
55
				.apply(i, SulfurCubeArchetype.AttributeEntry::new)
56
		);
57
58
		public static SulfurCubeArchetype.AttributeEntry add(final Holder<Attribute> attribute, final double amount, final ResourceKey<SulfurCubeArchetype> archetype) {
59
			return new SulfurCubeArchetype.AttributeEntry(
60
				attribute,
61
				new AttributeModifier(
62
					Identifier.withDefaultNamespace(archetype.identifier().getPath() + "_add_" + attribute.unwrapKey().get().identifier().getPath()),
63
					amount,
64
					AttributeModifier.Operation.ADD_VALUE
65
				)
66
			);
67
		}
68
69
		public static SulfurCubeArchetype.AttributeEntry multiply(
70
			final Holder<Attribute> attribute, final double amount, final ResourceKey<SulfurCubeArchetype> archetype
71
		) {
72
			return new SulfurCubeArchetype.AttributeEntry(
73
				attribute,
74
				new AttributeModifier(
75
					Identifier.withDefaultNamespace(archetype.identifier().getPath() + "_mul_" + attribute.unwrapKey().get().identifier().getPath()),
76
					amount - 1.0,
77
					AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL
78
				)
79
			);
80
		}
81
	}
82
83
	public record ContactDamage(Holder<DamageType> damageType, FloatProvider amount, boolean attributeToSource) {
84
		public static final Codec<SulfurCubeArchetype.ContactDamage> CODEC = RecordCodecBuilder.create(
85
			i -> i.group(
86
					DamageType.CODEC.fieldOf("damage_type").forGetter(SulfurCubeArchetype.ContactDamage::damageType),
87
					FloatProviders.codec(0.0F).fieldOf("amount").forGetter(SulfurCubeArchetype.ContactDamage::amount),
88
					Codec.BOOL.fieldOf("attribute_to_source").forGetter(SulfurCubeArchetype.ContactDamage::attributeToSource)
89
				)
90
				.apply(i, SulfurCubeArchetype.ContactDamage::new)
91
		);
92
	}
93
94
	public record ExplosionData(int power, boolean causesFire, int fuse) {
95
		public static final Codec<SulfurCubeArchetype.ExplosionData> CODEC = RecordCodecBuilder.create(
96
			i -> i.group(
97
					ExtraCodecs.NON_NEGATIVE_INT.fieldOf("power").forGetter(SulfurCubeArchetype.ExplosionData::power),
98
					Codec.BOOL.fieldOf("causes_fire").forGetter(SulfurCubeArchetype.ExplosionData::causesFire),
99
					ExtraCodecs.POSITIVE_INT.fieldOf("fuse").forGetter(SulfurCubeArchetype.ExplosionData::fuse)
100
				)
101
				.apply(i, SulfurCubeArchetype.ExplosionData::new)
102
		);
103
	}
104
105
	public record KnockbackModifiers(float horizontalPower, float verticalPower) {
106
		public static final Codec<SulfurCubeArchetype.KnockbackModifiers> CODEC = RecordCodecBuilder.create(
107
			i -> i.group(
108
					Codec.FLOAT.fieldOf("horizontal_power").forGetter(SulfurCubeArchetype.KnockbackModifiers::horizontalPower),
109
					Codec.FLOAT.fieldOf("vertical_power").forGetter(SulfurCubeArchetype.KnockbackModifiers::verticalPower)
110
				)
111
				.apply(i, SulfurCubeArchetype.KnockbackModifiers::new)
112
		);
113
	}
114
115
	public record SoundSettings(Holder<SoundEvent> hitSound, Holder<SoundEvent> pushSound, float pushSoundImpulseThreshold, float pushSoundCooldown) {
116
		public static final Codec<SulfurCubeArchetype.SoundSettings> CODEC = RecordCodecBuilder.create(
117
			i -> i.group(
118
					SoundEvent.CODEC.fieldOf("hit_sound").forGetter(SulfurCubeArchetype.SoundSettings::hitSound),
119
					SoundEvent.CODEC.fieldOf("push_sound").forGetter(SulfurCubeArchetype.SoundSettings::pushSound),
120
					Codec.FLOAT.fieldOf("push_sound_impulse_threshold").forGetter(SulfurCubeArchetype.SoundSettings::pushSoundImpulseThreshold),
121
					Codec.FLOAT.fieldOf("push_sound_cooldown").forGetter(SulfurCubeArchetype.SoundSettings::pushSoundCooldown)
122
				)
123
				.apply(i, SulfurCubeArchetype.SoundSettings::new)
124
		);
125
	}
126
}
127

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