Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

performance fixes + raycast system #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions data/lock_block/functions/configs.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scoreboard players set lock_chest_with lock_block.configs 0
scoreboard players set print_summon_commands lock_block.configs 0
3 changes: 1 addition & 2 deletions data/lock_block/functions/func/block/trapdoors.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ execute if block ~ ~ ~ #minecraft:trapdoors[open=true,facing=west] run summon in
execute if block ~ ~ ~ #minecraft:trapdoors[open=true,facing=west] run summon interaction ~.405 ~-.001 ~-0.386 {width:0.193f,height:1.001f,response:0b,Tags:["blockLock.lock"]}
execute if block ~ ~ ~ #minecraft:trapdoors[open=true,facing=west] run summon interaction ~.405 ~-.001 ~-0.4123 {width:0.193f,height:1.001f,response:0b,Tags:["blockLock.lock"]}


execute if block ~ ~ ~ #minecraft:trapdoors[open=true,facing=north] run summon interaction ~ ~-.001 ~.405 {width:0.193f,height:1.001f,response:0b,Tags:["blockLock.lock"]}
execute if block ~ ~ ~ #minecraft:trapdoors[open=true,facing=north] run summon interaction ~0.193 ~-.001 ~.405 {width:0.193f,height:1.001f,response:0b,Tags:["blockLock.lock"]}
execute if block ~ ~ ~ #minecraft:trapdoors[open=true,facing=north] run summon interaction ~0.386 ~-.001 ~.405 {width:0.193f,height:1.001f,response:0b,Tags:["blockLock.lock"]}
execute if block ~ ~ ~ #minecraft:trapdoors[open=true,facing=north] run summon interaction ~0.4123 ~-.001 ~.405 {width:0.193f,height:1.001f,response:0b,Tags:["blockLock.lock"]}
execute if block ~ ~ ~ #minecraft:trapdoors[open=true,facing=north] run summon interaction ~-0.193 ~-.001 ~.405 {width:0.193f,height:1.001f,response:0b,Tags:["blockLock.lock"]}
execute if block ~ ~ ~ #minecraft:trapdoors[open=true,facing=north] run summon interaction ~-0.386 ~-.001 ~.405 {width:0.193f,height:1.001f,response:0b,Tags:["blockLock.lock"]}
execute if block ~ ~ ~ #minecraft:trapdoors[open=true,facing=north] run summon interaction ~-0.4123 ~-.001 ~.405 {width:0.193f,height:1.001f,response:0b,Tags:["blockLock.lock"]}
execute if block ~ ~ ~ #minecraft:trapdoors[open=true,facing=north] run summon interaction ~-0.4123 ~-.001 ~.405 {width:0.001f,height:1.001f,response:0b,Tags:["blockLock.lock"]}
3 changes: 1 addition & 2 deletions data/lock_block/functions/func/kill.mcfunction
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
kill @e[type=interaction,distance=..0.8,tag=blockLock.lock]
kill @s[type=armor_stand]
kill @e[type=interaction,distance=..0.5,tag=blockLock.lock]
tellraw @a[distance=..6] [{"text":"Succesfully unlocked, the block.","color":"gray"}]
3 changes: 1 addition & 2 deletions data/lock_block/functions/give_items.mcfunction
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
give @s armor_stand{display:{Name:'[{"text":"[Block Lock]","color":"white","bold":true,"italic":false},{"text":" Lock","color":"light_purple","bold":false,"italic":false}]',Lore:['{"text":"Place at the same hitbox as a block."}']},EntityTag:{NoGravity:1b,Silent:1b,Fire:100s,Glowing:1b,Small:1b,Marker:1b,Invisible:1b,Tags:["lockBlock.block"]}}
give @s armor_stand{display:{Name:'[{"text":"[Block Lock]","color":"white","bold":true,"italic":false},{"text":" Unlock","color":"light_purple","bold":false,"italic":false}]',Lore:['{"text":"Place, hit, or throw onto a locked block."}']},EntityTag:{NoGravity:1b,Silent:1b,Fire:100s,Glowing:1b,Small:1b,Marker:1b,Invisible:0b,Tags:["lockBlock.remove"]}}
give @p carrot_on_a_stick{Tags:["lockBlock"],display:{Name:'[{"text":"[Block Lock]","italic":false,"color":"gray"},{"text":" Lock & Unlock","color":"green"}]'}}
2 changes: 2 additions & 0 deletions data/lock_block/functions/load.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scoreboard objectives add lock_block.configs dummy
say loaded.
2 changes: 2 additions & 0 deletions data/lock_block/functions/run.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scoreboard players reset * lock_block_raycast.carrot_on_a_stick
function lock_block_raycast:fire
14 changes: 4 additions & 10 deletions data/lock_block/functions/tick.mcfunction
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
execute as @e[type=minecraft:armor_stand,tag=lockBlock.block] store result entity @s Pos[1] double 1 run data get entity @s Pos[1] 1
execute as @e[type=minecraft:armor_stand,tag=lockBlock.remove] store result entity @s Pos[1] double 1 run data get entity @s Pos[1] 1
execute as @e[type=minecraft:armor_stand,tag=lockBlock.block] at @s if block ~ ~ ~ #lock_block:lockable_block run function lock_block:func/anazlize_and_lock
execute as @e[type=minecraft:armor_stand,tag=lockBlock.block] at @s if block ~ ~ ~ #lock_block:lockable_block run kill @s
execute as @e[type=minecraft:armor_stand,tag=lockBlock.block,nbt={Fire:0s}] run kill @s
execute as @e[type=minecraft:armor_stand,tag=lockBlock.remove,nbt={Fire:0s}] run kill @s
execute as @e[type=armor_stand,tag=lockBlock.remove] at @s run function lock_block:func/kill
execute as @e[type=item,nbt={Item:{id:"minecraft:armor_stand",tag:{EntityTag:{Tags:["lockBlock.remove"]}}}}] at @s positioned ~ ~-.3 ~ if entity @e[type=interaction,distance=..0.8,tag=blockLock.lock] run function lock_block:func/kill
execute as @e[type=item,nbt={Item:{id:"minecraft:armor_stand",tag:{EntityTag:{Tags:["lockBlock.remove"]}}}}] at @s positioned ~ ~ ~ if entity @e[type=interaction,distance=..0.8,tag=blockLock.lock] run function lock_block:func/kill
execute as @e[type=interaction,tag=blockLock.lock] at @s on attacker if entity @s[nbt={SelectedItem:{id:"minecraft:armor_stand",tag:{EntityTag:{Tags:["lockBlock.remove"]}}}}] run function lock_block:func/kill
execute as @e[type=interaction,tag=blockLock.lock] at @s on attacker if entity @s[nbt={SelectedItem:{id:"minecraft:carrot_on_a_stick",tag:{Tags:["lockBlock"]}}}] align xyz positioned ~.5 ~ ~.5 run function lock_block:func/kill

