Skip to content

Commit

Permalink
New XOR algorithm and 1.16 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcarter11 committed Mar 16, 2022
1 parent 9e07063 commit 25efe7c
Show file tree
Hide file tree
Showing 119 changed files with 522 additions and 418 deletions.
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Intro
Minecraft Ray Collision Detector is a super precise raycast system in vanilla minecraft! This datapack solved the raycast problem perfectly with minimal command cost. It defines the hitbox of most blocks and does some calculations to judge which surface will be touched.

Current datapack version: 2.4
Current datapack version: 2.5

Supported minecraft version: 1.17, 1.18
Supported minecraft version: 1.16, 1.17, 1.18

# How to use
Set scoreboard `mrcd_x0`, `mrcd_y0`, `mrcd_z0` for any ray (entity used as the ray marker, usually area_effect_cloud or markers). These three scoreboards stand for how many milliblocks that the ray can fly in three dimensions respectively each time you call `function mrcd:ray_tick` as the ray. If it **touches a block**, it will have the tags `mrcd_touch_edge` and `mrcd_touch_DIRECTION`. You can recognize which surface it touched from those tags.
Expand Down Expand Up @@ -34,7 +34,7 @@ Finally, move the marker to #targetx,y,z!

# Block Support

These blocks listed below are supported in is datapack. Please post an issue if you find some unsupported blocks and bugs.
These blocks listed below are supported in is datapack. Please post an issue if you find some unsupported blocks and bugs. *All blocks are listed using the latest minecraft block tags*

* any full block
* simple blocks
Expand Down Expand Up @@ -64,6 +64,8 @@ These blocks listed below are supported in is datapack. Please post an issue if
* minecraft:chain
* minecraft:twisting_vines
* minecraft:twisting_vines_plant
* minecraft:weeping_vines
* minecraft:weeping_vines_plant
* minecraft:nether_sprouts
* minecraft:soul_fire
* minecraft:small_dripleaf
Expand All @@ -74,10 +76,12 @@ These blocks listed below are supported in is datapack. Please post an issue if
* minecraft:large_amethyst_bud
* minecraft:amethyst_cluster
* minecraft:pointed_dripstone
* minecraft:hanging_roots
* minecraft:turtle_egg
* minecraft:light
* minecraft:sculk_sensor
* #minecraft:slabs
* #minecraft:pressure_plates
* #minecraft:wall_signs
* #minecraft:flower_pots
* #minecraft:buttons
Expand All @@ -88,12 +92,11 @@ These blocks listed below are supported in is datapack. Please post an issue if
* #minecraft:small_flowers
* #minecraft:campfires
* #minecraft:candles
* #minecraft:cave_vines
* #mrcd:mushroom
* red mushroom and brown mushroom
* #mrcd:standing_sign_like
* standing sign and standing banner
* #mrcd:pressure_plate_like
* all kinds of pressure plates
* #mrcd:repeater_like
* repeater and comparator
* #mrcd:attached_melon_stem_like
Expand All @@ -110,11 +113,11 @@ These blocks listed below are supported in is datapack. Please post an issue if
* all kinds of skulls, including dragon head
* #mrcd:wall_skull_like
* all kinds of skulls, including dragon head
* #mrcd:wall_torch_like
* #mrcd:wall_torches
* torch, soul torch and redstone torch
* #mrcd:grass_path_like
* grass path and farmland
* #mrcd:torch_like
* #mrcd:torches
* torch, soul torch and redstone torch
* #mrcd:wall_coral_like
* all kinds of corals
Expand All @@ -132,18 +135,13 @@ These blocks listed below are supported in is datapack. Please post an issue if
* crimson and warped fungus
* #mrcd:roots
* crimson and warped roots
* #mrcd:hanging_roots_like
* hanging root and weeping vines
* #mrcd:rod_like
* end rod and lightning rod
* #mrcd:weeping_like
* weeping_vines plant and cave vine head

