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: bca97a8f7 replace spaces in world key (touches #5397) de94f6485 Refactor chat message composition (#5396) e27f334bb [CI-SKIP] Fix makemcdevsrc.sh for nms relocations (#5389) ae15e85da Updated Upstream (CraftBukkit) 26fe0ac5a Only set despawnTimer for Wandering Traders spawned by MobSpawnerTrader (#5391) b748eb7b8 Fix VanillaMobGoalTest#testBukkitMap (#5390) 18dbbb578 [Auto] Updated Upstream (CraftBukkit) fac9cc5d5 [CI-SKIP] Ignore .gitignore 087aa70e7 Deprecate ItemStack#setLore(List<String>) and ItemStack#getLore, add Component based alternatives 9889c651c apply fixup c310f0a61 Updated Upstream (Bukkit/CraftBukkit) f17560ab0 wtf is this t file -jmp 347f3a9b8 fix compile 700e9e6a5 rebase cf4dc464a Revert de5f4e469...c270abe96 6870db613 script & POM fix 743c6533c Replace ** with * (BSD/macOS) 376d7b097 Don't remove the .java fcb3fd42a Fix macOS/BSD support 8cfc05249 Link correctly ba1031ca7 Rename work dir c8d844ab7 Actually fix preloading this time e62aa5e3e Fix class preloading 1c03cf898 It's mojang math, not minecraft math 1034873df Apply fixups 39b125771 Use revision file 956150da7 Welcome to 1.16.5-R0.2 ccb217c01 Change cache keys 0d217001c more work f6d820f07 It compiles 0f78e9525 More work 1718f61bf Updated Upstream (CraftBukkit/Spigot) b28d46114 Update scripts for NMS repackaging Tuinity Changes: 9bdcb9b8e Delete work dir when running jar 6351d7ca7 Update Upstream (Paper) 932c199a6 Generate md-dev correctly bf3e73778 Make packet limiter work from IDE 1686f3861 Fix packet limiter config f40f7b425 Update README.md styling (#264) da1c3ace5 GH Actions Changes (#213) 5f325ecf1 Update Upstream (Paper) 0f83fe48d Update Upstream (Paper) Airplane Changes: f94d39947 Merge pull request #18 from notOM3GA/upstream/nms-repackage 0fc622631 Force build for Flare update 08439d6a9 Update Upstream (Tuinity)
236 lines
12 KiB
Diff
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 97eb81338207c93125bea082256384946a8305bb..eecb17e887bf0d1680a5fb5198a8b4246c14e548 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 f1e586754396439dfb70a4d63e3b8b34fb36ebf4..8a049d3de8937a6c8afe178ccd134e2511fb3baf 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
|
|
@@ -5,6 +5,8 @@ import net.minecraft.CrashReportSystemDetails;
|
|
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;
|
|
@@ -104,9 +106,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);
|
|
}
|
|
|
|
@@ -267,4 +285,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 22aa4709d1db75eb901a6145b75689bd766bf10b..4843d4a0794e05386d6cdf05a7059598291aafe7 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);
|