From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Mon, 2 Jun 2025 03:29:20 +0800 Subject: [PATCH] Old Blast Protection explosion knockback diff --git a/net/minecraft/world/entity/EquipmentSlot.java b/net/minecraft/world/entity/EquipmentSlot.java index dbf31389f0e9796c80afbffddf6a20cbaf184e6e..f1b456bf96e4764fd202f5575bbfa58694c1c069 100644 --- a/net/minecraft/world/entity/EquipmentSlot.java +++ b/net/minecraft/world/entity/EquipmentSlot.java @@ -23,6 +23,7 @@ public enum EquipmentSlot implements StringRepresentable { // Gale start - JettPack - reduce array allocations public static final EquipmentSlot[] VALUES_ARRAY = values(); public static final List VALUES = List.of(VALUES_ARRAY); + public static final EquipmentSlot[] ARMOR_SLOTS = new EquipmentSlot[]{EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET}; // Leaf - Old Blast Protection explosion knockback public static final IntFunction BY_ID = ByIdMap.continuous(equipmentSlot -> equipmentSlot.id, VALUES_ARRAY, ByIdMap.OutOfBoundsStrategy.ZERO); public static final StringRepresentable.EnumCodec CODEC = StringRepresentable.fromEnum(() -> VALUES_ARRAY); // Gale end - JettPack - reduce array allocations diff --git a/net/minecraft/world/level/ServerExplosion.java b/net/minecraft/world/level/ServerExplosion.java index 1039cf820ecac54e290dc5dfe7f714bf2b9d2bdd..7426a7f4bf17277b0355185b58973140dab3c7b9 100644 --- a/net/minecraft/world/level/ServerExplosion.java +++ b/net/minecraft/world/level/ServerExplosion.java @@ -532,7 +532,7 @@ public class ServerExplosion implements Explosion { double d4 = (1.0 - d) * f1 * knockbackMultiplier; double d5; if (entity instanceof LivingEntity livingEntity) { - d5 = entity instanceof Player && this.level.paperConfig().environment.disableExplosionKnockback ? 0 : d4 * (1.0 - livingEntity.getAttributeValue(Attributes.EXPLOSION_KNOCKBACK_RESISTANCE)); // Paper + d5 = entity instanceof Player && this.level.paperConfig().environment.disableExplosionKnockback ? 0 : getExplosionKnockback(livingEntity, d4); // Paper // Leaf - Old Blast Protection explosion knockback } else { d5 = d4; } @@ -561,6 +561,49 @@ public class ServerExplosion implements Explosion { } } + // Leaf start - Old Blast Protection explosion knockback + private static double getExplosionKnockback(LivingEntity entity, double velocity) { + if (!org.dreeam.leaf.config.modules.gameplay.Knockback.oldBlastProtectionKnockbackBehavior) { + return velocity * (1.0 - entity.getAttributeValue(Attributes.EXPLOSION_KNOCKBACK_RESISTANCE)); + } + + // Old BLAST_PROTECTION logic + // BLAST_PROTECTION used ARMOR_SLOTS for slot types + // See 1.20.4's ProtectionEnchantment#getExplosionKnockbackAfterDampener, + // EnchantmentHelper#getEnchantmentLevel, Enchantment#getSlotItems, + // EnchantmentHelper#getItemEnchantmentLevel, Enchantments#BLAST_PROTECTION, + // these methods/fields for reference. + Map map = com.google.common.collect.Maps.newEnumMap(net.minecraft.world.entity.EquipmentSlot.class); + + for (net.minecraft.world.entity.EquipmentSlot slot : net.minecraft.world.entity.EquipmentSlot.ARMOR_SLOTS) { + ItemStack itemStack = entity.getItemBySlot(slot); + if (!itemStack.isEmpty()) { + map.put(slot, itemStack); + } + } + + Iterable items = map.values(); + int i = 0; + + if (items == null) { + return 0; + } + + for (ItemStack itemStack : items) { + int enchantmentLevel = net.minecraft.world.item.enchantment.EnchantmentHelper.getItemEnchantmentLevel(net.minecraft.world.item.enchantment.Enchantments.BLAST_PROTECTION, itemStack); + if (enchantmentLevel > i) { + i = enchantmentLevel; + } + } + + if (i > 0) { + velocity *= Mth.clamp(1.0 - (double) i * 0.15, 0.0, 1.0); + } + + return velocity; + } + // Leaf end - Old Blast Protection explosion knockback + private void interactWithBlocks(List blocks) { List list = new ArrayList<>(); Util.shuffle(blocks, this.level.random);