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 13faa9a0c923546eba04ab7e77840c3debce0e9f..195afbce5d366e8fa433dac57858bea28ce2d758 100644 --- a/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java +++ b/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java @@ -595,7 +595,13 @@ public class ArmorStand extends LivingEntity { } private org.bukkit.event.entity.EntityDeathEvent brokenByPlayer(DamageSource damageSource) { // Paper - drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(new ItemStack(Items.ARMOR_STAND))); // CraftBukkit - add to drops + // Purpur start + final ItemStack armorStand = new ItemStack(Items.ARMOR_STAND); + if (this.level.purpurConfig.persistentDroppableEntityDisplayNames && this.hasCustomName()) { + armorStand.setHoverName(this.getCustomName()); + } + drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(armorStand)); // CraftBukkit - add to drops + // Purpur end return this.brokenByAnything(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 428523feaa4f30260e32ba03937e88200246c693..16e54d8c29d67d2db3f1186559f5ba71e47db6f3 100644 --- a/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java +++ b/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java @@ -268,7 +268,13 @@ public class ItemFrame extends HangingEntity { } if (alwaysDrop) { - this.spawnAtLocation(this.getFrameItemStack()); + // Purpur start + final ItemStack itemFrame = this.getFrameItemStack(); + if (this.level.purpurConfig.persistentDroppableEntityDisplayNames && this.hasCustomName()) { + itemFrame.setHoverName(this.getCustomName()); + } + 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 05a0a890a719a957d9aea736d6c0e85bae9e4eec..320dce948023e23df32601820146fa64e1b2fa71 100644 --- a/src/main/java/net/minecraft/world/entity/decoration/Painting.java +++ b/src/main/java/net/minecraft/world/entity/decoration/Painting.java @@ -152,7 +152,13 @@ public class Painting extends HangingEntity implements VariantHolder { } protected void destroy(DamageSource source) { - this.spawnAtLocation((ItemLike) this.getDropItem()); + // Purpur start + final ItemStack boat = new ItemStack(this.getDropItem()); + if (this.level.purpurConfig.persistentDroppableEntityDisplayNames && this.hasCustomName()) { + boat.setHoverName(this.getCustomName()); + } + this.spawnAtLocation(boat); + // Purpur end } @Override diff --git a/src/main/java/net/minecraft/world/item/ArmorStandItem.java b/src/main/java/net/minecraft/world/item/ArmorStandItem.java index 07850a88f3b8f834669394b733b9dca3968dfabc..d21a6d62d1d8b7c208e72acafc42f975012f7107 100644 --- a/src/main/java/net/minecraft/world/item/ArmorStandItem.java +++ b/src/main/java/net/minecraft/world/item/ArmorStandItem.java @@ -62,6 +62,14 @@ public class ArmorStandItem extends Item { return InteractionResult.FAIL; } // CraftBukkit end + // Purpur start + if (world.purpurConfig.persistentDroppableEntityDisplayNames && itemstack.hasCustomHoverName()) { + entityarmorstand.setCustomName(itemstack.getHoverName()); + if (world.purpurConfig.armorstandSetNameVisible) { + 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 1a95ac11a2fbc811c89afa3adf38e0fc9eaab09b..91280f8c39ea191b90da2a9ff5c49f43c255bd9a 100644 --- a/src/main/java/net/minecraft/world/item/BoatItem.java +++ b/src/main/java/net/minecraft/world/item/BoatItem.java @@ -69,6 +69,11 @@ public class BoatItem extends Item { entityboat.setVariant(this.type); entityboat.setYRot(user.getYRot()); + // Purpur start + if (world.purpurConfig.persistentDroppableEntityDisplayNames && itemstack.hasCustomHoverName()) { + entityboat.setCustomName(itemstack.getHoverName()); + } + // 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 489558eb0126e7a41e2e379e352bddc034375b61..062152b258224f28e07f96d6135bbb7a9f8a3f9a 100644 --- a/src/main/java/net/minecraft/world/item/HangingEntityItem.java +++ b/src/main/java/net/minecraft/world/item/HangingEntityItem.java @@ -41,7 +41,7 @@ public class HangingEntityItem extends Item { return InteractionResult.FAIL; } else { Level world = context.getLevel(); - Object object; + Entity object; // Purpur if (this.type == EntityType.PAINTING) { Optional optional = Painting.create(world, blockposition1, enumdirection); @@ -65,6 +65,11 @@ public class HangingEntityItem extends Item { if (nbttagcompound != null) { EntityType.updateCustomEntityTag(world, entityhuman, (Entity) object, nbttagcompound); + // Purpur start + if (world.purpurConfig.persistentDroppableEntityDisplayNames && itemstack.hasCustomHoverName()) { + object.setCustomName(itemstack.getHoverName()); + } + // 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 c0afa86b018f2af481c7e0494d1274abceb0f783..3041cf05568f2b9b432fffa1d0c298440f102eeb 100644 --- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java +++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java @@ -100,8 +100,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; @@ -114,6 +116,7 @@ public class PurpurWorldConfig { public boolean disableDropsOnCrammingDeath = false; public boolean entitiesCanUsePortals = true; public boolean milkCuresBadOmen = true; + public boolean persistentDroppableEntityDisplayNames = false; public double tridentLoyaltyVoidReturnHeight = 0.0D; public double voidDamageHeight = -64.0D; public double voidDamageDealt = 4.0D; @@ -125,6 +128,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); voidDamageHeight = getDouble("gameplay-mechanics.void-damage-height", voidDamageHeight); voidDamageDealt = getDouble("gameplay-mechanics.void-damage-dealt", voidDamageDealt);