mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
165 lines
7.9 KiB
Diff
165 lines
7.9 KiB
Diff
From f49cd2fcfc97aa16866e036a2b7064c37851d6f0 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 +-
|
|
.../net/pl3x/purpur/PurpurWorldConfig.java | 22 ++++++++++++
|
|
5 files changed, 82 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..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 {
|
|
return new TileEntityMobSpawner();
|
|
}
|
|
|
|
+ // Purpur start
|
|
+ @Override
|
|
+ public void a(World world, EntityHuman entityhuman, BlockPosition blockposition, IBlockData iblockdata, TileEntity tileentity, ItemStack 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());
|
|
+
|
|
+ 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(World world, ItemStack itemstack) {
|
|
+ return itemstack != null && world.purpurConfig.silkTouchTools.contains(itemstack.getItem()) && 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(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..babe8ad2c
|
|
--- /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 (world.purpurConfig.silkTouchEnabled && 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);
|
|
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
index c7fb5a737..818c4da17 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,22 @@ public class PurpurWorldConfig {
|
|
playerInvulnerableWhileAcceptingResourcePack = getBoolean("gameplay-mechanics.player.invulnerable-while-accepting-resource-pack", playerInvulnerableWhileAcceptingResourcePack);
|
|
}
|
|
|
|
+ public boolean silkTouchEnabled = false;
|
|
+ public List<Item> silkTouchTools = new ArrayList<>();
|
|
+ private void silkTouchSettings() {
|
|
+ silkTouchEnabled = getBoolean("gameplay-mechanics.silk-touch.enabled", silkTouchEnabled);
|
|
+ silkTouchTools.clear();
|
|
+ getList("gameplay-mechanics.silk-touch.tools", new ArrayList<String>(){{
|
|
+ add("minecraft:iron_pickaxe");
|
|
+ add("minecraft:golden_pickaxe");
|
|
+ add("minecraft:diamond_pickaxe");
|
|
+ add("minecraft:netherite_pickaxe");
|
|
+ }}).forEach(key -> {
|
|
+ Item item = IRegistry.ITEM.get(new MinecraftKey(key.toString()));
|
|
+ if (item != Items.AIR) silkTouchTools.add(item);
|
|
+ });
|
|
+ }
|
|
+
|
|
public int villagerBrainTicks = 1;
|
|
public boolean villagerUseBrainTicksOnlyWhenLagging = true;
|
|
private void villagerSettings() {
|
|
--
|
|
2.26.2
|
|
|