mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +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: William Blake Galbreath <blake.galbreath@gmail.com>
|
|
Date: Thu, 9 May 2019 14:27:37 -0500
|
|
Subject: [PATCH] Silk touch spawners
|
|
|
|
|
|
diff --git a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
|
index 71938ad7b3494e803beca7e4022aad12a51f2096..0b77884d8134c328f8fd1bbb8230d260606dc5ee 100644
|
|
--- a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
|
+++ b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
|
@@ -81,6 +81,7 @@ public final class PaperAdventure {
|
|
})
|
|
.build();
|
|
public static final LegacyComponentSerializer LEGACY_SECTION_UXRC = LegacyComponentSerializer.builder().flattener(FLATTENER).hexColors().useUnusualXRepeatedCharacterHexFormat().build();
|
|
+ public static final LegacyComponentSerializer LEGACY_AMPERSAND = LegacyComponentSerializer.builder().character(LegacyComponentSerializer.AMPERSAND_CHAR).hexColors().build(); // Purpur
|
|
public static final PlainComponentSerializer PLAIN = PlainComponentSerializer.builder().flattener(FLATTENER).build();
|
|
static final GsonComponentSerializer GSON = GsonComponentSerializer.builder()
|
|
.legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.INSTANCE)
|
|
diff --git a/src/main/java/net/minecraft/server/ItemSpawner.java b/src/main/java/net/minecraft/server/ItemSpawner.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..599672ed4d0fc412ad3c0fa2e9d9df7035694fa2
|
|
--- /dev/null
|
|
+++ b/src/main/java/net/minecraft/server/ItemSpawner.java
|
|
@@ -0,0 +1,35 @@
|
|
+package net.minecraft.server;
|
|
+
|
|
+import net.minecraft.core.BlockPosition;
|
|
+import net.minecraft.nbt.NBTTagCompound;
|
|
+import net.minecraft.world.entity.EntityTypes;
|
|
+import net.minecraft.world.entity.player.EntityHuman;
|
|
+import net.minecraft.world.item.ItemBlock;
|
|
+import net.minecraft.world.item.ItemStack;
|
|
+import net.minecraft.world.level.World;
|
|
+import net.minecraft.world.level.block.Block;
|
|
+import net.minecraft.world.level.block.entity.TileEntity;
|
|
+import net.minecraft.world.level.block.entity.TileEntityMobSpawner;
|
|
+import net.minecraft.world.level.block.state.IBlockData;
|
|
+
|
|
+public class ItemSpawner extends ItemBlock {
|
|
+ public ItemSpawner(Block block, Info info) {
|
|
+ super(block, info);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ protected boolean a(BlockPosition blockposition, World world, EntityHuman entityhuman, ItemStack itemstack, IBlockData iblockdata) {
|
|
+ boolean handled = super.a(blockposition, world, entityhuman, itemstack, iblockdata);
|
|
+ if (world.purpurConfig.silkTouchEnabled && entityhuman.getBukkitEntity().hasPermission("purpur.place.spawners")) {
|
|
+ TileEntity spawner = world.getTileEntity(blockposition);
|
|
+ if (spawner instanceof TileEntityMobSpawner && itemstack.hasTag()) {
|
|
+ NBTTagCompound tag = itemstack.getTag();
|
|
+ if (tag.hasKey("Purpur.mob_type")) {
|
|
+ EntityTypes.getByName(tag.getString("Purpur.mob_type")).ifPresent(type ->
|
|
+ ((TileEntityMobSpawner) spawner).getSpawner().setMobName(type));
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ return handled;
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/world/item/Items.java b/src/main/java/net/minecraft/world/item/Items.java
|
|
index fc5cc610e7ea584ce72600b9d9f47543265725bb..8e9a25495d76251a86268d3059e2960a86dc46b3 100644
|
|
--- a/src/main/java/net/minecraft/world/item/Items.java
|
|
+++ b/src/main/java/net/minecraft/world/item/Items.java
|
|
@@ -2,6 +2,7 @@ package net.minecraft.world.item;
|
|
|
|
import net.minecraft.core.IRegistry;
|
|
import net.minecraft.resources.MinecraftKey;
|
|
+import net.minecraft.server.ItemSpawner;
|
|
import net.minecraft.sounds.SoundEffects;
|
|
import net.minecraft.world.entity.EntityTypes;
|
|
import net.minecraft.world.entity.EnumItemSlot;
|
|
@@ -193,7 +194,7 @@ public class Items {
|
|
public static final Item ct = a(Blocks.PURPUR_BLOCK, CreativeModeTab.b);
|
|
public static final Item cu = a(Blocks.PURPUR_PILLAR, CreativeModeTab.b);
|
|
public static final Item cv = a(Blocks.PURPUR_STAIRS, CreativeModeTab.b);
|
|
- public static final Item cw = a(Blocks.SPAWNER);
|
|
+ public static final Item cw = a(Blocks.SPAWNER, new ItemSpawner(Blocks.SPAWNER, new Item.Info().a(EnumItemRarity.EPIC))); // Purpur
|
|
public static final Item cx = a(Blocks.OAK_STAIRS, CreativeModeTab.b);
|
|
public static final Item cy = a(Blocks.CHEST, CreativeModeTab.c);
|
|
public static final Item cz = a(Blocks.DIAMOND_ORE, CreativeModeTab.b);
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/BlockMobSpawner.java b/src/main/java/net/minecraft/world/level/block/BlockMobSpawner.java
|
|
index 287dd5f1b2b913df4029966860cd1a426947b187..af3c1a6307fb9e244226794508382d2ffa2aeb4b 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/BlockMobSpawner.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/BlockMobSpawner.java
|
|
@@ -1,14 +1,35 @@
|
|
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.core.BlockPosition;
|
|
+import net.minecraft.nbt.NBTTagCompound;
|
|
+import net.minecraft.nbt.NBTTagList;
|
|
+import net.minecraft.nbt.NBTTagString;
|
|
+import net.minecraft.resources.MinecraftKey;
|
|
import net.minecraft.server.level.WorldServer;
|
|
+import net.minecraft.world.entity.EntityTypes;
|
|
+import net.minecraft.world.entity.player.EntityHuman;
|
|
import net.minecraft.world.item.ItemStack;
|
|
+import net.minecraft.world.item.enchantment.EnchantmentManager;
|
|
+import net.minecraft.world.item.enchantment.Enchantments;
|
|
import net.minecraft.world.level.IBlockAccess;
|
|
+import net.minecraft.world.level.World;
|
|
import net.minecraft.world.level.block.entity.TileEntity;
|
|
import net.minecraft.world.level.block.entity.TileEntityMobSpawner;
|
|
import net.minecraft.world.level.block.state.BlockBase;
|
|
import net.minecraft.world.level.block.state.IBlockData;
|
|
|
|
+// Purpur start
|
|
+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) {
|
|
@@ -20,6 +41,59 @@ public class BlockMobSpawner extends BlockTileEntity {
|
|
return new TileEntityMobSpawner();
|
|
}
|
|
|
|
+ // Purpur start
|
|
+ @Override
|
|
+ public void a(World world, EntityHuman entityhuman, BlockPosition blockposition, IBlockData iblockdata, TileEntity tileentity, ItemStack itemstack) {
|
|
+ if (world.purpurConfig.silkTouchEnabled && entityhuman.getBukkitEntity().hasPermission("purpur.drop.spawners") && isSilkTouch(world, itemstack)) {
|
|
+ MinecraftKey type = ((TileEntityMobSpawner) tileentity).getSpawner().getMobName();
|
|
+ if (type != null) {
|
|
+ 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")) {
|
|
+ final Component displayName = PaperAdventure.LEGACY_AMPERSAND.deserialize(name).replaceText(config).decoration(ITALIC, false);
|
|
+ display.set("Name", NBTTagString.create(GsonComponentSerializer.gson().serialize(displayName)));
|
|
+ customDisplay = true;
|
|
+ }
|
|
+
|
|
+ List<String> lore = world.purpurConfig.silkTouchSpawnerLore;
|
|
+ if (lore != null && !lore.isEmpty()) {
|
|
+ NBTTagList list = new NBTTagList();
|
|
+ for (String line : lore) {
|
|
+ final Component lineComponent = PaperAdventure.LEGACY_AMPERSAND.deserialize(line).replaceText(config).decoration(ITALIC, false);
|
|
+ list.add(NBTTagString.create(GsonComponentSerializer.gson().serialize(lineComponent)));
|
|
+ }
|
|
+ display.set("Lore", list);
|
|
+ customDisplay = true;
|
|
+ }
|
|
+
|
|
+ NBTTagCompound tag = new NBTTagCompound();
|
|
+ if (customDisplay) {
|
|
+ tag.set("display", display);
|
|
+ }
|
|
+ tag.setString("Purpur.mob_type", type.toString());
|
|
+
|
|
+ ItemStack item = new ItemStack(Blocks.SPAWNER.getItem());
|
|
+ item.setTag(tag);
|
|
+
|
|
+ dropItem(world, blockposition, item);
|
|
+ }
|
|
+ }
|
|
+ super.a(world, entityhuman, blockposition, iblockdata, tileentity, itemstack);
|
|
+ }
|
|
+
|
|
+ private boolean isSilkTouch(World world, ItemStack itemstack) {
|
|
+ return itemstack != null && world.purpurConfig.silkTouchTools.contains(itemstack.getItem()) && EnchantmentManager.getEnchantmentLevel(Enchantments.SILK_TOUCH, itemstack) > 0;
|
|
+ }
|
|
+ // Purpur end
|
|
+
|
|
@Override
|
|
public void dropNaturally(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack) {
|
|
super.dropNaturally(iblockdata, worldserver, blockposition, itemstack);
|
|
@@ -32,6 +106,7 @@ public class BlockMobSpawner extends BlockTileEntity {
|
|
|
|
@Override
|
|
public int getExpDrop(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack) {
|
|
+ if (isSilkTouch(worldserver, itemstack)) return 0; // Purpur
|
|
int i = 15 + worldserver.random.nextInt(15) + worldserver.random.nextInt(15);
|
|
|
|
return i;
|
|
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
index c7fb5a737cab0083c39732247acb8f4e87562894..10a6fcd70869719ed2b2d1442a83ab912e00c898 100644
|
|
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
@@ -1,6 +1,12 @@
|
|
package net.pl3x.purpur;
|
|
|
|
+import net.minecraft.core.IRegistry;
|
|
+import net.minecraft.world.item.Item;
|
|
+import net.minecraft.world.item.Items;
|
|
+import net.minecraft.resources.MinecraftKey;
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
+
|
|
+import java.util.ArrayList;
|
|
import java.util.List;
|
|
import static net.pl3x.purpur.PurpurConfig.log;
|
|
|
|
@@ -75,6 +81,29 @@ public class PurpurWorldConfig {
|
|
playerInvulnerableWhileAcceptingResourcePack = getBoolean("gameplay-mechanics.player.invulnerable-while-accepting-resource-pack", playerInvulnerableWhileAcceptingResourcePack);
|
|
}
|
|
|
|
+ public boolean silkTouchEnabled = false;
|
|
+ public String silkTouchSpawnerName = "Spawner";
|
|
+ public List<String> silkTouchSpawnerLore = new ArrayList<>();
|
|
+ public List<Item> silkTouchTools = new ArrayList<>();
|
|
+ private void silkTouchSettings() {
|
|
+ silkTouchEnabled = getBoolean("gameplay-mechanics.silk-touch.enabled", silkTouchEnabled);
|
|
+ silkTouchSpawnerName = getString("gameplay-mechanics.silk-touch.spawner-name", silkTouchSpawnerName);
|
|
+ silkTouchSpawnerLore.clear();
|
|
+ getList("gameplay-mechanics.silk-touch.spawner-lore", new ArrayList<String>(){{
|
|
+ add("Spawns a {mob}");
|
|
+ }}).forEach(line -> silkTouchSpawnerLore.add(line.toString()));
|
|
+ silkTouchTools.clear();
|
|
+ getList("gameplay-mechanics.silk-touch.tools", new ArrayList<String>(){{
|
|
+ add("minecraft:iron_pickaxe");
|
|
+ add("minecraft:golden_pickaxe");
|
|
+ add("minecraft:diamond_pickaxe");
|
|
+ add("minecraft:netherite_pickaxe");
|
|
+ }}).forEach(key -> {
|
|
+ Item item = IRegistry.ITEM.get(new MinecraftKey(key.toString()));
|
|
+ if (item != Items.AIR) silkTouchTools.add(item);
|
|
+ });
|
|
+ }
|
|
+
|
|
public int villagerBrainTicks = 1;
|
|
public boolean villagerUseBrainTicksOnlyWhenLagging = true;
|
|
private void villagerSettings() {
|