Jump to content

How to code mining spawners with silk touch?


Recommended Posts

How would I go about doing this? I would assume that I have to use the block breaking event. Then, I know what I need to do, but I don't know the correct syntax for doing so. I think I need to


1. Check if the item the player is holding has the silk touch enchantment

2. Check if the block broken is a spawner

3. Spawn a dropped itemstack of the spawner at the location where the block was broken


Could someone please help me figure out how to write code for checking a tool's enchantments, checking if a block is a spawner (and what kind), and dropping the spawner as an item on the ground?



Link to comment
Share on other sites

@diesieben07 Thanks! I still don't know how to make a spawner though. I looked online and for 1.7 it's TileEntityMobSpawner, but that doesn't exist anymore. So far, I figured out how to check if the tool has silk touch or not. I don't know how to retrieve the block that is being broken, and I don't know how to determine whether it is a spawner or not. How would I check if the block is a spawner, what kind of spawner it is, and finally add the spawner to the list of drops?


Also I am unable to check whether I have silk touch or not... the ID value always returns 10 regardless of the enchantment for some reason.


	public void silkMiner(HarvestDropsEvent e) {
		if (e.getHarvester() != null) {
			EntityPlayer p = e.getHarvester();
			ItemStack item = p.inventory.getCurrentItem();
			if (item != null) {
				NBTTagList enchants = item.getEnchantmentTagList();
				boolean silk = false;
				for (int i = 0; i < enchants.tagCount(); i++) {
					if (enchants.get(i).getId() == 33) {
						silk = true;
				if (silk) {
					p.sendMessage(new TextComponentTranslation("nice"));



Edited by Turbin
Link to comment
Share on other sites

If I'm not mistaken, 


checks if the block is being dropped in its original state as the result of a silk touch material. So it returns true if for example I'm mining a grass block with a silk touch tool. But it returns false if I'm mining a spawner with a silk touch tool, because the spawner is not being naturally dropped.


I don't think e.isSilkTouching() can explicitly check if I'm holding a Silk Touch tool or not.

Link to comment
Share on other sites

Glancing at the documentation it states "isSilkTouching is set if this is considered a silk touch harvesting operation, vs a normal harvesting operation. Act accordingly."

I believe you can just setDropChance to 1f if isSilkTouching, but I may be mistaken. That would only work if the spawner is in the List<ItemStack> drops.


Link to comment
Share on other sites

20 hours ago, Turbin said:

ItemStack item = p.inventory.getCurrentItem();

Don't you need to check hands (main hand) now? What version are we working in here?


What tool/item did you want this to work with? Are you trying to override all silk, or just silktouch on a new custom item (e.g. a pick made of some new wonder-material)? If the latter, then you might have more options.


If you hit a dead-end, then you might try block substitution whereby you hook a chunk-generating event to replace all vanilla spawners in the game with spawners you've modified.


The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.