mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
Update silk touch spawners patch to use adventure
Also disables the forced italics for spawner display names and lore
This commit is contained in:
@@ -5,25 +5,28 @@ Subject: [PATCH] Silk touch spawners
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/BlockMobSpawner.java b/src/main/java/net/minecraft/server/BlockMobSpawner.java
|
||||
index 81e145ff0759322f74888c81df8d2133fece7144..91b92d95a961ba00ddd7026bb83d021bb1ac51ed 100644
|
||||
index 81e145ff0759322f74888c81df8d2133fece7144..f9c4fe9bec9f0ca32e2de907f8705a5d627e0736 100644
|
||||
--- a/src/main/java/net/minecraft/server/BlockMobSpawner.java
|
||||
+++ b/src/main/java/net/minecraft/server/BlockMobSpawner.java
|
||||
@@ -1,5 +1,14 @@
|
||||
@@ -1,5 +1,17 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+// Purpur start
|
||||
+import net.md_5.bungee.api.ChatColor;
|
||||
+import net.md_5.bungee.api.chat.BaseComponent;
|
||||
+import net.md_5.bungee.api.chat.TextComponent;
|
||||
+import net.md_5.bungee.chat.ComponentSerializer;
|
||||
+import io.papermc.paper.adventure.PaperAdventure;
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import net.kyori.adventure.text.TextReplacementConfig;
|
||||
+import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
+
|
||||
+import java.util.List;
|
||||
+
|
||||
+import static net.kyori.adventure.text.format.TextDecoration.ITALIC;
|
||||
+// Purpur end
|
||||
+
|
||||
public class BlockMobSpawner extends BlockTileEntity {
|
||||
|
||||
protected BlockMobSpawner(BlockBase.Info blockbase_info) {
|
||||
@@ -11,6 +20,59 @@ public class BlockMobSpawner extends BlockTileEntity {
|
||||
@@ -11,6 +23,59 @@ public class BlockMobSpawner extends BlockTileEntity {
|
||||
return new TileEntityMobSpawner();
|
||||
}
|
||||
|
||||
@@ -33,17 +36,19 @@ index 81e145ff0759322f74888c81df8d2133fece7144..91b92d95a961ba00ddd7026bb83d021b
|
||||
+ if (world.purpurConfig.silkTouchEnabled && entityhuman.getBukkitEntity().hasPermission("purpur.drop.spawners") && isSilkTouch(world, itemstack)) {
|
||||
+ MinecraftKey type = ((TileEntityMobSpawner) tileentity).getSpawner().getMobName();
|
||||
+ if (type != null) {
|
||||
+ String mobName = EntityTypes.getFromKey(type).getTranslatedName();
|
||||
+ final Component mobName = PaperAdventure.asAdventure(EntityTypes.getFromKey(type).getNameComponent());
|
||||
+ final TextReplacementConfig config = TextReplacementConfig.builder()
|
||||
+ .matchLiteral("{mob}")
|
||||
+ .replacement(mobName)
|
||||
+ .build();
|
||||
+
|
||||
+ NBTTagCompound display = new NBTTagCompound();
|
||||
+ boolean customDisplay = false;
|
||||
+
|
||||
+ String name = world.purpurConfig.silkTouchSpawnerName;
|
||||
+ if (name != null && !name.isEmpty() && !name.equals("Spawner")) {
|
||||
+ name = ChatColor.translateAlternateColorCodes('&', name
|
||||
+ .replace("{mob}", mobName));
|
||||
+ BaseComponent[] comp = TextComponent.fromLegacyText(name);
|
||||
+ display.set("Name", NBTTagString.create(ComponentSerializer.toString(comp)));
|
||||
+ final Component displayName = LegacyComponentSerializer.legacyAmpersand().deserialize(name).replaceText(config).decoration(ITALIC, false);
|
||||
+ display.set("Name", NBTTagString.create(GsonComponentSerializer.gson().serialize(displayName)));
|
||||
+ customDisplay = true;
|
||||
+ }
|
||||
+
|
||||
@@ -51,10 +56,8 @@ index 81e145ff0759322f74888c81df8d2133fece7144..91b92d95a961ba00ddd7026bb83d021b
|
||||
+ if (lore != null && !lore.isEmpty()) {
|
||||
+ NBTTagList list = new NBTTagList();
|
||||
+ for (String line : lore) {
|
||||
+ line = ChatColor.translateAlternateColorCodes('&', line
|
||||
+ .replace("{mob}", mobName));
|
||||
+ BaseComponent[] comp = TextComponent.fromLegacyText(line);
|
||||
+ list.add(NBTTagString.create(ComponentSerializer.toString(comp)));
|
||||
+ final Component lineComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(line).replaceText(config).decoration(ITALIC, false);
|
||||
+ list.add(NBTTagString.create(GsonComponentSerializer.gson().serialize(lineComponent)));
|
||||
+ }
|
||||
+ display.set("Lore", list);
|
||||
+ customDisplay = true;
|
||||
@@ -83,7 +86,7 @@ index 81e145ff0759322f74888c81df8d2133fece7144..91b92d95a961ba00ddd7026bb83d021b
|
||||
@Override
|
||||
public void dropNaturally(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack) {
|
||||
super.dropNaturally(iblockdata, worldserver, blockposition, itemstack);
|
||||
@@ -23,6 +85,7 @@ public class BlockMobSpawner extends BlockTileEntity {
|
||||
@@ -23,6 +88,7 @@ public class BlockMobSpawner extends BlockTileEntity {
|
||||
|
||||
@Override
|
||||
public int getExpDrop(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack) {
|
||||
|
||||
Reference in New Issue
Block a user