SilkTouch - Allow the Silk Touch enchantment to work with any block!

This plugin is currently not supported, sorry!

SilkTouch is a very simple to use plugin. It allows a tool with the Silk Touch enchantment to break more items! (sorry for the terrible graphic - I made it in about 40 seconds)

Download
You can download SilkTouch from the Releases section on the GitHub page.

wercker status

Issues, Ideas, and Help
If you have any issues, ideas, or need help please open an issue on the GitHub page.

Configuration
The configuration file is found in config/net.redstoneore.silktouch/config.json. This is a JSON file, so be sure to run it through a JSON validator before putting it on your server.

// Should permission be required?
"requirePermission": false, 

// Which blocks should SilkTouch be enabled for? (add more items at will)
"enableSilkTouchFor": [
  "minecraft:mob_spawner",
  "minecraft:cake"
]

Permissions

  • silktouch.item replacing item with the item name - e.g. silktouch.minecraft:mob_spawner

Your server can only use permissions if you have requirePermission set to true in the configuration file. If you do this only items listed in enableSilkTouchFor can be used if the player has the correct permission.

Commands
There are no commands (yet).

3 Likes

A couple code suggestions:

  • You can @Inject a PluginContainer, no need for the manager stuff.
  • If you need a Player from the event cause, and will exit without it, just add it to the method arguments, like so;
public void onBreakBlock(ChangeBlockEvent.Break event, @First Player player) {
  • Here’s an implementation for findDropFor that will work in most cases:
return Sponge.getRegistry().getType(CatalogTypes.ITEM_TYPE, type.getId());
  • Not sure why you made a Lists class, Google’s Lists class is better; just use Lists.newArrayList. Or you could do Arrays.asList.

Also, just out of curiosity, may I inquire as to why you’re not using Configurate? Sponge gives you a default HoconConfigurationLoader, and JSON is valid HOCON syntax. If you’re dead-set on using JSON only, there’s also a JSONConfigurationLoader and GsonConfigurationLoader.

Thanks for that. This is more so a plugin for me to learn the Sponge API, sorry if it seems a bit dodgy. Didn’t even realise you could do those things - thats so awesome. Cheers :beers:

I don’t really know anything about Hocon but my Rson class is just a wrapper around Gson. I don’t really know anything about Hocon either, but my Rson class is to let me use the one standard across Basic, Bukkit, and Sponge projects. :slight_smile: If I find a simple way to work it on both Bukkit and Sponge I’ll give it a go.

1 Like

Does this include the NBT data of the tile entity? Can I use this to silk touch a chest in order to create a backpack?

Will this remember the details of the mob spawner?

@MarkehMe

In your event listener, replace your usage of @First with @Root. @First means the first Player in the cause which can be the Player who did it or the player associated with what is happening!. Root will net you the direct cause and is the replacement for Bukkit’s PlayerPlaceBlockEvent.

2 Likes

HOCON is basically looser JSON. For example, here’s some JSON:

{
    "text": "Hello world!", 
    "color" : "green", 
    "clickEvent" : {
        "action" : "run_command", 
        "value" : "Hello World!" 
    } 
} 

And here’s the same in HOCON:

text="Hello World!"
color=green
clickEvent {
  action=run_command
  value="Hello World!"
} 

Basically it’s JSON, but everything’s optional. Hell, JSON itself is valid HOCON.
Meanwhile, Configurate does not depend on Sponge, it’s @zml’s side project. You can therefore use it anywhere you wish. It supports JSON (using either Gson or Jackson), HOCON, and YAML. In fact, you can @Inject @DefaultConfig a ConfigurationLoader, which will point to your plugin’s default configuration file. It also supports easy serialization, such as:

node.getNode("name").getValue(TypeToken.of(Text.class))

@pie_flavor seems like I can easily migrate to it then. I’ll look into it a bit more. Thanks!

Thank you @Zidane! Was not aware, just pushed the changes then.

@ryantheleach not currently, I can add an option to do this though!

Once again I forgot about stupid fking Markdown. I meant to say ConfigurationLoader<CommentedConfigurationNode>, but Discourse interpreted it as an HTML tag.

1 Like

Will this work with Pixelmon items such as Healers?

@Quakethorn honestly, not sure. It uses the type name and grabs the type name by going over BlockTypeRegistryModule

I have little experience with Sponge Forge mods, but I know the minecraft names use a minecraft:mob_spawner, so maybe Pixelmon uses pixelmon:healer or something?

Perhaps someone with more experience can help me out here, this is how I’m doing it currently (I already know there is probably a better way to do this, I was rushing here :laughing: ):
https://github.com/MarkehMe/Rson/blob/master/src/net/redstoneore/rson/adapter/type/sponge/TypeAdapterBlockType.java

I think it should work. Don’t know if you should ignore the case however.

HOWEVER, in you listener you split the name at the : character and use only the later part for permissions. This means that permissions will break for modded items.

The problem here is that you don’t use the domain/modid for the name. So for example if you have two mods that both add a wrench item, and they both use "<modid>:wrench", it will collide and grant permission for both wrenches, even though you might not want that. A simple fix for that is to just use the full name.

1 Like

Good point, wasn’t too sure. I’ll remove that second check - thanks :smile:

Remember, if you switch to Configurate, you can serialize/deserialize things like CatalogTypes or DataHolders directly, using systems that Sponge has already put in place.

Just letting you know I still plan to do add on the backpack feature and storing mob spawner data. I’m just waiting on the API (haven’t checked out inventory API recently, but I’m still waiting on the mob spawner portion).

Unless there is a way to easily extract and apply NBT data I haven’t found!

When I try to run your plugin here it says that there is an error due to it being invalidly named. I’m rather new to plugins and am self teaching how they work by experience mostly. Is there a way that I can fix this so that it will load the plugin?

I haven’t tried this on the latest API yet, but I’m guessing there was breaking changes :’( I’ll have to go through and see what happened.

Hey was Just wondering if this will work in the 1.12 version of minecraft or not?

When I started my server the config file didnt load in.

API 7 pls :disappointed_relieved: 1.12.2 :’(

1 Like

Update to API 7 please 1.12.2