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

Commit

Permalink
完善Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
twoone3l committed Jan 29, 2022
1 parent ff336bb commit 7b7dab0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 41 deletions.
7 changes: 2 additions & 5 deletions cpp.hint
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
#define METH_NOARGS
#define METH_VARARGS
#define METH_KEYWORDS
#define GET_PLAYER Player* p = asPlayer(self);if (p == nullptr)return nullptr
#define Py_METHOD_VARARGS(name) {#name, reinterpret_cast<PyCFunction>(name), METH_VARARGS, nullptr}
#define Py_METHOD_VARARGS(name) {#name, reinterpret_cast<PyCFunction>(name), METH_VARARGS, nullptr}
#define Py_METHOD_END {nullptr, nullptr, 0, nullptr}
2 changes: 1 addition & 1 deletion mod/CPython.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define Py_METHOD_VARARGS(name) {#name, reinterpret_cast<PyCFunction>(name), METH_VARARGS, nullptr}
#define Py_METHOD_NOARGS(name) {#name, reinterpret_cast<PyCFunction>(name), METH_NOARGS, nullptr}
#define Py_METHOD_KEYWORDS(name) {#name, reinterpret_cast<PyCFunction>(name), METH_VARARGS | METH_KEYWORDS, nullptr}

#define Py_METHOD_END {nullptr, nullptr, 0, nullptr}
#define Py_METHOD_DEFINE(name) static PyObject* name(PyObject * self, PyObject* args)

//#define Py_BEGIN_CALL\
Expand Down
10 changes: 5 additions & 5 deletions mod/Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,14 @@ void EnableEventListener(EventCode code) {
break;
case EventCode::onOpenContainer:
EVENT_BEGIN(PlayerOpenContainerEvent);
// todo container
//TODO: container
EVENT_INSERT(BlockInstance);
EVENT_INSERT(Player);
EVENT_END;
break;
case EventCode::onCloseContainer:
EVENT_BEGIN(PlayerCloseContainerEvent);
//todo
//TODO: container
EVENT_INSERT(BlockInstance);
EVENT_INSERT(Player);
EVENT_END;
Expand Down Expand Up @@ -377,12 +377,11 @@ void EnableEventListener(EventCode code) {
EVENT_INSERT2(ObjectiveName, e.mObjective->getName());
EVENT_INSERT(Player);
EVENT_INSERT(Score);
//todo
//TODO: more info about Objective
EVENT_END;
break;
case EventCode::onServerStarted:
EVENT_BEGIN(ServerStartedEvent);
e;
EVENT_END;
break;
case EventCode::onConsoleCmd:
Expand Down Expand Up @@ -410,7 +409,8 @@ void EnableEventListener(EventCode code) {
case EventCode::onConsumeTotem:
break;
case EventCode::onEffectChanged:
EVENT_BEGIN(PlayerEffectChangedEvent);//todo
EVENT_BEGIN(PlayerEffectChangedEvent);
//TODO: more info about Effect
EVENT_INSERT2(Effect, e.mEffect->getDisplayName());
EVENT_INSERT(Player);
EVENT_INSERT2(Type, magic_enum::enum_name(e.mEventType));
Expand Down
67 changes: 37 additions & 30 deletions mod/PyEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,13 @@ struct PyEntity {
//发送数据包
Py_METHOD_DEFINE(sendTextPacket) {
const char* msg = "";
int mode = 0;
TextType mode = TextType::RAW;
Py_PARSE("s|i", &msg, &mode);
Py_GET_PLAYER;
p->sendTextPacket(msg, TextType(mode));
p->sendTextPacket(msg, mode);
Py_RETURN_NONE;
}
Py_METHOD_DEFINE(sendCommandPacket) {
Py_METHOD_DEFINE(runCommandAs) {
const char* cmd = "";
Py_PARSE("s", &cmd);
Py_GET_PLAYER;
Expand Down Expand Up @@ -328,6 +328,13 @@ struct PyEntity {
p->reduceScore(objname, count);
Py_RETURN_NONE;
}
//获取等级
Py_METHOD_DEFINE(getLevel) {
Py_GET_PLAYER;
//p->getex();
//TODO: get levels from player
Py_RETURN_NONE;
}
//增加等级
Py_METHOD_DEFINE(addLevel) {
int level;
Expand Down Expand Up @@ -434,14 +441,14 @@ struct PyEntity {
float per;
Py_PARSE("sf", &name, &per);
Py_GET_PLAYER;
p->sendBossEventPacket(BossEvent::Show, name, per, BossEventColour::Red); // Todo
p->sendBossEventPacket(BossEvent::Show, name, per, BossEventColour::Red);
Py_RETURN_NONE;
}
Py_METHOD_DEFINE(removeBossbar) {
const char* name = "";
Py_PARSE("s:removeBossbar", &name);
Py_GET_PLAYER;
p->sendBossEventPacket(BossEvent::Hide, name, 0, BossEventColour::Red); // Todo
p->sendBossEventPacket(BossEvent::Hide, name, 0, BossEventColour::Red);
Py_RETURN_NONE;
}
//标签
Expand Down Expand Up @@ -498,31 +505,31 @@ struct PyEntity {
Py_METHOD_VARARGS(setAllItem),
Py_METHOD_VARARGS(setHand),
Py_METHOD_VARARGS(addItem),
{ "addItem", addItem, METH_VARARGS, nullptr },
{ "removeItem", removeItem, METH_VARARGS, nullptr },
{ "teleport", teleport, METH_VARARGS, nullptr },
{ "sendTextPacket", sendTextPacket, METH_VARARGS, nullptr },
{ "sendCommandPacket", sendCommandPacket, METH_VARARGS, nullptr },
{ "resendAllChunks", resendAllChunks, METH_NOARGS, nullptr },
{ "disconnect", disconnect, METH_VARARGS, nullptr },
{ "getScore", getScore, METH_VARARGS, nullptr },
{ "setScore", setScore, METH_VARARGS, nullptr },
{ "addScore", addScore, METH_VARARGS, nullptr },
{ "reduceScore", reduceScore, METH_VARARGS, nullptr },
{ "addLevel", addLevel, METH_VARARGS, nullptr },
{ "transferServer", transferServer, METH_VARARGS, nullptr },
{ "sendCustomForm", sendCustomForm, METH_VARARGS, nullptr },
{ "sendSimpleForm", sendSimpleForm, METH_VARARGS, nullptr },
{ "sendModalForm", sendModalForm, METH_VARARGS, nullptr },
{ "setSidebar", setSidebar, METH_VARARGS, nullptr },
{ "removeSidebar", removeSidebar, METH_NOARGS, nullptr },
{ "setBossbar", setBossbar, METH_VARARGS, nullptr },
{ "removeBossbar", removeBossbar, METH_NOARGS, nullptr },
{ "addTag", addTag, METH_VARARGS, nullptr },
{ "removeTag", removeTag, METH_VARARGS, nullptr },
{ "getTags", getTags, METH_NOARGS, nullptr },
{ "kill", kill, METH_NOARGS, nullptr },
{ nullptr }
Py_METHOD_VARARGS(removeItem),
Py_METHOD_VARARGS(teleport),
Py_METHOD_VARARGS(sendTextPacket),
Py_METHOD_VARARGS(runCommandAs),
Py_METHOD_VARARGS(resendAllChunks),
Py_METHOD_VARARGS(disconnect),
Py_METHOD_VARARGS(getScore),
Py_METHOD_VARARGS(setScore),
Py_METHOD_VARARGS(addScore),
Py_METHOD_VARARGS(reduceScore),
Py_METHOD_VARARGS(getLevel),
Py_METHOD_VARARGS(addLevel),
Py_METHOD_VARARGS(transferServer),
Py_METHOD_VARARGS(sendCustomForm),
Py_METHOD_VARARGS(sendSimpleForm),
Py_METHOD_VARARGS(sendModalForm),
Py_METHOD_VARARGS(setSidebar),
Py_METHOD_VARARGS(removeSidebar),
Py_METHOD_VARARGS(setBossbar),
Py_METHOD_VARARGS(removeBossbar),
Py_METHOD_VARARGS(addTag),
Py_METHOD_VARARGS(removeTag),
Py_METHOD_VARARGS(getTags),
Py_METHOD_VARARGS(kill),
Py_METHOD_END
};
};
//Entity类型
Expand Down

0 comments on commit 7b7dab0

Please sign in to comment.