HT's TreeChop

HT's TreeChop

3M Downloads

[Enhancement] Customizable loot table roll on each chop level

MetalKnight56 opened this issue Β· 15 comments

commented

So i've been trying to make a datapack for a while now but due to the complexity of how TreeChop and because chopped logs don't use the vanilla BlockStates it makes it very hard for me to set the blocks to a certain level and thus it's basically almost impossible for me to create a proper datapack that changes each drop per level of breaking... So i'm here to request to you to maybe add some kind of function event that's triggered every time a chop level is executed, or simply allowing us to assign a loot table for each Chop level for each tree, so i can finally make my pack complete and so other looking for something simmilar be able to have the tools :)

Thanks in advance + just reply to this if you need more explanation, maybe i can even help you out, just gotta know what i'm dealing with...

commented

Looking into this now, I'll get back to you shortly

commented

I see that your loot tables only get used when chopping is off (like when sneaking) - is this what you really want, or just a workaround?

Note that when chopping, treechop:chopped_log always spawns its drops. Here's what happens when you chop an oak log block:

  1. The minecraft:oak_log gets replaced by treechop:chopped_log
  2. Drops for minecraft:oak_log are stored inside the chopped log, only released when the chopped log is fully broken
  3. Drops for treechop:chopped_log are spawned. This repeats X times if X chops are performed

If you just want to spawn an "oak bark" item when an "oak log" block is broken, maybe you can detect when an oak block is broken, then add oak bark to the next treechop:chopped_log loot? Just an idea, I'm not super familiar with the limits of datapacks. EDIT - Oops, the drops mentioned in 3 actually aren't spawning correctly.

In any case, I'm gonna see what loot parameters and conditions I can add to help with your loot tables. I think that'll be the easiest way to get this working

commented

turn_to_broken_oak_logx1:

execute align xyz run setblock ~ ~ ~ treechop:chopped_log{Chops:1, OriginalState:130, Shape:13} replace
summon minecraft:item ~ ~1 ~ {Item:{id:"kubejs:oak_bark",Count:1}}
kill @s

turn_to_broken_oak_logy1:

execute align xyz run setblock ~ ~ ~ treechop:chopped_log{Chops:1, OriginalState:131, Shape:0} replace
summon minecraft:item ~ ~1 ~ {Item:{id:"kubejs:oak_bark",Count:1}}
kill @s

turn_to_broken_oak_logz1:

execute align xyz run setblock ~ ~ ~ treechop:chopped_log{Chops:1, OriginalState:132, Shape:8} replace
summon minecraft:item ~ ~1 ~ {Item:{id:"kubejs:oak_bark",Count:1}}
kill @s

Here are all the functions. Please try and run the first command of each one (the execute one), but not in a datapack, just do /command bla bla bla, you'll see it works just fine when players do it, but not when ran by functions

What version of minecraft and treechop are you using @MetalKnight56? I put these functions in a datapack (just the first line of each) and they worked for me. I used Minecraft 1.19.2 (Fabric) and TreeChop-1.19.2-fabric-0.18.3

commented

turn_to_broken_oak_logx1:

execute align xyz run setblock ~ ~ ~ treechop:chopped_log{Chops:1, OriginalState:130, Shape:13} replace
summon minecraft:item ~ ~1 ~ {Item:{id:"kubejs:oak_bark",Count:1}}
kill @s

turn_to_broken_oak_logy1:

execute align xyz run setblock ~ ~ ~ treechop:chopped_log{Chops:1, OriginalState:131, Shape:0} replace
summon minecraft:item ~ ~1 ~ {Item:{id:"kubejs:oak_bark",Count:1}}
kill @s

turn_to_broken_oak_logz1:

execute align xyz run setblock ~ ~ ~ treechop:chopped_log{Chops:1, OriginalState:132, Shape:8} replace
summon minecraft:item ~ ~1 ~ {Item:{id:"kubejs:oak_bark",Count:1}}
kill @s

Here are all the functions. Please try and run the first command of each one (the execute one), but not in a datapack, just do /command bla bla bla, you'll see it works just fine when players do it, but not when ran by functions

What version of minecraft and treechop are you using @MetalKnight56? I put these functions in a datapack (just the first line of each) and they worked for me. I used Minecraft 1.19.2 (Fabric) and TreeChop-1.19.2-fabric-0.18.3

1.20.1 Forge

commented

I see that your loot tables only get used when chopping is off (like when sneaking) - is this what you really want, or just a workaround?

Note that when chopping, treechop:chopped_log always spawns its drops. Here's what happens when you chop an oak log block:

1. The minecraft:oak_log gets replaced by treechop:chopped_log

