mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
Add old Blast Protection explosion knockback behavior (#346)
Added configurable old Blast Protection explosion knockback behavior that is from <=1.21.4 version.
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Samsuik <kfian294ma4@gmail.com>
|
||||
Date: Thu, 1 May 2025 22:38:48 +0200
|
||||
Subject: [PATCH] Sakura: Optimise-check-inside-blocks-and-traverse-blocks
|
||||
Date: Fri, 8 Nov 2024 19:35:49 +0000
|
||||
Subject: [PATCH] Sakura: Optimise check inside blocks and traverse blocks
|
||||
|
||||
Dreeam TODO: refactor checkinsideblcoks
|
||||
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index df4b26a6304df92f4eda27ac986ca78d5217ce6c..a4de10a32f49b7b361fc9dd1d142caeef8d7d148 100644
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Samsuik <kfian294ma4@gmail.com>
|
||||
Date: Thu, 1 May 2025 22:28:50 +0200
|
||||
Subject: [PATCH] Sakura: copy-EntityList-implementation-to-BasicEntityList
|
||||
Date: Sun, 2 Feb 2025 17:05:05 +0000
|
||||
Subject: [PATCH] Sakura: copy EntityList implementation to BasicEntityList
|
||||
|
||||
|
||||
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
|
||||
@@ -0,0 +1,81 @@
|
||||
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 0a5611b1ece4dbe2887e7fbdef45f58e7f4d53ad..9f6fc274525f2fe4e4e35e0feaa410bf5d8eba04 100644
|
||||
--- a/net/minecraft/world/entity/EquipmentSlot.java
|
||||
+++ b/net/minecraft/world/entity/EquipmentSlot.java
|
||||
@@ -21,6 +21,7 @@ public enum EquipmentSlot implements StringRepresentable {
|
||||
public static final int NO_COUNT_LIMIT = 0;
|
||||
public static final EquipmentSlot[] VALUES_ARRAY = values(); // Gale - JettPack - reduce array allocations
|
||||
public static final List<EquipmentSlot> VALUES = List.of(VALUES_ARRAY); // Gale - JettPack - reduce array allocations
|
||||
+ 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(), ByIdMap.OutOfBoundsStrategy.ZERO);
|
||||
public static final StringRepresentable.EnumCodec<EquipmentSlot> CODEC = StringRepresentable.fromEnum(EquipmentSlot::values);
|
||||
public static final StreamCodec<ByteBuf, EquipmentSlot> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, equipmentSlot -> equipmentSlot.id);
|
||||
diff --git a/net/minecraft/world/level/ServerExplosion.java b/net/minecraft/world/level/ServerExplosion.java
|
||||
index ea9c641fe9a9685307b6de2999ea4ff5342269b7..ae0dab1f8470cf53031a2ba776fa70d8ae074a87 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;
|
||||
}
|
||||
@@ -564,6 +564,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);
|
||||
@@ -15,6 +15,7 @@ public class Knockback extends ConfigModules {
|
||||
public static boolean canPlayerKnockbackZombie = true;
|
||||
@Experimental
|
||||
public static boolean flushKnockback = false;
|
||||
public static boolean oldBlastProtectionKnockbackBehavior = false;
|
||||
|
||||
@Override
|
||||
public void onLoaded() {
|
||||
@@ -34,5 +35,6 @@ public class Knockback extends ConfigModules {
|
||||
"使玩家可以击退僵尸."
|
||||
));
|
||||
flushKnockback = config.getBoolean(getBasePath() + ".flush-location-while-knockback-player", flushKnockback);
|
||||
oldBlastProtectionKnockbackBehavior = config.getBoolean(getBasePath() + ".old-blast-protection-explosion-knockback", oldBlastProtectionKnockbackBehavior);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public final class BlockPosIterator extends AbstractIterator<BlockPos> {
|
||||
Vec3 movement = vec.scale(toTravel);
|
||||
AABB fromBB = boundingBox.move(-vec.x, -vec.y, -vec.z);
|
||||
AABB searchArea = fromBB.expandTowards(movement);
|
||||
return org.dreeam.leaf.util.map.BlockPosIterator.iterable(searchArea);
|
||||
return iterable(searchArea);
|
||||
}
|
||||
|
||||
public BlockPosIterator(AABB bb) {
|
||||
|
||||
Reference in New Issue
Block a user