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 76c83fdd744cc8f31a52c733de521a6fb2024499..0c4b76cd3b6248df99d31d28c7521a0fe6aea89e 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 void brokenByPlayer(DamageSource damageSource) { - 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 this.brokenByAnything(damageSource); } 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 0c5caad2a5bfc14450cf8d37f988ee176e8d1450..c01af317e14ae1a0ed58821557cb7ac6e45b00bc 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 95db5152a5aefa6a2f9fbb525d0538bba28d3489..31cfad49b65ea3469d77ad967e409422cc1a18fe 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);