Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Added Raycast
Browse files Browse the repository at this point in the history
  • Loading branch information
Vianpyro committed Feb 15, 2021
1 parent 7c004ee commit 7df8590
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from wmcpy import Datapack, import_from_file

my_datapack_title = 'My_Datapack'
subfolder_title = Datapack(my_datapack_title).subfolder_title

myDatapack = Datapack(
title = my_datapack_title,
Expand Down Expand Up @@ -56,11 +57,23 @@ myDatapack = Datapack(
},
'functions': {
'main': [
'title Vianpyro actionbar {"text":"YAY", "color":"dark_red"}'
'title Vianpyro actionbar {"text":"YAY", "color":"dark_red"}',
'scoreboard objectives add vianpyro_RAYCAST minecraft.used:minecraft.carrot_on_a_stick',
f'execute as @a if score @s vianpyro_RAYCAST matches 1 at @s run function {subfolder_title}:raycast',
'scoreboard players set @a[scores={vianpyro_RAYCAST=1}] vianpyro_RAYCAST 0'
],
'load': [
f'tellraw @a ["", {{"text": "{my_datapack_title} > Successfuly reloaded the datapack!", "color": "green"}}]'
],
'raycast': Raycast(
datapack_name=subfolder_title,
function_name='raycast',
distance=50,
step=0.5,
end_condition='execute if block ~ ~ ~ stone',
output="say Stoned",
display_particle='flame'
),
'test': [
'say test ok',
'say test ko'
Expand Down Expand Up @@ -94,7 +107,7 @@ myDatapack.compile()
* The author is me, [Vianpyro](https://github.com/Vianpyro).
* The pack_meta is the informations I'll set in the *pack.mcmeta* file, this file is very important; it allows [Minecraft](https://www.minecraft.net/download) to read your datapack.
* As you can see I use 2 *reserved* names: ***main*** - containing the functions I want to repeat every [Minecraft](https://www.minecraft.net/download) tick - and ***load*** - once when the datapack is reloaded.
* Then I write whatever I want to be in my datapack ; 2 functions and a predicate.
* Then I write whatever I want to be in my datapack ; one advancement, 5 functions and a predicate.
* I know that the new version of my datapack is better than the older so I want to replace it without being asked when I run the program.
* I also add another function after the initialisation of my datapack because I want to be able to change it whenever I want without having to search for it in the big block of code above.
* Once I'm sure I don't have anything to add to my datapack I compile it.
Expand Down
2 changes: 2 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Data Storage Resource: https://www.youtube.com/watch?v=-uOd5mCqIJ4
Optimize Datapack Resource: https://www.youtube.com/watch?v=YFZenjaiN6Y
8 changes: 8 additions & 0 deletions wmcpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ def create_file(name, path='', content=''):
print(f'Successfuly created the file "{name}".')
f.close()


def Raycast(datapack_name, function_name, distance=20, step=0.3, end_condition=None, output=None, display_particle=None):
return [
f'particle {display_particle} ~ ~ ~ 0 0 0 0 1 normal @a' if display_particle is not None else None,
f'{end_condition} run {output}' if end_condition is not None else None,
f'execute if entity @s[distance=..{distance}] positioned ^ ^ ^{step} run function {datapack_name}:{function_name}'
]

def create_pack_meta(minecraft_version='1.6.1', description=None, author=None):
'''
This function helps with creating the string of a "pack.mcmeta" file ready to be written.
Expand Down

0 comments on commit 7df8590

Please sign in to comment.