mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 08:27:43 +01:00
Configurable block fall damage modifiers
This commit is contained in:
@@ -18,3 +18,12 @@
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -175,7 +_,7 @@
|
||||
|
||||
@Override
|
||||
public void fallOn(Level level, BlockState state, BlockPos pos, Entity entity, float fallDistance) {
|
||||
- super.fallOn(level, state, pos, entity, fallDistance * 0.5F);
|
||||
+ super.fallOn(level, state, pos, entity, fallDistance); // Purpur - Configurable block fall damage modifiers
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
--- a/net/minecraft/world/level/block/Block.java
|
||||
+++ b/net/minecraft/world/level/block/Block.java
|
||||
@@ -90,6 +_,10 @@
|
||||
public static final int UPDATE_LIMIT = 512;
|
||||
protected final StateDefinition<Block, BlockState> stateDefinition;
|
||||
private BlockState defaultBlockState;
|
||||
+ // Purpur start - Configurable block fall damage modifiers
|
||||
+ public float fallDamageMultiplier = 1.0F;
|
||||
+ public float fallDistanceMultiplier = 1.0F;
|
||||
+ // Purpur end - Configurable block fall damage modifiers
|
||||
// Paper start - Protect Bedrock and End Portal/Frames from being destroyed
|
||||
public final boolean isDestroyable() {
|
||||
return io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.allowPermanentBlockBreakExploits ||
|
||||
@@ -299,7 +_,7 @@
|
||||
event.setExpToDrop(block.getExpDrop(state, serverLevel, pos, net.minecraft.world.item.ItemStack.EMPTY, true)); // Paper - Properly handle xp dropping
|
||||
event.callEvent();
|
||||
@@ -67,3 +78,12 @@
|
||||
|
||||
public boolean isPossibleToRespawnInThis(BlockState state) {
|
||||
return !state.isSolid() && !state.liquid();
|
||||
@@ -423,7 +_,7 @@
|
||||
}
|
||||
|
||||
public void fallOn(Level level, BlockState state, BlockPos pos, Entity entity, float fallDistance) {
|
||||
- entity.causeFallDamage(fallDistance, 1.0F, entity.damageSources().fall());
|
||||
+ entity.causeFallDamage(fallDistance * fallDistanceMultiplier, fallDamageMultiplier, entity.damageSources().fall()); // Purpur - Configurable block fall damage modifiers
|
||||
}
|
||||
|
||||
public void updateEntityMovementAfterFallOn(BlockGetter level, Entity entity) {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
--- a/net/minecraft/world/level/block/HayBlock.java
|
||||
+++ b/net/minecraft/world/level/block/HayBlock.java
|
||||
@@ -23,6 +_,6 @@
|
||||
|
||||
@Override
|
||||
public void fallOn(Level level, BlockState state, BlockPos pos, Entity entity, float fallDistance) {
|
||||
- entity.causeFallDamage(fallDistance, 0.2F, level.damageSources().fall());
|
||||
+ super.fallOn(level, state, pos, entity, fallDistance); // Purpur - Configurable block fall damage modifiers
|
||||
}
|
||||
}
|
||||
@@ -509,4 +509,50 @@ public class PurpurConfig {
|
||||
block.explosionResistance = blastResistance.floatValue();
|
||||
});
|
||||
}
|
||||
private static void blockFallMultiplierSettings() {
|
||||
getMap("settings.block-fall-multipliers", Map.ofEntries(
|
||||
Map.entry("minecraft:hay_block", Map.of("damage", 0.2F)),
|
||||
Map.entry("minecraft:white_bed", Map.of("distance", 0.5F)),
|
||||
Map.entry("minecraft:light_gray_bed", Map.of("distance", 0.5F)),
|
||||
Map.entry("minecraft:gray_bed", Map.of("distance", 0.5F)),
|
||||
Map.entry("minecraft:black_bed", Map.of("distance", 0.5F)),
|
||||
Map.entry("minecraft:brown_bed", Map.of("distance", 0.5F)),
|
||||
Map.entry("minecraft:pink_bed", Map.of("distance", 0.5F)),
|
||||
Map.entry("minecraft:red_bed", Map.of("distance", 0.5F)),
|
||||
Map.entry("minecraft:orange_bed", Map.of("distance", 0.5F)),
|
||||
Map.entry("minecraft:yellow_bed", Map.of("distance", 0.5F)),
|
||||
Map.entry("minecraft:green_bed", Map.of("distance", 0.5F)),
|
||||
Map.entry("minecraft:lime_bed", Map.of("distance", 0.5F)),
|
||||
Map.entry("minecraft:cyan_bed", Map.of("distance", 0.5F)),
|
||||
Map.entry("minecraft:light_blue_bed", Map.of("distance", 0.5F)),
|
||||
Map.entry("minecraft:blue_bed", Map.of("distance", 0.5F)),
|
||||
Map.entry("minecraft:purple_bed", Map.of("distance", 0.5F)),
|
||||
Map.entry("minecraft:magenta_bed", Map.of("distance", 0.5F))
|
||||
)).forEach((blockId, value) -> {
|
||||
Block block = BuiltInRegistries.BLOCK.getValue(ResourceLocation.parse(blockId));
|
||||
if (block == Blocks.AIR) {
|
||||
log(Level.SEVERE, "Invalid block for `settings.block-fall-multipliers`: " + blockId);
|
||||
return;
|
||||
}
|
||||
if (!(value instanceof Map<?, ?> map)) {
|
||||
log(Level.SEVERE, "Invalid fall multiplier for `settings.block-fall-multipliers." + blockId + "`: " + value
|
||||
+ ", expected a map with keys `damage` and `distance` to floats.");
|
||||
return;
|
||||
}
|
||||
Object rawFallDamageMultiplier = map.get("damage");
|
||||
if (rawFallDamageMultiplier == null) rawFallDamageMultiplier = 1F;
|
||||
if (!(rawFallDamageMultiplier instanceof Number fallDamageMultiplier)) {
|
||||
log(Level.SEVERE, "Invalid multiplier for `settings.block-fall-multipliers." + blockId + ".damage`: " + map.get("damage"));
|
||||
return;
|
||||
}
|
||||
Object rawFallDistanceMultiplier = map.get("distance");
|
||||
if (rawFallDistanceMultiplier == null) rawFallDistanceMultiplier = 1F;
|
||||
if (!(rawFallDistanceMultiplier instanceof Number fallDistanceMultiplier)) {
|
||||
log(Level.SEVERE, "Invalid multiplier for `settings.block-fall-multipliers." + blockId + ".distance`: " + map.get("distance"));
|
||||
return;
|
||||
}
|
||||
block.fallDamageMultiplier = fallDamageMultiplier.floatValue();
|
||||
block.fallDistanceMultiplier = fallDistanceMultiplier.floatValue();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user