Files
Purpur/patches/server/0122-Apply-display-names-from-item-forms-of-entities-to-e.patch
William Blake Galbreath d783ad703b Airplane patches
2021-08-18 14:55:29 -05:00

175 lines
10 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 7a3a364f5e3b025cc0a5694401cb9298c80cb733..796ab61f4513c02b0d55d34044d2f7084c447796 100644
--- a/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java
+++ b/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java
@@ -597,7 +597,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 b829efdb40051a41b3bf1cabb8bf7d7c952797b5..90f1ecd97eef93316f61bf5d761d33c313e1a077 100644
--- a/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java
+++ b/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java
@@ -257,7 +257,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 a853e2cc2e3f06a0ca0bb1799b3fd02890ae6521..a8265cd631d335d4eaec1918bd48570ee1fc9429 100644
--- a/src/main/java/net/minecraft/world/entity/decoration/Painting.java
+++ b/src/main/java/net/minecraft/world/entity/decoration/Painting.java
@@ -114,7 +114,13 @@ public class Painting extends HangingEntity {
}
}
- this.spawnAtLocation((ItemLike) Items.PAINTING);
+ // Purpur start
+ final ItemStack painting = new ItemStack(Items.PAINTING);
+ if (this.level.purpurConfig.persistentDroppableEntityDisplayNames && this.hasCustomName()) {
+ painting.setHoverName(this.getCustomName());
+ }
+ 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 4688cfb6f24066d3034efcd6b4816ceb37561f1f..0f6e577e47a3b1ce5a356801b6192d1d306d19c2 100644
--- a/src/main/java/net/minecraft/world/entity/vehicle/Boat.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/Boat.java
@@ -209,7 +209,13 @@ public class Boat extends Entity {
}
// CraftBukkit end
if (!flag && this.level.getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
- 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
}
this.discard();
diff --git a/src/main/java/net/minecraft/world/item/ArmorStandItem.java b/src/main/java/net/minecraft/world/item/ArmorStandItem.java
index 44d63145480d38a4ec3a38be108200af070bcffa..7de67b75010f0da52004c911f6ee98eb133fdaed 100644
--- a/src/main/java/net/minecraft/world/item/ArmorStandItem.java
+++ b/src/main/java/net/minecraft/world/item/ArmorStandItem.java
@@ -63,6 +63,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);
world.gameEvent((Entity) context.getPlayer(), GameEvent.ENTITY_PLACE, (Entity) entityarmorstand);
diff --git a/src/main/java/net/minecraft/world/item/BoatItem.java b/src/main/java/net/minecraft/world/item/BoatItem.java
index 9a11248b13d231c1797e14f843cb8cbec0d35a6e..eb8f15432200856dc49129a4a3fe1ee1ae516d02 100644
--- a/src/main/java/net/minecraft/world/item/BoatItem.java
+++ b/src/main/java/net/minecraft/world/item/BoatItem.java
@@ -67,6 +67,11 @@ public class BoatItem extends Item {
entityboat.setType(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().inflate(-net.minecraft.Util.COLLISION_EPSILON))) { // Paper
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 e5b042f2445eb06fb8075ba539c836595814fa14..8cdede6a9698d6c99b4f08edc2a3403fec854f66 100644
--- a/src/main/java/net/minecraft/world/item/HangingEntityItem.java
+++ b/src/main/java/net/minecraft/world/item/HangingEntityItem.java
@@ -40,7 +40,7 @@ public class HangingEntityItem extends Item {
return InteractionResult.FAIL;
} else {
Level world = context.getLevel();
- Object object;
+ Entity object; // Purpur
if (this.type == EntityType.PAINTING) {
object = new Painting(world, blockposition1, enumdirection);
@@ -58,6 +58,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/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 21b93da96d17ef6c87c18d5d9bb3b99d36beea5c..525c05f3d64c76b2a0d470ba38125b49232a8dbd 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/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 int daytimeTicks = 12000;
@@ -345,6 +347,7 @@ public class PurpurWorldConfig {
public boolean entitiesCanUsePortals = true;
public boolean milkCuresBadOmen = true;
public boolean persistentTileEntityDisplayNames = false;
+ public boolean persistentDroppableEntityDisplayNames = false;
public double tridentLoyaltyVoidReturnHeight = 0.0D;
public double voidDamageHeight = -64.0D;
public double voidDamageDealt = 4.0D;
@@ -357,6 +360,7 @@ public class PurpurWorldConfig {
entitiesCanUsePortals = getBoolean("gameplay-mechanics.entities-can-use-portals", entitiesCanUsePortals);
milkCuresBadOmen = getBoolean("gameplay-mechanics.milk-cures-bad-omen", milkCuresBadOmen);
persistentTileEntityDisplayNames = getBoolean("gameplay-mechanics.persistent-tileentity-display-names-and-lore", persistentTileEntityDisplayNames);
+ 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);