mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
82 lines
4.6 KiB
Diff
82 lines
4.6 KiB
Diff
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<EquipmentSlot> 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<EquipmentSlot> BY_ID = ByIdMap.continuous(equipmentSlot -> equipmentSlot.id, VALUES_ARRAY, ByIdMap.OutOfBoundsStrategy.ZERO);
|
|
public static final StringRepresentable.EnumCodec<EquipmentSlot> 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 33cd3a7755ada2fb632cfc97a80c8a9000ab0bd9..c67a9aa4431134ea25baf83a3ca9a646c8d8140d 100644
|
|
--- a/net/minecraft/world/level/ServerExplosion.java
|
|
+++ b/net/minecraft/world/level/ServerExplosion.java
|
|
@@ -529,7 +529,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;
|
|
}
|
|
@@ -558,6 +558,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<net.minecraft.world.entity.EquipmentSlot, ItemStack> 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<ItemStack> 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<BlockPos> blocks) {
|
|
List<ServerExplosion.StackCollector> list = new ArrayList<>();
|
|
Util.shuffle(blocks, this.level.random);
|