Dont run with scissors!

inspired by https://modrinth.com/mod/dont-run-with-scissors
This commit is contained in:
JustDoom
2025-01-10 14:48:42 -08:00
committed by granny
parent 6224111edb
commit d2410edc75
8 changed files with 137 additions and 192 deletions

View File

@@ -149,6 +149,38 @@
Location oldTo = to.clone();
PlayerMoveEvent event = new PlayerMoveEvent(player, from, to);
this.cserver.getPluginManager().callEvent(event);
@@ -1582,6 +_,13 @@
this.player.tryResetCurrentImpulseContext();
}
+ // Purpur start - Dont run with scissors!
+ if (this.player.serverLevel().purpurConfig.dontRunWithScissors && this.player.isSprinting() && !(this.player.serverLevel().purpurConfig.ignoreScissorsInWater && this.player.isInWater()) && !(this.player.serverLevel().purpurConfig.ignoreScissorsInLava && this.player.isInLava()) && (isScissors(this.player.getItemInHand(InteractionHand.MAIN_HAND)) || isScissors(this.player.getItemInHand(InteractionHand.OFF_HAND))) && (int) (Math.random() * 10) == 0) {
+ this.player.hurtServer(this.player.serverLevel(), this.player.damageSources().scissors(), (float) this.player.serverLevel().purpurConfig.scissorsRunningDamage);
+ if (!org.purpurmc.purpur.PurpurConfig.dontRunWithScissors.isBlank()) this.player.sendActionBarMessage(org.purpurmc.purpur.PurpurConfig.dontRunWithScissors);
+ }
+ // Purpur end - Dont run with scissors!
+
this.player.checkMovementStatistics(this.player.getX() - x, this.player.getY() - y, this.player.getZ() - z);
this.lastGoodX = this.player.getX();
this.lastGoodY = this.player.getY();
@@ -1630,6 +_,17 @@
}
}
+ // Purpur start - Dont run with scissors!
+ public boolean isScissors(ItemStack stack) {
+ if (!stack.is(Items.SHEARS)) return false;
+
+ ResourceLocation itemModelReference = stack.get(net.minecraft.core.component.DataComponents.ITEM_MODEL);
+ if (itemModelReference != null && itemModelReference.equals(this.player.serverLevel().purpurConfig.dontRunWithScissorsItemModelReference)) return true;
+
+ return stack.getOrDefault(DataComponents.CUSTOM_MODEL_DATA, net.minecraft.world.item.component.CustomModelData.EMPTY).equals(net.minecraft.world.item.component.CustomModelData.EMPTY);
+ }
+ // Purpur end - Dont run with scissors!
+
// Paper start - optimise out extra getCubes
private boolean hasNewCollision(final ServerLevel level, final Entity entity, final AABB oldBox, final AABB newBox) {
final List<AABB> collisionsBB = new java.util.ArrayList<>();
@@ -2734,6 +_,7 @@
AABB boundingBox = target.getBoundingBox();

View File

@@ -0,0 +1,14 @@
--- a/net/minecraft/world/damagesource/CombatTracker.java
+++ b/net/minecraft/world/damagesource/CombatTracker.java
@@ -98,6 +_,11 @@
Component component = ComponentUtils.wrapInSquareBrackets(Component.translatable(string + ".link")).withStyle(INTENTIONAL_GAME_DESIGN_STYLE);
return Component.translatable(string + ".message", this.mob.getDisplayName(), component);
} else {
+ // Purpur start - Dont run with scissors!
+ if (damageSource.isScissors()) {
+ return damageSource.getLocalizedDeathMessage(org.purpurmc.purpur.PurpurConfig.deathMsgRunWithScissors, this.mob);
+ }
+ // Purpur end - Dont run with scissors!
return damageSource.getLocalizedDeathMessage(this.mob);
}
}

View File

@@ -1,9 +1,44 @@
--- a/net/minecraft/world/damagesource/DamageSource.java
+++ b/net/minecraft/world/damagesource/DamageSource.java
@@ -188,6 +_,15 @@
}
@@ -28,6 +_,7 @@
private boolean sweep = false;
private boolean melting = false;
private boolean poison = false;
+ private boolean scissors = false; // Purpur - Dont run with scissors!
@Nullable
private Entity customEventDamager = null; // This field is a helper for when causing entity damage is not set by vanilla // Paper - fix DamageSource API
@@ -58,6 +_,17 @@
return this.poison;
}
+ // Purpur start - Dont run with scissors!
+ public DamageSource scissors() {
+ this.scissors = true;
+ return this;
+ }
+
+ public boolean isScissors() {
+ return this.scissors;
+ }
+ // Purpur end - Dont run with scissors!
+
// Paper start - fix DamageSource API
@Nullable
public Entity getCustomEventDamager() {
@@ -116,6 +_,7 @@
damageSource.sweep = this.isSweep();
damageSource.poison = this.isPoison();
damageSource.melting = this.isMelting();
+ damageSource.scissors = this.isScissors(); // Purpur - Dont run with scissors!
return damageSource;
}
// CraftBukkit end
@@ -187,6 +_,15 @@
: Component.translatable(string, livingEntity.getDisplayName(), component);
}
}
+
+ // Purpur start - Component related conveniences
+ public Component getLocalizedDeathMessage(String str, LivingEntity entity) {
+ net.kyori.adventure.text.Component name = io.papermc.paper.adventure.PaperAdventure.asAdventure(entity.getDisplayName());
@@ -12,7 +47,6 @@
+ return io.papermc.paper.adventure.PaperAdventure.asVanilla(component);
+ }
+ // Purpur end - Component related conveniences
+
public String getMsgId() {
return this.type().msgId();
}

View File

@@ -0,0 +1,29 @@
--- a/net/minecraft/world/damagesource/DamageSources.java
+++ b/net/minecraft/world/damagesource/DamageSources.java
@@ -45,11 +_,13 @@
// CraftBukkit start
private final DamageSource melting;
private final DamageSource poison;
+ private final DamageSource scissors; // Purpur - Dont run with scissors!
public DamageSources(RegistryAccess registry) {
this.damageTypes = registry.lookupOrThrow(Registries.DAMAGE_TYPE);
this.melting = this.source(DamageTypes.ON_FIRE).melting();
this.poison = this.source(DamageTypes.MAGIC).poison();
+ this.scissors = this.source(DamageTypes.MAGIC).scissors(); // Purpur - Dont run with scissors!
// CraftBukkit end
this.inFire = this.source(DamageTypes.IN_FIRE);
this.campfire = this.source(DamageTypes.CAMPFIRE);
@@ -99,6 +_,12 @@
return this.poison;
}
// CraftBukkit end
+
+ // Purpur start - Dont run with scissors!
+ public DamageSource scissors() {
+ return this.scissors;
+ }
+ // Purpur end - Dont run with scissors!
public DamageSource inFire() {
return this.inFire;