mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-18 00:47:42 +01:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: 9a129fa99 Add #getEligibleHumans to SkeletonHorseTrapEvent b5e23c7a6 Fix merging spawning values a932e8ad7 Turn off spigot verbose world by default 8ced89f65 Fix Delegation to vanilla chunk gen
183 lines
8.7 KiB
Diff
183 lines
8.7 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/net/minecraft/server/BlockMobSpawner.java b/src/main/java/net/minecraft/server/BlockMobSpawner.java
|
|
index 81e145ff07..91b92d95a9 100644
|
|
--- a/src/main/java/net/minecraft/server/BlockMobSpawner.java
|
|
+++ b/src/main/java/net/minecraft/server/BlockMobSpawner.java
|
|
@@ -1,5 +1,14 @@
|
|
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 java.util.List;
|
|
+// Purpur end
|
|
+
|
|
public class BlockMobSpawner extends BlockTileEntity {
|
|
|
|
protected BlockMobSpawner(BlockBase.Info blockbase_info) {
|
|
@@ -11,6 +20,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) {
|
|
+ String mobName = EntityTypes.getFromKey(type).getTranslatedName();
|
|
+
|
|
+ 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)));
|
|
+ customDisplay = true;
|
|
+ }
|
|
+
|
|
+ List<String> lore = world.purpurConfig.silkTouchSpawnerLore;
|
|
+ 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)));
|
|
+ }
|
|
+ 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);
|
|
@@ -23,6 +85,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/minecraft/server/ItemSpawner.java b/src/main/java/net/minecraft/server/ItemSpawner.java
|
|
new file mode 100644
|
|
index 0000000000..5c7f739185
|
|
--- /dev/null
|
|
+++ b/src/main/java/net/minecraft/server/ItemSpawner.java
|
|
@@ -0,0 +1,23 @@
|
|
+package net.minecraft.server;
|
|
+
|
|
+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/server/Items.java b/src/main/java/net/minecraft/server/Items.java
|
|
index 1c861bccc2..67ebcbe4da 100644
|
|
--- a/src/main/java/net/minecraft/server/Items.java
|
|
+++ b/src/main/java/net/minecraft/server/Items.java
|
|
@@ -180,7 +180,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/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
index c7fb5a737c..ba89efb315 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.server.IRegistry;
|
|
+import net.minecraft.server.Item;
|
|
+import net.minecraft.server.Items;
|
|
+import net.minecraft.server.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() {
|