SulfurCubeArchetypes .java

net.minecraft.world.entity.SulfurCubeArchetypes (class): members: HIGH_RESISTANCE, FAST_SLIDING, SLOW_SLIDING, SLOW_BOUNCY, EXPLOSIVE, FAST_FLAT, maxFuse.

net.minecraft.world.entityclass237 linescommon9.1 KB

API Surface (1)

void bootstrap(final BootstrapContext<SulfurCubeArchetype> context)

Fields & Constants (23)

REGULAR
BOUNCY
SLOW_BOUNCY
SLOW_FLAT
FAST_FLAT
LIGHT
FAST_SLIDING
SLOW_SLIDING
HIGH_RESISTANCE
STICKY
EXPLOSIVE
HOT
friction
amount
threshold
context
name
blocks
modifiers
floats
maxFuse
contactDamage
knockbackModifiers

String literals (11)

"regular"
"bouncy"
"slow_bouncy"
"slow_flat"
"fast_flat"
"light"
"fast_sliding"
"slow_sliding"
"high_resistance"
"sticky"
"explosive"

Full Source

SulfurCubeArchetypes.java237 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity;
2
3
import java.util.List;
4
import java.util.Optional;
5
import java.util.function.Function;
6
import net.minecraft.core.Holder;
7
import net.minecraft.core.registries.Registries;
8
import net.minecraft.data.worldgen.BootstrapContext;
9
import net.minecraft.resources.Identifier;
10
import net.minecraft.resources.ResourceKey;
11
import net.minecraft.sounds.SoundEvent;
12
import net.minecraft.sounds.SoundEvents;
13
import net.minecraft.tags.ItemTags;
14
import net.minecraft.tags.TagKey;
15
import net.minecraft.util.valueproviders.ConstantFloat;
16
import net.minecraft.util.valueproviders.FloatProvider;
17
import net.minecraft.world.damagesource.DamageType;
18
import net.minecraft.world.damagesource.DamageTypes;
19
import net.minecraft.world.entity.ai.attributes.Attribute;
20
import net.minecraft.world.entity.ai.attributes.Attributes;
21
import net.minecraft.world.item.Item;
22
23
public class SulfurCubeArchetypes {
24
	public static final ResourceKey<SulfurCubeArchetype> REGULAR = createKey(Identifier.withDefaultNamespace("regular"));
25
	public static final ResourceKey<SulfurCubeArchetype> BOUNCY = createKey(Identifier.withDefaultNamespace("bouncy"));
26
	public static final ResourceKey<SulfurCubeArchetype> SLOW_BOUNCY = createKey(Identifier.withDefaultNamespace("slow_bouncy"));
27
	public static final ResourceKey<SulfurCubeArchetype> SLOW_FLAT = createKey(Identifier.withDefaultNamespace("slow_flat"));
28
	public static final ResourceKey<SulfurCubeArchetype> FAST_FLAT = createKey(Identifier.withDefaultNamespace("fast_flat"));
29
	public static final ResourceKey<SulfurCubeArchetype> LIGHT = createKey(Identifier.withDefaultNamespace("light"));
30
	public static final ResourceKey<SulfurCubeArchetype> FAST_SLIDING = createKey(Identifier.withDefaultNamespace("fast_sliding"));
31
	public static final ResourceKey<SulfurCubeArchetype> SLOW_SLIDING = createKey(Identifier.withDefaultNamespace("slow_sliding"));
32
	public static final ResourceKey<SulfurCubeArchetype> HIGH_RESISTANCE = createKey(Identifier.withDefaultNamespace("high_resistance"));
33
	public static final ResourceKey<SulfurCubeArchetype> STICKY = createKey(Identifier.withDefaultNamespace("sticky"));
34
	public static final ResourceKey<SulfurCubeArchetype> EXPLOSIVE = createKey(Identifier.withDefaultNamespace("explosive"));
35
	public static final ResourceKey<SulfurCubeArchetype> HOT = createKey(Identifier.withDefaultNamespace("hot"));
36
37
	public static void bootstrap(final BootstrapContext<SulfurCubeArchetype> context) {
38
		register(
39
			context,
40
			REGULAR,
41
			ItemTags.SULFUR_CUBE_ARCHETYPE_REGULAR,
42
			archetype(1.0F, 0.5F, 0.3F, 0.1F),
43
			true,
44
			Optional.empty(),
45
			Optional.empty(),
46
			knockBackHitScale(0.4125F, 0.09F),
47
			soundSettings(SoundEvents.SULFUR_CUBE_REGULAR_HIT, SoundEvents.SULFUR_CUBE_REGULAR_PUSH, 0.2F, 0.5F)
48
		);
49
		register(
50
			context,
51
			BOUNCY,
52
			ItemTags.SULFUR_CUBE_ARCHETYPE_BOUNCY,
53
			archetype(2.0F, 0.9F, 0.3F, 0.01F),
54
			true,
55
			Optional.empty(),
56
			Optional.empty(),
57
			knockBackHitScale(0.4125F, 0.105F),
58
			soundSettings(SoundEvents.SULFUR_CUBE_BOUNCY_HIT, SoundEvents.SULFUR_CUBE_BOUNCY_PUSH, 0.3F, 0.7F)
59
		);
60
		register(
61
			context,
62
			SLOW_BOUNCY,
63
			ItemTags.SULFUR_CUBE_ARCHETYPE_SLOW_BOUNCY,
64
			archetype(-0.4F, 0.6F, 0.3F, 0.05F),
65
			false,
66
			Optional.empty(),
67
			Optional.empty(),
68
			knockBackHitScale(0.4125F, 0.24F),
69
			soundSettings(SoundEvents.SULFUR_CUBE_SLOW_BOUNCY_HIT, SoundEvents.SULFUR_CUBE_SLOW_BOUNCY_PUSH, 0.05F, 0.5F)
70
		);
71
		register(
72
			context,
73
			SLOW_FLAT,
74
			ItemTags.SULFUR_CUBE_ARCHETYPE_SLOW_FLAT,
75
			archetype(-0.5F, 0.4F, 0.4F, 0.1F),
76
			false,
77
			Optional.empty(),
78
			Optional.empty(),
79
			knockBackHitScale(0.4125F, 0.105F),
80
			soundSettings(SoundEvents.SULFUR_CUBE_SLOW_FLAT_HIT, SoundEvents.SULFUR_CUBE_SLOW_FLAT_PUSH, 0.03F, 0.9F)
81
		);
82
		register(
83
			context,
84
			FAST_FLAT,
85
			ItemTags.SULFUR_CUBE_ARCHETYPE_FAST_FLAT,
86
			archetype(1.0F, 0.5F, 0.2F, 0.01F),
87
			false,
88
			Optional.empty(),
89
			Optional.empty(),
90
			knockBackHitScale(0.9125F, 0.09F),
91
			soundSettings(SoundEvents.SULFUR_CUBE_FAST_FLAT_HIT, SoundEvents.SULFUR_CUBE_FAST_FLAT_PUSH, 0.03F, 0.9F)
92
		);
93
		register(
94
			context,
95
			LIGHT,
96
			ItemTags.SULFUR_CUBE_ARCHETYPE_LIGHT,
97
			archetype(1.0F, 1.0F, 0.3F, 1.8F),
98
			true,
99
			Optional.empty(),
100
			Optional.empty(),
101
			knockBackHitScale(0.4125F, 0.18F),
102
			soundSettings(SoundEvents.SULFUR_CUBE_LIGHT_HIT, SoundEvents.SULFUR_CUBE_LIGHT_PUSH, 0.2F, 0.7F)
103
		);
104
		register(
105
			context,
106
			FAST_SLIDING,
107
			ItemTags.SULFUR_CUBE_ARCHETYPE_FAST_SLIDING,
108
			archetype(-0.5F, 0.1F, 0.05F, 0.01F),
109
			false,
110
			Optional.empty(),
111
			Optional.empty(),
112
			knockBackHitScale(0.6625F, 0.09F),
113
			soundSettings(SoundEvents.SULFUR_CUBE_FAST_SLIDING_HIT, SoundEvents.SULFUR_CUBE_FAST_SLIDING_PUSH, 0.05F, 1.0F)
114
		);
115
		register(
116
			context,
117
			SLOW_SLIDING,
118
			ItemTags.SULFUR_CUBE_ARCHETYPE_SLOW_SLIDING,
119
			archetype(-0.8F, 0.1F, 0.05F, 0.01F),
120
			false,
121
			Optional.empty(),
122
			Optional.empty(),
123
			knockBackHitScale(0.4125F, 0.09F),
124
			soundSettings(SoundEvents.SULFUR_CUBE_SLOW_SLIDING_HIT, SoundEvents.SULFUR_CUBE_SLOW_SLIDING_PUSH, 0.02F, 1.0F)
125
		);
126
		register(
127
			context,
128
			STICKY,
129
			ItemTags.SULFUR_CUBE_ARCHETYPE_STICKY,
130
			archetype(2.0F, 0.0F, 2.0F, 0.01F),
131
			false,
132
			Optional.empty(),
133
			Optional.empty(),
134
			knockBackHitScale(0.4125F, 0.09F),
135
			soundSettings(SoundEvents.SULFUR_CUBE_STICKY_HIT, SoundEvents.SULFUR_CUBE_STICKY_PUSH, 0.05F, 0.5F)
136
		);
137
		register(
138
			context,
139
			HIGH_RESISTANCE,
140
			ItemTags.SULFUR_CUBE_ARCHETYPE_HIGH_RESISTANCE,
141
			archetype(-0.7F, 0.2F, 1.0F, 0.01F),
142
			false,
143
			Optional.empty(),
144
			Optional.empty(),
145
			knockBackHitScale(0.4125F, 0.09F),
146
			soundSettings(SoundEvents.SULFUR_CUBE_HIGH_RESISTANCE_HIT, SoundEvents.SULFUR_CUBE_HIGH_RESISTANCE_PUSH, 0.03F, 0.7F)
147
		);
148
		register(
149
			context,
150
			EXPLOSIVE,
151
			ItemTags.SULFUR_CUBE_ARCHETYPE_EXPLOSIVE,
152
			archetype(1.0F, 0.5F, 0.3F, 0.3F),
153
			true,
154
			Optional.of(new SulfurCubeArchetype.ExplosionData(3, false, 120)),
155
			Optional.empty(),
156
			knockBackHitScale(0.4125F, 0.09F),
157
			soundSettings(SoundEvents.SULFUR_CUBE_EXPLOSIVE_HIT, SoundEvents.SULFUR_CUBE_EXPLOSIVE_PUSH, 0.1F, 0.7F)
158
		);
159
		register(
160
			context,
161
			HOT,
162
			ItemTags.SULFUR_CUBE_ARCHETYPE_HOT,
163
			archetype(1.0F, 0.5F, 0.3F, 0.1F),
164
			true,
165
			Optional.empty(),
166
			Optional.of(contactDamage(context, DamageTypes.SULFUR_CUBE_HOT, ConstantFloat.of(1.0F), false)),
167
			knockBackHitScale(0.4125F, 0.09F),
168
			soundSettings(SoundEvents.SULFUR_CUBE_HOT_HIT, SoundEvents.SULFUR_CUBE_HOT_PUSH, 0.2F, 0.7F)
169
		);
170
	}
171
172
	private static ResourceKey<SulfurCubeArchetype> createKey(final Identifier id) {
173
		return ResourceKey.create(Registries.SULFUR_CUBE_ARCHETYPE, id);
174
	}
175
176
	private static Function<ResourceKey<SulfurCubeArchetype>, SulfurCubeArchetype.AttributeEntry> add(final Holder<Attribute> attribute, final double amount) {
177
		return key -> SulfurCubeArchetype.AttributeEntry.add(attribute, amount, key);
178
	}
179
180
	private static Function<ResourceKey<SulfurCubeArchetype>, SulfurCubeArchetype.AttributeEntry> multiply(final Holder<Attribute> attribute, final double amount) {
181
		return key -> SulfurCubeArchetype.AttributeEntry.multiply(attribute, amount, key);
182
	}
183
184
	private static List<Function<ResourceKey<SulfurCubeArchetype>, SulfurCubeArchetype.AttributeEntry>> archetype(
185
		final float speed, final float bounce, final float friction, final float drag
186
	) {
187
		return List.of(
188
			add(Attributes.KNOCKBACK_RESISTANCE, -speed),
189
			add(Attributes.EXPLOSION_KNOCKBACK_RESISTANCE, -speed),
190
			add(Attributes.BOUNCINESS, bounce),
191
			multiply(Attributes.FRICTION_MODIFIER, friction),
192
			multiply(Attributes.AIR_DRAG_MODIFIER, drag)
193
		);
194
	}
195
196
	private static SulfurCubeArchetype.ContactDamage contactDamage(
197
		final BootstrapContext<SulfurCubeArchetype> context, final ResourceKey<DamageType> damageType, final FloatProvider amount, final boolean attributeToSource
198
	) {
199
		return new SulfurCubeArchetype.ContactDamage(context.lookup(Registries.DAMAGE_TYPE).getOrThrow(damageType), amount, attributeToSource);
200
	}
201
202
	private static SulfurCubeArchetype.KnockbackModifiers knockBackHitScale(final float horizontalPower, final float verticalPower) {
203
		return new SulfurCubeArchetype.KnockbackModifiers(horizontalPower, verticalPower);
204
	}
205
206
	private static SulfurCubeArchetype.SoundSettings soundSettings(
207
		final Holder<SoundEvent> hitSound, final Holder<SoundEvent> pushSound, final float threshold, final float cooldown
208
	) {
209
		return new SulfurCubeArchetype.SoundSettings(hitSound, pushSound, threshold, cooldown);
210
	}
211
212
	private static void register(
213
		final BootstrapContext<SulfurCubeArchetype> context,
214
		final ResourceKey<SulfurCubeArchetype> name,
215
		final TagKey<Item> blocks,
216
		final List<Function<ResourceKey<SulfurCubeArchetype>, SulfurCubeArchetype.AttributeEntry>> modifiers,
217
		final boolean floats,
218
		final Optional<SulfurCubeArchetype.ExplosionData> maxFuse,
219
		final Optional<SulfurCubeArchetype.ContactDamage> contactDamage,
220
		final SulfurCubeArchetype.KnockbackModifiers knockbackModifiers,
221
		final SulfurCubeArchetype.SoundSettings soundSettings
222
	) {
223
		context.register(
224
			name,
225
			new SulfurCubeArchetype(
226
				context.lookup(Registries.ITEM).getOrThrow(blocks),
227
				modifiers.stream().map(f -> f.apply(name)).toList(),
228
				floats,
229
				maxFuse,
230
				contactDamage,
231
				knockbackModifiers,
232
				soundSettings
233
			)
234
		);
235
	}
236
}
237

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