Skip to content

Commit

Permalink
add three commands
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddeCraft committed Nov 12, 2022
1 parent 56cfcf2 commit 03a25d6
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ These are the currently supported commands. Feel free to create a PR, the goal i
- [x] /defaultgamemode
- [x] /deop
- [x] /difficulty
- [ ] /effect
- [x] /effect
- [ ] /enchant
- [x] /execute
- [ ] /experience (/xp)
- [x] /experience (/xp)
- [ ] /fill
- [ ] /forceload
- [x] /function
Expand Down Expand Up @@ -78,7 +78,7 @@ These are the currently supported commands. Feel free to create a PR, the goal i
- [x] /teammsg (/tm)
- [x] /teleport (/tp)
- [ ] /tellraw
- [ ] /time
- [x] /time
- [ ] /title
- [ ] /trigger
- [x] /weather
Expand Down
8 changes: 6 additions & 2 deletions pymcfunction/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
__version__ = "0.1.5"
__version__ = "0.1.6"

from .util import *

from .commands.tag import tag
from .commands.time import time
from .commands.team import team
from .commands.item import item
from .commands.effect import effect
from .commands.bossbar import bossbar
from .commands.execute import execute
from .commands.teleport import teleport
from .commands.experience import experience
from .commands.scoreboard import Scoreboard

from .commands.simple import *


# Aliases
sb = Scoreboard
xp = experience
exec = execute
gm = gamemode
tp = teleport
bb = bossbar
bb = bossbar
3 changes: 0 additions & 3 deletions pymcfunction/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,3 @@ def publish():
print("\nMaking archive...")
shutil.make_archive(file, "zip", outFolder)
print("Created archive!")


app()
38 changes: 38 additions & 0 deletions pymcfunction/commands/effect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from pymcfunction.update_specific_types.effect import Effect


class effect:
def __init__(self, target: str = "@s") -> None:
self.target = target

def give(
self,
effect: Effect,
seconds: int = None,
amplifier: int = None,
hideParticles: bool = None,
):
return f"effect give {self.target} {effect.value}" + (
" "
+ (
str(seconds)
+ (
" "
+ (
str(amplifier)
+ (
" " + ("true" if hideParticles else "false")
if hideParticles != None
else ""
)
)
if amplifier
else ""
)
)
if seconds
else ""
)

def clear(self, effect: Effect = None) -> str:
return f"effect clear {self.target}" + ((" " + effect.value) if effect else "")
20 changes: 20 additions & 0 deletions pymcfunction/commands/experience.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from pymcfunction.types import ExperienceUnit


class experience:
def __init__(self, selector: str = "@s") -> None:
self.selector = selector

def add(self, anmount: int, unit: ExperienceUnit):
return f"xp add {self.selector} {anmount} {unit.value}"

def remove(self, anmount: int, unit: ExperienceUnit):
# xp remove is not an actual command in the game,
# but uses xp add with a negative anmount
return self.add(anmount * -1, unit)

def query(self, unit: ExperienceUnit):
return f"xp query {self.target} {unit.value}"

def set(self, anmount, unit: ExperienceUnit):
return f"xp set {self.selector} {anmount} {unit.value}"
15 changes: 15 additions & 0 deletions pymcfunction/commands/time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pymcfunction.types import TimePreset, TimeQueryType


class time:
def __init__(self) -> None:
pass

def add(self, _time: int):
return f"time add {_time}"

def set(self, _time: int | TimePreset):
return "time set " + (str(_time) if type(_time) == int else _time.value)

def query(self, type: TimeQueryType):
return f"time query {type.value}"
18 changes: 18 additions & 0 deletions pymcfunction/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,21 @@ class Difficultiy(Enum):
EASY = "easy"
NORMAL = "normal"
HARD = "hard"


class ExperienceUnit(Enum):
LEVELS = "levels"
POINTS = "points"


class TimeQueryType(Enum):
DAYTIME = "daytime"
GAMETIME = "gametime"
DAY = "day"


class TimePreset(Enum):
DAY = "day"
NIGHT = "night"
NOON = "noon"
MIDNIGHT = "midnight"
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pymcfunction"
version = "0.1.5"
version = "0.1.6"
description = "PyMCFunction is a tool to write Minecraft datapacks in Python."
authors = ["PaddeCraft <paddecraft@gmail.com>"]
include = [
Expand All @@ -11,9 +11,9 @@ repository = "https://github.com/PaddeCraft/PyMCFunction"
keywords = ["python", "minecraft", "toml", "cli"]

[tool.poetry.scripts]
pymcfunction = "pymcfunction.cli.app:run"
pyfunction = "pymcfunction.cli.app:run"
pmf = "pymcfunction.cli.app:run"
pymcfunction = "pymcfunction.cli:app"
pyfunction = "pymcfunction.cli:app"
pmf = "pymcfunction.cli:app"

[tool.poetry.dependencies]
python = "^3.10"
Expand Down
8 changes: 8 additions & 0 deletions test/data/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@
item().replaceBlock("~ ~ ~", "0", Item.DIAMOND)

tag("@s").add("test")

effect("@e").give(Effect.DARKNESS)
effect("@e").give(Effect.DARKNESS, 12)
effect("@e").give(Effect.DARKNESS, 12, 255)
effect("@e").give(Effect.DARKNESS, 12, 255, True)

effect("@e").clear()
effect("@e").clear(Effect.DARKNESS)
3 changes: 2 additions & 1 deletion test/pymcfunctionconfig.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace = "testdp"
compiled_folder_name = "testdpfolder"
description = "Test datapack"
datapack_folder = "/run/media/paddecraft/4EE0F299E0F2870D/Dev/PythonScripting/pyfunction/test"
#datapack_folder = "/run/media/paddecraft/4EE0F299E0F2870D/Dev/PythonScripting/PyMCFunction/test"
datapack_folder = "."
pack_version = 10

[includes]

0 comments on commit 03a25d6

Please sign in to comment.