shot_testgun:
type: world
events:
on player right clicks block with:testgun:
- define start_location <player.eye_location>
- define target_location <[start_location].ray_trace[range=60;entities=*;ignore=<player>;fluids=true;nonsolids=true;default=air]>
- playeffect effect:redstone at:<[start_location].points_between[<[target_location]>].distance[0.5]> quantity:1 offset:0 visibility:100 special_data:1|<red>
- playsound sound:entity_firework_rocket_blast pitch:0 at:<[start_location]> effect:crit offset:0 visibility:1 volume:1
- inject beshot_testgun
- inject recoil
- determine cancelled
beshot_testgun:
type: task
script:
- define hit_location <player.precise_target_position.y>
- define target <player.precise_target[60]>
- if <[hit_location]> >= <player.target.eye_location.y.sub[0.05].if_null[0]> && <[hit_location]> <= <player.target.eye_location.y.add[0.70]>:
- hurt 100 <[target]> source:<player>
- else if <[hit_location]> <= <player.target.eye_location.y.sub[1.4].if_null[0]> && <[hit_location]> <= <player.target.eye_location.y.add[0.70]>:
- hurt 1 <[target]> source:<player>
- else:
- hurt 10 <[target]> source:<player>
recoil:
type: task
script:
- if <player.is_sneaking>:
- define recoil <player.eye_location.forward[1000].up[<util.random.int[1].to[5]>].left[<util.random.int[-5].to[5]>]>
- else:
- define recoil <player.eye_location.forward[100].up[<util.random.int[1].to[5]>].left[<util.random.int[-5].to[5]>]>
- look <[recoil]>
testgun:
type: item
material: wooden_hoe
display name: <green>TestGun
flags:
gun:
headdamage: 100
bodydamage: 10
feetdamage: 1
range: 60
maxbullet: 30
currentbullet: 30
recoil: 100
sneakrecoil: 1000
reloadrate: 2
fireraterate: 0.3