# new code
execute as @a[scores={lock_block_raycast.carrot_on_a_stick=0..}] at @s run function lock_block:run
3 changes: 3 additions & 0 deletions data/lock_block/functions/uninstall.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard objectives remove lock_block_raycast.carrot_on_a_stick
scoreboard objectives remove lock_block_raycast
scoreboard objectives add lock_block.configs dummy
2 changes: 1 addition & 1 deletion data/lock_block/tags/blocks/blocks_1px.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"minecraft:cave_vines_plant",
"minecraft:cave_vines"
]
}
}
3 changes: 1 addition & 2 deletions data/lock_block/tags/blocks/full_block_lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
"minecraft:composter",
"minecraft:crafting_table",
"minecraft:cartography_table",
"minecraft:fletching_table",
MarkinoTeck marked this conversation as resolved.
Show resolved Hide resolved
"minecraft:cauldron",
"minecraft:smithing_table",
"minecraft:loom",
"minecraft:note_block",
"minecraft:decorated_pot",
"minecraft:respawn_anchor",
"minecraft:hopper",
"minecraft:spawner",
"minecraft:dropper",
"minecraft:dispenser",
"minecraft:beacon",
"minecraft:lodestone",
"minecraft:fletching_table",
"minecraft:bee_nest",
"minecraft:chiseled_bookshelf",
"minecraft:barrel",
Expand Down
1 change: 0 additions & 1 deletion data/lock_block/tags/blocks/lockable_block.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"minecraft:cake",
"minecraft:lever",
"minecraft:lectern",

