Files
Purpur/patches/server/0100-Apply-display-names-from-item-forms-of-entities-to-e.patch
2024-10-03 18:17:26 -07:00

159 lines
9.5 KiB
Diff

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/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java b/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java
index 8d360dc542099af90f0c11839c12910859f0402b..4d6df7ec1bffbd30d4aac906f393ead0dfd8f69d 100644
--- a/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java
+++ b/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java
@@ -620,6 +620,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/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java b/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java
index 5b7245cd99593ee90e17c97e0104f3aba9ae05ea..cf78531b193ba56991ccb0c4f62844208e4a5706 100644
--- a/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java
+++ b/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java
@@ -227,7 +227,13 @@ public class ItemFrame extends HangingEntity {
}
if (alwaysDrop) {
- this.spawnAtLocation(this.getFrameItemStack());
+ // Purpur start
+ final ItemStack itemFrame = this.getFrameItemStack();
+ if (!this.level().purpurConfig.persistentDroppableEntityDisplayNames) {
+ itemFrame.set(DataComponents.CUSTOM_NAME, null);
+ }
+ this.spawnAtLocation(itemFrame);
+ // Purpur end
}
if (!itemstack.isEmpty()) {
diff --git a/src/main/java/net/minecraft/world/entity/decoration/Painting.java b/src/main/java/net/minecraft/world/entity/decoration/Painting.java
index e86fdf5d6853b7bddfe19d6e5d41d3dec0c25f23..f45567aa7695da68f92809a6c208eb515c2f838a 100644
--- a/src/main/java/net/minecraft/world/entity/decoration/Painting.java
+++ b/src/main/java/net/minecraft/world/entity/decoration/Painting.java
@@ -178,7 +178,13 @@ public class Painting extends HangingEntity implements VariantHolder<Holder<Pain
}
}
- this.spawnAtLocation((ItemLike) Items.PAINTING);
+ // Purpur start
+ final ItemStack painting = new ItemStack(Items.PAINTING);
+ if (!this.level().purpurConfig.persistentDroppableEntityDisplayNames) {
+ painting.set(net.minecraft.core.component.DataComponents.CUSTOM_NAME, null);
+ }
+ this.spawnAtLocation(painting);
+ // Purpur end
}
}
diff --git a/src/main/java/net/minecraft/world/entity/vehicle/Boat.java b/src/main/java/net/minecraft/world/entity/vehicle/Boat.java
index 7f7abef3c5b7ad124c5c1dda02173bc5f70c9506..5f3d58099d83fef4a9230e680b5e199d00eb7c7b 100644
--- a/src/main/java/net/minecraft/world/entity/vehicle/Boat.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/Boat.java
@@ -1017,7 +1017,13 @@ public class Boat extends VehicleEntity implements Leashable, VariantHolder<Boat
@Override
public ItemStack getPickResult() {
- return new ItemStack(this.getDropItem());
+ // Purpur start
+ final ItemStack boat = new ItemStack(this.getDropItem());
+ if (!this.level().purpurConfig.persistentDroppableEntityDisplayNames) {
+ boat.set(net.minecraft.core.component.DataComponents.CUSTOM_NAME, null);
+ }
+ return boat;
+ // Purpur end
}
public static enum Type implements StringRepresentable {
diff --git a/src/main/java/net/minecraft/world/item/ArmorStandItem.java b/src/main/java/net/minecraft/world/item/ArmorStandItem.java
index 066a6e5ed2632a55324ec0d10f2f8a6bf3f30a0f..1921ecf2c0a9f18c93d207692fb9c2db58c9358f 100644
--- a/src/main/java/net/minecraft/world/item/ArmorStandItem.java
+++ b/src/main/java/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/src/main/java/net/minecraft/world/item/BoatItem.java b/src/main/java/net/minecraft/world/item/BoatItem.java
index eb74d45ad458b80cf8455297c3bc550186adaea3..ef01856c487e4ab982996e01537618233592ac32 100644
--- a/src/main/java/net/minecraft/world/item/BoatItem.java
+++ b/src/main/java/net/minecraft/world/item/BoatItem.java
@@ -72,6 +72,11 @@ public class BoatItem extends Item {
entityboat.setVariant(this.type);
entityboat.setYRot(user.getYRot());
+ // Purpur start
+ if (!world.purpurConfig.persistentDroppableEntityDisplayNames) {
+ entityboat.setCustomName(null);
+ }
+ // Purpur end
if (!world.noCollision(entityboat, entityboat.getBoundingBox())) {
return InteractionResultHolder.fail(itemstack);
} else {
diff --git a/src/main/java/net/minecraft/world/item/HangingEntityItem.java b/src/main/java/net/minecraft/world/item/HangingEntityItem.java
index d8a63ac5444eff8e3decb2f4addc2decb8a5d648..41cc9229108aa8e4f5655dfe590ff414a16b1444 100644
--- a/src/main/java/net/minecraft/world/item/HangingEntityItem.java
+++ b/src/main/java/net/minecraft/world/item/HangingEntityItem.java
@@ -74,6 +74,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 eefd829f617f2af60b9846f2fe8003676a997c88..cc95e8ba5d847348afdd4263c9e84554cb2ec713 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;
@@ -112,6 +114,7 @@ public class PurpurWorldConfig {
public boolean disableDropsOnCrammingDeath = false;
public boolean entitiesCanUsePortals = true;
public boolean milkCuresBadOmen = true;
+ public boolean persistentDroppableEntityDisplayNames = true;
public double tridentLoyaltyVoidReturnHeight = 0.0D;
public int raidCooldownSeconds = 0;
public int animalBreedingCooldownSeconds = 0;
@@ -121,6 +124,7 @@ public class PurpurWorldConfig {
disableDropsOnCrammingDeath = getBoolean("gameplay-mechanics.disable-drops-on-cramming-death", disableDropsOnCrammingDeath);
entitiesCanUsePortals = getBoolean("gameplay-mechanics.entities-can-use-portals", entitiesCanUsePortals);
milkCuresBadOmen = getBoolean("gameplay-mechanics.milk-cures-bad-omen", milkCuresBadOmen);
+ persistentDroppableEntityDisplayNames = getBoolean("gameplay-mechanics.persistent-droppable-entity-display-names", persistentDroppableEntityDisplayNames);
tridentLoyaltyVoidReturnHeight = getDouble("gameplay-mechanics.trident-loyalty-void-return-height", tridentLoyaltyVoidReturnHeight);
raidCooldownSeconds = getInt("gameplay-mechanics.raid-cooldown-seconds", raidCooldownSeconds);
animalBreedingCooldownSeconds = getInt("gameplay-mechanics.animal-breeding-cooldown-seconds", animalBreedingCooldownSeconds);