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

Commit

Permalink
2.0.8更新
Browse files Browse the repository at this point in the history
- 修复上版本的监听器小错误
- 修复getBlock的错误
- 更新了pybind11和magic_enum
  • Loading branch information
twoone3 committed Jul 30, 2022
1 parent 2290c76 commit ad8b783
Show file tree
Hide file tree
Showing 37 changed files with 2,277 additions and 863 deletions.
1 change: 1 addition & 0 deletions API/CommandAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <MC/ItemStack.hpp>
#include <MC/JsonHelpers.hpp>
#include <MC/MobEffect.hpp>
#include <LoggerAPI.h>

py::object convertResult(const DynamicCommand::Result& result) {
if (!result.isSet)
Expand Down
1 change: 1 addition & 0 deletions API/CommandOriginAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <MC/Command.hpp>
#include <MC/CommandOrigin.hpp>
#include <MC/Dimension.hpp>
#include <magic_enum/magic_enum.hpp>

CommandOriginClass::CommandOriginClass(CommandOrigin* p) : thiz(p) {}

Expand Down
2 changes: 2 additions & 0 deletions API/CommandOriginAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ struct EntityClass;
struct PlayerClass;
struct NBTClass;
class CommandOrigin;
class BlockPos;
class Vec3;
struct CommandOriginClass {
CommandOrigin* thiz;

Expand Down
29 changes: 0 additions & 29 deletions API/LoggerAPI.cpp

This file was deleted.

19 changes: 0 additions & 19 deletions API/LoggerAPI.h

This file was deleted.

8 changes: 7 additions & 1 deletion API/McAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <MC/SimulatedPlayer.hpp>
#include <MC/Spawner.hpp>
#include <MC/SignBlockActor.hpp>
#include <LoggerAPI.h>

namespace mc {
void setListener(const string& event_name, const py::function& cb) {
Expand Down Expand Up @@ -65,7 +66,12 @@ py::list getAllEntities() {
}

BlockClass getBlock(const BlockPos& pos, int dim) {
return BlockInstance::createBlockInstance(Level::getBlock(pos, dim), pos, dim);
if (Global<Level> == nullptr)
throw std::runtime_error("Level is not loaded");
Block* b = Level::getBlockEx(pos, dim);
if (b == nullptr)
throw py::value_error("Failed to find block");
return BlockInstance::createBlockInstance(b, pos, dim);
}

bool setBlock(const BlockPos& pos, int dim, const string& name, int tile_data) {
Expand Down
1 change: 1 addition & 0 deletions API/PlayerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <MC/SimulatedPlayer.hpp>
#include <MC/Level.hpp>
#include <MC/Packet.hpp>
#include <LoggerAPI.h>

py::dict NavigateResultToObject(const ScriptModuleMinecraft::ScriptNavigationResult& res) {
py::dict obj;
Expand Down
3 changes: 1 addition & 2 deletions BDSpyrunner.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<ErrorReporting>Send</ErrorReporting>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -79,7 +80,6 @@ copy $(OutputPath)$(ProjectName).pdb ..\BDS\plugins\$(ProjectName).pdb
<ClCompile Include="API\EntityAPI.cpp" />
<ClCompile Include="API\EventAPI.cpp" />
<ClCompile Include="API\ItemAPI.cpp" />
<ClCompile Include="API\LoggerAPI.cpp" />
<ClCompile Include="API\McAPI.cpp" />
<ClCompile Include="API\NBTAPI.cpp" />
<ClCompile Include="API\PlayerAPI.cpp" />
Expand All @@ -99,7 +99,6 @@ copy $(OutputPath)$(ProjectName).pdb ..\BDS\plugins\$(ProjectName).pdb
<ClInclude Include="API\EntityAPI.h" />
<ClInclude Include="API\EventAPI.h" />
<ClInclude Include="API\ItemAPI.h" />
<ClInclude Include="API\LoggerAPI.h" />
<ClInclude Include="API\McAPI.h" />
<ClInclude Include="API\NBTAPI.h" />
<ClInclude Include="API\PlayerAPI.h" />
Expand Down
6 changes: 0 additions & 6 deletions BDSpyrunner.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@
<ClCompile Include="API\ItemAPI.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="API\LoggerAPI.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="API\McAPI.cpp">
<Filter>源文件</Filter>
</ClCompile>
Expand Down Expand Up @@ -101,9 +98,6 @@
<ClInclude Include="API\ItemAPI.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="API\LoggerAPI.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="API\McAPI.h">
<Filter>头文件</Filter>
</ClInclude>
Expand Down
11 changes: 1 addition & 10 deletions Global.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
#include "Global.hpp"

fifo_json StrToJson(std::string_view str) {
try {
return fifo_json::parse(str);
}
catch (const std::exception& e) {
logger.error("\nParsing JSON failed! {}", e.what());
return nullptr;
}
}
#include <LoggerAPI.h>

Logger logger("BDSpyrunner");

Expand Down
21 changes: 8 additions & 13 deletions Global.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#pragma once
#pragma execution_character_set("utf-8")
#include <LoggerAPI.h>

#include <third-party/magic_enum/magic_enum.hpp>
#include <third-party/Nlohmann/fifo_json.hpp>

#include <pybind11/embed.h>
#include <pybind11/stl.h>

Expand All @@ -21,19 +15,20 @@

namespace py = pybind11;
using std::unique_ptr;
using std::string;
using std::string_view;
using std::vector;
using std::unordered_map;

enum GameType {
Survival = 0,
Creative = 1,
Adventure = 2,
Spectator = 6,
};

// 全局变量
enum class EventCode;
class Logger;

extern Logger logger;
extern std::unordered_map<enum class EventCode, std::vector<py::function>> listeners;
extern std::unordered_map<string, py::object> player_data;

// 字符串转JSON
fifo_json StrToJson(std::string_view str);
extern unordered_map<EventCode, vector<py::function>> listeners;
extern unordered_map<string, py::object> player_data;
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 = 7;
constexpr const char* PYR_VERSION = "v2.0.7";
constexpr unsigned PYR_VERSION_MICRO = 8;
constexpr const char* PYR_VERSION = "v2.0.8";

void entry() {
PY_TRY;
Expand Down
29 changes: 18 additions & 11 deletions ModuleDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
#include <API/EntityAPI.h>
#include <API/MoneyAPI.h>
#include <API/NBTAPI.h>
#include <API/LoggerAPI.h>
#include <API/PlayerAPI.h>
#include <API/ScoreboardAPI.h>
#include <API/McAPI.h>

#include <MC/Level.hpp>
#include <LoggerAPI.h>

// clang-format off
#define DEF_ENUM(name, type) { auto entries = magic_enum::enum_entries<type>(); auto e = py::enum_<type>(mc_module, name); for (auto& [val, n] : entries) { e.value(n.data(), val); } }
Expand Down Expand Up @@ -203,17 +203,24 @@ PYBIND11_EMBEDDED_MODULE(mc, mc_module) {
.def("toSNBT", &NBTClass::toSNBT, "indent"_a = 4, "format"_a = SnbtFormat::PartialNewLine)
.def("append", &NBTClass::append);

py::class_<LoggerClass>(mc_module, "Logger")
py::class_<Logger>(mc_module, "Logger")
.def(py::init<string>(), "title"_a)
.def("debug", &LoggerClass::debug)
.def("info", &LoggerClass::info)
.def("warn", &LoggerClass::warn)
.def("error", &LoggerClass::error)
.def("fatal", &LoggerClass::fatal)

.def("setTitle", &LoggerClass::setTitle)
.def("setFile", &LoggerClass::setFile)
.def("setPlayer", &LoggerClass::setPlayer);
.def("debug", [](Logger& l, const string& msg) { l.debug(msg); })
.def("info", [](Logger& l, const string& msg) { l.info(msg); })
.def("warn", [](Logger& l, const string& msg) { l.warn(msg); })
.def("error", [](Logger& l, const string& msg) { l.error(msg); })
.def("fatal", [](Logger& l, const string& msg) { l.fatal(msg); })

.def("setTitle", [](Logger& l, const string& title) { l.title = title; })
.def("setFile", [](Logger& l, const string& file, int level) {
l.setFile(file, std::ios::app);
l.fileLevel = level;
return l.ofs.is_open();
})
.def("setPlayer", [](Logger& l, const PlayerClass& player, int level) {
l.player = player.thiz;
l.playerLevel = level;
});

py::class_<PlayerClass>(mc_module, "Player")
.def_property("name", &PlayerClass::getName, nullptr)
Expand Down
2 changes: 1 addition & 1 deletion SDK
Submodule SDK updated from 16bc6a to 8444c3
Loading

0 comments on commit ad8b783

Please sign in to comment.