mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-18 08:57:44 +01:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: 5b20df6bf added PlayerNameEntityEvent ff9c82444 Add worldborder events 616b1f3cd consider enchants for destroy speed aaef1d5cc fix file conversion 674d8f7f7 Make discovered maps config work in treasure maps from loot tables too be1687914 stop firing pressure plate EntityInteractEvent for ignored entities (fixes #4962) 7d56f38ed Do not use the bukkit singleton for the GUI (Fixes #5301) 4c9bdf53a Updated Upstream (Bukkit/CraftBukkit/Spigot) (#5299) 8647bd130 Improve ServerGUI fcc6d3359 Throw proper exception on empty JsonList file 17d2e1291 Fix interact event in adventure mode 964e0bf42 MC-29274: Fix Wither hostility towards players 9e24a5213 Fixed furnace cook-speed multiplier losing precision when calculating cook time c7e42faa3 Do not create unnecessary copies of the passenger list 40881ad67 added tnt minecarts to the tnt height nerf 26be708f4 Remove streams from SensorNearest 5b5989b21 fix nullability of playerlist header/footer, closes #5290 45bc531dd Fix Material#getTranslationKey for Block Materials (#5294)
187 lines
9.4 KiB
Diff
187 lines
9.4 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/server/Block.java b/src/main/java/net/minecraft/server/Block.java
|
|
index d3026d8911c73e23315a545b9eb0753306c0e825..2c8d7024879392f37e53dfb72cc07971c7b4f27c 100644
|
|
--- a/src/main/java/net/minecraft/server/Block.java
|
|
+++ b/src/main/java/net/minecraft/server/Block.java
|
|
@@ -207,7 +207,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);
|
|
}
|
|
@@ -216,14 +216,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/server/ItemBlock.java b/src/main/java/net/minecraft/server/ItemBlock.java
|
|
index 9d62bc6d600526881dccb44d158e30f565078cec..b8c71925a6e4c58fcefba0ab38270aaa236aabba 100644
|
|
--- a/src/main/java/net/minecraft/server/ItemBlock.java
|
|
+++ b/src/main/java/net/minecraft/server/ItemBlock.java
|
|
@@ -96,7 +96,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/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
|
|
index 58d958a88ac5af5b889d719d9f1ea90ce45cf184..8e8749095427b44e04582593114cae8cf6d00f42 100644
|
|
--- a/src/main/java/net/minecraft/server/TileEntity.java
|
|
+++ b/src/main/java/net/minecraft/server/TileEntity.java
|
|
@@ -90,9 +90,25 @@ public abstract class TileEntity implements KeyedObject { // Paper
|
|
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);
|
|
}
|
|
|
|
@@ -253,4 +269,25 @@ public abstract class TileEntity implements KeyedObject { // Paper
|
|
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 6d0d43e77bbf6f792257eb368e572b1bfade3266..4515c95a195ab962513ddc6868f9cdfd47f61d68 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);
|