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

Commit

Permalink
2.0.3更新
Browse files Browse the repository at this point in the history
- 新增缺失的几个枚举值
- 更改NbtClass为NBTClass
- 完善mc.pyi
- 修复一些小错误
  • Loading branch information
twoone3 committed Jul 10, 2022
1 parent e26df36 commit 2c337aa
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 59 deletions.
7 changes: 2 additions & 5 deletions API/EntityAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Actor*>(it->getItemStack());
return reinterpret_cast<ItemActor*>(thiz)->getItemStack();
}

BlockClass EntityClass::getBlockStandingOn() {
Expand Down
7 changes: 4 additions & 3 deletions API/EntityAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#include <Global.hpp>

class Actor;
struct ContainerClass;
struct PlayerClass;
struct BlockClass;
struct ContainerClass;
struct ItemClass;
struct NBTClass;
struct PlayerClass;
struct EntityClass {
Actor* thiz;

Expand Down Expand Up @@ -33,7 +34,7 @@ struct EntityClass {
bool isPlayer();
PlayerClass toPlayer();
bool isItemEntity();
EntityClass toItem();
ItemClass toItem();
BlockClass getBlockStandingOn();
ContainerClass getArmor();
bool hasContainer();
Expand Down
2 changes: 1 addition & 1 deletion API/EventAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: 为什么需要增加引用计数?
Expand Down
2 changes: 1 addition & 1 deletion API/PlayerAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
105 changes: 68 additions & 37 deletions Example/mc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -803,104 +827,111 @@ 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


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


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


Expand Down
4 changes: 2 additions & 2 deletions Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 12 additions & 10 deletions ModuleDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -319,8 +322,8 @@ PYBIND11_EMBEDDED_MODULE(mc, mc_module) {
.def("simulateDestory", py::overload_cast<const BlockPos&, ScriptFacing>(&PlayerClass::simulateDestory))
.def("simulateDisconnect", &PlayerClass::simulateDisconnect)
.def("simulateInteract", py::overload_cast<>(&PlayerClass::simulateInteract))
.def("simulateInteract", py::overload_cast<const EntityClass&>(&PlayerClass::simulateInteract))
.def("simulateInteract", py::overload_cast<const BlockPos&, ScriptFacing>(&PlayerClass::simulateInteract))
.def("simulateInteractEntity", py::overload_cast<const EntityClass&>(&PlayerClass::simulateInteract))
.def("simulateInteractBlock", py::overload_cast<const BlockPos&, ScriptFacing>(&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)
Expand All @@ -330,22 +333,21 @@ PYBIND11_EMBEDDED_MODULE(mc, mc_module) {
.def("simulateLookAt", py::overload_cast<const BlockPos&>(&PlayerClass::simulateLookAt))
.def("simulateSetBodyRotation", &PlayerClass::simulateSetBodyRotation)
.def("simulateNavigateTo", py::overload_cast<vector<Vec3>, float>(&PlayerClass::simulateNavigateTo), "path"_a, "speed"_a = 1.0f)
.def("simulateNavigateTo", py::overload_cast<const Vec3&, float>(&PlayerClass::simulateNavigateTo), "poa"_a, "speed"_a = 1.0f)
.def("simulateNavigateTo", py::overload_cast<const Vec3&, float>(&PlayerClass::simulateNavigateTo), "pos"_a, "speed"_a = 1.0f)
.def("simulateNavigateTo", py::overload_cast<const EntityClass&, float>(&PlayerClass::simulateNavigateTo), "target"_a, "speed"_a = 1.0f)
.def("simulateUseItem", py::overload_cast<>(&PlayerClass::simulateUseItem))
.def("simulateUseItem", py::overload_cast<int>(&PlayerClass::simulateUseItem))
.def("simulateUseItem", py::overload_cast<const ItemClass&>(&PlayerClass::simulateUseItem))
.def("simulateUseItem", py::overload_cast<const ItemClass&, const BlockPos&, ScriptFacing, const Vec3&>(&PlayerClass::simulateUseItem),
.def("simulateUseItem2", py::overload_cast<int>(&PlayerClass::simulateUseItem))
.def("simulateUseItem3", py::overload_cast<const ItemClass&>(&PlayerClass::simulateUseItem))
.def("simulateUseItem4", py::overload_cast<const ItemClass&, const BlockPos&, ScriptFacing, const Vec3&>(&PlayerClass::simulateUseItem),
"item"_a, "pos"_a, "face"_a, "relativePos"_a = Vec3(0.5, 0.5, 0.5))
.def("simulateUseItem", py::overload_cast<int, const BlockPos&, ScriptFacing, const Vec3&>(&PlayerClass::simulateUseItem),
.def("simulateUseItem5", py::overload_cast<int, const BlockPos&, ScriptFacing, const Vec3&>(&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_<EntityClass>(mc_module, "Entity")
.def_property("name", &EntityClass::getName, nullptr)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2c337aa

Please sign in to comment.