mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
124 lines
6.0 KiB
Diff
124 lines
6.0 KiB
Diff
From 836c6dcd9b9cb396daeec8ddd59834f431bf1275 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
|
|
|
|
---
|
|
src/main/java/net/minecraft/server/Block.java | 1 +
|
|
.../net/minecraft/server/BlockMobSpawner.java | 35 +++++++++++++++++++
|
|
.../net/minecraft/server/ItemSpawner.java | 23 ++++++++++++
|
|
src/main/java/net/minecraft/server/Items.java | 2 +-
|
|
4 files changed, 60 insertions(+), 1 deletion(-)
|
|
create mode 100644 src/main/java/net/minecraft/server/ItemSpawner.java
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Block.java b/src/main/java/net/minecraft/server/Block.java
|
|
index 81725611d..c7232047c 100644
|
|
--- a/src/main/java/net/minecraft/server/Block.java
|
|
+++ b/src/main/java/net/minecraft/server/Block.java
|
|
@@ -226,6 +226,7 @@ public class Block extends BlockBase implements IMaterial {
|
|
iblockdata.dropNaturally(world, blockposition, itemstack);
|
|
}
|
|
|
|
+ public static void dropItem(World world, BlockPosition blockposition, ItemStack itemstack) { a(world, blockposition, itemstack); } // Purpur - OBFHELPER
|
|
public static void a(World world, BlockPosition blockposition, ItemStack itemstack) {
|
|
if (!world.isClientSide && !itemstack.isEmpty() && world.getGameRules().getBoolean(GameRules.DO_TILE_DROPS)) {
|
|
float f = 0.5F;
|
|
diff --git a/src/main/java/net/minecraft/server/BlockMobSpawner.java b/src/main/java/net/minecraft/server/BlockMobSpawner.java
|
|
index 16f9fb8e5..cf059e982 100644
|
|
--- a/src/main/java/net/minecraft/server/BlockMobSpawner.java
|
|
+++ b/src/main/java/net/minecraft/server/BlockMobSpawner.java
|
|
@@ -11,6 +11,40 @@ 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 (entityhuman.getBukkitEntity().hasPermission("purpur.drop.spawners") && isSilkTouch(itemstack)) {
|
|
+ MinecraftKey type = ((TileEntityMobSpawner) tileentity).getSpawner().getMobName();
|
|
+ if (type != null) {
|
|
+ ItemStack item = new ItemStack(Blocks.SPAWNER.getItem());
|
|
+
|
|
+ String mobName = EntityTypes.getFromKey(type).getTranslatedName();
|
|
+ ChatComponentText text = new ChatComponentText("Spawns a " + mobName);
|
|
+
|
|
+ NBTTagList lore = new NBTTagList();
|
|
+ lore.add(NBTTagString.a(IChatBaseComponent.ChatSerializer.a(text)));
|
|
+
|
|
+ NBTTagCompound display = new NBTTagCompound();
|
|
+ display.set("Lore", lore);
|
|
+
|
|
+ NBTTagCompound tag = new NBTTagCompound();
|
|
+ tag.set("display", display);
|
|
+ tag.setString("Purpur.mob_type", type.toString());
|
|
+
|
|
+ item.setTag(tag);
|
|
+
|
|
+ dropItem(world, blockposition, item);
|
|
+ }
|
|
+ }
|
|
+ super.a(world, entityhuman, blockposition, iblockdata, tileentity, itemstack);
|
|
+ }
|
|
+
|
|
+ private boolean isSilkTouch(ItemStack itemstack) {
|
|
+ return itemstack != null && itemstack.getItem() == Items.DIAMOND_PICKAXE && EnchantmentManager.getEnchantmentLevel(Enchantments.SILK_TOUCH, itemstack) > 0;
|
|
+ }
|
|
+ // Purpur end
|
|
+
|
|
@Override
|
|
public void dropNaturally(IBlockData iblockdata, World world, BlockPosition blockposition, ItemStack itemstack) {
|
|
super.dropNaturally(iblockdata, world, blockposition, itemstack);
|
|
@@ -23,6 +57,7 @@ public class BlockMobSpawner extends BlockTileEntity {
|
|
|
|
@Override
|
|
public int getExpDrop(IBlockData iblockdata, World world, BlockPosition blockposition, ItemStack itemstack) {
|
|
+ if (isSilkTouch(itemstack)) return 0; // Purpur
|
|
int i = 15 + world.random.nextInt(15) + world.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 000000000..7dc68ffe9
|
|
--- /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 (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.getType(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 89a9eec99..619c40b27 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);
|
|
--
|
|
2.26.2
|
|
|