mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
162 lines
7.4 KiB
Diff
162 lines
7.4 KiB
Diff
From c7c4b4cb423efb7af5bf71d0c2111a7b8adadf18 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/EntityTypes.java | 13 +++++++
|
|
.../net/minecraft/server/ItemSpawner.java | 22 ++++++++++++
|
|
src/main/java/net/minecraft/server/Items.java | 2 +-
|
|
5 files changed, 72 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 8f809a4ee4..44348130a2 100644
|
|
--- a/src/main/java/net/minecraft/server/Block.java
|
|
+++ b/src/main/java/net/minecraft/server/Block.java
|
|
@@ -493,6 +493,7 @@ public class Block 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("doTileDrops")) {
|
|
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 bb77d916ab..974a5d2816 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(new NBTTagString(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/EntityTypes.java b/src/main/java/net/minecraft/server/EntityTypes.java
|
|
index 77d4bbce19..fb0c6bce03 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityTypes.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityTypes.java
|
|
@@ -137,6 +137,12 @@ public class EntityTypes<T extends Entity> {
|
|
return (EntityTypes) IRegistry.a((IRegistry) IRegistry.ENTITY_TYPE, s, (Object) entitytypes_a.a(s));
|
|
}
|
|
|
|
+ // Purpur start
|
|
+ public static EntityTypes getFromKey(MinecraftKey key) {
|
|
+ return IRegistry.ENTITY_TYPE.get(key);
|
|
+ }
|
|
+ // Purpur end
|
|
+
|
|
public static MinecraftKey getName(EntityTypes<?> entitytypes) {
|
|
return IRegistry.ENTITY_TYPE.getKey(entitytypes);
|
|
}
|
|
@@ -255,6 +261,12 @@ public class EntityTypes<T extends Entity> {
|
|
return this.ba;
|
|
}
|
|
|
|
+ // Purpur start
|
|
+ public String getTranslatedName() {
|
|
+ return getNameComponent().getString();
|
|
+ }
|
|
+ // Purpur end
|
|
+
|
|
public String e() {
|
|
if (this.be == null) {
|
|
this.be = SystemUtils.a("entity", IRegistry.ENTITY_TYPE.getKey(this));
|
|
@@ -263,6 +275,7 @@ public class EntityTypes<T extends Entity> {
|
|
return this.be;
|
|
}
|
|
|
|
+ public IChatBaseComponent getNameComponent() { return f(); } // Purpur - OBFHELPER
|
|
public IChatBaseComponent f() {
|
|
if (this.bf == null) {
|
|
this.bf = new ChatMessage(this.e(), new Object[0]);
|
|
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..05dbc162fa
|
|
--- /dev/null
|
|
+++ b/src/main/java/net/minecraft/server/ItemSpawner.java
|
|
@@ -0,0 +1,22 @@
|
|
+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 te = world.getTileEntity(blockposition);
|
|
+ if (te instanceof TileEntityMobSpawner && itemstack.hasTag()) {
|
|
+ NBTTagCompound tag = itemstack.getTag();
|
|
+ if (tag.hasKey("Purpur.mob_type")) {
|
|
+ EntityTypes.a(tag.getString("Purpur.mob_type")).ifPresent(type -> ((TileEntityMobSpawner) te).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 84646dbc26..987297634c 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
|
|
|