Files
Purpur/patches/server/0122-One-Punch-Man.patch
2024-06-14 15:26:46 -07:00

57 lines
3.3 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Fourmisain <8464472+Fourmisain@users.noreply.github.com>
Date: Fri, 5 Mar 2021 17:42:35 -0500
Subject: [PATCH] One Punch Man!
inspired by https://modrinth.com/mod/creative-one-punch
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 13ada4aa83ddb75d6107d41b4a7d10196d5f01f0..ab9769d9a14d7736f9a9d1c3afbf44dc9339fc3b 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -1428,6 +1428,24 @@ public abstract class LivingEntity extends Entity implements Attackable {
this.stopSleeping();
}
+ // Purpur start
+ if (source.getEntity() instanceof net.minecraft.world.entity.player.Player player && source.getEntity().level().purpurConfig.creativeOnePunch && !source.is(DamageTypeTags.IS_PROJECTILE)) {
+ if (player.isCreative()) {
+ org.apache.commons.lang3.mutable.MutableDouble attackDamage = new org.apache.commons.lang3.mutable.MutableDouble();
+ player.getMainHandItem().forEachModifier(EquipmentSlot.MAINHAND, (attributeHolder, attributeModifier) -> {
+ if (attributeModifier.operation() == AttributeModifier.Operation.ADD_VALUE) {
+ attackDamage.addAndGet(attributeModifier.amount());
+ }
+ });
+
+ if (attackDamage.doubleValue() == 0.0D) {
+ // One punch!
+ amount = 9999F;
+ }
+ }
+ }
+ // Purpur end
+
this.noActionTime = 0;
float f1 = amount;
boolean flag = amount > 0.0F && this.isDamageSourceBlocked(source); // Copied from below
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
index 12d70d3a064c3cf031818f25777eb0aaf97b7ea1..0913c3f49fb36dd63c15e3cfb891a60a9495a92a 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
@@ -328,6 +328,7 @@ public class PurpurWorldConfig {
public int playerDeathExpDropMax = 100;
public boolean teleportIfOutsideBorder = false;
public boolean totemOfUndyingWorksInInventory = false;
+ public boolean creativeOnePunch = false;
private void playerSettings() {
if (PurpurConfig.version < 19) {
boolean oldVal = getBoolean("gameplay-mechanics.player.idle-timeout.mods-target", idleTimeoutTargetPlayer);
@@ -343,6 +344,7 @@ public class PurpurWorldConfig {
playerDeathExpDropMax = getInt("gameplay-mechanics.player.exp-dropped-on-death.maximum", playerDeathExpDropMax);
teleportIfOutsideBorder = getBoolean("gameplay-mechanics.player.teleport-if-outside-border", teleportIfOutsideBorder);
totemOfUndyingWorksInInventory = getBoolean("gameplay-mechanics.player.totem-of-undying-works-in-inventory", totemOfUndyingWorksInInventory);
+ creativeOnePunch = getBoolean("gameplay-mechanics.player.one-punch-in-creative", creativeOnePunch);
}
public boolean silkTouchEnabled = false;