summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2019-05-19 10:20:44 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2019-05-19 10:20:44 +0200
commit1d965bebefe11f1fd5e34c686058fa932bb6b82e (patch)
tree6205b3f36fdba69fa2af054d33b94a9949eca14e
parentImplemented more scripting APIs (diff)
downloadAltCraft-1d965bebefe11f1fd5e34c686058fa932bb6b82e.tar
AltCraft-1d965bebefe11f1fd5e34c686058fa932bb6b82e.tar.gz
AltCraft-1d965bebefe11f1fd5e34c686058fa932bb6b82e.tar.bz2
AltCraft-1d965bebefe11f1fd5e34c686058fa932bb6b82e.tar.lz
AltCraft-1d965bebefe11f1fd5e34c686058fa932bb6b82e.tar.xz
AltCraft-1d965bebefe11f1fd5e34c686058fa932bb6b82e.tar.zst
AltCraft-1d965bebefe11f1fd5e34c686058fa932bb6b82e.zip
-rw-r--r--cwd/assets/altcraft/scripts/init.lua12
-rw-r--r--src/Plugin.cpp71
2 files changed, 74 insertions, 9 deletions
diff --git a/cwd/assets/altcraft/scripts/init.lua b/cwd/assets/altcraft/scripts/init.lua
index 2137464..de58b90 100644
--- a/cwd/assets/altcraft/scripts/init.lua
+++ b/cwd/assets/altcraft/scripts/init.lua
@@ -20,9 +20,15 @@ function plugin.onUnload ()
end
function plugin.onTick (deltaTime)
- if AC.GetGameState() and AC.GetGameState():GetPlayer() then
- local player = AC.GetGameState():GetPlayer()
- player.pos.x = player.pos.x + deltaTime * 0.5
+ if AC.GetGameState() and AC.GetGameState():GetPlayer() and AC.GetGameState():GetTimeStatus().worldAge > 0 then
+ -- local player = AC.GetGameState():GetPlayer()
+ -- player.pos.x = player.pos.x + deltaTime * 0.5
+
+ -- local playerPos = AC.GetGameState():GetPlayer().pos
+ -- local wrld = AC.GetGameState():GetWorld()
+ -- playerPosV = Vector.new(playerPos.x, playerPos.y - 1, playerPos.z)
+ -- bid = wrld:GetBlockId(playerPosV)
+ -- print(bid.id..":"..bid.state)
end
end
diff --git a/src/Plugin.cpp b/src/Plugin.cpp
index 9641e0f..4ef1240 100644
--- a/src/Plugin.cpp
+++ b/src/Plugin.cpp
@@ -8,9 +8,11 @@
#include "GameState.hpp"
#include "Game.hpp"
+#include "Event.hpp"
struct Plugin {
+ int errors;
const std::string name;
const std::string displayName;
const std::function<void()> onLoad;
@@ -28,6 +30,7 @@ namespace PluginApi {
void RegisterPlugin(sol::table plugin) {
Plugin nativePlugin {
+ 0,
plugin["name"].get_or<std::string>(""),
plugin["displayName"].get_or<std::string>(""),
plugin["onLoad"].get_or(std::function<void()>()),
@@ -62,7 +65,7 @@ void PluginSystem::Init() {
OPTICK_EVENT();
LOG(INFO) << "Initializing plugin system";
for (Plugin &plugin : plugins) {
- if (plugin.onUnload)
+ if (plugin.onUnload && plugin.errors < 10)
plugin.onUnload();
}
@@ -75,16 +78,70 @@ void PluginSystem::Init() {
lua.new_usertype<GameState>("GameState",
"GetPlayer", &GameState::GetPlayer,
- "GetWorld", &GameState::GetWorld);
-
- lua.new_usertype<World>("World");
+ "GetWorld", &GameState::GetWorld,
+ "GetTimeStatus", &GameState::GetTimeStatus,
+ "GetGameStatus", &GameState::GetGameStatus,
+ "GetPlayerStatus", &GameState::GetPlayerStatus,
+ "GetSelectionStatus", &GameState::GetSelectionStatus,
+ "GetInventory", &GameState::GetInventory);
+
+ lua.new_usertype<TimeStatus>("TimeStatus",
+ "interpolatedTimeOfDay", &TimeStatus::interpolatedTimeOfDay,
+ "worldAge", &TimeStatus::worldAge,
+ "timeOfDay", &TimeStatus::timeOfDay,
+ "doDaylightCycle", &TimeStatus::doDaylightCycle);
+
+ lua.new_usertype<GameStatus>("GameStatus",
+ "levelType", &GameStatus::levelType,
+ "spawnPosition", &GameStatus::spawnPosition,
+ "gamemode", &GameStatus::gamemode,
+ "dimension", &GameStatus::dimension,
+ "difficulty", &GameStatus::difficulty,
+ "maxPlayers", &GameStatus::maxPlayers,
+ "isGameStarted", &GameStatus::isGameStarted,
+ "reducedDebugInfo", &GameStatus::reducedDebugInfo);
+
+ lua.new_usertype<SelectionStatus>("SelectionStatus",
+ "raycastHit", &SelectionStatus::raycastHit,
+ "selectedBlock", &SelectionStatus::selectedBlock,
+ "distanceToSelectedBlock", &SelectionStatus::distanceToSelectedBlock,
+ "isBlockSelected", &SelectionStatus::isBlockSelected);
+
+ lua.new_usertype<PlayerStatus>("PlayerStatus",
+ "uid", &PlayerStatus::uid,
+ "name", &PlayerStatus::name,
+ "flyingSpeed", &PlayerStatus::flyingSpeed,
+ "fovModifier", &PlayerStatus::fovModifier,
+ "health", &PlayerStatus::health,
+ "eid", &PlayerStatus::eid,
+ "invulnerable", &PlayerStatus::invulnerable,
+ "flying", &PlayerStatus::flying,
+ "allowFlying", &PlayerStatus::allowFlying,
+ "creativeMode", &PlayerStatus::creativeMode);
+
+ lua.new_usertype<World>("World",
+ "GetEntitiesList", &World::GetEntitiesList,
+ "GetEntity",&World::GetEntityPtr,
+ "Raycast", &World::Raycast,
+ "GetBlockId", &World::GetBlockId,
+ "SetBlockId", &World::SetBlockId);
+
+ lua.new_usertype<BlockId>("BlockId",
+ "id", sol::property(
+ [](BlockId & bid) { return bid.id; },
+ [](BlockId & bid, unsigned short id) { bid.id = id; }),
+ "state", sol::property(
+ [](BlockId & bid) { return bid.state; },
+ [](BlockId & bid, unsigned char state) { bid.state = state; }));
lua.new_usertype<Vector>("Vector",
+ sol::constructors<Vector(),Vector(long long, long long, long long)>(),
"x", &Vector::x,
"y", &Vector::y,
"z", &Vector::z);
lua.new_usertype<VectorF>("VectorF",
+ sol::constructors<VectorF(), VectorF(double, double, double)>(),
"x", &VectorF::x,
"y", &VectorF::y,
"z", &VectorF::z);
@@ -112,12 +169,13 @@ void PluginSystem::Execute(const std::string &luaCode, bool except) {
void PluginSystem::CallOnChangeState(std::string newState) {
OPTICK_EVENT();
for (Plugin &plugin : plugins) {
- if (plugin.onChangeState)
+ if (plugin.onChangeState && plugin.errors < 10)
try {
plugin.onChangeState(newState);
}
catch (sol::error &e) {
LOG(ERROR) << e.what();
+ plugin.errors++;
}
}
}
@@ -125,12 +183,13 @@ void PluginSystem::CallOnChangeState(std::string newState) {
void PluginSystem::CallOnTick(double deltaTime) {
OPTICK_EVENT();
for (Plugin& plugin : plugins) {
- if (plugin.onTick)
+ if (plugin.onTick && plugin.errors < 10)
try {
plugin.onTick(deltaTime);
}
catch (sol::error &e) {
LOG(ERROR) << e.what();
+ plugin.errors++;
}
}
}