Silk spawners now NBT based, lore only for display

This commit is contained in:
William Blake Galbreath
2019-05-19 04:50:30 -05:00
parent 0554ce8234
commit b153699691
3 changed files with 109 additions and 68 deletions

View File

@@ -1,80 +1,128 @@
From 9d9becd499b2fcea1601e0c18f9f090c359a297a Mon Sep 17 00:00:00 2001
From 3d81446a71c62cdc61ee17dfee17d1f4fb77132a 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/Block.java | 1 +
.../net/minecraft/server/BlockMobSpawner.java | 35 +++++++++++++++++++
.../net/minecraft/server/EntityTypes.java | 13 +++++++
.../net/minecraft/server/ItemSpawner.java | 20 +++++++++++
src/main/java/net/minecraft/server/Items.java | 2 +-
3 files changed, 54 insertions(+), 4 deletions(-)
5 files changed, 70 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 5b98c5255..b5c8f2cb3 100644
--- a/src/main/java/net/minecraft/server/Block.java
+++ b/src/main/java/net/minecraft/server/Block.java
@@ -494,6 +494,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 bb77d916a..a2812d397 100644
index bb77d916a..01b7e10a7 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 {
@@ -11,6 +11,40 @@ 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) {
+ public void a(World world, EntityHuman entityhuman, BlockPosition blockposition, IBlockData iblockdata, TileEntity tileentity, ItemStack itemstack) {
+ if (isSilkTouch(itemstack)) {
+ 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;
+ 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,9 +50,7 @@ public class BlockMobSpawner extends BlockTileEntity {
@@ -23,6 +57,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
+ 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 77d4bbce1..fb0c6bce0 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 000000000..1287c071f
index 000000000..17da40083
--- /dev/null
+++ b/src/main/java/net/minecraft/server/ItemSpawner.java
@@ -0,0 +1,25 @@
@@ -0,0 +1,20 @@
+package net.minecraft.server;
+
+import java.util.List;
+
+public class ItemSpawner extends ItemBlock {
+ public ItemSpawner(Block block, Info info) {
+ super(block, info);
@@ -83,14 +131,11 @@ index 000000000..1287c071f
+ @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));
+ }
+ 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;