Files
Purpur/patches/server/0114-Persistent-TileEntity-Lore-and-DisplayName.patch
Ben Kerllenevich e97d062cb0 Updated Upstream (Paper, Tuinity, & Airplane)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
809466f2e Fix anchor respawn acting as a bed respawn when using the end portal (#5540)
d219fd642 [Auto] Updated Upstream (Bukkit/CraftBukkit)
db464b099 Implement methods to convert between Component and Brigadier's Message (#5542)
4047cffca Add PlayerBedFailEnterEvent (#4935)
70d697e6e Update Paperpclip
5ed771591 [CI-SKIP] Remove bad null annotation (#5538)
454a4c78e More World API (#3850)
869e02304 Add PlayerDeepSleepEvent (#5525)
fb56fc35e fix non-dummy objectives not updating
dc859a61f [CI-SKIP] [Auto] Rebuild Patches
7d1689f1a  Add missing checkReachable check for shulker boxes (#5453)
ba8eb3d4b Add missing Javadoc for COLORABLE MaterialTag (#5376)
db801cbf3 Fix PlayerItemHeldEvent firing twice (#5534)
14de2b795 fix PigZombieAngerEvent cancellation (fixes #5319) (v2) (#5329)
86d684ad1 Add get-set drop chance to EntityEquipment (#5528)
33fb8cf63 Add consumeFuel to FurnaceBurnEvent (#5532)
9957f4630 Fix duplicating /give items on item drop cancel (#5536)
d94882043 Fix legacyComposer not using AsyncChatEvent messages (#5509)
053bd82cc Don't print spawn load time when not loading spawn (#5467)
a6d78caae Add isDeeplySleeping to HumanEntity (#5470)
711b7a80b Expose more Adventure serializers through PaperComponents (#5443)
3f63bde0c Set Area Effect Cloud Rotation (#5462)
3523f0fda Remove useless check on player interact cancellation (#5448)
6574d1aa8 fix #5526 - use correct type when sending message to clients
dbfa833ec don't throw when loading TE with invalid keys
a9525a6f7 Do not schedule poi task for each block write on chunk gen
39bf5b525 Update teams known as code owners
fbae9dbe0 [Auto] Updated Upstream (Bukkit/CraftBukkit)
ac4a33aab [Auto] Updated Upstream (Bukkit)
c1e07158b [Auto] Updated Upstream (Bukkit/CraftBukkit)
5e4b88e95 Fix dangling sout
23afda179 basic hostname validation
0fb8bdf0e Updated Upstream (Bukkit/CraftBukkit) (#5508)
88ab784da [Auto] Updated Upstream (CraftBukkit)
ca7111d5f Fix PlayerItemConsumeEvent cancelling (fixes #4682) (#5383)
06fb560dc Add support for tab completing and highlighting console input from the Brigadier command tree (#5437)
0a9b89c7a Fix occasional light gen issues for neighbor blocks (#5500)

Tuinity Changes:
b12d0cce3 Replace ticket level propagator
42df8e1e0 Correctly handle recursion for chunkholder updates
73eb2a856 Do not copy visible chunks
8a4f3be69 Do not schedule poi task for each block write on chunk gen
7d36676fc Fix light source locking
f1ec0c20d Add concurrency check to ProtoChunk light sources
159d1468f Improvements to chunk loader system
32b4d526b Updated Upstream (Paper)
ac5adca33 Make sure lit is set for pre 1.14 chunks

Airplane Changes:
d8bdbc508 Reduce allocations for fire spreading
41051fd56 Redo reduction of entity chunk ticking check patch
31272d80f Flare Update
8f3271328 Remove criterion patch
0fed2df62 Various patches that need to be reorganized later
f78856bde Updated Upstream (Tuinity)
f7d6382ad Flare Update
71d079991 Update gradle configuration
0f7977428 Updated Upstream (Tuinity)
3b3cde7b0 Correctly use DEAR values, fix config reloading
dd6091981 Updated Upstream (Tuinity)
07897895b Updated Upstream (Tuinity)
c1e4d7143 Fluid cache patch
2021-04-25 14:24:36 -07:00

236 lines
12 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: jmp <jasonpenilla2@me.com>
Date: Wed, 30 Sep 2020 14:32:46 -0700
Subject: [PATCH] Persistent TileEntity Lore and DisplayName
Makes it so that when a TileEntity is placed in the world and then broken,
the dropped ItemStack retains any original custom display name/lore.
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 9c01ec42342cf0420bf5215604c24fbc89c1361b..3de0f21648ca60bdfcbc078bca896d51bf84e207 100644
--- a/src/main/java/net/minecraft/world/entity/decoration/EntityPainting.java
+++ b/src/main/java/net/minecraft/world/entity/decoration/EntityPainting.java
@@ -15,6 +15,7 @@ import net.minecraft.sounds.SoundEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityTypes;
import net.minecraft.world.entity.player.EntityHuman;
+import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.IMaterial;
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 01839c7319e175477ded7001e00e5937734ff516..e5cda8c040c93639211dacbf5b0c7cd6a9df9e6d 100644
--- a/src/main/java/net/minecraft/world/entity/vehicle/EntityBoat.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/EntityBoat.java
@@ -34,6 +34,7 @@ import net.minecraft.world.entity.animal.EntityAnimal;
import net.minecraft.world.entity.animal.EntityWaterAnimal;
import net.minecraft.world.entity.player.EntityHuman;
import net.minecraft.world.item.Item;
+import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.IMaterial;
diff --git a/src/main/java/net/minecraft/world/item/ItemBlock.java b/src/main/java/net/minecraft/world/item/ItemBlock.java
index 59d52c252b2e59923b8e513dd4d2e1ec9ce34dc7..4be1c8ee85f411a8b01be50b8cc3dc3835f80a2e 100644
--- a/src/main/java/net/minecraft/world/item/ItemBlock.java
+++ b/src/main/java/net/minecraft/world/item/ItemBlock.java
@@ -119,7 +119,24 @@ public class ItemBlock extends Item {
}
protected boolean a(BlockPosition blockposition, World world, @Nullable EntityHuman entityhuman, ItemStack itemstack, IBlockData iblockdata) {
- return a(world, entityhuman, blockposition, itemstack);
+ // Purpur start
+ boolean handled = a(world, entityhuman, blockposition, itemstack);
+ if (world.purpurConfig.persistentTileEntityDisplayNames && itemstack.hasTag()) {
+ NBTTagCompound display = itemstack.getSubTag("display");
+ if (display != null) {
+ TileEntity tile = world.getTileEntity(blockposition);
+ if (tile != null) {
+ if (display.hasKeyOfType("Name", 8)) {
+ tile.setPersistentDisplayName(display.getString("Name"));
+ }
+ if (display.hasKeyOfType("Lore", 9)) {
+ tile.setPersistentLore(display.getList("Lore", 8));
+ }
+ }
+ }
+ }
+ return handled;
+ // Purpur end
}
@Nullable
diff --git a/src/main/java/net/minecraft/world/level/block/Block.java b/src/main/java/net/minecraft/world/level/block/Block.java
index 26cda907063f104fd4a3fbd2286b37fb539f741a..fab55929f72c5784291b3bc87f7717ac24b7806f 100644
--- a/src/main/java/net/minecraft/world/level/block/Block.java
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
@@ -15,10 +15,15 @@ import net.minecraft.core.EnumDirection;
import net.minecraft.core.IRegistry;
import net.minecraft.core.NonNullList;
import net.minecraft.core.RegistryBlockID;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.nbt.NBTTagList;
+import net.minecraft.nbt.NBTTagString;
+import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.server.level.WorldServer;
import net.minecraft.stats.StatisticList;
import net.minecraft.tags.Tag;
import net.minecraft.tags.TagsBlock;
+import net.minecraft.world.INamableTileEntity;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityExperienceOrb;
import net.minecraft.world.entity.EntityLiving;
@@ -248,7 +253,7 @@ public class Block extends BlockBase implements IMaterial {
public static void a(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition, @Nullable TileEntity tileentity) {
if (generatoraccess instanceof WorldServer) {
a(iblockdata, (WorldServer) generatoraccess, blockposition, tileentity).forEach((itemstack) -> {
- a((World) ((WorldServer) generatoraccess), blockposition, itemstack);
+ dropItem((WorldServer) generatoraccess, blockposition, applyDisplayNameAndLoreFromTile(itemstack, tileentity)); // Purpur
});
iblockdata.dropNaturally((WorldServer) generatoraccess, blockposition, ItemStack.b);
}
@@ -257,14 +262,56 @@ public class Block extends BlockBase implements IMaterial {
public static void dropItems(IBlockData iblockdata, World world, BlockPosition blockposition, @Nullable TileEntity tileentity, Entity entity, ItemStack itemstack) {
if (world instanceof WorldServer) {
- getDrops(iblockdata, (WorldServer) world, blockposition, tileentity, entity, itemstack).forEach((itemstack1) -> {
- a(world, blockposition, itemstack1);
+ // Purpur start
+ getDrops(iblockdata, (WorldServer) world, blockposition, tileentity, entity, itemstack).forEach(stackToDrop -> {
+ dropItem(world, blockposition, applyDisplayNameAndLoreFromTile(stackToDrop, tileentity));
+ // Purpur end
});
iblockdata.dropNaturally((WorldServer) world, blockposition, itemstack);
}
}
+ // Purpur start
+ private static ItemStack applyDisplayNameAndLoreFromTile(ItemStack itemStack, TileEntity tile) {
+ if (itemStack.getItem() instanceof ItemBlock) {
+ if (tile != null && tile.getWorld() instanceof WorldServer && tile.getWorld().purpurConfig.persistentTileEntityDisplayNames) {
+ String name = tile.getPersistentDisplayName();
+ NBTTagList lore = tile.getPersistentLore();
+ if (tile instanceof INamableTileEntity) {
+ INamableTileEntity namedTile = (INamableTileEntity) tile;
+ if (namedTile.hasCustomName()) {
+ name = IChatBaseComponent.ChatSerializer.componentToJson(namedTile.getCustomName());
+ }
+ }
+
+ if (name != null || lore != null) {
+ NBTTagCompound display = itemStack.getSubTag("display");
+ if (display == null) {
+ display = new NBTTagCompound();
+ }
+
+ if (name != null) {
+ display.set("Name", NBTTagString.create(name));
+ }
+ if (lore != null) {
+ display.set("Lore", lore);
+ }
+
+ NBTTagCompound tag = itemStack.getTag();
+ if (tag == null) {
+ tag = new NBTTagCompound();
+ }
+ tag.set("display", display);
+
+ itemStack.setTag(tag);
+ }
+ }
+ }
+ return itemStack;
+ }
+ // Purpur end
+
public static void a(World world, BlockPosition blockposition, ItemStack itemstack) { dropItem(world, blockposition, itemstack); } public static void dropItem(World world, BlockPosition blockposition, ItemStack itemstack) { // Paper - OBFHELPER
if (!world.isClientSide && !itemstack.isEmpty() && world.getGameRules().getBoolean(GameRules.DO_TILE_DROPS)) {
float f = 0.5F;
diff --git a/src/main/java/net/minecraft/world/level/block/entity/TileEntity.java b/src/main/java/net/minecraft/world/level/block/entity/TileEntity.java
index 93d02ccb87c17404c55884f52ae40c7b7ddfb103..35c4d5414db66b977a354ac50d35a6aa0fcd4cf8 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/TileEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/TileEntity.java
@@ -6,6 +6,8 @@ import net.minecraft.ResourceKeyInvalidException;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.IRegistry;
import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.nbt.NBTTagList;
+import net.minecraft.nbt.NBTTagString;
import net.minecraft.network.protocol.game.PacketPlayOutTileEntityData;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.world.level.World;
@@ -105,9 +107,25 @@ public abstract class TileEntity implements net.minecraft.server.KeyedObject { /
this.persistentDataContainer.putAll((NBTTagCompound) persistentDataTag);
}
// CraftBukkit end
+ // Purpur start
+ if (nbttagcompound.hasKey("Purpur.persistentDisplayName")) {
+ this.persistentDisplayName = nbttagcompound.getString("Purpur.persistentDisplayName");
+ }
+ if (nbttagcompound.hasKey("Purpur.persistentLore")) {
+ this.persistentLore = nbttagcompound.getList("Purpur.persistentLore", 8);
+ }
+ // Purpur end
}
public NBTTagCompound save(NBTTagCompound nbttagcompound) {
+ // Purpur start
+ if (this.persistentDisplayName != null) {
+ nbttagcompound.set("Purpur.persistentDisplayName", NBTTagString.create(this.persistentDisplayName));
+ }
+ if (this.persistentLore != null) {
+ nbttagcompound.set("Purpur.persistentLore", this.persistentLore);
+ }
+ // Purpur end
return this.b(nbttagcompound);
}
@@ -274,4 +292,25 @@ public abstract class TileEntity implements net.minecraft.server.KeyedObject { /
return null;
}
// CraftBukkit end
+
+ // Purpur start
+ private String persistentDisplayName = null;
+ private NBTTagList persistentLore = null;
+
+ public void setPersistentDisplayName(String json) {
+ this.persistentDisplayName = json;
+ }
+
+ public void setPersistentLore(NBTTagList lore) {
+ this.persistentLore = lore;
+ }
+
+ public String getPersistentDisplayName() {
+ return this.persistentDisplayName;
+ }
+
+ public NBTTagList getPersistentLore() {
+ return this.persistentLore;
+ }
+ // Purpur end
}
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 93d934b020203dbcd20d01ee650a4a204a9ac201..abe5bc17ff209edbbcb3bb366669887b8d3c75f3 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -200,6 +200,7 @@ public class PurpurWorldConfig {
public boolean entitiesPickUpLootBypassMobGriefing = false;
public boolean entitiesCanUsePortals = true;
public boolean milkCuresBadOmen = true;
+ public boolean persistentTileEntityDisplayNames = false;
public double tridentLoyaltyVoidReturnHeight = 0.0D;
public double voidDamageHeight = -64.0D;
public int raidCooldownSeconds = 0;
@@ -210,6 +211,7 @@ public class PurpurWorldConfig {
entitiesPickUpLootBypassMobGriefing = getBoolean("gameplay-mechanics.entities-pick-up-loot-bypass-mob-griefing", entitiesPickUpLootBypassMobGriefing);
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);
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);