Files
Purpur/patches/server/0126-Apply-display-names-from-item-forms-of-entities-to-e.patch
2021-03-24 19:26:18 -05:00

187 lines
11 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: jmp <jasonpenilla2@me.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/EntityArmorStand.java b/src/main/java/net/minecraft/world/entity/decoration/EntityArmorStand.java
index 89d3734489b65245e815376edf4e2d9baea1563a..43dc0925887e2e9e86445cccff57be7994ca0d58 100644
--- a/src/main/java/net/minecraft/world/entity/decoration/EntityArmorStand.java
+++ b/src/main/java/net/minecraft/world/entity/decoration/EntityArmorStand.java
@@ -588,7 +588,13 @@ public class EntityArmorStand extends EntityLiving {
}
private void f(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.world.purpurConfig.persistentDroppableEntityDisplayNames && this.hasCustomName()) {
+ armorStand.setName(this.getCustomName());
+ }
+ drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(armorStand)); // CraftBukkit - add to drops
+ // Purpur end
this.g(damagesource);
}
diff --git a/src/main/java/net/minecraft/world/entity/decoration/EntityItemFrame.java b/src/main/java/net/minecraft/world/entity/decoration/EntityItemFrame.java
index 43152a6c70c9433d627a58051101530ddd693307..eb07db442c5a0da73249f4a02be7dacae0ff0e45 100644
--- a/src/main/java/net/minecraft/world/entity/decoration/EntityItemFrame.java
+++ b/src/main/java/net/minecraft/world/entity/decoration/EntityItemFrame.java
@@ -229,7 +229,13 @@ public class EntityItemFrame extends EntityHanging {
}
if (flag) {
- this.a((IMaterial) Items.ITEM_FRAME);
+ // Purpur start
+ final ItemStack itemFrame = new ItemStack(Items.ITEM_FRAME);
+ if (this.world.purpurConfig.persistentDroppableEntityDisplayNames && this.hasCustomName()) {
+ itemFrame.setName(this.getCustomName());
+ }
+ this.dropItem(itemFrame);
+ // Purpur end
}
if (!itemstack.isEmpty()) {
diff --git a/src/main/java/net/minecraft/world/entity/decoration/EntityPainting.java b/src/main/java/net/minecraft/world/entity/decoration/EntityPainting.java
index 3de0f21648ca60bdfcbc078bca896d51bf84e207..7517e861301e0c329c70aa6f2bf5aa40114b6589 100644
--- a/src/main/java/net/minecraft/world/entity/decoration/EntityPainting.java
+++ b/src/main/java/net/minecraft/world/entity/decoration/EntityPainting.java
@@ -108,7 +108,13 @@ public class EntityPainting extends EntityHanging {
}
}
- this.a((IMaterial) Items.PAINTING);
+ // Purpur start
+ final ItemStack painting = new ItemStack(Items.PAINTING);
+ if (this.world.purpurConfig.persistentDroppableEntityDisplayNames && this.hasCustomName()) {
+ painting.setName(this.getCustomName());
+ }
+ this.dropItem(painting);
+ // Purpur end
}
}
diff --git a/src/main/java/net/minecraft/world/entity/vehicle/EntityBoat.java b/src/main/java/net/minecraft/world/entity/vehicle/EntityBoat.java
index e5cda8c040c93639211dacbf5b0c7cd6a9df9e6d..9cd1a2a2a8db1d8daf7c712d6bd03fad1b048485 100644
--- a/src/main/java/net/minecraft/world/entity/vehicle/EntityBoat.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/EntityBoat.java
@@ -201,7 +201,13 @@ public class EntityBoat extends Entity {
}
// CraftBukkit end
if (!flag && this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) {
- this.a((IMaterial) this.g());
+ // Purpur start
+ final ItemStack boat = new ItemStack(this.getBoatItem());
+ if (this.world.purpurConfig.persistentDroppableEntityDisplayNames && this.hasCustomName()) {
+ boat.setName(this.getCustomName());
+ }
+ this.dropItem(boat);
+ // Purpur end
}
this.die();
diff --git a/src/main/java/net/minecraft/world/item/ItemArmorStand.java b/src/main/java/net/minecraft/world/item/ItemArmorStand.java
index cd46df5485ebfd597ea72360a27872d46174ee19..245d3fe09feb9dc27b097642d40664a9f2377581 100644
--- a/src/main/java/net/minecraft/world/item/ItemArmorStand.java
+++ b/src/main/java/net/minecraft/world/item/ItemArmorStand.java
@@ -63,6 +63,14 @@ public class ItemArmorStand extends Item {
return EnumInteractionResult.FAIL;
}
// CraftBukkit end
+ // Purpur start
+ if (itemactioncontext.getWorld().purpurConfig.persistentDroppableEntityDisplayNames && itemactioncontext.getItemStack().hasName()) {
+ entityarmorstand.setCustomName(itemactioncontext.getItemStack().getName());
+ if (itemactioncontext.getWorld().purpurConfig.armorstandSetNameVisible) {
+ entityarmorstand.setCustomNameVisible(true);
+ }
+ }
+ // Purpur end
worldserver.addAllEntities(entityarmorstand); // Paper - moved down
world.playSound((EntityHuman) null, entityarmorstand.locX(), entityarmorstand.locY(), entityarmorstand.locZ(), SoundEffects.ENTITY_ARMOR_STAND_PLACE, SoundCategory.BLOCKS, 0.75F, 0.8F);
}
diff --git a/src/main/java/net/minecraft/world/item/ItemBoat.java b/src/main/java/net/minecraft/world/item/ItemBoat.java
index 1d812b3e27f87213afc3e441eb20ca984458ce2a..636a8bc76d436fc770b4e05a93f1991210b64230 100644
--- a/src/main/java/net/minecraft/world/item/ItemBoat.java
+++ b/src/main/java/net/minecraft/world/item/ItemBoat.java
@@ -65,6 +65,11 @@ public class ItemBoat extends Item {
entityboat.setType(this.b);
entityboat.yaw = entityhuman.yaw;
+ // Purpur start
+ if (world.purpurConfig.persistentDroppableEntityDisplayNames && itemstack.hasName()) {
+ entityboat.setCustomName(itemstack.getName());
+ }
+ // Purpur end
if (!world.getCubes(entityboat, entityboat.getBoundingBox().g(-0.1D))) {
return InteractionResultWrapper.fail(itemstack);
} else {
diff --git a/src/main/java/net/minecraft/world/item/ItemHanging.java b/src/main/java/net/minecraft/world/item/ItemHanging.java
index bbd3bb2d12e500d15485598783d39b0cb63a6d83..8e4c3304779cfccf7d45d4843f9c15bffce8ba07 100644
--- a/src/main/java/net/minecraft/world/item/ItemHanging.java
+++ b/src/main/java/net/minecraft/world/item/ItemHanging.java
@@ -39,7 +39,7 @@ public class ItemHanging extends Item {
return EnumInteractionResult.FAIL;
} else {
World world = itemactioncontext.getWorld();
- Object object;
+ Entity object; // Purpur
if (this.a == EntityTypes.PAINTING) {
object = new EntityPainting(world, blockposition1, enumdirection);
@@ -55,6 +55,11 @@ public class ItemHanging extends Item {
if (nbttagcompound != null) {
EntityTypes.a(world, entityhuman, (Entity) object, nbttagcompound);
+ // Purpur start
+ if (itemactioncontext.getWorld().purpurConfig.persistentDroppableEntityDisplayNames && itemactioncontext.getItemStack().hasName()) {
+ object.setCustomName(itemactioncontext.getItemStack().getName());
+ }
+ // Purpur end
}
if (((EntityHanging) object).survives()) {
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 81e2ccfa4f6cf6a4ad9236cf0ce94df8dc3ec5b6..132972755ac74838f3386e0fac5033380b71fce5 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -788,6 +788,7 @@ public final class ItemStack {
return this.getItem().h(this);
}
+ public ItemStack setName(@Nullable IChatBaseComponent component) { return this.a(component); } // Purpur - OBFHELPER
public ItemStack a(@Nullable IChatBaseComponent ichatbasecomponent) {
NBTTagCompound nbttagcompound = this.a("display");
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 71e6f39d8a75061e8bb37db20f03ec616ca1d165..d054678a1fc7825a4b43e5841ca9715a86d0d091 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -83,8 +83,10 @@ public class PurpurWorldConfig {
return PurpurConfig.config.getString("world-settings." + worldName + "." + path, PurpurConfig.config.getString("world-settings.default." + path));
}
+ public boolean armorstandSetNameVisible = false;
public float armorstandStepHeight = 0.0F;
private void armorstandSettings() {
+ armorstandSetNameVisible = getBoolean("gameplay-mechanics.armorstand.set-name-visible-when-placing-with-custom-name", armorstandSetNameVisible);
armorstandStepHeight = (float) getDouble("gameplay-mechanics.armorstand.step-height", armorstandStepHeight);
}
@@ -217,6 +219,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 int raidCooldownSeconds = 0;
@@ -229,6 +232,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);
raidCooldownSeconds = getInt("gameplay-mechanics.raid-cooldown-seconds", raidCooldownSeconds);