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

Commit

Permalink
update clang-format
Browse files Browse the repository at this point in the history
fix registerCommand error
fix mc.pyi
  • Loading branch information
twoone3 committed Jul 24, 2022
1 parent ed4b68e commit b32e6d1
Show file tree
Hide file tree
Showing 34 changed files with 1,144 additions and 1,145 deletions.
25 changes: 17 additions & 8 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Author: twoone-3
# Reference: https://releases.llvm.org/13.0.0/tools/clang/docs/ClangFormatStyleOptions.html

# General Options
BasedOnStyle: LLVM
Language: Cpp
Standard: Auto
TabWidth: 4
UseTab: ForIndentation

# Other Options
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignArrayOfStructures: Left
Expand All @@ -10,31 +18,34 @@ AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: None
AlignEscapedNewlines: Left
AlignOperands: DontAlign
AlignTrailingComments: false
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: false
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BasedOnStyle: LLVM
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Attach
BreakBeforeBraces: Custom
BraceWrapping:
BeforeCatch: true
BeforeElse: true
BeforeWhile: true
ColumnLimit: 0
Cpp11BracedListStyle: true
EmptyLineAfterAccessModifier: Leave
FixNamespaceComments: true
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PointerAlignment: Left
Expand All @@ -45,10 +56,8 @@ SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeParens: ControlStatements
SpacesBeforeTrailingComments: 0
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Latest
TabWidth: 4
UseTab: Always
2 changes: 1 addition & 1 deletion API/BlockAPI.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "BlockAPI.h"
#include "BlockAPI.h"
#include "McAPI.h"
#include "ContainerAPI.h"
#include "BlockEntityAPI.h"
Expand Down
2 changes: 1 addition & 1 deletion API/BlockAPI.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <Global.hpp>
#include <MC/BlockInstance.hpp>

Expand Down
2 changes: 1 addition & 1 deletion API/BlockEntityAPI.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "BlockAPI.h"
#include "BlockAPI.h"
#include "BlockEntityAPI.h"
#include "NBTAPI.h"
#include <MC/BlockActor.hpp>
Expand Down
4 changes: 2 additions & 2 deletions API/BlockEntityAPI.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <Global.hpp>

