package net.minecraft.world.entity; import java.util.List; import java.util.Optional; import java.util.function.Function; import net.minecraft.core.Holder; import net.minecraft.core.registries.Registries; import net.minecraft.data.worldgen.BootstrapContext; import net.minecraft.resources.Identifier; import net.minecraft.resources.ResourceKey; import net.minecraft.tags.ItemTags; import net.minecraft.tags.TagKey; import net.minecraft.util.valueproviders.ConstantFloat; import net.minecraft.util.valueproviders.FloatProvider; import net.minecraft.world.damagesource.DamageType; import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.SulfurCubeArchetype.AttributeEntry; import net.minecraft.world.entity.SulfurCubeArchetype.ContactDamage; import net.minecraft.world.entity.SulfurCubeArchetype.ExplosionData; import net.minecraft.world.entity.SulfurCubeArchetype.KnockbackModifiers; import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.item.Item; public class SulfurCubeArchetypes { public static final ResourceKey REGULAR = createKey(Identifier.withDefaultNamespace("regular")); public static final ResourceKey BOUNCY = createKey(Identifier.withDefaultNamespace("bouncy")); public static final ResourceKey SLOW_BOUNCY = createKey(Identifier.withDefaultNamespace("slow_bouncy")); public static final ResourceKey SLOW_FLAT = createKey(Identifier.withDefaultNamespace("slow_flat")); public static final ResourceKey FAST_FLAT = createKey(Identifier.withDefaultNamespace("fast_flat")); public static final ResourceKey LIGHT = createKey(Identifier.withDefaultNamespace("light")); public static final ResourceKey FAST_SLIDING = createKey(Identifier.withDefaultNamespace("fast_sliding")); public static final ResourceKey SLOW_SLIDING = createKey(Identifier.withDefaultNamespace("slow_sliding")); public static final ResourceKey HIGH_RESISTANCE = createKey(Identifier.withDefaultNamespace("high_resistance")); public static final ResourceKey STICKY = createKey(Identifier.withDefaultNamespace("sticky")); public static final ResourceKey EXPLOSIVE = createKey(Identifier.withDefaultNamespace("explosive")); public static final ResourceKey HOT = createKey(Identifier.withDefaultNamespace("hot")); public static void bootstrap(final BootstrapContext context) { register( context, REGULAR, ItemTags.SULFUR_CUBE_ARCHETYPE_REGULAR, archetype(1.0F, 0.5F, 0.3F, 0.1F), true, Optional.empty(), Optional.empty(), knockBackHitScale(0.33F, 0.06F) ); register( context, BOUNCY, ItemTags.SULFUR_CUBE_ARCHETYPE_BOUNCY, archetype(2.0F, 0.9F, 0.3F, 0.01F), true, Optional.empty(), Optional.empty(), knockBackHitScale(0.33F, 0.07F) ); register( context, SLOW_BOUNCY, ItemTags.SULFUR_CUBE_ARCHETYPE_SLOW_BOUNCY, archetype(-0.4F, 0.6F, 0.3F, 0.05F), false, Optional.empty(), Optional.empty(), knockBackHitScale(0.33F, 0.16F) ); register( context, SLOW_FLAT, ItemTags.SULFUR_CUBE_ARCHETYPE_SLOW_FLAT, archetype(-0.5F, 0.4F, 0.4F, 0.1F), false, Optional.empty(), Optional.empty(), knockBackHitScale(0.33F, 0.07F) ); register( context, FAST_FLAT, ItemTags.SULFUR_CUBE_ARCHETYPE_FAST_FLAT, archetype(1.0F, 0.5F, 0.2F, 0.01F), false, Optional.empty(), Optional.empty(), knockBackHitScale(0.73F, 0.06F) ); register( context, LIGHT, ItemTags.SULFUR_CUBE_ARCHETYPE_LIGHT, archetype(1.0F, 1.0F, 0.3F, 1.8F), true, Optional.empty(), Optional.empty(), knockBackHitScale(0.33F, 0.12F) ); register( context, FAST_SLIDING, ItemTags.SULFUR_CUBE_ARCHETYPE_FAST_SLIDING, archetype(-0.5F, 0.1F, 0.05F, 0.01F), false, Optional.empty(), Optional.empty(), knockBackHitScale(0.53F, 0.06F) ); register( context, SLOW_SLIDING, ItemTags.SULFUR_CUBE_ARCHETYPE_SLOW_SLIDING, archetype(-0.8F, 0.1F, 0.05F, 0.01F), false, Optional.empty(), Optional.empty(), knockBackHitScale(0.33F, 0.06F) ); register( context, STICKY, ItemTags.SULFUR_CUBE_ARCHETYPE_STICKY, archetype(2.0F, 0.0F, 2.0F, 0.01F), false, Optional.empty(), Optional.empty(), knockBackHitScale(0.33F, 0.06F) ); register( context, HIGH_RESISTANCE, ItemTags.SULFUR_CUBE_ARCHETYPE_HIGH_RESISTANCE, archetype(-0.7F, 0.2F, 1.0F, 0.01F), false, Optional.empty(), Optional.empty(), knockBackHitScale(0.33F, 0.06F) ); register( context, EXPLOSIVE, ItemTags.SULFUR_CUBE_ARCHETYPE_EXPLOSIVE, archetype(1.0F, 0.5F, 0.3F, 0.3F), true, Optional.of(new ExplosionData(3, false, 120)), Optional.empty(), knockBackHitScale(0.33F, 0.06F) ); register( context, HOT, ItemTags.SULFUR_CUBE_ARCHETYPE_HOT, archetype(1.0F, 0.5F, 0.3F, 0.1F), true, Optional.empty(), Optional.of(contactDamage(context, DamageTypes.HOT_FLOOR, ConstantFloat.of(1.0F), false)), knockBackHitScale(0.33F, 0.06F) ); } private static ResourceKey createKey(final Identifier id) { return ResourceKey.create(Registries.SULFUR_CUBE_ARCHETYPE, id); } private static Function, AttributeEntry> add(final Holder attribute, final double amount) { return key -> AttributeEntry.add(attribute, amount, key); } private static Function, AttributeEntry> multiply(final Holder attribute, final double amount) { return key -> AttributeEntry.multiply(attribute, amount, key); } private static List, AttributeEntry>> archetype( final float speed, final float bounce, final float friction, final float drag ) { return List.of( add(Attributes.KNOCKBACK_RESISTANCE, -speed), add(Attributes.EXPLOSION_KNOCKBACK_RESISTANCE, -speed), add(Attributes.BOUNCINESS, bounce), multiply(Attributes.FRICTION_MODIFIER, friction), multiply(Attributes.AIR_DRAG_MODIFIER, drag) ); } private static ContactDamage contactDamage( final BootstrapContext context, final ResourceKey damageType, final FloatProvider amount, final boolean attributeToSource ) { return new ContactDamage(context.lookup(Registries.DAMAGE_TYPE).getOrThrow(damageType), amount, attributeToSource); } private static KnockbackModifiers knockBackHitScale(final float horizontalPower, final float verticalPower) { return new KnockbackModifiers(horizontalPower, verticalPower); } private static void register( final BootstrapContext context, final ResourceKey name, final TagKey blocks, final List, AttributeEntry>> modifiers, final boolean floats, final Optional maxFuse, final Optional contactDamage, final KnockbackModifiers knockbackModifiers ) { context.register( name, new SulfurCubeArchetype( context.lookup(Registries.ITEM).getOrThrow(blocks), modifiers.stream().map(f -> (AttributeEntry)f.apply(name)).toList(), floats, maxFuse, contactDamage, knockbackModifiers ) ); } }