Add configuration options for silk touch spawners

This commit is contained in:
William Blake Galbreath
2020-07-01 20:08:44 -05:00
parent 7503e60580
commit 0a94563749
37 changed files with 179 additions and 158 deletions

View File

@@ -1,4 +1,4 @@
From 6c9014787c2208705d67fad563db8b13bd7e186a Mon Sep 17 00:00:00 2001
From 6ac97172d3fcd533dec614e4f4de61e4443d9cc0 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
@@ -8,7 +8,8 @@ Subject: [PATCH] Silk touch spawners
.../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(-)
.../net/pl3x/purpur/PurpurWorldConfig.java | 21 +++++++++++
5 files changed, 81 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
@@ -24,7 +25,7 @@ index 81725611d..c7232047c 100644
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
index 16f9fb8e5..c002a65cf 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 {
@@ -34,7 +35,7 @@ index 16f9fb8e5..cf059e982 100644
+ // 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)) {
+ if (world.purpurConfig.silkTouchEnabled && entityhuman.getBukkitEntity().hasPermission("purpur.drop.spawners") && isSilkTouch(world, itemstack)) {
+ MinecraftKey type = ((TileEntityMobSpawner) tileentity).getSpawner().getMobName();
+ if (type != null) {
+ ItemStack item = new ItemStack(Blocks.SPAWNER.getItem());
@@ -60,8 +61,8 @@ index 16f9fb8e5..cf059e982 100644
+ 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;
+ 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
+
@@ -72,13 +73,13 @@ index 16f9fb8e5..cf059e982 100644
@Override
public int getExpDrop(IBlockData iblockdata, World world, BlockPosition blockposition, ItemStack itemstack) {
+ if (isSilkTouch(itemstack)) return 0; // Purpur
+ if (isSilkTouch(world, 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
index 000000000..babe8ad2c
--- /dev/null
+++ b/src/main/java/net/minecraft/server/ItemSpawner.java
@@ -0,0 +1,23 @@
@@ -92,7 +93,7 @@ index 000000000..7dc68ffe9
+ @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")) {
+ 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();
@@ -118,6 +119,45 @@ index 89a9eec99..619c40b27 100644
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 644501d5e..6ddd3442f 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,21 @@ public class PurpurWorldConfig {
playerInvulnerableWhileAcceptingResourcePack = getBoolean("gameplay-mechanics.player.invulnerable-while-accepting-resource-pack", playerInvulnerableWhileAcceptingResourcePack);
}
+ public boolean silkTouchEnabled = false;
+ public List<Item> silkTouchTools = new ArrayList<Item>(){{
+ add(Items.IRON_PICKAXE);
+ add(Items.GOLDEN_PICKAXE);
+ add(Items.DIAMOND_PICKAXE);
+ add(Items.NETHERITE_PICKAXE);
+ }};
+ private void silkTouchSettings() {
+ silkTouchEnabled = getBoolean("gameplay-mechanics.silk-touch.enabled", silkTouchEnabled);
+ getList("gameplay-mechanics.silk-touch.tools", silkTouchTools).forEach(key -> {
+ Item item = IRegistry.ITEM.get(new MinecraftKey((String) key));
+ if (item != Items.AIR) silkTouchTools.add(item);
+ });
+ }
+
public int villagerBrainTicks = 1;
public boolean villagerUseBrainTicksOnlyWhenLagging = true;
private void villagerSettings() {
--
2.26.2