
# -> Debug particles
#particle happy_villager ~ ~ ~ 0 0 0 0.0001 1 force @a

# -> Store item
execute if items entity @s weapon.mainhand *[custom_data~{IsEntityBucket:1b}] run \
    item replace entity 00000001-0000-002b-0000-00010000002b contents from entity @s weapon.mainhand
execute if items entity @s weapon.offhand *[custom_data~{IsEntityBucket:1b}] \
    unless items entity @s weapon.mainhand *[custom_data~{IsEntityBucket:1b}] run \
        item replace entity 00000001-0000-002b-0000-00010000002b contents from entity @s weapon.offhand

# -> Set block
execute align xyz run \
    summon marker ~0.5 ~ ~0.5 {Tags:["OverlyRealistic.Block.EntityWaterPlacementMarker","OverlyRealistic.TempBucketEntity"]}

# -> Save data into block marker
data modify entity @n[type=marker,tag=OverlyRealistic.TempBucketEntity,distance=..32] data.bucket_entity_type set from entity 00000001-0000-002b-0000-00010000002b item.components."minecraft:custom_data".bucket_entity_type
tag @n[type=marker,tag=OverlyRealistic.TempBucketEntity,distance=..32] remove OverlyRealistic.TempBucketEntity

# -> Create water placement
schedule function overly_realistic:players/items/entity_bucket/block_placement_operate 1t

# -> If player is in creative then return
execute if entity @s[gamemode=creative] run \
    return fail

# -> Replace water bucket
execute if items entity @s weapon.mainhand *[custom_data~{IsEntityBucket:1b}] run \
    return run \
        item replace entity @s weapon.mainhand with bucket
item replace entity @s weapon.offhand with bucket