class BlockActor;
Expand All @@ -8,7 +8,7 @@ struct BlockEntityClass {
BlockActor* thiz;
int dim;

BlockEntityClass(BlockActor* be,int dim);
BlockEntityClass(BlockActor* be, int dim);

BlockPos getPos();
int getType();
Expand Down
133 changes: 66 additions & 67 deletions API/CommandAPI.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "CommandAPI.h"
#include "CommandAPI.h"
#include "McAPI.h"
#include "ItemAPI.h"
#include "EntityAPI.h"
Expand All @@ -14,68 +14,68 @@

py::object convertResult(const DynamicCommand::Result& result) {
if (!result.isSet)
return py::object(); // null
return py::object();// null
switch (result.type) {
case DynamicCommand::ParameterType::Bool:
return py::bool_(result.getRaw<bool>());
case DynamicCommand::ParameterType::Int:
return py::int_(result.getRaw<int>());
case DynamicCommand::ParameterType::Float:
return py::float_(result.getRaw<float>());
case DynamicCommand::ParameterType::String:
return py::str(result.getRaw<string>());
case DynamicCommand::ParameterType::Actor: {
py::list arr;
for (auto i : result.get<vector<Actor*>>()) {
arr.append(EntityClass(i));
case DynamicCommand::ParameterType::Bool:
return py::bool_(result.getRaw<bool>());
case DynamicCommand::ParameterType::Int:
return py::int_(result.getRaw<int>());
case DynamicCommand::ParameterType::Float:
return py::float_(result.getRaw<float>());
case DynamicCommand::ParameterType::String:
return py::str(result.getRaw<string>());
case DynamicCommand::ParameterType::Actor: {
py::list arr;
for (auto i : result.get<vector<Actor*>>()) {
arr.append(EntityClass(i));
}
return arr;
}
return arr;
}
case DynamicCommand::ParameterType::Player: {
py::list arr;
for (auto i : result.get<vector<Player*>>()) {
arr.append(PlayerClass(i));
case DynamicCommand::ParameterType::Player: {
py::list arr;
for (auto i : result.get<vector<Player*>>()) {
arr.append(PlayerClass(i));
}
return arr;
}
return arr;
}
case DynamicCommand::ParameterType::BlockPos: {
py::list arr;
arr.append(result.get<BlockPos>());
auto dim = result.origin->getDimension();
arr.append(dim ? int(dim->getDimensionId()) : -1);
return arr;
}
case DynamicCommand::ParameterType::Vec3: {
py::list arr;
arr.append(result.get<Vec3>());
auto dim = result.origin->getDimension();
arr.append(dim ? int(dim->getDimensionId()) : -1);
return arr;
}
case DynamicCommand::ParameterType::Message:
return py::str(result.getRaw<CommandMessage>().getMessage(*result.origin));
case DynamicCommand::ParameterType::RawText:
return py::str(result.getRaw<string>());
case DynamicCommand::ParameterType::JsonValue:
return py::str(JsonHelpers::serialize(result.getRaw<Json::Value>()));
case DynamicCommand::ParameterType::Item:
return py::cast(ItemClass(new ItemStack(result.getRaw<CommandItem>().createInstance(1, 1, nullptr, true).value_or(ItemInstance::EMPTY_ITEM))));
case DynamicCommand::ParameterType::Block:
return py::cast(BlockClass(BlockInstance::createBlockInstance(
const_cast<Block*>(result.getRaw<Block const*>()), BlockPos::MIN, -1)));
case DynamicCommand::ParameterType::Effect:
return py::str(result.getRaw<MobEffect const*>()->getResourceName());
case DynamicCommand::ParameterType::Enum:
return py::str(result.getRaw<string>());
case DynamicCommand::ParameterType::SoftEnum:
return py::str(result.getRaw<string>());
case DynamicCommand::ParameterType::Command:
return py::str(result.getRaw<unique_ptr<Command>>()->getCommandName());
case DynamicCommand::ParameterType::ActorType:
return py::str(result.getRaw<ActorDefinitionIdentifier const*>()->getCanonicalName());
default:
return py::object(); // null
break;
case DynamicCommand::ParameterType::BlockPos: {
py::list arr;
arr.append(result.get<BlockPos>());
auto dim = result.origin->getDimension();
arr.append(dim ? int(dim->getDimensionId()) : -1);
return arr;
}
case DynamicCommand::ParameterType::Vec3: {
py::list arr;
arr.append(result.get<Vec3>());
auto dim = result.origin->getDimension();
arr.append(dim ? int(dim->getDimensionId()) : -1);
return arr;
}
case DynamicCommand::ParameterType::Message:
return py::str(result.getRaw<CommandMessage>().getMessage(*result.origin));
case DynamicCommand::ParameterType::RawText:
return py::str(result.getRaw<string>());
case DynamicCommand::ParameterType::JsonValue:
return py::str(JsonHelpers::serialize(result.getRaw<Json::Value>()));
case DynamicCommand::ParameterType::Item:
return py::cast(ItemClass(new ItemStack(result.getRaw<CommandItem>().createInstance(1, 1, nullptr, true).value_or(ItemInstance::EMPTY_ITEM))));
case DynamicCommand::ParameterType::Block:
return py::cast(BlockClass(BlockInstance::createBlockInstance(
const_cast<Block*>(result.getRaw<Block const*>()), BlockPos::MIN, -1)));
case DynamicCommand::ParameterType::Effect:
return py::str(result.getRaw<MobEffect const*>()->getResourceName());
case DynamicCommand::ParameterType::Enum:
return py::str(result.getRaw<string>());
case DynamicCommand::ParameterType::SoftEnum:
return py::str(result.getRaw<string>());
case DynamicCommand::ParameterType::Command:
return py::str(result.getRaw<unique_ptr<Command>>()->getCommandName());
case DynamicCommand::ParameterType::ActorType:
return py::str(result.getRaw<ActorDefinitionIdentifier const*>()->getCanonicalName());
default:
return py::object();// null
break;
}
}

Expand Down Expand Up @@ -157,13 +157,12 @@ bool CommandClass::setCallback(const py::function& cb) {
if (thiz == nullptr)
return false;
thiz->setCallback(
[cb](const DynamicCommand& command, const CommandOrigin& origin,
CommandOutput& output, std::unordered_map<string, DynamicCommand::Result>& results) {
PY_TRY;
py::gil_scoped_acquire gil_;
cb(CommandOriginClass(const_cast<CommandOrigin*>(&origin)), results);
PY_CATCH;
});
[cb](const DynamicCommand& command, const CommandOrigin& origin, CommandOutput& output, std::unordered_map<string, DynamicCommand::Result>& results) {
PY_TRY;
py::gil_scoped_acquire gil_;
cb(CommandOriginClass(const_cast<CommandOrigin*>(&origin)), results);
PY_CATCH;
});
return true;
}

Expand Down
23 changes: 9 additions & 14 deletions API/CommandAPI.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <Global.hpp>
#include <DynamicCommandAPI.h>

Expand All @@ -11,17 +11,13 @@ struct CommandClass {
string getName();
bool setAlias(const string& alias);
// name, type, description, identifier, option
int64_t mandatory(const string& name, DynamicCommand::ParameterType type,
string description = "", string identifier = "", CommandParameterOption option = None);
int64_t mandatory(const string& name, DynamicCommand::ParameterType type, string description = "", string identifier = "", CommandParameterOption option = None);
// name, type, description, option
int64_t mandatory(const string& name, DynamicCommand::ParameterType type,
string description = "", CommandParameterOption option = None);
int64_t mandatory(const string& name, DynamicCommand::ParameterType type, string description = "", CommandParameterOption option = None);
// name, type, description, identifier, option
int64_t optional(const string& name, DynamicCommand::ParameterType type,
string description = "", string identifier = "", CommandParameterOption option = None);
int64_t optional(const string& name, DynamicCommand::ParameterType type, string description = "", string identifier = "", CommandParameterOption option = None);
// name, type, description, option
int64_t optional(const string& name, DynamicCommand::ParameterType type,
string description = "", CommandParameterOption option = None);
int64_t optional(const string& name, DynamicCommand::ParameterType type, string description = "", CommandParameterOption option = None);
bool addOverload();
// vector<index>
bool addOverload(const vector<size_t>& args);
Expand All @@ -33,10 +29,10 @@ struct CommandClass {
bool setup();
string toString();

// SoftEnum 是带补全的字符串
// 补全项可以实时更改
// 不同选项不能接不同参数
// Enum 则可以做到
// SoftEnum 是带补全的字符串
// 补全项可以实时更改
// 不同选项不能接不同参数
// Enum 则可以做到
// cmd <add|remove> name
// cmd <list>
// cmd <rename> name name2
Expand All @@ -48,4 +44,3 @@ struct CommandClass {
vector<string> getSoftEnumValues(const string& name);
vector<string> getSoftEnumNames();
};

2 changes: 1 addition & 1 deletion API/CommandOriginAPI.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "CommandOriginAPI.h"
#include "CommandOriginAPI.h"
#include "NBTAPI.h"
#include "EntityAPI.h"
#include "BlockAPI.h"
Expand Down
2 changes: 1 addition & 1 deletion API/CommandOriginAPI.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <Global.hpp>

struct EntityClass;
Expand Down
3 changes: 1 addition & 2 deletions API/CommandOutputAPI.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "CommandOutputAPI.h"
#include "CommandOutputAPI.h"
#include <MC/CommandOutput.hpp>


CommandOutputClass::CommandOutputClass(CommandOutput* p) : thiz(p) {}

bool CommandOutputClass::empty() {
Expand Down
2 changes: 1 addition & 1 deletion API/CommandOutputAPI.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <Global.hpp>

class CommandOutput;
Expand Down
2 changes: 1 addition & 1 deletion API/ContainerAPI.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <Global.hpp>

class Container;
Expand Down
6 changes: 3 additions & 3 deletions API/EntityAPI.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "BlockAPI.h"
#include "BlockAPI.h"
#include "EntityAPI.h"
#include "PlayerAPI.h"
#include "ItemAPI.h"
Expand Down Expand Up @@ -82,7 +82,7 @@ float EntityClass::getSpeed() {

Vec2 EntityClass::getDirection() {
if (thiz == nullptr)
return Vec2(0.f,0.f);
return Vec2(0.f, 0.f);
return *thiz->getDirection();
}

Expand Down Expand Up @@ -219,7 +219,7 @@ EntityClass EntityClass::getEntityFromViewVector(float maxDistance) {
return thiz->getActorFromViewVector(maxDistance);
}

BlockClass EntityClass::getBlockFromViewVector(bool includeLiquid, bool solidOnly, float maxDistance, bool ignoreBorderBlocks, bool fullOnly) {
BlockClass EntityClass::getBlockFromViewVector(bool includeLiquid, bool solidOnly, float maxDistance, bool ignoreBorderBlocks, bool fullOnly) {
if (thiz == nullptr)
return BlockInstance::Null;
return thiz->getBlockFromViewVector(includeLiquid, solidOnly, maxDistance, ignoreBorderBlocks, fullOnly);
Expand Down
12 changes: 6 additions & 6 deletions API/EntityAPI.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <Global.hpp>

class Actor;
Expand Down Expand Up @@ -49,9 +49,9 @@ struct EntityClass {
vector<string> getAllTags();
EntityClass getEntityFromViewVector(float maxDistance = 5.25f);
BlockClass getBlockFromViewVector(
bool includeLiquid = false,
bool solidOnly = false,
float maxDistance = 5.25f,
bool ignoreBorderBlocks = true,
bool fullOnly = false);
bool includeLiquid = false,
bool solidOnly = false,
float maxDistance = 5.25f,
bool ignoreBorderBlocks = true,
bool fullOnly = false);
};
Loading

0 comments on commit b32e6d1

Please sign in to comment.