Skip to content

Commit 03a25d6

Browse files
committed
add three commands
1 parent 56cfcf2 commit 03a25d6

10 files changed

Lines changed: 114 additions & 13 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ These are the currently supported commands. Feel free to create a PR, the goal i
3434
- [x] /defaultgamemode
3535
- [x] /deop
3636
- [x] /difficulty
37-
- [ ] /effect
37+
- [x] /effect
3838
- [ ] /enchant
3939
- [x] /execute
40-
- [ ] /experience (/xp)
40+
- [x] /experience (/xp)
4141
- [ ] /fill
4242
- [ ] /forceload
4343
- [x] /function
@@ -78,7 +78,7 @@ These are the currently supported commands. Feel free to create a PR, the goal i
7878
- [x] /teammsg (/tm)
7979
- [x] /teleport (/tp)
8080
- [ ] /tellraw
81-
- [ ] /time
81+
- [x] /time
8282
- [ ] /title
8383
- [ ] /trigger
8484
- [x] /weather

pymcfunction/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
__version__ = "0.1.5"
1+
__version__ = "0.1.6"
22

33
from .util import *
44

55
from .commands.tag import tag
6+
from .commands.time import time
67
from .commands.team import team
78
from .commands.item import item
9+
from .commands.effect import effect
810
from .commands.bossbar import bossbar
911
from .commands.execute import execute
1012
from .commands.teleport import teleport
13+
from .commands.experience import experience
1114
from .commands.scoreboard import Scoreboard
1215

1316
from .commands.simple import *
1417

1518

1619
# Aliases
1720
sb = Scoreboard
21+
xp = experience
1822
exec = execute
1923
gm = gamemode
2024
tp = teleport
21-
bb = bossbar
25+
bb = bossbar

pymcfunction/cli.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,3 @@ def publish():
211211
print("\nMaking archive...")
212212
shutil.make_archive(file, "zip", outFolder)
213213
print("Created archive!")
214-
215-
216-
app()

pymcfunction/commands/effect.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from pymcfunction.update_specific_types.effect import Effect
2+
3+
4+
class effect:
5+
def __init__(self, target: str = "@s") -> None:
6+
self.target = target
7+
8+
def give(
9+
self,
10+
effect: Effect,
11+
seconds: int = None,
12+
amplifier: int = None,
13+
hideParticles: bool = None,
14+
):
15+
return f"effect give {self.target} {effect.value}" + (
16+
" "
17+
+ (
18+
str(seconds)
19+
+ (
20+
" "
21+
+ (
22+
str(amplifier)
23+
+ (
24+
" " + ("true" if hideParticles else "false")
25+
if hideParticles != None
26+
else ""
27+
)
28+
)
29+
if amplifier
30+
else ""
31+
)
32+
)
33+
if seconds
34+
else ""
35+
)
36+
37+
def clear(self, effect: Effect = None) -> str:
38+
return f"effect clear {self.target}" + ((" " + effect.value) if effect else "")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from pymcfunction.types import ExperienceUnit
2+
3+
4+
class experience:
5+
def __init__(self, selector: str = "@s") -> None:
6+
self.selector = selector
7+
8+
def add(self, anmount: int, unit: ExperienceUnit):
9+
return f"xp add {self.selector} {anmount} {unit.value}"
10+
11+
def remove(self, anmount: int, unit: ExperienceUnit):
12+
# xp remove is not an actual command in the game,
13+
# but uses xp add with a negative anmount
14+
return self.add(anmount * -1, unit)
15+
16+
def query(self, unit: ExperienceUnit):
17+
return f"xp query {self.target} {unit.value}"
18+
19+
def set(self, anmount, unit: ExperienceUnit):
20+
return f"xp set {self.selector} {anmount} {unit.value}"

pymcfunction/commands/time.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from pymcfunction.types import TimePreset, TimeQueryType
2+
3+
4+
class time:
5+
def __init__(self) -> None:
6+
pass
7+
8+
def add(self, _time: int):
9+
return f"time add {_time}"
10+
11+
def set(self, _time: int | TimePreset):
12+
return "time set " + (str(_time) if type(_time) == int else _time.value)
13+
14+
def query(self, type: TimeQueryType):
15+
return f"time query {type.value}"

pymcfunction/types.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,21 @@ class Difficultiy(Enum):
111111
EASY = "easy"
112112
NORMAL = "normal"
113113
HARD = "hard"
114+
115+
116+
class ExperienceUnit(Enum):
117+
LEVELS = "levels"
118+
POINTS = "points"
119+
120+
121+
class TimeQueryType(Enum):
122+
DAYTIME = "daytime"
123+
GAMETIME = "gametime"
124+
DAY = "day"
125+
126+
127+
class TimePreset(Enum):
128+
DAY = "day"
129+
NIGHT = "night"
130+
NOON = "noon"
131+
MIDNIGHT = "midnight"

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pymcfunction"
3-
version = "0.1.5"
3+
version = "0.1.6"
44
description = "PyMCFunction is a tool to write Minecraft datapacks in Python."
55
authors = ["PaddeCraft <paddecraft@gmail.com>"]
66
include = [
@@ -11,9 +11,9 @@ repository = "https://github.com/PaddeCraft/PyMCFunction"
1111
keywords = ["python", "minecraft", "toml", "cli"]
1212

1313
[tool.poetry.scripts]
14-
pymcfunction = "pymcfunction.cli.app:run"
15-
pyfunction = "pymcfunction.cli.app:run"
16-
pmf = "pymcfunction.cli.app:run"
14+
pymcfunction = "pymcfunction.cli:app"
15+
pyfunction = "pymcfunction.cli:app"
16+
pmf = "pymcfunction.cli:app"
1717

1818
[tool.poetry.dependencies]
1919
python = "^3.10"

test/data/test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@
77
item().replaceBlock("~ ~ ~", "0", Item.DIAMOND)
88

99
tag("@s").add("test")
10+
11+
effect("@e").give(Effect.DARKNESS)
12+
effect("@e").give(Effect.DARKNESS, 12)
13+
effect("@e").give(Effect.DARKNESS, 12, 255)
14+
effect("@e").give(Effect.DARKNESS, 12, 255, True)
15+
16+
effect("@e").clear()
17+
effect("@e").clear(Effect.DARKNESS)

test/pymcfunctionconfig.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
namespace = "testdp"
22
compiled_folder_name = "testdpfolder"
33
description = "Test datapack"
4-
datapack_folder = "/run/media/paddecraft/4EE0F299E0F2870D/Dev/PythonScripting/pyfunction/test"
4+
#datapack_folder = "/run/media/paddecraft/4EE0F299E0F2870D/Dev/PythonScripting/PyMCFunction/test"
5+
datapack_folder = "."
56
pack_version = 10
67

78
[includes]

0 commit comments

Comments
 (0)