port Apply display names from item forms of entities to entities and vice versa patch

This commit is contained in:
granny
2025-01-09 20:29:41 -08:00
committed by granny
parent fb602e72eb
commit ef5f2bc21a
3 changed files with 116 additions and 159 deletions

View File

@@ -1,159 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
Date: Tue, 17 Nov 2020 03:23:48 -0800
Subject: [PATCH] Apply display names from item forms of entities to entities
and vice versa
diff --git a/net/minecraft/world/entity/decoration/ArmorStand.java b/net/minecraft/world/entity/decoration/ArmorStand.java
index edb0cd90e28016c44b0aaf5c9ed5d7bdbced5295..12ff824ffa81ea45f76337ec2b6d80b01047b698 100644
--- a/net/minecraft/world/entity/decoration/ArmorStand.java
+++ b/net/minecraft/world/entity/decoration/ArmorStand.java
@@ -618,6 +618,7 @@ public class ArmorStand extends LivingEntity {
private org.bukkit.event.entity.EntityDeathEvent brokenByPlayer(ServerLevel world, DamageSource damageSource) { // Paper
ItemStack itemstack = new ItemStack(Items.ARMOR_STAND);
+ if (this.level().purpurConfig.persistentDroppableEntityDisplayNames)
itemstack.set(DataComponents.CUSTOM_NAME, this.getCustomName());
this.drops.add(new DefaultDrop(itemstack, stack -> Block.popResource(this.level(), this.blockPosition(), stack))); // CraftBukkit - add to drops // Paper - Restore vanilla drops behavior
return this.brokenByAnything(world, damageSource); // Paper
diff --git a/net/minecraft/world/entity/decoration/ItemFrame.java b/net/minecraft/world/entity/decoration/ItemFrame.java
index 7d83ad8a61f6aafbc063506c1858554f9b700b70..fd1bd4fb88d1bd4a0734db463dc1be640c736d34 100644
--- a/net/minecraft/world/entity/decoration/ItemFrame.java
+++ b/net/minecraft/world/entity/decoration/ItemFrame.java
@@ -240,7 +240,13 @@ public class ItemFrame extends HangingEntity {
}
if (dropSelf) {
- this.spawnAtLocation(world, this.getFrameItemStack());
+ // Purpur start
+ final ItemStack itemFrame = this.getFrameItemStack();
+ if (!this.level().purpurConfig.persistentDroppableEntityDisplayNames) {
+ itemFrame.set(DataComponents.CUSTOM_NAME, null);
+ }
+ this.spawnAtLocation(world, itemFrame);
+ // Purpur end
}
if (!itemstack.isEmpty()) {
diff --git a/net/minecraft/world/entity/decoration/Painting.java b/net/minecraft/world/entity/decoration/Painting.java
index fd0e78a2318e3950d011c17358245e107b38154a..0fcab828e81176323cbdf16c0ec714d9a2846ae5 100644
--- a/net/minecraft/world/entity/decoration/Painting.java
+++ b/net/minecraft/world/entity/decoration/Painting.java
@@ -179,7 +179,13 @@ public class Painting extends HangingEntity implements VariantHolder<Holder<Pain
}
}
- this.spawnAtLocation(world, (ItemLike) Items.PAINTING);
+ // Purpur start
+ final ItemStack painting = new ItemStack((ItemLike) Items.PAINTING);
+ if (!this.level().purpurConfig.persistentDroppableEntityDisplayNames) {
+ painting.set(net.minecraft.core.component.DataComponents.CUSTOM_NAME, null);
+ }
+ this.spawnAtLocation(world, painting);
+ // Purpur end
}
}
diff --git a/net/minecraft/world/entity/vehicle/AbstractBoat.java b/net/minecraft/world/entity/vehicle/AbstractBoat.java
index a301f32a292afb010f3888732e339897b176243d..1a4fb057025689a22b3dd05f531f0d8639d7e47b 100644
--- a/net/minecraft/world/entity/vehicle/AbstractBoat.java
+++ b/net/minecraft/world/entity/vehicle/AbstractBoat.java
@@ -930,7 +930,13 @@ public abstract class AbstractBoat extends VehicleEntity implements Leashable {
@Override
public final ItemStack getPickResult() {
- return new ItemStack((ItemLike) this.dropItem.get());
+ // Purpur start
+ final ItemStack boat = new ItemStack((ItemLike) this.dropItem.get());
+ if (!this.level().purpurConfig.persistentDroppableEntityDisplayNames) {
+ boat.set(net.minecraft.core.component.DataComponents.CUSTOM_NAME, null);
+ }
+ return boat;
+ // Purpur end
}
public static enum Status {
diff --git a/net/minecraft/world/item/ArmorStandItem.java b/net/minecraft/world/item/ArmorStandItem.java
index cb4baebe22eeab17aed67a5ecc506b932fe2230b..c1a6734cc08de1c9fc413b1fa81a199ac9547ec2 100644
--- a/net/minecraft/world/item/ArmorStandItem.java
+++ b/net/minecraft/world/item/ArmorStandItem.java
@@ -59,6 +59,14 @@ public class ArmorStandItem extends Item {
return InteractionResult.FAIL;
}
// CraftBukkit end
+ // Purpur start
+ if (!world.purpurConfig.persistentDroppableEntityDisplayNames) {
+ entityarmorstand.setCustomName(null);
+ }
+ if (world.purpurConfig.armorstandSetNameVisible && entityarmorstand.getCustomName() != null) {
+ entityarmorstand.setCustomNameVisible(true);
+ }
+ // Purpur end
worldserver.addFreshEntityWithPassengers(entityarmorstand);
world.playSound((Player) null, entityarmorstand.getX(), entityarmorstand.getY(), entityarmorstand.getZ(), SoundEvents.ARMOR_STAND_PLACE, SoundSource.BLOCKS, 0.75F, 0.8F);
entityarmorstand.gameEvent(GameEvent.ENTITY_PLACE, context.getPlayer());
diff --git a/net/minecraft/world/item/BoatItem.java b/net/minecraft/world/item/BoatItem.java
index e51ffd6c5047ee907a58f3029f0ea7fc66aedfa7..78d41d57df9cb61b295f1f54db1e1d62c13db701 100644
--- a/net/minecraft/world/item/BoatItem.java
+++ b/net/minecraft/world/item/BoatItem.java
@@ -71,6 +71,11 @@ public class BoatItem extends Item {
return InteractionResult.FAIL;
} else {
abstractboat.setYRot(user.getYRot());
+ // Purpur start
+ if (!world.purpurConfig.persistentDroppableEntityDisplayNames) {
+ abstractboat.setCustomName(null);
+ }
+ // Purpur end
if (!world.noCollision(abstractboat, abstractboat.getBoundingBox())) {
return InteractionResult.FAIL;
} else {
diff --git a/net/minecraft/world/item/HangingEntityItem.java b/net/minecraft/world/item/HangingEntityItem.java
index cdc17ad948d8ac5de62f14b1a561433d33211f32..44a7cee7df2927a923455e8cedaab59307b42506 100644
--- a/net/minecraft/world/item/HangingEntityItem.java
+++ b/net/minecraft/world/item/HangingEntityItem.java
@@ -75,6 +75,11 @@ public class HangingEntityItem extends Item {
if (!customdata.isEmpty()) {
EntityType.updateCustomEntityTag(world, entityhuman, (Entity) object, customdata);
+ // Purpur start
+ if (!world.purpurConfig.persistentDroppableEntityDisplayNames) {
+ ((Entity) object).setCustomName(null);
+ }
+ // Purpur end
}
if (((HangingEntity) object).survives()) {
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
index e363a93bdfcef7408ecdd5618b63c345ab9525b4..4efb19a627b3735fe2ded2108576d76296b605f3 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
@@ -98,8 +98,10 @@ public class PurpurWorldConfig {
}
public float armorstandStepHeight = 0.0F;
+ public boolean armorstandSetNameVisible = false;
private void armorstandSettings() {
armorstandStepHeight = (float) getDouble("gameplay-mechanics.armorstand.step-height", armorstandStepHeight);
+ armorstandSetNameVisible = getBoolean("gameplay-mechanics.armorstand.set-name-visible-when-placing-with-custom-name", armorstandSetNameVisible);
}
public boolean arrowMovementResetsDespawnCounter = true;
@@ -115,6 +117,7 @@ public class PurpurWorldConfig {
public boolean entitiesCanUsePortals = true;
public int raidCooldownSeconds = 0;
public int animalBreedingCooldownSeconds = 0;
+ public boolean persistentDroppableEntityDisplayNames = true;
private void miscGameplayMechanicsSettings() {
useBetterMending = getBoolean("gameplay-mechanics.use-better-mending", useBetterMending);
boatEjectPlayersOnLand = getBoolean("gameplay-mechanics.boat.eject-players-on-land", boatEjectPlayersOnLand);
@@ -124,6 +127,8 @@ public class PurpurWorldConfig {
entitiesCanUsePortals = getBoolean("gameplay-mechanics.entities-can-use-portals", entitiesCanUsePortals);
raidCooldownSeconds = getInt("gameplay-mechanics.raid-cooldown-seconds", raidCooldownSeconds);
animalBreedingCooldownSeconds = getInt("gameplay-mechanics.animal-breeding-cooldown-seconds", animalBreedingCooldownSeconds);
+ persistentDroppableEntityDisplayNames = getBoolean("gameplay-mechanics.persistent-droppable-entity-display-names", persistentDroppableEntityDisplayNames);
+
}
public int daytimeTicks = 12000;

View File

@@ -0,0 +1,111 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
Date: Tue, 17 Nov 2020 03:23:48 -0800
Subject: [PATCH] Apply display names from item forms of entities to entities
and vice versa
diff --git a/net/minecraft/world/entity/decoration/ArmorStand.java b/net/minecraft/world/entity/decoration/ArmorStand.java
index 9f5b23fe003de62458a58b0f6af13e23606e3e85..9327841ad53bb6057394e0d009491a9e8e5c0344 100644
--- a/net/minecraft/world/entity/decoration/ArmorStand.java
+++ b/net/minecraft/world/entity/decoration/ArmorStand.java
@@ -561,6 +561,7 @@ public class ArmorStand extends LivingEntity {
private org.bukkit.event.entity.EntityDeathEvent brokenByPlayer(ServerLevel level, DamageSource damageSource) { // Paper
ItemStack itemStack = new ItemStack(Items.ARMOR_STAND);
+ if (level.purpurConfig.persistentDroppableEntityDisplayNames) // Purpur - Apply display names from item forms of entities to entities and vice versa
itemStack.set(DataComponents.CUSTOM_NAME, this.getCustomName());
this.drops.add(new DefaultDrop(itemStack, stack -> Block.popResource(this.level(), this.blockPosition(), stack))); // CraftBukkit - add to drops // Paper - Restore vanilla drops behavior
return this.brokenByAnything(level, damageSource); // Paper
diff --git a/net/minecraft/world/entity/decoration/ItemFrame.java b/net/minecraft/world/entity/decoration/ItemFrame.java
index 65e1d7c5ac94b1cfb921fa009be59d3e5872f0b5..3ee1d8798db666ee8d83556047e40ff217cda732 100644
--- a/net/minecraft/world/entity/decoration/ItemFrame.java
+++ b/net/minecraft/world/entity/decoration/ItemFrame.java
@@ -223,7 +223,11 @@ public class ItemFrame extends HangingEntity {
this.removeFramedMap(item);
} else {
if (dropItem) {
- this.spawnAtLocation(level, this.getFrameItemStack());
+ // Purpur start - Apply display names from item forms of entities to entities and vice versa
+ final ItemStack itemFrame = this.getFrameItemStack();
+ if (!level.purpurConfig.persistentDroppableEntityDisplayNames) itemFrame.set(DataComponents.CUSTOM_NAME, null);
+ this.spawnAtLocation(level, itemFrame);
+ // Purpur end - Apply display names from item forms of entities to entities and vice versa
}
if (!item.isEmpty()) {
diff --git a/net/minecraft/world/entity/decoration/Painting.java b/net/minecraft/world/entity/decoration/Painting.java
index 5b905a4d49c44b04d5795c2bf297f3c69d183d7c..b6429a2bbb6fc1e08610ab20e50f8f0414f0ad26 100644
--- a/net/minecraft/world/entity/decoration/Painting.java
+++ b/net/minecraft/world/entity/decoration/Painting.java
@@ -162,7 +162,11 @@ public class Painting extends HangingEntity implements VariantHolder<Holder<Pain
if (level.getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
this.playSound(SoundEvents.PAINTING_BREAK, 1.0F, 1.0F);
if (!(entity instanceof Player player && player.hasInfiniteMaterials())) {
- this.spawnAtLocation(level, Items.PAINTING);
+ // Purpur start - Apply display names from item forms of entities to entities and vice versa
+ final ItemStack painting = new ItemStack(Items.PAINTING);
+ if (!this.level().purpurConfig.persistentDroppableEntityDisplayNames) painting.set(net.minecraft.core.component.DataComponents.CUSTOM_NAME, null);
+ this.spawnAtLocation(level, painting);
+ // Purpur end - Apply display names from item forms of entities to entities and vice versa
}
}
}
diff --git a/net/minecraft/world/entity/vehicle/AbstractBoat.java b/net/minecraft/world/entity/vehicle/AbstractBoat.java
index 4e724a12f13032075aeff7cf71b9ceabd5a7bd88..b1b312e45ed4514eaa6fb3941af64b641220c5bd 100644
--- a/net/minecraft/world/entity/vehicle/AbstractBoat.java
+++ b/net/minecraft/world/entity/vehicle/AbstractBoat.java
@@ -879,7 +879,13 @@ public abstract class AbstractBoat extends VehicleEntity implements Leashable {
@Override
public final ItemStack getPickResult() {
- return new ItemStack(this.dropItem.get());
+ // Purpur start - Apply display names from item forms of entities to entities and vice versa
+ final ItemStack boat = new ItemStack(this.dropItem.get());
+ if (!this.level().purpurConfig.persistentDroppableEntityDisplayNames) {
+ boat.set(net.minecraft.core.component.DataComponents.CUSTOM_NAME, null);
+ }
+ return boat;
+ // Purpur end - Apply display names from item forms of entities to entities and vice versa
}
public static enum Status {
diff --git a/net/minecraft/world/item/ArmorStandItem.java b/net/minecraft/world/item/ArmorStandItem.java
index d82e6651999a2650ec8884c4c3d8de4133cb42a4..a26b9fe964c79da57aaa0f755a81934f51a79913 100644
--- a/net/minecraft/world/item/ArmorStandItem.java
+++ b/net/minecraft/world/item/ArmorStandItem.java
@@ -51,6 +51,10 @@ public class ArmorStandItem extends Item {
return InteractionResult.FAIL;
}
// CraftBukkit end
+ // Purpur start - Apply display names from item forms of entities to entities and vice versa
+ if (!serverLevel.purpurConfig.persistentDroppableEntityDisplayNames) armorStand.setCustomName(null);
+ if (serverLevel.purpurConfig.armorstandSetNameVisible && armorStand.getCustomName() != null) armorStand.setCustomNameVisible(true);
+ // Purpur end - Apply display names from item forms of entities to entities and vice versa
serverLevel.addFreshEntityWithPassengers(armorStand);
level.playSound(
null, armorStand.getX(), armorStand.getY(), armorStand.getZ(), SoundEvents.ARMOR_STAND_PLACE, SoundSource.BLOCKS, 0.75F, 0.8F
diff --git a/net/minecraft/world/item/BoatItem.java b/net/minecraft/world/item/BoatItem.java
index 13ce174e4f7e406f57a68ea0d3ef0ee3367f3f3b..ca86122e38688b29340cd8413ccf1746315e292a 100644
--- a/net/minecraft/world/item/BoatItem.java
+++ b/net/minecraft/world/item/BoatItem.java
@@ -63,6 +63,7 @@ public class BoatItem extends Item {
return InteractionResult.FAIL;
} else {
boat.setYRot(player.getYRot());
+ if (!level.purpurConfig.persistentDroppableEntityDisplayNames) boat.setCustomName(null); // Purpur - Apply display names from item forms of entities to entities and vice versa
if (!level.noCollision(boat, boat.getBoundingBox())) {
return InteractionResult.FAIL;
} else {
diff --git a/net/minecraft/world/item/HangingEntityItem.java b/net/minecraft/world/item/HangingEntityItem.java
index 85980c7e5ad63398e0f0948fb0250f580251fe63..cd9e0398876567afc337db8f6ff0ebb0ee162383 100644
--- a/net/minecraft/world/item/HangingEntityItem.java
+++ b/net/minecraft/world/item/HangingEntityItem.java
@@ -62,6 +62,7 @@ public class HangingEntityItem extends Item {
CustomData customData = itemInHand.getOrDefault(DataComponents.ENTITY_DATA, CustomData.EMPTY);
if (!customData.isEmpty()) {
EntityType.updateCustomEntityTag(level, player, hangingEntity, customData);
+ if (!level.purpurConfig.persistentDroppableEntityDisplayNames) hangingEntity.setCustomName(null); // Purpur - Apply display names from item forms of entities to entities and vice versa
}
if (hangingEntity.survives()) {

View File

@@ -89,8 +89,10 @@ public class PurpurWorldConfig {
}
public float armorstandStepHeight = 0.0F;
public boolean armorstandSetNameVisible = false;
private void armorstandSettings() {
armorstandStepHeight = (float) getDouble("gameplay-mechanics.armorstand.step-height", armorstandStepHeight);
armorstandSetNameVisible = getBoolean("gameplay-mechanics.armorstand.set-name-visible-when-placing-with-custom-name", armorstandSetNameVisible);
}
public boolean arrowMovementResetsDespawnCounter = true;
@@ -106,6 +108,7 @@ public class PurpurWorldConfig {
public boolean entitiesCanUsePortals = true;
public int raidCooldownSeconds = 0;
public int animalBreedingCooldownSeconds = 0;
public boolean persistentDroppableEntityDisplayNames = true;
private void miscGameplayMechanicsSettings() {
useBetterMending = getBoolean("gameplay-mechanics.use-better-mending", useBetterMending);
boatEjectPlayersOnLand = getBoolean("gameplay-mechanics.boat.eject-players-on-land", boatEjectPlayersOnLand);
@@ -115,6 +118,8 @@ public class PurpurWorldConfig {
entitiesCanUsePortals = getBoolean("gameplay-mechanics.entities-can-use-portals", entitiesCanUsePortals);
raidCooldownSeconds = getInt("gameplay-mechanics.raid-cooldown-seconds", raidCooldownSeconds);
animalBreedingCooldownSeconds = getInt("gameplay-mechanics.animal-breeding-cooldown-seconds", animalBreedingCooldownSeconds);
persistentDroppableEntityDisplayNames = getBoolean("gameplay-mechanics.persistent-droppable-entity-display-names", persistentDroppableEntityDisplayNames);
}
public int daytimeTicks = 12000;