Topic category: User side tutorials
I was trying to make my own mod, but have no time to develop it solo sadly.
So I'm here to share some feature, which probably will help somebody.
Procedure that behaves like hammer (3x3, 5x5, etc)
NeoForge 1.20.4, 2024.2, but should work in future versions too.
IF ANY LINKS OR IMAGES ARE BROKEN IN THIS GUIDE, CONTACT ME IN DISCORD - @doomsdayfire
Features:
- Universal to use with any blocks - you don't need to check for each block material manually
- Breaks only mineable by pickaxe blocks
- Supports enchantments (Silk touch, Fortune, Your custom ones like Auto-Smelting)
- Any direction
- Customizable for other sizes
- Clear & easy procedure (as far as I think...)
Step 1. Creating tool - pickaxe
There you choose your preferred properties: tier, efficiency, durability.
You have to create a trigger: When block destroyed with tool
Step 2. Procedure import
Open it and import Pickaxe_guide.ptpl file (Procedure file):
There are bunch of Local variables created automatically, they will be explained later
Step 3. Work explanation
Breaking the block makes procedure to check 5x5x5 area, where middle block is originally breaking one. Depending on the direction of breaking, the extra direction is blocked, making the area for checking 5x5 (25 blocks) instead of 5x5x5 (125 blocks lol). This is done to make the procedure compact.
Scheme: Green block is originally breaking one
Step 4. Procedure overview
There we have 5x5x5 matrix. Using 3 repeating blocks (green ones) we incrementing x, y, z parameters step by step and breaking block.
If any lock_x / lock_y / lock_y variable set to 0, repeating block looks like this: Repeat ((0 * 4) + 1) times -> Incrementing coordinate & break block
So in that case there is no actual repeat, using part of procedure just ones.
But it every direction case we locking just 1 lock, every time checking for 5x5 area we need.
First of all, we read procedure from inside to outside.
Lets assume we looking North or West, so we need to lock extra direction from incrementing - procedure sets lock_z = 0. Others are = 1.
Now we read procedure:
1) Repeat ((1*4) + 1) times (So 5 times): Break block with coordinates (local_x, local_y, local_z), then increment local_x by 1 to move to next block of layer
2) Repeat ((1*4) + 1) times (So 5 times): Break block witch coordinates (local_x, local_y, local_z), then increment local_x by 1 and decrement local_x by 5 to move to next layer
3) Repeat ((0*4) + 1) times (So 1 time only): Break block... But there is nothing left to break in that case - we cleared 5x5 area we wanted. But still increment local_z by 1 and decrement local_y by 5. It's needed since procedure is universal for any directions.
- We made 5x5=25 block breaks because of these repeating blocks.
Block breaking, part 1.
- Setting up local variable registry_name to actual registry_name of block with local coordinates. For example: minecraft:diamond_ore
-
Setting up second local variable reg_name_formatted using custom code snippet which removes everything before " : " symbol (including one)
Format example: minecraft:diamond_ore -> diamond_ore (saved in variable)
Huge thanks to @Bar1BoD for this code snippet. I'm not that good to make code by myself yet xD - Store each loot table item from [ blocks/variable_value ] granted for Player, making possible to consider enchantments of holding pickaxe as Itemstack iterator
- Itemstack iterator will be used to spawn loot for each block individually. For example, we have 5x5 area, where part of blocks is diamond ore, another part is iron ore.
-
By modifying vanilla loot tables, we can work with custom enchantments (check This site to make loot tables with vanilla presets)
- Example: Auto-smelting enchantment -> Create enchantment mod element -> Copy silk_touch part of vanilla loot table -> Input your enchantment name and loot
[Loot table example for iron ore with auto-smelting]
Block breaking, part 2.
- Check 1: Loot for block is not empty (to prevent bedrock from trying to drop for example)
Check 2: Can pickaxe break block with local coordinates (to check tool tier, if we set pickaxe to wood level) - Exclude original block from counting to reduce durability. So we lose -24 durability and -1 extra because of breaking event itself
- If pickaxe able to break only 10 blocks because of durability or block material, it will lose only 10 - Spawn loot table of each block at original block / each broken block coordinates (see variants below)
-
Remove block at local cooridnates (without original drop, because we use loot table) and spawn particles
[Full procedure overview]
Ingame examples
-
Applying Unbreaking enchantments work aswell
If you have any questions or suggestions, feel free to ask in comments or discord (@doomsdayfire).
Also you can use exact same procedure for Axe, Hoe, Shovel without changing anything.
And reassemble variable to make it work for 7x7, 3x3, and others. If you have troubles, ask me
Remember that discord no longer allows remote content!!! Use imgur or another image host.
Very nice explanation and graphics, awesome work! :)
Thank you @friyes for the reminder, fixed all the links ^^
Completely forgot about imgur somehow..
Thank you @Klemen! I will try to make some useful guides in the future
@doomsday_fire Hi, I'm just starting to develop my own mods, and deal with this topic. Can you please tell me exactly what needs to be changed in order to create a 3x3 or 7x7, I tried to change it on my own, but I was digging in a completely random direction
Hello @C1azare. Here you go ^^
- Pickaxe_3x3.ptpl
- Pickaxe_5x5.ptpl
Let me know if it works fine
@C1azare
Second link is meant for 7x7, sorry*
If you need better variable explanation, we may talk in dm somewhere.
I also speak russian if it's gonna help .-.
@doomsday_fire Yes, everything is working fine, thank you very much. You are my hero!
@doomsday_fire Please write your telegram, I will be glad to learn something new, or write to me in telegram @skyfay1
I am very new to procedures, when I try to save it says "External trigger you selected does not provide all the dependencies your procedure requires!"
to add context I am using event when "block is broken"