Files
Purpur/patches/server/0009-Silk-touch-spawners.patch

115 lines
5.2 KiB
Diff

From 9d9becd499b2fcea1601e0c18f9f090c359a297a 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
---
.../net/minecraft/server/BlockMobSpawner.java | 31 +++++++++++++++++--
.../net/minecraft/server/ItemSpawner.java | 25 +++++++++++++++
src/main/java/net/minecraft/server/Items.java | 2 +-
3 files changed, 54 insertions(+), 4 deletions(-)
create mode 100644 src/main/java/net/minecraft/server/ItemSpawner.java
diff --git a/src/main/java/net/minecraft/server/BlockMobSpawner.java b/src/main/java/net/minecraft/server/BlockMobSpawner.java
index bb77d916a..a2812d397 100644
--- a/src/main/java/net/minecraft/server/BlockMobSpawner.java
+++ b/src/main/java/net/minecraft/server/BlockMobSpawner.java
@@ -1,5 +1,12 @@
package net.minecraft.server;
+// Purpur start
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import javax.annotation.Nullable;
+import java.util.Collections;
+// Purpur end
+
public class BlockMobSpawner extends BlockTileEntity {
protected BlockMobSpawner(Block.Info block_info) {
@@ -11,6 +18,26 @@ public class BlockMobSpawner extends BlockTileEntity {
return new TileEntityMobSpawner();
}
+ // Purpur start
+ private boolean dropped = false;
+
+ @Override
+ public void a(World world, EntityHuman entityhuman, BlockPosition blockposition, IBlockData iblockdata, @Nullable TileEntity tileentity, ItemStack itemstack) {
+ if (itemstack != null && itemstack.getItem() == Items.DIAMOND_PICKAXE && tileentity instanceof TileEntityMobSpawner && EnchantmentManager.getEnchantmentLevel(Enchantments.SILK_TOUCH, itemstack) > 0) {
+ MinecraftKey type = ((TileEntityMobSpawner) tileentity).getSpawner().getMobName();
+ if (type != null) {
+ org.bukkit.inventory.ItemStack item = new ItemStack(Blocks.SPAWNER.getItem()).asBukkitMirror();
+ ItemMeta meta = item.getItemMeta();
+ meta.setLore(Collections.singletonList(type.toString()));
+ item.setItemMeta(meta);
+ a(world, blockposition, ((CraftItemStack) item).getHandle());
+ dropped = true;
+ }
+ }
+ super.a(world, entityhuman, blockposition, iblockdata, tileentity, itemstack);
+ }
+ // Purpur end
+
@Override
public void dropNaturally(IBlockData iblockdata, World world, BlockPosition blockposition, ItemStack itemstack) {
super.dropNaturally(iblockdata, world, blockposition, itemstack);
@@ -23,9 +50,7 @@ public class BlockMobSpawner extends BlockTileEntity {
@Override
public int getExpDrop(IBlockData iblockdata, World world, BlockPosition blockposition, ItemStack itemstack) {
- int i = 15 + world.random.nextInt(15) + world.random.nextInt(15);
-
- return i;
+ return dropped ? 0 : 15 + world.random.nextInt(15) + world.random.nextInt(15); // Purpur
// CraftBukkit end
}
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 000000000..1287c071f
--- /dev/null
+++ b/src/main/java/net/minecraft/server/ItemSpawner.java
@@ -0,0 +1,25 @@
+package net.minecraft.server;
+
+import java.util.List;
+
+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);
+ TileEntity tileentity = world.getTileEntity(blockposition);
+ if (tileentity instanceof TileEntityMobSpawner) {
+ org.bukkit.inventory.ItemStack item = itemstack.asBukkitMirror();
+ if (item.hasItemMeta()) {
+ List<String> lore = item.getItemMeta().getLore();
+ if (lore != null && !lore.isEmpty()) {
+ EntityTypes.a(lore.get(0)).ifPresent(type -> ((TileEntityMobSpawner) tileentity).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 84646dbc2..987297634 100644
--- a/src/main/java/net/minecraft/server/Items.java
+++ b/src/main/java/net/minecraft/server/Items.java
@@ -155,7 +155,7 @@ public class Items {
public static final Item bU = a(Blocks.PURPUR_BLOCK, CreativeModeTab.b);
public static final Item bV = a(Blocks.PURPUR_PILLAR, CreativeModeTab.b);
public static final Item bW = a(Blocks.PURPUR_STAIRS, CreativeModeTab.b);
- public static final Item bX = a(Blocks.SPAWNER);
+ public static final Item bX = a(Blocks.SPAWNER, new ItemSpawner(Blocks.SPAWNER, new Item.Info().a(EnumItemRarity.EPIC))); // Purpur
public static final Item bY = a(Blocks.OAK_STAIRS, CreativeModeTab.b);
public static final Item bZ = a(Blocks.CHEST, CreativeModeTab.c);
public static final Item ca = a(Blocks.DIAMOND_ORE, CreativeModeTab.b);
--
2.20.1