From 2c337aa11cdc5dfa8c28ef974d13533dc992597f Mon Sep 17 00:00:00 2001 From: twoone3 <3197653242@qq.com> Date: Sun, 10 Jul 2022 17:24:39 +0800 Subject: [PATCH] =?UTF-8?q?2.0.3=E6=9B=B4=E6=96=B0=20-=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E7=BC=BA=E5=A4=B1=E7=9A=84=E5=87=A0=E4=B8=AA=E6=9E=9A?= =?UTF-8?q?=E4=B8=BE=E5=80=BC=20-=20=E6=9B=B4=E6=94=B9NbtClass=E4=B8=BANBT?= =?UTF-8?q?Class=20-=20=E5=AE=8C=E5=96=84mc.pyi=20-=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E5=B0=8F=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API/EntityAPI.cpp | 7 +--- API/EntityAPI.h | 7 ++-- API/EventAPI.cpp | 2 +- API/PlayerAPI.h | 2 +- Example/mc.pyi | 105 ++++++++++++++++++++++++++++++---------------- Init.cpp | 4 +- ModuleDef.cpp | 22 +++++----- 7 files changed, 90 insertions(+), 59 deletions(-) diff --git a/API/EntityAPI.cpp b/API/EntityAPI.cpp index 38b744e..ba7a2cf 100644 --- a/API/EntityAPI.cpp +++ b/API/EntityAPI.cpp @@ -137,15 +137,12 @@ bool EntityClass::isItemEntity() { return thiz->isItemActor(); } -EntityClass EntityClass::toItem() { +ItemClass EntityClass::toItem() { if (thiz == nullptr) return nullptr; if (!thiz->isItemActor()) return nullptr; - auto it = (ItemActor*)thiz; - if (!it) - return nullptr; - return reinterpret_cast(it->getItemStack()); + return reinterpret_cast(thiz)->getItemStack(); } BlockClass EntityClass::getBlockStandingOn() { diff --git a/API/EntityAPI.h b/API/EntityAPI.h index d862b42..c14945c 100644 --- a/API/EntityAPI.h +++ b/API/EntityAPI.h @@ -2,10 +2,11 @@ #include class Actor; -struct ContainerClass; -struct PlayerClass; struct BlockClass; +struct ContainerClass; +struct ItemClass; struct NBTClass; +struct PlayerClass; struct EntityClass { Actor* thiz; @@ -33,7 +34,7 @@ struct EntityClass { bool isPlayer(); PlayerClass toPlayer(); bool isItemEntity(); - EntityClass toItem(); + ItemClass toItem(); BlockClass getBlockStandingOn(); ContainerClass getArmor(); bool hasContainer(); diff --git a/API/EventAPI.cpp b/API/EventAPI.cpp index 8800730..918219b 100644 --- a/API/EventAPI.cpp +++ b/API/EventAPI.cpp @@ -18,7 +18,7 @@ using namespace std; class Callbacker { public: Callbacker(EventCode t) : type_(t), arg_() {} - //事件回调 + bool callback() { bool pass = true; arg_.inc_ref(); // TODO: 为什么需要增加引用计数? diff --git a/API/PlayerAPI.h b/API/PlayerAPI.h index a4819c1..868d385 100644 --- a/API/PlayerAPI.h +++ b/API/PlayerAPI.h @@ -147,6 +147,6 @@ struct PlayerClass { string getOs(); string getClientId(); - bool removeItem(int inventory_id, int count); + bool removeItem(int slot, int count); bool setHeadShow(const string& name); }; \ No newline at end of file diff --git a/Example/mc.pyi b/Example/mc.pyi index 8b1691d..ceeaafe 100644 --- a/Example/mc.pyi +++ b/Example/mc.pyi @@ -723,6 +723,12 @@ class Player: ) -> Block: pass + def removeItem(self, slot, num) -> bool: + pass + + def setHeadShow(self, text) -> bool: + pass + # SimulatedPlayer API def isSimulatedPlayer(self) -> bool: pass @@ -742,30 +748,54 @@ class Player: def simulateInteract(self) -> bool: pass + def simulateInteractEntity(self, target: Entity) -> bool: + pass + + def simulateInteractBlock(self, pos, face: ScriptFacing) -> bool: + pass + def simulateJump(self) -> bool: pass - def simulateLocalMove(self) -> bool: + def simulateLocalMove(self, target, speed=1.0) -> bool: pass - def simulateWorldMove(self) -> bool: + def simulateWorldMove(self, target, speed=1.0) -> bool: pass - def simulateMoveTo(self) -> bool: + def simulateMoveTo(self, target, speed=1.0) -> bool: pass - def simulateLookAt(self) -> bool: + def simulateLookAt(self, target) -> bool: pass - def simulateSetBodyRotation(self) -> bool: + def simulateSetBodyRotation(self, rotation: float) -> bool: pass - def simulateNavigateTo(self) -> bool: + def simulateNavigateTo( + self, path_or_target: list[Vec3] or Entity or Vec3, speed=1.0 + ) -> bool: pass def simulateUseItem(self) -> bool: pass + def simulateUseItem2(self, slot) -> bool: + pass + + def simulateUseItem3(self, item) -> bool: + pass + + def simulateUseItem4( + self, item, pos, face, relativePos=Vec3(0.5, 0.5, 0.5) + ) -> bool: + pass + + def simulateUseItem5( + self, slot, pos, face, relativePos=Vec3(0.5, 0.5, 0.5) + ) -> bool: + pass + def simulateStopDestroyingBlock(self) -> bool: pass @@ -781,12 +811,6 @@ class Player: def simulateStopSneaking(self) -> bool: pass - def removeItem(self, slot, num) -> bool: - pass - - def setHeadShow(self, text) -> bool: - pass - class Entity: name: str @@ -803,67 +827,74 @@ class Entity: direction: Vec2 unique_id: str - def teleport(self) -> bool: + def teleport(self, pos, dim) -> bool: pass def kill(self) -> bool: pass - def hurt(self) -> bool: + def hurt(self, damage) -> bool: pass - def setOnFire(self) -> bool: + def setOnFire(self, value) -> bool: pass def isPlayer(self) -> bool: pass - def toPlayer(self) -> bool: + def toPlayer(self) -> Player: pass def isItemEntity(self) -> bool: pass - def toItem(self) -> bool: + def toItem(self) -> Item: pass - def getBlockStandingOn(self) -> bool: + def getBlockStandingOn(self) -> Block: pass - def getArmor(self) -> bool: + def getArmor(self) -> Container: pass def hasContainer(self) -> bool: pass - def getContainer(self) -> bool: + def getContainer(self) -> Container: pass def refreshItems(self) -> bool: pass - def setNbt(self) -> bool: + def setNbt(self, nbt) -> bool: pass - def getNbt(self) -> bool: + def getNbt(self) -> NBT: pass - def addTag(self) -> bool: + def addTag(self, tag) -> bool: pass - def removeTag(self) -> bool: + def removeTag(self, tag) -> bool: pass - def hasTag(self) -> bool: + def hasTag(self, tag) -> bool: pass - def getAllTags(self) -> bool: + def getAllTags(self) -> list[str]: pass - def getEntityFromViewVector(self) -> bool: + def getEntityFromViewVector(self, max_distance=5.25) -> Entity: pass - def getBlockFromViewVector(self) -> bool: + def getBlockFromViewVector( + self, + includeLiquid=False, + solidOnly=False, + maxDistance=5.25, + ignoreBorderBlocks=True, + fullOnly=False, + ) -> Block: pass @@ -871,13 +902,13 @@ class BlockEntity: pos: Vec3 type: str - def setNbt(self) -> bool: + def setNbt(self, nbt) -> bool: pass - def getNbt(self) -> bool: + def getNbt(self) -> NBT: pass - def getBlock(self) -> bool: + def getBlock(self) -> Block: pass @@ -885,22 +916,22 @@ class Objective: name: str display_name: str - def setDisplay(self) -> bool: + def setDisplay(self, slot: str, sort=0) -> bool: pass - def setScore(self) -> bool: + def setScore(self, id, score) -> bool: pass - def addScore(self) -> bool: + def addScore(self, id, score) -> bool: pass - def reduceScore(self) -> bool: + def reduceScore(self, id, score) -> bool: pass - def deleteScore(self) -> bool: + def deleteScore(self, id) -> bool: pass - def getScore(self) -> bool: + def getScore(self, id) -> bool: pass diff --git a/Init.cpp b/Init.cpp index 338c6d9..6f38afe 100644 --- a/Init.cpp +++ b/Init.cpp @@ -8,8 +8,8 @@ using namespace std; constexpr unsigned PYR_VERSION_MAJOR = 2; constexpr unsigned PYR_VERSION_MINOR = 0; -constexpr unsigned PYR_VERSION_MICRO = 2; -constexpr const char* PYR_VERSION = "v2.0.2"; +constexpr unsigned PYR_VERSION_MICRO = 3; +constexpr const char* PYR_VERSION = "v2.0.3"; void entry() { PY_TRY; diff --git a/ModuleDef.cpp b/ModuleDef.cpp index bda29e4..f40e504 100644 --- a/ModuleDef.cpp +++ b/ModuleDef.cpp @@ -310,6 +310,9 @@ PYBIND11_EMBEDDED_MODULE(mc, mc_module) { .def("getBlockFromViewVector", &PlayerClass::getBlockFromViewVector, "includeLiquid"_a = false, "solidOnly"_a = false, "maxDistance"_a = 5.25f, "ignoreBorderBlocks"_a = true, "fullOnly"_a = false) + .def("removeItem", &PlayerClass::removeItem) + .def("setHeadShow", &PlayerClass::setHeadShow) + // SimulatedPlayer API .def("isSimulatedPlayer", &PlayerClass::isSimulatedPlayer) .def("simulateSneak", &PlayerClass::simulateSneak) @@ -319,8 +322,8 @@ PYBIND11_EMBEDDED_MODULE(mc, mc_module) { .def("simulateDestory", py::overload_cast(&PlayerClass::simulateDestory)) .def("simulateDisconnect", &PlayerClass::simulateDisconnect) .def("simulateInteract", py::overload_cast<>(&PlayerClass::simulateInteract)) - .def("simulateInteract", py::overload_cast(&PlayerClass::simulateInteract)) - .def("simulateInteract", py::overload_cast(&PlayerClass::simulateInteract)) + .def("simulateInteractEntity", py::overload_cast(&PlayerClass::simulateInteract)) + .def("simulateInteractBlock", py::overload_cast(&PlayerClass::simulateInteract)) .def("simulateJump", &PlayerClass::simulateJump) .def("simulateLocalMove", &PlayerClass::simulateLocalMove, "target"_a, "speed"_a = 1.0f) .def("simulateWorldMove", &PlayerClass::simulateWorldMove, "target"_a, "speed"_a = 1.0f) @@ -330,22 +333,21 @@ PYBIND11_EMBEDDED_MODULE(mc, mc_module) { .def("simulateLookAt", py::overload_cast(&PlayerClass::simulateLookAt)) .def("simulateSetBodyRotation", &PlayerClass::simulateSetBodyRotation) .def("simulateNavigateTo", py::overload_cast, float>(&PlayerClass::simulateNavigateTo), "path"_a, "speed"_a = 1.0f) - .def("simulateNavigateTo", py::overload_cast(&PlayerClass::simulateNavigateTo), "poa"_a, "speed"_a = 1.0f) + .def("simulateNavigateTo", py::overload_cast(&PlayerClass::simulateNavigateTo), "pos"_a, "speed"_a = 1.0f) .def("simulateNavigateTo", py::overload_cast(&PlayerClass::simulateNavigateTo), "target"_a, "speed"_a = 1.0f) .def("simulateUseItem", py::overload_cast<>(&PlayerClass::simulateUseItem)) - .def("simulateUseItem", py::overload_cast(&PlayerClass::simulateUseItem)) - .def("simulateUseItem", py::overload_cast(&PlayerClass::simulateUseItem)) - .def("simulateUseItem", py::overload_cast(&PlayerClass::simulateUseItem), + .def("simulateUseItem2", py::overload_cast(&PlayerClass::simulateUseItem)) + .def("simulateUseItem3", py::overload_cast(&PlayerClass::simulateUseItem)) + .def("simulateUseItem4", py::overload_cast(&PlayerClass::simulateUseItem), "item"_a, "pos"_a, "face"_a, "relativePos"_a = Vec3(0.5, 0.5, 0.5)) - .def("simulateUseItem", py::overload_cast(&PlayerClass::simulateUseItem), + .def("simulateUseItem5", py::overload_cast(&PlayerClass::simulateUseItem), "slot"_a, "pos"_a, "face"_a, "relativePos"_a = Vec3(0.5, 0.5, 0.5)) .def("simulateStopDestroyingBlock", &PlayerClass::simulateStopDestroyingBlock) .def("simulateStopInteracting", &PlayerClass::simulateStopInteracting) .def("simulateStopMoving", &PlayerClass::simulateStopMoving) .def("simulateStopUsingItem", &PlayerClass::simulateStopUsingItem) - .def("simulateStopSneaking", &PlayerClass::simulateStopSneaking) + .def("simulateStopSneaking", &PlayerClass::simulateStopSneaking); - .def("removeItem", &PlayerClass::removeItem); py::class_(mc_module, "Entity") .def_property("name", &EntityClass::getName, nullptr) @@ -396,7 +398,7 @@ PYBIND11_EMBEDDED_MODULE(mc, mc_module) { .def_property("name", &ObjectiveClass::getName, nullptr) .def_property("display_name", &ObjectiveClass::getDisplayName, nullptr) - .def("setDisplay", &ObjectiveClass::setDisplay) + .def("setDisplay", &ObjectiveClass::setDisplay, "slot"_a, "sort"_a=0) .def("setScore", &ObjectiveClass::setScore) .def("addScore", &ObjectiveClass::addScore) .def("reduceScore", &ObjectiveClass::reduceScore)