2. Drops for minecraft:oak_log are stored inside the chopped log, only released when the chopped log is fully broken

3. ~Drops for treechop:chopped_log are spawned. This repeats X times if X chops are performed~

If you just want to spawn an "oak bark" item when an "oak log" block is broken, maybe you can detect when an oak block is broken, then add oak bark to the next treechop:chopped_log loot? Just an idea, I'm not super familiar with the limits of datapacks. EDIT - Oops, the drops mentioned in 3 actually aren't spawning correctly.

In any case, I'm gonna see what loot parameters and conditions I can add to help with your loot tables. I think that'll be the easiest way to get this working

Yeah, no that's just a workaround yk, cuz i'm unable to properly roll loot tables on each chop state. This whole function datapack thing could all be avoided if i could do the following -

  1. Make it so when breaking each log till it's final state it doesn't actually cut the whole tree, as i just want to make it harder to cut each log, and not make it easier yk

  2. If i could roll a loot table drop on each broken state, so like,
    Full Log ---Breaks---Drops X Item, like idk wootype_bark------replaces Full Log with cut variant----> Cut variant Level 1 -------repeats until fully broken----->

  3. If i can set a different loot table for each break state of the log and if i can later customize it so axes break logs as the mod intended (prefearbly through tags, so i can add modded axes to the list of tools that break logs as if you were shifting, skipping the whole break state thing or just making it so it breaks as you intended, by slowly breaking the whole tree)

commented
  1. Make it so when breaking each log till it's final state it doesn't actually cut the whole tree, as i just want to make it harder to cut each log, and not make it easier yk