* complex blocks
* minecraft:redstone_wire
* minecraft:piston_head
* minecraft:brewing_stand
* minecraft:cauldron
* minecraft:grindstone
* minecraft:bell
* minecraft:hopper
Expand All @@ -152,6 +150,8 @@ These blocks listed below are supported in is datapack. Please post an issue if
* minecraft:scaffolding
* minecraft:big_dripleaf
* minecraft:candle_cake
* minecraft:glow_lichen
* #minecraft:cauldrons
* #minecraft:anvil
* #minecraft:stairs
* #minecraft:walls
Expand All @@ -162,7 +162,7 @@ These blocks listed below are supported in is datapack. Please post an issue if
* #mrcd:azalea
* azalea and flower_azalea
* #mrcd:vine_like
* vine, glow lichen and fire (what????)
* vines and fire (what????)
* #mrcd:piston
* sticky piston and normal piston
* #mrcd:lanterns
Expand Down Expand Up @@ -223,3 +223,13 @@ These blocks listed below are supported in is datapack. Please post an issue if
* v2.4
* Updates
* Added new type of ray `mrcd_entity_bullet`
* v2.5
* Updates
* Merged the pull request of the new XOR algorithm (from 350 lines to 100) for offset blocks done by xwjcool123
* Added support for 1.16
* Changes
* 1.17 block checks are now skiped in older versions
* This means some changes on some block tags
* Fixes
* Weeping vines and Cave Vines were grouped with the same hitbox
* Blackstone pressure plate was missing
14 changes: 7 additions & 7 deletions data/mrcd/functions/example/tick.mcfunction
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# summon each diferent ray. In this example, we use the player as a reference for where and towards where the ray will go.
# So, we use oriented relative coordinates and some math to eassily assing the speed (this case, 0.5 b/ray_tick).
# Since the summoned area_effect_cloud lasts for 10 ticks (Duration), it will travel at max 5 blocks
execute as @e[nbt={SelectedItem:{id:"minecraft:stick"}}] at @s run function mrcd:example/raycast
execute as @e[nbt={SelectedItem:{id:"minecraft:blaze_rod"}}] at @s run function mrcd:example/bullet
execute as @e[nbt={SelectedItem:{id:"minecraft:bone"}}] at @s run function mrcd:example/entity
execute as @e[nbt={SelectedItem:{id:"minecraft:bamboo"}}] at @s run tag @e[type=armor_stand] add mrcd_target
execute as @e[nbt={SelectedItem:{id:"minecraft:bamboo"}}] at @s run function mrcd:example/entity_targeted
execute as @e[nbt={SelectedItem:{id:"minecraft:arrow"}}] at @s run function mrcd:example/bullet_entity
execute as @e[nbt={SelectedItem:{id:"minecraft:spectral_arrow"}}] at @s run function mrcd:example/bullet_and_entity
execute as @a[nbt={SelectedItem:{id:"minecraft:stick"}}] at @s run function mrcd:example/raycast
execute as @a[nbt={SelectedItem:{id:"minecraft:blaze_rod"}}] at @s run function mrcd:example/bullet
execute as @a[nbt={SelectedItem:{id:"minecraft:bone"}}] at @s run function mrcd:example/entity
execute as @a[nbt={SelectedItem:{id:"minecraft:bamboo"}}] at @s run tag @e[type=armor_stand] add mrcd_target
execute as @a[nbt={SelectedItem:{id:"minecraft:bamboo"}}] at @s run function mrcd:example/entity_targeted
execute as @a[nbt={SelectedItem:{id:"minecraft:arrow"}}] at @s run function mrcd:example/bullet_entity
execute as @a[nbt={SelectedItem:{id:"minecraft:spectral_arrow"}}] at @s run function mrcd:example/bullet_and_entity

# Do something at the ray (trace ray path)
execute at @e[tag=test_mark] run particle mycelium ~ ~ ~ 0 0 0 0 1 force
Expand Down
3 changes: 0 additions & 3 deletions data/mrcd/functions/private/category/pcp_117.mcfunction

This file was deleted.

8 changes: 0 additions & 8 deletions data/mrcd/functions/private/category/solid_117.mcfunction

This file was deleted.

30 changes: 15 additions & 15 deletions data/mrcd/functions/private/recurse.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
tag @s[tag=mrcd_detected] remove mrcd_detected
tag @s[tag=mrcd_touch_edge_air] remove mrcd_touch_edge_air