"#minecraft:campfires",
"#minecraft:candle_cakes",
"#minecraft:flower_pots",
Expand Down
15 changes: 15 additions & 0 deletions data/lock_block_raycast/functions/doors.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
execute store result score #x lock_block_raycast run data get entity @s Pos[0] 100.0
execute store result score #z lock_block_raycast run data get entity @s Pos[2] 100.0
scoreboard players operation #x lock_block_raycast %= #100 lock_block_raycast
scoreboard players operation #z lock_block_raycast %= #100 lock_block_raycast

### Rotation Invarience
scoreboard players operation .x lock_block_raycast = #x lock_block_raycast
scoreboard players operation .z lock_block_raycast = #z lock_block_raycast
execute if block ~ ~ ~ #minecraft:doors[facing=north] run function lock_block_raycast:transforms/rotate_90
execute if block ~ ~ ~ #minecraft:doors[facing=west] run function lock_block_raycast:transforms/rotate_180
execute if block ~ ~ ~ #minecraft:doors[facing=south] run function lock_block_raycast:transforms/rotate_270

execute if block ~ ~ ~ #minecraft:doors[hinge=left,open=true] if score .z lock_block_raycast matches ..25 run scoreboard players set .itt lock_block_raycast 0
execute if block ~ ~ ~ #minecraft:doors[hinge=right,open=true] if score .z lock_block_raycast matches 75.. run scoreboard players set .itt lock_block_raycast 0
execute if block ~ ~ ~ #minecraft:doors[open=false] if score .x lock_block_raycast matches ..25 run scoreboard players set .itt lock_block_raycast 0
15 changes: 15 additions & 0 deletions data/lock_block_raycast/functions/fire.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# executed by player that uses carrot on a stick
summon marker ~ ~ ~ {Tags: ["raycaster"]}

## distance = #itt * step_size = 80 * 0.25 = 20 blocks
scoreboard players set .itt lock_block_raycast 80

## temporary tag to remember who fired the raycast
tag @s add lock_block_raycast.this
## anchors lock_block_raycast starting position to the eyes
execute anchored eyes positioned ^ ^ ^ as @e[type=marker,tag=raycaster] run function lock_block_raycast:raycast

tag @s remove lock_block_raycast.this


kill @e[type=marker,tag=raycaster]
3 changes: 3 additions & 0 deletions data/lock_block_raycast/functions/init.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scoreboard objectives add lock_block_raycast dummy
scoreboard players set #100 lock_block_raycast 100
scoreboard objectives add lock_block_raycast.carrot_on_a_stick minecraft.used:minecraft.carrot_on_a_stick
30 changes: 30 additions & 0 deletions data/lock_block_raycast/functions/my.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
execute store result score #x lock_block_raycast run data get entity @s Pos[0] 100.0
execute store result score .y lock_block_raycast run data get entity @s Pos[1] 100.0
execute store result score #z lock_block_raycast run data get entity @s Pos[2] 100.0
scoreboard players operation #x lock_block_raycast %= #100 lock_block_raycast
scoreboard players operation .y lock_block_raycast %= #100 lock_block_raycast
scoreboard players operation #z lock_block_raycast %= #100 lock_block_raycast

### Rotation Invarience
scoreboard players operation .x lock_block_raycast = #x lock_block_raycast
scoreboard players operation .z lock_block_raycast = #z lock_block_raycast
execute if block ~ ~ ~ #minecraft:stairs[facing=north] run function lock_block_raycast:transforms/rotate_90
execute if block ~ ~ ~ #minecraft:stairs[facing=west] run function lock_block_raycast:transforms/rotate_180
execute if block ~ ~ ~ #minecraft:stairs[facing=south] run function lock_block_raycast:transforms/rotate_270