In config/treechop-common.toml you can disable felling (I think there's a "permissions" section). The next version of treechop will have a console command to fell trees: /treechop fell X Y Z. So, if you want, you'll be able to choose when trees get felled

  1. If i could roll a loot table drop on each broken state, so like,
    Full Log ---Breaks---Drops X Item, like idk wootype_bark------replaces Full Log with cut variant----> Cut variant Level 1 -------repeats until fully broken----->

The next version will add a chopping loot table. It works like the normal block table but has two extra conditions, treechop:count_block_chops and treechop:tree_felled. The files go in the loot_tables/chopping folder instead of loot_tables/blocks. Here's an example:

data
    treechop
        loot_tables
            chopping
                chopped_log.json

Inside of chopped_log.json (based on your oak_log.json):

{
  "type": "treechop:chopping",
  "pools": [
    {
      "rolls": 1,
      "bonus_rolls": 0,
      "entries": [
        {
          "type": "minecraft:alternatives",
          "children": [
            {
              "type": "minecraft:item",
              "name": "minecraft:coal",
              "conditions": [
                {
                  "condition": "treechop:count_block_chops",
                  "range": 1
                }
              ]
            },
            {
              "type": "minecraft:item",
              "name": "minecraft:diamond",
              "conditions": [
                {
                  "condition": "treechop:tree_felled"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

This drops 1 coal on the first chop, and 1 diamond when the tree is felled. All the other conditions you were using should work too, so you can call functions and set nbt values and all that.

Will this work for ya?

commented

This drops 1 coal on the first chop, and 1 diamond when the tree is felled. All the other conditions you were using should work too, so you can call functions and set nbt values and all that.
Will this work for ya?

Yeah i love the new condition you've added :) It's actually perfect !

In config/treechop-common.toml you can disable felling (I think there's a "permissions" section). The next version of treechop will have a console command to fell trees: /treechop fell X Y Z. So, if you want, you'll be able to choose when trees get felled

Just wanted to know how could i glue this command to certain tools? I'm not sure how you currently determine which tools are considered axes, but maybe make it so you have a config option like "only-axe-tree-chopping:true|false" where you can only initiate the whole tree chopping thing when the tool you are holding is included in data/minecraft/tags/items/axes.json (the vanilla tag for axes) , so basically a new config option that's a checker for this condition of the currently held tool, but aside from that, it's perfect !

commented

Yeah i love the new condition you've added :) It's actually perfect !

Oh good! πŸ˜ƒ

Just wanted to know how could i glue this command to certain tools? I'm not sure how you currently determine which tools are considered axes, but maybe make it so you have a config option like "only-axe-tree-chopping:true|false" where you can only initiate the whole tree chopping thing when the tool you are holding is included in data/minecraft/tags/items/axes.json (the vanilla tag for axes) , so basically a new config option that's a checker for this condition of the currently held tool, but aside from that, it's perfect !

You can do this in treechop-common.toml using the items blacklist/whitelist like so:

[compatibility]
    [compatibility.general]
        [compatibility.general.blacklist]
            #Whether the listed items should be blacklisted or whitelisted
            #Allowed Values: BLACKLIST, WHITELIST
            blacklistOrWhitelist = "WHITELIST"
            #List of item registry names (mod:item), tags (#mod:tag), and namespaces (@mod) for items that should not chop when used to break a log
            #- Items in this list that have special support for TreeChop will not be blacklisted; see https://github.com/hammertater/treechop/blob/main/docs/compatibility.md#blacklist
            items = ["#minecraft:axes"]

Another way - some mods make it so that only axes are the "correct tool" for breaking logs (like picks for iron ore, etc.), so if that's the case, the setting below will only allow players to chop when using the right tool

[compatibility]
    [compatibility.general]
        #Only chop when using a tool that increases block breaking speed (such as axes for logs)
        choppingRequiresFastBreakingTool = true
commented

Yeah i love the new condition you've added :) It's actually perfect !

Oh good! πŸ˜ƒ

Just wanted to know how could i glue this command to certain tools? I'm not sure how you currently determine which tools are considered axes, but maybe make it so you have a config option like "only-axe-tree-chopping:true|false" where you can only initiate the whole tree chopping thing when the tool you are holding is included in data/minecraft/tags/items/axes.json (the vanilla tag for axes) , so basically a new config option that's a checker for this condition of the currently held tool, but aside from that, it's perfect !

You can do this in treechop-common.toml using the items blacklist/whitelist like so:

[compatibility]
    [compatibility.general]
        [compatibility.general.blacklist]
            #Whether the listed items should be blacklisted or whitelisted
            #Allowed Values: BLACKLIST, WHITELIST
            blacklistOrWhitelist = "WHITELIST"
            #List of item registry names (mod:item), tags (#mod:tag), and namespaces (@mod) for items that should not chop when used to break a log
            #- Items in this list that have special support for TreeChop will not be blacklisted; see https://github.com/hammertater/treechop/blob/main/docs/compatibility.md#blacklist
            items = ["#minecraft:axes"]

Another way - some mods make it so that only axes are the "correct tool" for breaking logs (like picks for iron ore, etc.), so if that's the case, the setting below will only allow players to chop when using the right tool

[compatibility]
    [compatibility.general]
        #Only chop when using a tool that increases block breaking speed (such as axes for logs)
        choppingRequiresFastBreakingTool = true

Perfect !!!

commented

Added in 0.19.0, only for minecraft 1.20.1 at the moment. Hope it works!

commented

Added in 0.19.0, only for minecraft 1.20.1 at the moment. Hope it works!

Hey sorry to bother you, but i have a question, so i've been trying to make each tree drop their bark. This is what i have

{
  "type": "treechop:chopping",
  "pools": [
    {
      "rolls": 1,
      "bonus_rolls": 0,
      "entries": [
        {
          "type": "minecraft:alternatives",
          "children": [
            {
              "type": "minecraft:item",
              "name": "immersive_weathering:oak_bark",
              "conditions": [
                {
                  "condition": "treechop:count_block_chops",
                  "range": 1
                },
                { //this property, that checks the block_state (wanted it to check the block being broken) doesn't seem to be working for some reason...
                  "condition": "minecraft:block_state_property",
                  "block": "minecraft:oak_log",
                  "properties": {}
                }
              ]
            },
            {
              "type": "minecraft:item",
              "name": "thermal:sawdust",
              "conditions": [
                {
                  "condition": "treechop:count_block_chops",
                  "range": 2
                }
              ]
            },
            {
              "type": "minecraft:item",
              "name": "minecraft:diamond",
              "conditions": [
                {
                  "condition": "treechop:tree_felled"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

I'd change the bark drop depending on the log type that's being cut, but i have 0 idea how i could check the NBT vaalue of the block and not the tool/item being used, i've never had to check the other way around too, so i'm kinda confused on this.

commented

Hey, sorry for the late reply! I don't have much experience with datapacks, so bear with me.

because chopped logs don't use the vanilla BlockStates it makes it very hard for me to set the blocks to a certain level

You should be able to set the number of chops using stuff like this:

/setblock X Y Z treechop:chopped_log replace
/data modify block X Y Z Chops set value 3

add some kind of function event that's triggered every time a chop level is executed

Can you point me to a mod that adds custom function events? So I can look at how they do it

allowing us to assign a loot table for each Chop level for each tree

This might work if I can add a custom loot parameter

I'll probably come back with more questions or concerns as I tinker around :)

commented

You should be able to set the number of chops using stuff like this:

/setblock X Y Z treechop:chopped_log replace
/data modify block X Y Z Chops set value 3

Ok so on this, basically what i'm doing is, the following:

I've changed the loot table for the oak_log block, so it checks if the player is using air, or an item with the "axes" tag. If the player is using an axe, it'll return an oak log as the loot drop, but if the player is using air, it'll first check the rotation of the log, and then it'll drop an item like a command block, barrier or bedrock and inside of it, it'll set an nbt tag with one of the following:

{Tags:["broke_oak_log_x"]}
{Tags:["broke_oak_log_y"]}
{Tags:["broke_oak_log_z"]}

(I'm doing this because i can't exactly just change the rotational value of TreeChopped blocks, as contrary to oak logs, whom use axis rotation [so if i want to set an oak log rotated in the x axis i'd need to do this: "/setblock ~ ~ ~ minecraft:oak_log[axis=x]" while on treeChopped blocks you don't use any block states, like rotation or cardinal/axis and so i need to convert it to an id, and so a treechop:chopped_log block rotated in its x axis would look like this "/setblock ~ ~ ~ treechop:chopped_log{OriginalState:130}"] )

Here's my oak_log loot table
oak_log.json

After that i run a tick.mcfuntion every tick, so it checks for the specified items with the specified tags and so its able to run a set of commands replacing the block, which in theory looks like it could work, but in reality i'm unable to set chopped_log blocks and their nbt data properly with functions for some unkown reason...

This is what it looks like inside of my tick function:

execute as @e[type=item,nbt={Item:{id:"minecraft:bedrock",tag:{Tags:["hoe.broke_grass"]}}}] at @s run function plow_grass:turn_to_dirt //don't mind this as i'm using the same thing for another mod

execute as @e[type=item,nbt={Item:{id:"minecraft:bedrock",tag:{Tags:["broke_oak_log_y"]}}}] at @s run function plow_grass:turn_to_broken_oak_logy1
execute as @e[type=item,nbt={Item:{id:"minecraft:barrier",tag:{Tags:["broke_oak_log_x"]}}}] at @s run function plow_grass:turn_to_broken_oak_logx1
execute as @e[type=item,nbt={Item:{id:"minecraft:command_block",tag:{Tags:["broke_oak_log_z"]}}}] at @s run function plow_grass:turn_to_broken_oak_logz1

And this is what it looks like inside one of the functions irs running after detecting the block with said tag

execute align xyz run setblock ~ ~ ~ treechop:chopped_log{Chops:1, OriginalState:130, Shape:13} replace
summon minecraft:item ~ ~1 ~ {Item:{id:"kubejs:oak_bark",Count:1}}
kill @s

Here's a video showing that it doesn't rotate with functions inside of datapacks:

https://www.youtube.com/watch?v=0Uf8LvmhaUA

The ideal scenario would either be to have an event i can detect each time a log breaks and use it in a datapack, but i don't really have any references for mods that do that, aside maybe KubeJs or GameStages (maybe FTB quests too), or on the best case scenario would be to have a config option that allows me to run a specific loot table on each tree chopping state

Can you point me to a mod that adds custom function events? So I can look at how they do it

Again, GameStages, FTBQuests, KubeJs, and i guess anything that has advencements? Idk, yeah, those would be my guesses but i wouldn't really know too

This might work if I can add a custom loot parameter

This would be ideal ^, but if you can just fix the incorrect OriginalState assigning with datapacks, it would also work :)

I'll probably come back with more questions or concerns as I tinker around :)

Ok, thats completely fine, i'll be here awaiting any questions, if you want maybe i can also assist you on it, but then i'd need to investigate your code and all that...

commented

turn_to_broken_oak_logx1:

execute align xyz run setblock ~ ~ ~ treechop:chopped_log{Chops:1, OriginalState:130, Shape:13} replace
summon minecraft:item ~ ~1 ~ {Item:{id:"kubejs:oak_bark",Count:1}}
kill @s

turn_to_broken_oak_logy1:

execute align xyz run setblock ~ ~ ~ treechop:chopped_log{Chops:1, OriginalState:131, Shape:0} replace
summon minecraft:item ~ ~1 ~ {Item:{id:"kubejs:oak_bark",Count:1}}
kill @s

turn_to_broken_oak_logz1:

execute align xyz run setblock ~ ~ ~ treechop:chopped_log{Chops:1, OriginalState:132, Shape:8} replace
summon minecraft:item ~ ~1 ~ {Item:{id:"kubejs:oak_bark",Count:1}}
kill @s

Here are all the functions. Please try and run the first command of each one (the execute one), but not in a datapack, just do /command bla bla bla, you'll see it works just fine when players do it, but not when ran by functions

commented

Thanks for all the info! Life’s getting in the way right now but I will get back to you sometime next week πŸ™ Sorry bout the wait