[TUTOTIAL] 5x5 pickaxe with enchantment support | No custom code | Using loot table | 2024.2 | NeoForge 1.20.4

Started by doomsday_fire on

Topic category: User side tutorials

Last seen on 19:02, 26. Sep 2024
Joined Feb 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[TUTOTIAL] 5x5 pickaxe with enchantment support | No custom code | Using loot table | 2024.2 | NeoForge 1.20.4

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
Area checking

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 to 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.

  1. Check 1: Loot for block is not empty (to prevent bedrock from dropping for example)
    Check 2: Can pickaxe break block with local coordinates (to check tool tier, if we set pickaxe to wood level)
  2. 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
  3. Spawn loot table of each block at original block / each broken block coordinates (see variants below)
  4. Remove block at local cooridnates (without original drop, because we use loot table) and spawn particles

    [Full procedure overview]


    Ingame examples

  5. Applying Unbreaking enchantments work aswell
     


    If you have any questions or suggestions, feel free to ask in comments or discord (@doomsdayfire).

    Procedure link

Last seen on 19:02, 26. Sep 2024
Joined Feb 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Also you can use exact same…
Thu, 09/26/2024 - 19:03

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