scoreboard players set #bool lock_block_raycast 0
### Shape = Straight
execute if score .x lock_block_raycast matches 55.. run scoreboard players set #bool lock_block_raycast 1

### Shapes
execute if block ~ ~ ~ #minecraft:stairs[shape=inner_left] if score .z lock_block_raycast matches ..45 run scoreboard players set #bool lock_block_raycast 1
execute if block ~ ~ ~ #minecraft:stairs[shape=inner_right] if score .z lock_block_raycast matches 55.. run scoreboard players set #bool lock_block_raycast 1
execute if block ~ ~ ~ #minecraft:stairs[shape=outer_left] if score .z lock_block_raycast matches 45.. run scoreboard players set #bool lock_block_raycast 0
execute if block ~ ~ ~ #minecraft:stairs[shape=outer_right] if score .z lock_block_raycast matches ..55 run scoreboard players set #bool lock_block_raycast 0

### Bottom Step
execute store result score #type lock_block_raycast if block ~ ~ ~ #minecraft:stairs[half=bottom]
execute if score #type lock_block_raycast matches 1 if score .y lock_block_raycast matches ..55 run scoreboard players set #bool lock_block_raycast 1
execute if score #type lock_block_raycast matches 0 if score .y lock_block_raycast matches 45.. run scoreboard players set #bool lock_block_raycast 1

execute if score #bool lock_block_raycast matches 1 run scoreboard players set .itt lock_block_raycast 0
4 changes: 4 additions & 0 deletions data/lock_block_raycast/functions/partial.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tp @s ~ ~ ~
execute if block ~ ~ ~ #minecraft:slabs at @s run function lock_block_raycast:slabs
execute if block ~ ~ ~ #minecraft:stairs at @s run function lock_block_raycast:stairs
execute if block ~ ~ ~ #minecraft:doors at @s run function lock_block_raycast:doors
10 changes: 10 additions & 0 deletions data/lock_block_raycast/functions/raycast.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
particle crit ~ ~ ~ 0 0 0 0 1

execute if block ~ ~ ~ #lock_block_raycast:partial run function lock_block_raycast:partial

scoreboard players remove .itt lock_block_raycast 1


execute if score .itt lock_block_raycast matches 1.. if block ~ ~ ~ #lock_block_raycast:air positioned ^ ^ ^0.25 run function lock_block_raycast:raycast
execute if score .itt lock_block_raycast matches 1.. if block ~ ~ ~ #lock_block:lockable_block align xyz positioned ~.5 ~ ~.5 run function lock_block:func/anazlize_and_lock
execute if score .itt lock_block_raycast matches 1.. if block ~ ~ ~ #lock_block:lockable_block run return 0
12 changes: 12 additions & 0 deletions data/lock_block_raycast/functions/slabs.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## get y coord's decimal points (ex: Y=69.45 -> .y = 45)
execute store result score .y lock_block_raycast run data get entity @s Pos[1] 100.0
scoreboard players operation .y lock_block_raycast %= #100 lock_block_raycast

## check if its a bottom slab
execute store result score .type lock_block_raycast if block ~ ~ ~ #minecraft:slabs[type=bottom]
## if double slab, dont go through at all
execute if block ~ ~ ~ #minecraft:slabs[type=double] run scoreboard players set .itt lock_block_raycast 0
## if bottom slab, stop lock_block_raycast if inside bottom part
execute if score .type lock_block_raycast matches 1 if score .y lock_block_raycast matches ..55 run scoreboard players set .itt lock_block_raycast 0
## if top slab, stop lock_block_raycast if inside top part
execute if score .type lock_block_raycast matches 0 if score .y lock_block_raycast matches 45.. run scoreboard players set .itt lock_block_raycast 0
30 changes: 30 additions & 0 deletions data/lock_block_raycast/functions/stairs.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
execute store result score #x lock_block_raycast run data get entity @s Pos[0] 100.0
execute store result score .y lock_block_raycast run data get entity @s Pos[1] 100.0
execute store result score #z lock_block_raycast run data get entity @s Pos[2] 100.0
scoreboard players operation #x lock_block_raycast %= #100 lock_block_raycast
scoreboard players operation .y lock_block_raycast %= #100 lock_block_raycast
scoreboard players operation #z lock_block_raycast %= #100 lock_block_raycast