# Block collision test
## 当前是空气类方块,跳过 Skip if current block is air
# === Block collision test ===
# Skip if current block is air
execute if block ~ ~ ~ #mrcd:air_like run tag @s add mrcd_detected
## 当前是子弹可穿过方块,跳过 Skip if the marker type is bullet and current block can be passed by player
# Skip if the marker type is bullet and current block can be passed by player
execute if entity @s[tag=!mrcd_detected,tag=mrcd_bullet] if block ~ ~ ~ #mrcd:player_can_pass run tag @s add mrcd_detected
## 玩家不可穿过方块碰撞 Test if current block can't be passed by player
execute if entity @s[tag=!mrcd_detected] unless block ~ ~ ~ #mrcd:player_can_pass run function mrcd:private/category/solid
## 玩家可穿过方块碰撞 Test if current block can be passed by player
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:player_can_pass run function mrcd:private/category/player_can_pass
## 所有未定义方块碰撞(视为完整方块) Test if current block is undefined (treated as a full block)
# Test if current block can't be passed by player
execute if entity @s[tag=!mrcd_detected] unless block ~ ~ ~ #mrcd:player_can_pass run function mrcd:private/sort/solid
# Test if current block can be passed by player
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:player_can_pass run function mrcd:private/sort/player_can_pass
# Test if current block is undefined (treated as a full block)
execute if entity @s[tag=!mrcd_detected] run function mrcd:private/types/solid
## 当前未触碰碰撞箱,移动到边界 Move to the edge of the block if marker doesn't touch the hitbox of the block
# Move to the edge of the block if marker doesn't touch the hitbox of the block
execute if entity @s[tag=!mrcd_touch_edge] run function mrcd:private/types/air/main

#tellraw @a ["-----hit recurse-----"]
Expand All @@ -31,15 +31,15 @@ tag @s[tag=mrcd_entity_bullet] remove mrcd_touch_entity
tag @s[tag=mrcd_entity_bullet] remove mrcd_touch_edge


# Move marker
## Convert #target_x,y,z to a coordinate(#target_c_x,y,z) which based on the coordinate of marker (before based on the coordinate of block corner)
# === Move marker ===
# Convert #target_x,y,z to a coordinate(#target_c_x,y,z) which based on the coordinate of marker (before based on the coordinate of block corner)
execute store result score #target_c_x mrcd_system run scoreboard players get #target_x mrcd_system
execute store result score #target_c_y mrcd_system run scoreboard players get #target_y mrcd_system
execute store result score #target_c_z mrcd_system run scoreboard players get #target_z mrcd_system
scoreboard players operation #target_c_x mrcd_system -= #block_x mrcd_system
scoreboard players operation #target_c_y mrcd_system -= #block_y mrcd_system
scoreboard players operation #target_c_z mrcd_system -= #block_z mrcd_system
## Which is longer? Length of #target_c_x,y,z or #total_x,y,z?
# Which is longer? Length of #target_c_x,y,z or #total_x,y,z?
execute store result score #var0 mrcd_system run scoreboard players get #total_x mrcd_system
execute store result score #var1 mrcd_system run scoreboard players get #target_c_x mrcd_system
execute store result score #var2 mrcd_system run scoreboard players get #total_y mrcd_system
Expand All @@ -57,9 +57,9 @@ scoreboard players operation #var2 mrcd_system -= #var3 mrcd_system
scoreboard players operation #var4 mrcd_system -= #var5 mrcd_system
execute if score #var0 mrcd_system matches ..0 if score #var2 mrcd_system matches ..0 if score #var4 mrcd_system matches ..0 run scoreboard players set #if_reach_target mrcd_system 1
execute if score #var0 mrcd_system matches 0.. if score #var2 mrcd_system matches 0.. if score #var4 mrcd_system matches 0.. run scoreboard players set #if_reach_target mrcd_system 0
### #total_x,y,z<#target_c_x,y,z ----> Reached the distance limit
# #total_x,y,z<#target_c_x,y,z ----> Reached the distance limit
execute if score #if_reach_target mrcd_system matches 1 run function mrcd:private/reach_target
### #total_x,y,z >= #target_c_x,y,z and collide with a block ----> Collide with a block
# #total_x,y,z >= #target_c_x,y,z and collide with a block ----> Collide with a block
execute if score #if_reach_target mrcd_system matches 0 if entity @s[tag=mrcd_touch_edge] run function mrcd:private/hit_block
### #total_x,y,z >= #target_c_x,y,z and not collide with a block ----> Next cycle
# #total_x,y,z >= #target_c_x,y,z and not collide with a block ----> Next cycle
execute if score #if_reach_target mrcd_system matches 0 if entity @s[tag=!mrcd_touch_edge] run function mrcd:private/next_cycle
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,31 @@ execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ sugar_cane run function
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ sweet_berry_bush run function mrcd:private/types/sweet_berry_bush
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ tripwire run function mrcd:private/types/tripwire
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ bamboo_sapling run function mrcd:private/types/bamboo_sapling
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ twisting_vines run function mrcd:private/types/twisting_vines
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ twisting_vines_plant run function mrcd:private/types/twisting_vines_plant
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ nether_sprouts run function mrcd:private/types/sprouts
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ soul_fire run function mrcd:private/types/soul_fire

execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #wall_signs run function mrcd:private/types/wall_sign
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #buttons run function mrcd:private/types/button
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #rails run function mrcd:private/types/rail
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #small_flowers run function mrcd:private/types/flower

execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:hanging_roots_like run function mrcd:private/types/hanging_roots_like
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:weeping_like run function mrcd:private/types/weeping_like
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:pressure_plate_like run function mrcd:private/types/pressure_plate
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:standing_sign_like run function mrcd:private/types/standing_sign
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:attached_melon_stem_like run function mrcd:private/types/attached_melon_stem
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:melon_stem_like run function mrcd:private/types/melon_stem
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:wall_torch_like run function mrcd:private/types/wall_torch
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:torch_like run function mrcd:private/types/torch
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:wall_torches run function mrcd:private/types/wall_torch
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:torches run function mrcd:private/types/torch
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:wall_coral_like run function mrcd:private/types/wall_coral
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:coral_plant_like run function mrcd:private/types/coral_plant
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:coral_fan_like run function mrcd:private/types/coral_fan
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:grass_like run function mrcd:private/types/grass
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:sapling_like run function mrcd:private/types/sapling
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:wall_banner_like run function mrcd:private/types/wall_banner
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:carrots_like run function mrcd:private/types/carrots
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:pressure_plate_like run function mrcd:private/types/pressure_plate
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:mushroom run function mrcd:private/types/mushroom
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:fungus run function mrcd:private/types/fungus
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:roots run function mrcd:private/types/roots

function mrcd:private/category/pcp_117
# 1.15
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #small_flowers run function mrcd:private/types/flower

# 1.16
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:player_can_pass/1_16 run function mrcd:private/sort/player_can_pass/1_16

# 1.17
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:player_can_pass/1_17 run function mrcd:private/sort/player_can_pass/1_17
14 changes: 14 additions & 0 deletions data/mrcd/functions/private/sort/player_can_pass/1_16.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Global/Grouped: Soul torch, Blackstone Presureplate and button

# Complex blocks

# Simple blocks
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ nether_sprouts run function mrcd:private/types/1_16/sprouts
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ soul_fire run function mrcd:private/types/1_16/soul_fire
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ twisting_vines run function mrcd:private/types/1_16/twisting_vines
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ twisting_vines_plant run function mrcd:private/types/1_16/twisting_vines_plant
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ weeping_vines run function mrcd:private/types/1_16/weeping_vines
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ weeping_vines_plant run function mrcd:private/types/1_16/weeping_vines_plant

execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:fungus run function mrcd:private/types/1_16/fungus
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #mrcd:roots run function mrcd:private/types/1_16/roots
11 changes: 11 additions & 0 deletions data/mrcd/functions/private/sort/player_can_pass/1_17.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Global/Grouped: Glow Lichen

# Complex blocks

# Simple blocks
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ small_dripleaf run function mrcd:private/types/1_17/small_dripleaf
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ big_dripleaf_stem run function mrcd:private/types/1_17/big_dripleaf_stem/main
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ spore_blossom run function mrcd:private/types/1_17/spore_blossom
execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ hanging_roots run function mrcd:private/types/hanging_roots

execute if entity @s[tag=!mrcd_detected] if block ~ ~ ~ #cave_vines run function mrcd:private/types/1_17/cave_vines
Loading

0 comments on commit 25efe7c

Please sign in to comment.