### Rotation Invarience
scoreboard players operation .x lock_block_raycast = #x lock_block_raycast
scoreboard players operation .z lock_block_raycast = #z lock_block_raycast
execute if block ~ ~ ~ #minecraft:stairs[facing=north] run function raycast:transforms/rotate_90
execute if block ~ ~ ~ #minecraft:stairs[facing=west] run function raycast:transforms/rotate_180
execute if block ~ ~ ~ #minecraft:stairs[facing=south] run function raycast:transforms/rotate_270

scoreboard players set #bool lock_block_raycast 0
### Shape = Straight
execute if score .x lock_block_raycast matches 55.. run scoreboard players set #bool lock_block_raycast 1

### Shapes
execute if block ~ ~ ~ #minecraft:stairs[shape=inner_left] if score .z lock_block_raycast matches ..45 run scoreboard players set #bool lock_block_raycast 1
execute if block ~ ~ ~ #minecraft:stairs[shape=inner_right] if score .z lock_block_raycast matches 55.. run scoreboard players set #bool lock_block_raycast 1
execute if block ~ ~ ~ #minecraft:stairs[shape=outer_left] if score .z lock_block_raycast matches 45.. run scoreboard players set #bool lock_block_raycast 0
execute if block ~ ~ ~ #minecraft:stairs[shape=outer_right] if score .z lock_block_raycast matches ..55 run scoreboard players set #bool lock_block_raycast 0

### Bottom Step
execute store result score #type lock_block_raycast if block ~ ~ ~ #minecraft:stairs[half=bottom]
execute if score #type lock_block_raycast matches 1 if score .y lock_block_raycast matches ..55 run scoreboard players set #bool lock_block_raycast 1
execute if score #type lock_block_raycast matches 0 if score .y lock_block_raycast matches 45.. run scoreboard players set #bool lock_block_raycast 1

execute if score #bool lock_block_raycast matches 1 run scoreboard players set .itt lock_block_raycast 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [x,z]*Rot(180) = [-x,-z]
scoreboard players set .x lock_block_raycast 100
scoreboard players set .z lock_block_raycast 100
scoreboard players operation .x lock_block_raycast -= #x lock_block_raycast
scoreboard players operation .z lock_block_raycast -= #z lock_block_raycast
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# [x,z]*Rot(270) = [z,-x]
scoreboard players set .z lock_block_raycast 100
scoreboard players operation .z lock_block_raycast -= #x lock_block_raycast
scoreboard players operation .x lock_block_raycast = #z lock_block_raycast
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# [x,z]*Rot(90) = [-z,x]
scoreboard players set .x lock_block_raycast 100
scoreboard players operation .x lock_block_raycast -= #z lock_block_raycast
scoreboard players operation .z lock_block_raycast = #x lock_block_raycast
24 changes: 24 additions & 0 deletions data/lock_block_raycast/tags/blocks/air.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"values":[
"minecraft:air",
"#minecraft:buttons",
"#minecraft:wool_carpets",
"#minecraft:candles",
"minecraft:cave_air",
"#minecraft:cave_vines",
"#minecraft:crops",
"#minecraft:fire",
"#minecraft:flowers",
"#minecraft:leaves",
"#minecraft:pressure_plates",
"#minecraft:rails",
"minecraft:redstone_wire",
"#minecraft:saplings",
"#minecraft:signs",
"#minecraft:small_flowers",
"#minecraft:tall_flowers",
"minecraft:void_air",
"#minecraft:wall_signs",
"#lock_block_raycast:partial"
]
}
7 changes: 7 additions & 0 deletions data/lock_block_raycast/tags/blocks/partial.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"values":[
"#minecraft:slabs",
"#minecraft:stairs",
"#minecraft:doors"
]
}
2 changes: 1 addition & 1 deletion data/minecraft/tags/functions/load.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"values": [
"lock_block:load"
"lock_block:load", "lock_block_raycast:init"
]
}