Clean up the Register* functions, make them all one header file
* Reorganize src/lua * Add `environment` table to Biome Definitionsmaster
parent
732a166dab
commit
7c54de84fa
|
@ -1,6 +1,6 @@
|
|||
#version 330 core
|
||||
|
||||
#define TAU 6.28318530718f
|
||||
#define TAU 6.28318530718
|
||||
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec2 aTexCoords;
|
||||
|
|
|
@ -130,18 +130,14 @@ set(ZEPHA_SRC
|
|||
def/DefinitionAtlas.h
|
||||
lua/LuaParser.cpp
|
||||
lua/LuaParser.h
|
||||
lua/server/ServerLuaParser.cpp
|
||||
lua/server/ServerLuaParser.h
|
||||
lua/client/ServerLuaParser.cpp
|
||||
lua/client/ServerLuaParser.h
|
||||
util/Log.h
|
||||
lua/Callback.h
|
||||
game/graph/shader/GuiUniforms.h
|
||||
game/graph/meshtypes/EntityMesh.cpp
|
||||
game/graph/meshtypes/EntityMesh.h
|
||||
lua/client/LocalRegisterBlocks.cpp
|
||||
lua/client/LocalRegisterBlocks.h
|
||||
lua/server/ServerRegisterBlocks.cpp
|
||||
lua/server/ServerRegisterBlocks.h
|
||||
server/conn/ServerClient.cpp
|
||||
server/conn/ServerClient.cpp
|
||||
server/config/ServerConfig.cpp
|
||||
server/config/ServerConfig.h
|
||||
util/net/PacketType.h
|
||||
|
@ -204,12 +200,8 @@ set(ZEPHA_SRC
|
|||
game/scene/world/graph/ChunkRenderElem.h
|
||||
world/ServerDimension.cpp
|
||||
world/ServerDimension.h
|
||||
lua/client/LocalRegisterItems.cpp
|
||||
lua/client/LocalRegisterItems.h
|
||||
def/item/CraftItemDef.cpp
|
||||
def/item/CraftItemDef.cpp
|
||||
def/item/CraftItemDef.h
|
||||
lua/server/ServerRegisterItems.cpp
|
||||
lua/server/ServerRegisterItems.h
|
||||
lua/api/modules/add_entity.h
|
||||
lua/api/type/LocalLuaEntity.cpp
|
||||
lua/api/type/LocalLuaEntity.h
|
||||
|
@ -218,11 +210,9 @@ set(ZEPHA_SRC
|
|||
def/model/ModelStore.h
|
||||
lua/api/modules/remove_entity.h
|
||||
lua/api/functions/cUpdateEntities.h
|
||||
lua/client/LocalRegisterKeybinds.cpp
|
||||
lua/client/LocalRegisterKeybinds.h
|
||||
lua/api/modules/register_keybind.h
|
||||
lua/client/LuaInputManager.cpp
|
||||
lua/client/LuaInputManager.h
|
||||
lua/LuaInputManager.cpp
|
||||
lua/LuaInputManager.h
|
||||
lua/api/type/cLuaLocalPlayer.h
|
||||
lua/api/type/LocalLuaPlayer.cpp
|
||||
lua/api/type/LocalLuaPlayer.h
|
||||
|
@ -240,9 +230,7 @@ set(ZEPHA_SRC
|
|||
game/hud/SerializedGuiElem.h
|
||||
util/Voronoi3D.cpp
|
||||
util/Voronoi3D.h
|
||||
lua/server/ServerRegisterBiomes.cpp
|
||||
lua/server/ServerRegisterBiomes.h
|
||||
def/gen/BiomeDef.cpp
|
||||
def/gen/BiomeDef.cpp
|
||||
def/gen/BiomeDef.h
|
||||
def/gen/BiomeAtlas.cpp
|
||||
def/gen/BiomeAtlas.h
|
||||
|
@ -250,9 +238,7 @@ set(ZEPHA_SRC
|
|||
def/gen/ServerBiomeAtlas.h
|
||||
def/gen/LocalBiomeAtlas.cpp
|
||||
def/gen/LocalBiomeAtlas.h
|
||||
lua/client/LocalRegisterBiomes.cpp
|
||||
lua/client/LocalRegisterBiomes.h
|
||||
world/Dimension.cpp
|
||||
world/Dimension.cpp
|
||||
world/Dimension.h
|
||||
def/texture/RawTexData.h
|
||||
game/hud/components/compound/GUIImageButton.cpp
|
||||
|
@ -263,13 +249,13 @@ set(ZEPHA_SRC
|
|||
game/scene/menu/SubgameConfig.h
|
||||
game/scene/menu/MenuSandbox.cpp
|
||||
game/scene/menu/MenuSandbox.h
|
||||
lua/api/modules/mDelay.h
|
||||
lua/api/modules/mSetGui.h
|
||||
lua/api/menu/mDelay.h
|
||||
lua/api/menu/mSetGui.h
|
||||
game/hud/GuiBuilder.cpp
|
||||
game/hud/GuiBuilder.h
|
||||
game/hud/GameGuiBuilder.cpp
|
||||
game/hud/GameGuiBuilder.h
|
||||
lua/api/modules/mStartGame.h
|
||||
lua/api/menu/mStartGame.h
|
||||
lua/api/type/LuaInventoryList.cpp
|
||||
lua/api/type/LuaInventoryList.h
|
||||
lua/api/type/LuaInventory.cpp
|
||||
|
@ -294,6 +280,6 @@ set(ZEPHA_SRC
|
|||
util/net/Serializer.h
|
||||
util/net/Deserializer.h
|
||||
lua/api/type/ServerLocalLuaEntity.cpp
|
||||
lua/api/type/ServerLocalLuaEntity.h lua/api/modules/register_item.h lua/api/modules/register_biome.h lua/api/modules/delay.h lua/api/modules/register_block.h lua/api/modules/register_blockmodel.h lua/api/modules/register_entity.h game/scene/world/World.cpp game/scene/world/World.h lua/api/modules/set_block.h lua/api/modules/get_block.h lua/api/modules/remove_block.h)
|
||||
lua/api/type/ServerLocalLuaEntity.h lua/api/modules/register_item.h lua/api/modules/register_biome.h lua/api/modules/delay.h lua/api/modules/register_block.h lua/api/modules/register_blockmodel.h lua/api/modules/register_entity.h game/scene/world/World.cpp game/scene/world/World.h lua/api/modules/set_block.h lua/api/modules/get_block.h lua/api/modules/remove_block.h lua/register/RegisterBiomes.h lua/register/RegisterBlocks.h lua/register/RegisterItems.h lua/register/RegisterKeybinds.h)
|
||||
|
||||
add_library (Zepha_Core ${ZEPHA_SRC})
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
|
||||
#include "ServerDefinitionAtlas.h"
|
||||
#include "../lua/server/ServerLuaParser.h"
|
||||
#include "../lua/client/ServerLuaParser.h"
|
||||
#include "../server/asset/AssetStorage.h"
|
||||
#include "gen/ServerBiomeAtlas.h"
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ MapGen::MapGen(unsigned int seed, DefinitionAtlas& atlas, BiomeAtlas& biomes) :
|
|||
worldFeatureBase.SetSeed(seed);
|
||||
worldFeatureBase.SetFrequency(0.2);
|
||||
worldFeatureBase.SetOctaveCount(3);
|
||||
|
||||
worldFeatureScaled.SetSourceModule(0, worldFeatureBase);
|
||||
worldFeatureScaled.SetScale(6);
|
||||
worldFeatureScaled.SetBias(6);
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
#include "MenuSandbox.h"
|
||||
|
||||
#include "../../../lua/api/modules/mDelay.h"
|
||||
#include "../../../lua/api/modules/mSetGui.h"
|
||||
#include "../../../lua/api/modules/mStartGame.h"
|
||||
#include "../../../lua/api/menu/mDelay.h"
|
||||
#include "../../../lua/api/menu/mSetGui.h"
|
||||
#include "../../../lua/api/menu/mStartGame.h"
|
||||
|
||||
MenuSandbox::MenuSandbox(glm::ivec2 &win, ClientState& state, std::shared_ptr<GUIContainer> container) :
|
||||
win(win),
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
//
|
||||
|
||||
#include "LuaInputManager.h"
|
||||
#include "../../util/Util.h"
|
||||
#include "../util/Util.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <iostream>
|
||||
|
|
@ -11,7 +11,6 @@
|
|||
namespace Api {
|
||||
static void set_block(sol::table &core, DefinitionAtlas& defs, World& world) {
|
||||
core.set_function("set_block", [&](sol::table pos, std::string identifier) {
|
||||
std::cout << identifier << std::endl;
|
||||
if (!pos["x"] || !pos["y"] || !pos["z"]) throw "expected a vector as the first argument.";
|
||||
auto& block = defs.fromStr(identifier);
|
||||
world.setBlock({pos.get<float>("x"), pos.get<float>("y"), pos.get<float>("z")}, block.index);
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
//
|
||||
|
||||
#include "LocalLuaParser.h"
|
||||
#include "LocalRegisterBlocks.h"
|
||||
#include "LocalRegisterItems.h"
|
||||
#include "LocalRegisterKeybinds.h"
|
||||
#include "LocalRegisterBiomes.h"
|
||||
#include "../register/RegisterBlocks.h"
|
||||
#include "../register/RegisterItems.h"
|
||||
#include "../register/RegisterKeybinds.h"
|
||||
#include "../register/RegisterBiomes.h"
|
||||
|
||||
#include "../../def/LocalDefs.h"
|
||||
#include "../api/type/LocalLuaPlayer.h"
|
||||
|
@ -108,10 +108,10 @@ void LocalLuaParser::loadMods() {
|
|||
}
|
||||
|
||||
void LocalLuaParser::registerDefinitions(LocalDefs &defs) {
|
||||
LocalRegisterBlocks(core, defs);
|
||||
LocalRegisterItems(core, defs);
|
||||
LocalRegisterKeybinds(core, defs, manager);
|
||||
LocalRegisterBiomes(core, defs);
|
||||
RegisterBlocks ::client(core, defs);
|
||||
RegisterItems ::client(core, defs);
|
||||
RegisterBiomes ::client(core, defs);
|
||||
RegisterKeybinds::client(core, manager);
|
||||
}
|
||||
|
||||
void LocalLuaParser::update(double delta, bool* keys) {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <cute_files/cute_files.h>
|
||||
#include "../LuaParser.h"
|
||||
#include "../LuaMod.h"
|
||||
#include "LuaInputManager.h"
|
||||
#include "../LuaInputManager.h"
|
||||
|
||||
class LocalDefs;
|
||||
class LocalWorld;
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 2019-11-18.
|
||||
//
|
||||
|
||||
#include "LocalRegisterBiomes.h"
|
||||
|
||||
LocalRegisterBiomes::LocalRegisterBiomes(sol::table& core, LocalDefs &defs) {
|
||||
//Register all of the biomes in the zepha.registered_biomes table.
|
||||
for (auto biomeRef : core.get<sol::table>("registered_biomes")) {
|
||||
//Get the unique identifier of the biome
|
||||
std::string identifier = biomeRef.first.as<std::string>();
|
||||
|
||||
//Make sure the biome table is actually a table, and get it.
|
||||
if (!biomeRef.second || !biomeRef.second.is<sol::table>()) throw identifier + "'s definition table is not a table!";
|
||||
sol::table biomeTable = biomeRef.second.as<sol::table>();
|
||||
|
||||
//Get biome properties and throw errors if required ones are missing
|
||||
auto temperature = biomeTable.get_or<float>("temperature", -10000);
|
||||
auto humidity = biomeTable.get_or<float>("humidity", -10000);
|
||||
auto roughness = biomeTable.get_or<float>("roughness", -10000);
|
||||
|
||||
if (temperature == -10000) throw identifier + " is missing temperature property!";
|
||||
if (temperature < -1 || temperature > 1) throw identifier + "'s temperature property is out of range!";
|
||||
if (humidity == -10000) throw identifier + " is missing humidity property!";
|
||||
if (humidity < 0 || humidity > 1) throw identifier + "'s humidity property is out of range!";
|
||||
if (roughness == -10000) throw identifier + " is missing roughness property!";
|
||||
if (roughness < 0 || roughness > 1) throw identifier + "'s roughness property is out of range!";
|
||||
|
||||
//Get the blocks for the terrain to be made out of.
|
||||
auto blocksList = biomeTable.get<sol::optional<sol::table>>("blocks");
|
||||
if (!blocksList) throw identifier + "'s definition is missing blocks list.";
|
||||
|
||||
auto topBlock = (*blocksList).get<sol::optional<std::string>>("top");
|
||||
auto soilBlock = (*blocksList).get<sol::optional<std::string>>("soil");
|
||||
auto rockBlock = (*blocksList).get<sol::optional<std::string>>("rock");
|
||||
|
||||
if (!topBlock) throw identifier + "'s blocks property is missing a `top` block.";
|
||||
if (!soilBlock) throw identifier + "'s blocks property is missing a `soil` block.";
|
||||
if (!rockBlock) throw identifier + "'s blocks property is missing a `rock` block.";
|
||||
|
||||
auto biomeTint = biomeTable.get<sol::optional<std::string>>("biome_tint");
|
||||
|
||||
if (!biomeTint) throw identifier + "'s blocks property is missing a `biome_tint`.";
|
||||
|
||||
BiomeDef* biomeDef = new BiomeDef(
|
||||
identifier, defs.biomes.size(),
|
||||
temperature, humidity, roughness,
|
||||
defs.defs.blockFromStr(*topBlock).index,
|
||||
defs.defs.blockFromStr(*soilBlock).index,
|
||||
defs.defs.blockFromStr(*rockBlock).index,
|
||||
glm::vec3(Util::hexToColorVec((*biomeTint)))
|
||||
);
|
||||
|
||||
//Add Biome Definition to the Gen
|
||||
defs.biomes.registerBiome(biomeDef);
|
||||
}
|
||||
|
||||
defs.biomes.generateVoronoi();
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 2019-11-18.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sol2/sol.hpp>
|
||||
#include "../../def/LocalDefs.h"
|
||||
|
||||
class LocalRegisterBiomes {
|
||||
public:
|
||||
LocalRegisterBiomes(sol::table& core, LocalDefs& defs);
|
||||
};
|
|
@ -1,247 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 28/06/19.
|
||||
//
|
||||
|
||||
#include "LocalRegisterBlocks.h"
|
||||
|
||||
LocalRegisterBlocks::LocalRegisterBlocks(sol::table& core, LocalDefs &defs) {
|
||||
//Register all of the blocks in the zepha.registered_blocks table.
|
||||
for (auto blockRef : core.get<sol::table>("registered_blocks")) {
|
||||
//Get the unique identifier of the block
|
||||
std::string identifier = blockRef.first.as<std::string>();
|
||||
|
||||
//Make sure the block table is actually a table, and get it.
|
||||
if (!blockRef.second || !blockRef.second.is<sol::table>())
|
||||
throw identifier + "'s definition table is not a table!";
|
||||
sol::table blockTable = blockRef.second.as<sol::table>();
|
||||
|
||||
//Get block properties and throw errors if required ones are missing
|
||||
auto nameOpt = blockTable.get<sol::optional<std::string>>("name");
|
||||
auto modelStrOpt = blockTable.get<sol::optional<std::string>>("model");
|
||||
auto texturesOpt = blockTable.get<sol::optional<sol::table>> ("textures");
|
||||
auto selectionOpt = blockTable.get<sol::optional<sol::table>> ("selection_box");
|
||||
auto collisionOpt = blockTable.get<sol::optional<sol::table>> ("collision_box");
|
||||
auto ldTexturesOpt= blockTable.get<sol::optional<sol::table>> ("lowdef_textures");
|
||||
|
||||
if (!nameOpt) throw identifier + " is missing name property!";
|
||||
if (!texturesOpt) throw identifier + " is missing textures property!";
|
||||
|
||||
bool visible = blockTable.get_or("visible", true);
|
||||
bool culls = blockTable.get_or("culls", true);
|
||||
bool solid = blockTable.get_or("solid", true);
|
||||
auto ldRender = blockTable.get_or("lowdef_render", true);
|
||||
auto maxStack = blockTable.get_or("stack", 64);
|
||||
|
||||
//Get the identifier for the blockModel, and then get the model from the zepha.registered_blockmodels table.
|
||||
std::string modelStr = (modelStrOpt ? *modelStrOpt : "default:cube");
|
||||
auto modelOpt = core.get<sol::table>("registered_blockmodels").get<sol::optional<sol::table>>(modelStr);
|
||||
if (!modelOpt) throw identifier + " specifies invalid model " + modelStr + "!";
|
||||
|
||||
//Create a vector of selection boxes
|
||||
std::vector<SelectionBox> sBoxes;
|
||||
if (selectionOpt) {
|
||||
for (auto pair : *selectionOpt) {
|
||||
sol::table s = pair.second;
|
||||
sBoxes.push_back({{s[1], s[2], s[3]}, {s[4], s[5], s[6]}});
|
||||
}
|
||||
}
|
||||
else sBoxes.push_back({{0, 0, 0}, {1, 1, 1}});
|
||||
|
||||
//Create a vector of collision boxes
|
||||
std::vector<SelectionBox> cBoxes;
|
||||
|
||||
if (collisionOpt) {
|
||||
for (auto pair : *collisionOpt) {
|
||||
sol::table s = pair.second;
|
||||
cBoxes.push_back({{s[1], s[2], s[3]}, {s[4], s[5], s[6]}});
|
||||
}
|
||||
}
|
||||
else cBoxes.push_back({{0, 0, 0}, {1, 1, 1}});
|
||||
|
||||
//Create a block model from the above properties
|
||||
sol::table model = *modelOpt;
|
||||
BlockModel blockModel;
|
||||
|
||||
blockModel.culls = culls;
|
||||
blockModel.visible = visible;
|
||||
|
||||
//Convert Textures Table to Vector
|
||||
std::vector<std::string> textures;
|
||||
for (auto pair : *texturesOpt) {
|
||||
if (!pair.second.is<std::string>()) throw "Textures table has non-string value!";
|
||||
textures.push_back(pair.second.as<std::string>());
|
||||
}
|
||||
if (textures.size() == 0) textures.push_back("_missing");
|
||||
|
||||
//Convert LowDef Textures Table to Vector
|
||||
std::vector<std::string> lowdef_textures;
|
||||
if (ldTexturesOpt) {
|
||||
for (auto pair : *ldTexturesOpt) {
|
||||
if (!pair.second.is<std::string>()) throw "Textures table has non-string value!";
|
||||
lowdef_textures.push_back(pair.second.as<std::string>());
|
||||
}
|
||||
if (lowdef_textures.size() == 0) lowdef_textures.push_back("_missing");
|
||||
}
|
||||
else {
|
||||
lowdef_textures = textures;
|
||||
}
|
||||
|
||||
//Add Mesh Mods
|
||||
sol::optional<sol::table> meshModTable = model.get<sol::optional<sol::table>>("mesh_mods");
|
||||
if (meshModTable) {
|
||||
for (auto modEntry : (*meshModTable)) {
|
||||
auto modTable = modEntry.second.as<sol::table>();
|
||||
std::string meshMod = modTable.get_or<std::string>("type", "none");
|
||||
|
||||
if (meshMod == "none") { continue; }
|
||||
else if (meshMod == "offset_x") {
|
||||
blockModel.meshMods.emplace_back(
|
||||
MeshMod::OFFSET_X, modTable.get_or<float>("amplitude", 1));
|
||||
}
|
||||
else if (meshMod == "offset_y") {
|
||||
blockModel.meshMods.emplace_back(
|
||||
MeshMod::OFFSET_Y, modTable.get_or<float>("amplitude", 1));
|
||||
}
|
||||
else if (meshMod == "offset_z") {
|
||||
blockModel.meshMods.emplace_back(
|
||||
MeshMod::OFFSET_Z, modTable.get_or<float>("amplitude", 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Convert all of the mesh parts to C++ Objects and add them to blockModel
|
||||
model.get<sol::table>("parts").for_each([&](sol::object key, sol::object value) {
|
||||
|
||||
//Make sure LocalMeshPart is in fact a table
|
||||
if (!value.is<sol::table>()) throw "Meshpart is not a table";
|
||||
sol::table meshPartTable = value.as<sol::table>();
|
||||
|
||||
//Get The points table, and make sure it's valid
|
||||
auto points_optional = meshPartTable.get<sol::optional<sol::table>>("points");
|
||||
if (!points_optional) throw "Meshpart is missing a points table (Local)";
|
||||
|
||||
sol::table points = *points_optional;
|
||||
|
||||
if (points.size() % 20 != 0) throw "Points array is ill-formed. (Not a multiple of 20 values)";
|
||||
|
||||
//Populate the Vertices and Indices vectors from the points table
|
||||
std::vector<BlockModelVertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
|
||||
for (int i = 1; i <= points.size()/5; i++) {
|
||||
int offset = (i - 1) * 5 + 1;
|
||||
|
||||
glm::vec3 pos(points[offset], points[offset + 1], points[offset + 2]);
|
||||
glm::vec2 tex(points[offset + 3], points[offset + 4]);
|
||||
|
||||
vertices.push_back({pos, {0, 0, 0}, tex, {0, 0}});
|
||||
}
|
||||
|
||||
int ind = 0;
|
||||
for (int i = 1; i <= points.size() / 20; i++) {
|
||||
indices.push_back(ind);
|
||||
indices.push_back(ind + 1);
|
||||
indices.push_back(ind + 2);
|
||||
indices.push_back(ind + 2);
|
||||
indices.push_back(ind + 3);
|
||||
indices.push_back(ind);
|
||||
ind += 4;
|
||||
}
|
||||
|
||||
//Get the texture for the part
|
||||
int tex = std::max((int)meshPartTable.get_or<float>("tex", 1), 1);
|
||||
auto texture = textures[std::min(tex - 1, (int)textures.size() - 1)];
|
||||
|
||||
//TODO: More robust solution needed.
|
||||
bool biometint = false;
|
||||
if (strncmp(texture.data(), "biometint(", 10) == 0) {
|
||||
biometint = true;
|
||||
texture = texture.substr(10, texture.length() - 11);
|
||||
}
|
||||
|
||||
auto textureRef = defs.textures[texture];
|
||||
|
||||
//Add a reference to the texture to the blockModel's list of required textures to keep it in memory.
|
||||
blockModel.textureRefs.insert(textureRef);
|
||||
|
||||
//Create a LocalMeshPart object
|
||||
MeshPart meshPart(std::move(vertices), std::move(indices), textureRef, biometint);
|
||||
|
||||
//Add ShaderMod
|
||||
sol::optional<sol::table> shaderModTable = meshPartTable.get<sol::optional<sol::table>>("shader_mod");
|
||||
if (shaderModTable) {
|
||||
std::string shaderMod = (*shaderModTable).get_or<std::string>("type", "none");
|
||||
|
||||
if (shaderMod == "none") {
|
||||
meshPart.shaderMod = ShaderMod::NONE;
|
||||
}
|
||||
else if (shaderMod == "rotate_x") {
|
||||
meshPart.shaderMod = ShaderMod::ROTATE_X;
|
||||
meshPart.modValue = (*shaderModTable).get_or<float>("speed", 1);
|
||||
}
|
||||
else if (shaderMod == "rotate_y") {
|
||||
meshPart.shaderMod = ShaderMod::ROTATE_Y;
|
||||
meshPart.modValue = (*shaderModTable).get_or<float>("speed", 1);
|
||||
}
|
||||
else if (shaderMod == "rotate_z") {
|
||||
meshPart.shaderMod = ShaderMod::ROTATE_Z;
|
||||
meshPart.modValue = (*shaderModTable).get_or<float>("speed", 1);
|
||||
}
|
||||
else if (shaderMod == "sway_attached") {
|
||||
meshPart.shaderMod = ShaderMod::SWAY_ATTACHED;
|
||||
meshPart.modValue = (*shaderModTable).get_or<float>("amplitude", 1);
|
||||
}
|
||||
else if (shaderMod == "sway_full_block") {
|
||||
meshPart.shaderMod = ShaderMod::SWAY_FULL_BLOCK;
|
||||
meshPart.modValue = (*shaderModTable).get_or<float>("amplitude", 1);
|
||||
}
|
||||
}
|
||||
|
||||
//Add the meshpart to the proper face vector
|
||||
std::string face = meshPartTable.get_or<std::string>("face", "nocull");
|
||||
|
||||
Dir d = face == "top" ? Dir::TOP :
|
||||
face == "bottom" ? Dir::BOTTOM :
|
||||
face == "left" ? Dir::LEFT :
|
||||
face == "right" ? Dir::RIGHT :
|
||||
face == "front" ? Dir::FRONT :
|
||||
face == "back" ? Dir::BACK :
|
||||
face == "nocull" ? Dir::NO_CULL :
|
||||
Dir::INVALID;
|
||||
|
||||
if (d == Dir::INVALID)
|
||||
throw "Face value \"" + face + "\" is not one of 'top', 'bottom', 'left', 'right', 'front', 'back', 'nocull'.";
|
||||
|
||||
blockModel.parts[static_cast<int>(d)].push_back(meshPart);
|
||||
});
|
||||
|
||||
std::vector<std::shared_ptr<AtlasRef>> refs;
|
||||
for (auto i = 0; i < lowdef_textures.size(); i++) {
|
||||
//TODO: More robust solution needed.
|
||||
std::string texture = lowdef_textures[i];
|
||||
bool biometint = false;
|
||||
if (strncmp(texture.data(), "biometint(", 10) == 0) {
|
||||
biometint = true;
|
||||
texture = texture.substr(10, texture.length() - 11);
|
||||
}
|
||||
refs.push_back(defs.textures[texture]);
|
||||
}
|
||||
|
||||
BlockModel lowdefBlockModel = BlockModel::createCube(refs);
|
||||
lowdefBlockModel.culls = ldRender;
|
||||
lowdefBlockModel.visible = ldRender;
|
||||
|
||||
BlockDef* blockDef = new BlockDef(identifier, defs.defs.size(), *nameOpt, maxStack, blockModel, solid, std::move(sBoxes), std::move(cBoxes));
|
||||
blockDef->createModel();
|
||||
|
||||
//Bind Callbacks
|
||||
auto on_place_client = blockTable.get<sol::optional<sol::function>>("on_place_client");
|
||||
if (on_place_client) blockDef->callbacks.insert({Callback::PLACE_CLIENT, *on_place_client});
|
||||
|
||||
auto on_break_client = blockTable.get<sol::optional<sol::function>>("on_break_client");
|
||||
if (on_break_client) blockDef->callbacks.insert({Callback::BREAK_CLIENT, *on_break_client});
|
||||
|
||||
//Add Block Definition to the Atlas
|
||||
defs.defs.registerDef(blockDef);
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 28/06/19.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sol2/sol.hpp>
|
||||
#include "../../def/LocalDefs.h"
|
||||
|
||||
class LocalRegisterBlocks {
|
||||
public:
|
||||
LocalRegisterBlocks(sol::table& core, LocalDefs& defs);
|
||||
};
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 01/10/19.
|
||||
//
|
||||
|
||||
#include "LocalRegisterItems.h"
|
||||
|
||||
LocalRegisterItems::LocalRegisterItems(sol::table& core, LocalDefs &defs) {
|
||||
//Register all of the items in the zepha.registered_items table.
|
||||
for (auto itemRef : core.get<sol::table>("registered_items")) {
|
||||
//Get the unique identifier of the item
|
||||
std::string identifier = itemRef.first.as<std::string>();
|
||||
|
||||
//Make sure the block table is actually a table, and get it.
|
||||
if (!itemRef.second || !itemRef.second.is<sol::table>()) throw identifier + "'s definition table is not a table!";
|
||||
sol::table itemTable = itemRef.second.as<sol::table>();
|
||||
|
||||
//Get item properties and throw errors if required ones are missing
|
||||
auto nameOpt = itemTable.get<sol::optional<std::string>>("name");
|
||||
auto texturesOpt = itemTable.get<sol::optional<sol::table>> ("textures");
|
||||
|
||||
if (!nameOpt) throw identifier + " is missing name property!";
|
||||
if (!texturesOpt) throw identifier + " is missing textures property!";
|
||||
|
||||
auto maxStack = itemTable.get_or("stack", 64);
|
||||
|
||||
//Convert Textures Table to Vector
|
||||
std::vector<std::string> textures;
|
||||
std::vector<sptr<AtlasRef>> textureRefs;
|
||||
for (auto pair : *texturesOpt) {
|
||||
if (!pair.second.is<std::string>()) throw "Textures table has non-string value!";
|
||||
textures.push_back(pair.second.as<std::string>());
|
||||
textureRefs.push_back(defs.textures[pair.second.as<std::string>()]);
|
||||
}
|
||||
if (textures.size() == 0) {
|
||||
textures.push_back("_missing");
|
||||
textureRefs.push_back(defs.textures["_missing"]);
|
||||
}
|
||||
|
||||
CraftItemDef* itemDef = new CraftItemDef(identifier, defs.defs.size(), *nameOpt, maxStack, textures, textureRefs);
|
||||
itemDef->createModel(defs.textures);
|
||||
|
||||
//Add Block Definition to the Atlas
|
||||
defs.defs.registerDef(itemDef);
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 01/10/19.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sol2/sol.hpp>
|
||||
#include "../../def/LocalDefs.h"
|
||||
|
||||
class LocalRegisterItems {
|
||||
public:
|
||||
LocalRegisterItems(sol::table& core, LocalDefs& defs);
|
||||
|
||||
};
|
|
@ -1,23 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 12/10/19.
|
||||
//
|
||||
|
||||
#include "LocalRegisterKeybinds.h"
|
||||
|
||||
LocalRegisterKeybinds::LocalRegisterKeybinds(sol::table& core, LocalDefs &defs, LuaInputManager& manager) {
|
||||
//Register all of the items in the zepha.registered_keybinds table.
|
||||
for (auto keybindRef : core.get<sol::table>("registered_keybinds")) {
|
||||
//Get the unique identifier of the item
|
||||
std::string identifier = keybindRef.first.as<std::string>();
|
||||
//Make sure the keybind table is actually a table, and get it.
|
||||
if (!keybindRef.second || !keybindRef.second.is<sol::table>()) throw identifier + "'s definition table is not a table!";
|
||||
sol::table keybindTbl = keybindRef.second.as<sol::table>();
|
||||
ushort def = keybindTbl.get<ushort>("default");
|
||||
|
||||
auto onPress = keybindTbl.get<sol::optional<sol::function>>("on_press");
|
||||
auto onRelease = keybindTbl.get<sol::optional<sol::function>>("on_release");
|
||||
|
||||
if (onPress) manager.bindOnDown(def, *onPress);
|
||||
if (onRelease) manager.bindOnUp(def, *onRelease);
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 12/10/19.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../def/LocalDefs.h"
|
||||
|
||||
class LocalRegisterKeybinds {
|
||||
public:
|
||||
LocalRegisterKeybinds(sol::table& core, LocalDefs &defs, LuaInputManager& manager);
|
||||
};
|
|
@ -5,11 +5,9 @@
|
|||
#include <gzip/compress.hpp>
|
||||
|
||||
#include "ServerLuaParser.h"
|
||||
#include "ServerRegisterBlocks.h"
|
||||
#include "ServerRegisterItems.h"
|
||||
#include "ServerRegisterBiomes.h"
|
||||
|
||||
#include "../../def/ServerDefs.h"
|
||||
#include "../register/RegisterBlocks.h"
|
||||
#include "../register/RegisterItems.h"
|
||||
#include "../register/RegisterBiomes.h"
|
||||
|
||||
#include "../api/type/sServerLuaEntity.h"
|
||||
|
||||
|
@ -85,9 +83,9 @@ void ServerLuaParser::loadModules(ServerDefs &defs, ServerWorld &world) {
|
|||
}
|
||||
|
||||
void ServerLuaParser::registerDefinitions(ServerDefs &defs) {
|
||||
ServerRegisterBlocks(core, defs);
|
||||
ServerRegisterItems(core, defs);
|
||||
ServerRegisterBiomes(core, defs);
|
||||
RegisterBlocks::server(core, defs);
|
||||
RegisterItems ::server(core, defs);
|
||||
RegisterBiomes::server(core, defs);
|
||||
}
|
||||
|
||||
void ServerLuaParser::loadMods(ServerDefs& defs, const std::string& rootPath) {
|
|
@ -0,0 +1,79 @@
|
|||
//
|
||||
// Created by aurailus on 2020-01-10.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sol2/sol.hpp>
|
||||
#include "../../def/LocalDefs.h"
|
||||
#include "../../def/ServerDefs.h"
|
||||
#include "../../def/gen/BiomeDef.h"
|
||||
|
||||
namespace RegisterBiomes {
|
||||
static void registerBiomes(sol::table source, DefinitionAtlas& defs, BiomeAtlas& biomes) {
|
||||
// Parses through all of the zepha.registered_biomes and makes BiomeDefs.
|
||||
for (auto biomeRef : source) {
|
||||
|
||||
// Validate that the identifier and definition table exist
|
||||
std::string identifier = biomeRef.first.as<std::string>();
|
||||
|
||||
if (!biomeRef.second || !biomeRef.second.is<sol::table>())
|
||||
throw "register_biome expects a table as the second parameter";
|
||||
sol::table biomeTable = biomeRef.second.as<sol::table>();
|
||||
|
||||
// Environment Properties for Voronoi Diagram
|
||||
auto environment = biomeTable.get<sol::optional<sol::table>>("environment");
|
||||
if (!environment) throw "biome definitions require an environment table";
|
||||
|
||||
auto temperature = environment->get_or<float>("temperature", -2);
|
||||
auto humidity = environment->get_or<float>("humidity", -2);
|
||||
auto roughness = environment->get_or<float>("roughness", -2);
|
||||
|
||||
if (temperature < -1 || temperature > 1)
|
||||
throw "environment.temperature property is out of range or missing";
|
||||
if (humidity < 0 || humidity > 1)
|
||||
throw "environment.humidity property is out of range or missing";
|
||||
if (roughness < 0 || roughness > 1)
|
||||
throw "environment.roughness property is out of range or missing";
|
||||
|
||||
// Blocks to form the environment out of
|
||||
auto blocksList = biomeTable.get<sol::optional<sol::table>>("blocks");
|
||||
if (!blocksList) throw identifier + "biome definitions require a blocks table";
|
||||
|
||||
auto bTop = (*blocksList).get<sol::optional<std::string>>("top");
|
||||
auto bSoil = (*blocksList).get<sol::optional<std::string>>("soil");
|
||||
auto bRock = (*blocksList).get<sol::optional<std::string>>("rock");
|
||||
|
||||
if (!bTop) throw identifier + "blocks.top property is missing";
|
||||
if (!bSoil) throw identifier + "blocks.soil property is missing";
|
||||
if (!bRock) throw identifier + "blocks.rock property is missing";
|
||||
|
||||
// Get biome tint
|
||||
auto biomeTint = biomeTable.get < sol::optional < std::string >> ("biome_tint");
|
||||
if (!biomeTint) throw identifier + "biome definitions require a biome_tint";
|
||||
|
||||
// Create biome definition
|
||||
BiomeDef* biomeDef = new BiomeDef(
|
||||
identifier, biomes.size(),
|
||||
temperature, humidity, roughness,
|
||||
defs.blockFromStr(*bTop).index,
|
||||
defs.blockFromStr(*bSoil).index,
|
||||
defs.blockFromStr(*bRock).index,
|
||||
glm::vec3(Util::hexToColorVec((*biomeTint)))
|
||||
);
|
||||
|
||||
// Add biome to biomes
|
||||
biomes.registerBiome(biomeDef);
|
||||
}
|
||||
}
|
||||
|
||||
static void server(sol::table& core, ServerDefs& defs) {
|
||||
registerBiomes(core.get<sol::table>("registered_biomes"), defs.defs, defs.biomes);
|
||||
defs.biomes.generateVoronoi();
|
||||
}
|
||||
|
||||
static void client(sol::table& core, LocalDefs& defs) {
|
||||
registerBiomes(core.get<sol::table>("registered_biomes"), defs.defs, defs.biomes);
|
||||
defs.biomes.generateVoronoi();
|
||||
}
|
||||
};
|
|
@ -0,0 +1,302 @@
|
|||
//
|
||||
// Created by aurailus on 2020-01-10.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sol2/sol.hpp>
|
||||
#include "../../def/LocalDefs.h"
|
||||
#include "../../def/ServerDefs.h"
|
||||
#include "../../def/gen/BiomeDef.h"
|
||||
|
||||
namespace RegisterBlocks {
|
||||
|
||||
static std::vector<SelectionBox> parseBoxes(sol::table boxesTable) {
|
||||
std::vector<SelectionBox> boxes {};
|
||||
|
||||
for (auto pair : boxesTable) {
|
||||
if (!pair.second.is<sol::table>()) throw "must be a table";
|
||||
sol::table table = pair.second;
|
||||
|
||||
if (table.size() != 6) throw "must contain exactly 6 elements";
|
||||
boxes.emplace_back(glm::vec3 {table[1], table[2], table[3]}, glm::vec3 {table[4], table[5], table[6]});
|
||||
}
|
||||
|
||||
return boxes;
|
||||
}
|
||||
|
||||
static std::pair<BlockModel, BlockModel> createBlockModel(sol::table blockTable, sol::table blockModels, TextureAtlas* atlas) {
|
||||
// Get the specified block model
|
||||
auto modelStr = blockTable.get_or<std::string>("model", "default:cube");
|
||||
auto modelOpt = blockModels.get<sol::optional<sol::table>>(modelStr);
|
||||
if (!modelOpt) throw "Non-existent model \"" + modelStr + "\" specified";
|
||||
|
||||
sol::table modelTable = *modelOpt;
|
||||
BlockModel model;
|
||||
|
||||
// Apply basic properties
|
||||
model.culls = blockTable.get_or("culls", true);
|
||||
model.visible = blockTable.get_or("visible", true);
|
||||
|
||||
// Convert textures and low-def textures into vectors
|
||||
auto texturesOpt = blockTable.get<sol::optional<sol::table >>("textures");
|
||||
auto ldTexturesOpt = blockTable.get<sol::optional<sol::table >>("lowdef_textures");
|
||||
|
||||
if (!texturesOpt) throw "Missing textures property";
|
||||
|
||||
std::vector<std::string> textures;
|
||||
for (auto pair : *texturesOpt) {
|
||||
if (!pair.second.is<std::string>()) throw "textures table contains non-string value";
|
||||
textures.push_back(pair.second.as<std::string>());
|
||||
}
|
||||
if (textures.size() == 0) textures.push_back("_missing");
|
||||
|
||||
std::vector<std::string> lowdef_textures;
|
||||
if (!ldTexturesOpt) lowdef_textures = textures;
|
||||
else {
|
||||
for (auto pair : *ldTexturesOpt) {
|
||||
if (!pair.second.is<std::string>()) throw "textures table has non-string value!";
|
||||
lowdef_textures.push_back(pair.second.as<std::string>());
|
||||
}
|
||||
}
|
||||
if (lowdef_textures.size() == 0) lowdef_textures.push_back("_missing");
|
||||
|
||||
// Parse through mesh mods and add them
|
||||
sol::optional<sol::table> meshModTable = modelTable.get<sol::optional<sol::table>> ("mesh_mods");
|
||||
if (meshModTable) {
|
||||
for (auto& modEntry : *meshModTable) {
|
||||
auto modTable = modEntry.second.as<sol::table>();
|
||||
std::string meshMod = modTable.get_or<std::string>("type", "none");
|
||||
|
||||
if (meshMod == "none") continue;
|
||||
else if (meshMod == "offset_x")
|
||||
model.meshMods.emplace_back(MeshMod::OFFSET_X, modTable.get_or<float>("amplitude", 1));
|
||||
else if (meshMod == "offset_y")
|
||||
model.meshMods.emplace_back(MeshMod::OFFSET_Y, modTable.get_or<float>("amplitude", 1));
|
||||
else if (meshMod == "offset_z")
|
||||
model.meshMods.emplace_back(MeshMod::OFFSET_Z, modTable.get_or<float>("amplitude", 1));
|
||||
}
|
||||
}
|
||||
|
||||
// Parse through all of the parts and add them to the model
|
||||
auto partsOpt = modelTable.get<sol::optional<sol::table>>("parts");
|
||||
if (!partsOpt) throw "blockmodel is missing parts table";
|
||||
partsOpt->for_each([&](sol::object key, sol::object value) {
|
||||
|
||||
// Validate that variables are what we expect them to be
|
||||
if (!value.is<sol::table>()) throw "meshpart must be a table";
|
||||
sol::table meshPartTable = value.as<sol::table>();
|
||||
|
||||
auto points_optional = meshPartTable.get<sol::optional<sol::table>>("points");
|
||||
if (!points_optional) throw "Meshpart is missing a points table";
|
||||
sol::table points = *points_optional;
|
||||
|
||||
if (points.size() % 20 != 0) throw "Points table must contain a multiple of 20 values";
|
||||
|
||||
// Populate the Vertices and Indices vectors from the points table
|
||||
std::vector<BlockModelVertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
|
||||
for (int i = 1; i <= points.size() / 5; i++) {
|
||||
int offset = (i - 1) * 5 + 1;
|
||||
|
||||
glm::vec3 pos(points[offset], points[offset + 1], points[offset + 2]);
|
||||
glm::vec2 tex(points[offset + 3], points[offset + 4]);
|
||||
|
||||
vertices.push_back({pos, {0, 0, 0}, tex, {0, 0}});
|
||||
}
|
||||
|
||||
int ind = 0;
|
||||
for (int i = 1; i <= points.size() / 20; i++) {
|
||||
indices.push_back(ind);
|
||||
indices.push_back(ind + 1);
|
||||
indices.push_back(ind + 2);
|
||||
indices.push_back(ind + 2);
|
||||
indices.push_back(ind + 3);
|
||||
indices.push_back(ind);
|
||||
ind += 4;
|
||||
}
|
||||
|
||||
// Get the part's texture
|
||||
int tex = std::max(static_cast<int>(meshPartTable.get_or<float>("tex", 1)), 1);
|
||||
auto texture = textures[std::min(tex - 1, (int) textures.size() - 1)];
|
||||
|
||||
//TODO: Make this a proper texture modifier, dont do jank bullshit
|
||||
bool biometint = false;
|
||||
if (strncmp(texture.data(), "biometint(", 10) == 0) {
|
||||
biometint = true;
|
||||
texture = texture.substr(10, texture.length() - 11);
|
||||
}
|
||||
|
||||
// Add texture refs to blockModel if the textures table is provided
|
||||
std::shared_ptr<AtlasRef> textureRef = nullptr;
|
||||
if (atlas) {
|
||||
textureRef = (*atlas)[texture];
|
||||
model.textureRefs.insert(textureRef);
|
||||
}
|
||||
|
||||
// Create the meshpart object
|
||||
MeshPart meshPart(std::move(vertices), std::move(indices), textureRef, biometint);
|
||||
|
||||
// Add the shader mod, if it exists
|
||||
sol::optional<sol::table> shaderModTable = meshPartTable.get<sol::optional<sol::table>>("shader_mod");
|
||||
if (shaderModTable) {
|
||||
std::string shaderMod = shaderModTable->get_or<std::string>("type", "none");
|
||||
|
||||
if (shaderMod == "none") meshPart.shaderMod = ShaderMod::NONE;
|
||||
else if (shaderMod == "rotate_x") {
|
||||
meshPart.shaderMod = ShaderMod::ROTATE_X;
|
||||
meshPart.modValue = (*shaderModTable).get_or<float>("speed", 1);
|
||||
}
|
||||
else if (shaderMod == "rotate_y") {
|
||||
meshPart.shaderMod = ShaderMod::ROTATE_Y;
|
||||
meshPart.modValue = (*shaderModTable).get_or<float>("speed", 1);
|
||||
}
|
||||
else if (shaderMod == "rotate_z") {
|
||||
meshPart.shaderMod = ShaderMod::ROTATE_Z;
|
||||
meshPart.modValue = (*shaderModTable).get_or<float>("speed", 1);
|
||||
}
|
||||
else if (shaderMod == "sway_attached") {
|
||||
meshPart.shaderMod = ShaderMod::SWAY_ATTACHED;
|
||||
meshPart.modValue = (*shaderModTable).get_or<float>("amplitude", 1);
|
||||
}
|
||||
else if (shaderMod == "sway_full_block") {
|
||||
meshPart.shaderMod = ShaderMod::SWAY_FULL_BLOCK;
|
||||
meshPart.modValue = (*shaderModTable).get_or<float>("amplitude", 1);
|
||||
}
|
||||
}
|
||||
|
||||
//Add the meshpart to the proper face of the model
|
||||
std::string face = meshPartTable.get_or<std::string>("face", "nocull");
|
||||
|
||||
Dir d = face == "top" ? Dir::TOP :
|
||||
face == "bottom" ? Dir::BOTTOM :
|
||||
face == "left" ? Dir::LEFT :
|
||||
face == "right" ? Dir::RIGHT :
|
||||
face == "front" ? Dir::FRONT :
|
||||
face == "back" ? Dir::BACK :
|
||||
face == "nocull" ? Dir::NO_CULL :
|
||||
Dir::INVALID;
|
||||
|
||||
if (d == Dir::INVALID) throw "face value is unrecognized";
|
||||
model.parts[static_cast<int>(d)].push_back(meshPart);
|
||||
});
|
||||
|
||||
// Create the low-def block model
|
||||
BlockModel lowdefModel;
|
||||
auto ldRender = blockTable.get_or("lowdef_render", true);
|
||||
/*hiccup*/
|
||||
|
||||
if (atlas) {
|
||||
std::vector<std::shared_ptr<AtlasRef>> refs;
|
||||
for (auto i = 0; i < lowdef_textures.size(); i++) {
|
||||
// TODO: Make biome tint work on LD models
|
||||
std::string texture = lowdef_textures[i];
|
||||
if (strncmp(texture.data(), "biometint(", 10) == 0) {
|
||||
texture = texture.substr(10, texture.length() - 11);
|
||||
}
|
||||
refs.push_back((*atlas)[texture]);
|
||||
}
|
||||
/*hiccup*/
|
||||
lowdefModel = BlockModel::createCube(refs);
|
||||
}
|
||||
else {
|
||||
/*hiccup*//*hiccup*/
|
||||
lowdefModel = BlockModel::createCube({}); /*hiccup*/
|
||||
}
|
||||
/*hiccup*//*hiccup*/
|
||||
lowdefModel.culls = ldRender;
|
||||
lowdefModel.visible = ldRender;
|
||||
/*hiccup*/
|
||||
return {model, lowdefModel}/*hiccup*/;
|
||||
}
|
||||
|
||||
static void registerBlocks(sol::table source, sol::table blockModels, DefinitionAtlas& defs, TextureAtlas* atlas) {
|
||||
// Parses through all of the zepha.registered_blocks and makes BlockDefs.
|
||||
for (auto blockRef : source) {
|
||||
|
||||
// Validate that the identifier and definition table exist
|
||||
std::string identifier = blockRef.first.as<std::string>();
|
||||
|
||||
if (!blockRef.second || !blockRef.second.is<sol::table>())
|
||||
throw "register_block expects a table as the second parameter";
|
||||
sol::table blockTable = blockRef.second.as<sol::table>();
|
||||
|
||||
// Basic Block Properties
|
||||
auto nameOpt = blockTable.get<sol::optional<std::string>>("name");
|
||||
if (!nameOpt) throw identifier + " is missing name property!";
|
||||
|
||||
bool solid = blockTable.get_or("solid", true);
|
||||
auto maxStack = blockTable.get_or("stack", 64);
|
||||
/*hiccup*/
|
||||
// Parse through selection boxes and collision boxes
|
||||
auto selectionOpt = blockTable.get<sol::optional<sol::table>>("selection_box");
|
||||
auto collisionOpt = blockTable.get<sol::optional<sol::table>>("collision_box");
|
||||
|
||||
std::vector<SelectionBox> selectionBoxes {};
|
||||
try { if (selectionOpt) selectionBoxes = parseBoxes(*selectionOpt); }
|
||||
catch (const char* error) { throw std::string("selection boxes " + std::string(error)).c_str(); }
|
||||
if (selectionBoxes.size() == 0) selectionBoxes.emplace_back(glm::vec3 {0, 0, 0}, glm::vec3 {1, 1, 1});
|
||||
|
||||
std::vector<SelectionBox> collisionBoxes {};
|
||||
try { if (collisionOpt) collisionBoxes = parseBoxes(*collisionOpt); }
|
||||
catch (const char* error) { throw std::string("collision boxes " + std::string(error)).c_str(); }
|
||||
if (collisionBoxes.size() == 0) collisionBoxes.emplace_back(glm::vec3 {0, 0, 0}, glm::vec3 {1, 1, 1});
|
||||
|
||||
// Create the block model
|
||||
std::pair<BlockModel, BlockModel> models = createBlockModel(blockTable, blockModels, atlas);
|
||||
/*hiccup*//*hiccup*/
|
||||
BlockDef *blockDef = new BlockDef(
|
||||
/*hiccup*/identifier,
|
||||
defs.size(),
|
||||
*nameOpt,
|
||||
maxStack, /*hiccup*//*hiccup*/
|
||||
models.first,
|
||||
/*hiccup*/solid,/*hiccup*/
|
||||
std::move(selectionBoxes),
|
||||
std::move(collisionBoxes)
|
||||
);/*hiccup*/
|
||||
|
||||
// Create entity model/*hiccup*//*hiccup*/
|
||||
if (atlas) blockDef->createModel();
|
||||
|
||||
// Bind Callbacks
|
||||
auto on_place = blockTable.get<sol::optional<sol::function>>("on_place");
|
||||
if (on_place) blockDef->callbacks.insert({Callback::PLACE, *on_place});
|
||||
|
||||
auto on_place_client = blockTable.get<sol::optional<sol::function>>("on_place_client");
|
||||
if (on_place_client) blockDef->callbacks.insert({Callback::PLACE_CLIENT, *on_place_client});
|
||||
|
||||
auto on_break = blockTable.get<sol::optional<sol::function>>("on_break");
|
||||
if (on_break) blockDef->callbacks.insert({Callback::BREAK, *on_break});
|
||||
|
||||
auto on_break_client = blockTable.get<sol::optional<sol::function>>("on_break_client");
|
||||
if (on_break_client) blockDef->callbacks.insert({Callback::BREAK_CLIENT, *on_break_client});
|
||||
|
||||
auto on_construct = blockTable.get<sol::optional<sol::function>>("on_construct");
|
||||
if (on_construct) blockDef->callbacks.insert({Callback::CONSTRUCT, *on_construct});
|
||||
|
||||
auto after_construct = blockTable.get<sol::optional<sol::function>>("after_construct");
|
||||
if (after_construct) blockDef->callbacks.insert({Callback::AFTER_CONSTRUCT, *after_construct});
|
||||
|
||||
auto on_destruct = blockTable.get<sol::optional<sol::function>>("on_destruct");
|
||||
if (on_destruct) blockDef->callbacks.insert({Callback::DESTRUCT, *on_destruct});
|
||||
|
||||
auto after_destruct = blockTable.get<sol::optional<sol::function>>("after_destruct");
|
||||
if (after_destruct) blockDef->callbacks.insert({Callback::AFTER_DESTRUCT, *after_destruct});
|
||||
|
||||
// Add Block Definition to the Atlas
|
||||
defs.registerDef(blockDef);
|
||||
}
|
||||
}
|
||||
|
||||
static void server(sol::table& core, ServerDefs& defs) {
|
||||
registerBlocks(core.get<sol::table>("registered_blocks"),
|
||||
core.get<sol::table>("registered_blockmodels"), defs.defs, nullptr);
|
||||
}
|
||||
|
||||
static void client(sol::table& core, LocalDefs& defs) {
|
||||
registerBlocks(core.get<sol::table>("registered_blocks"),
|
||||
core.get<sol::table>("registered_blockmodels"), defs.defs, &defs.textures);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,67 @@
|
|||
//
|
||||
// Created by aurailus on 2020-01-10.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sol2/sol.hpp>
|
||||
#include "../../def/LocalDefs.h"
|
||||
#include "../../def/ServerDefs.h"
|
||||
#include "../../def/gen/BiomeDef.h"
|
||||
|
||||
namespace RegisterItems {
|
||||
static void registerItems(sol::table source, DefinitionAtlas& defs, TextureAtlas* atlas) {
|
||||
// Parses through all of the zepha.registered_items and makes ItemDefs.
|
||||
for (auto itemRef : source) {
|
||||
|
||||
// Validate that the identifier and definition table exist
|
||||
std::string identifier = itemRef.first.as<std::string>();
|
||||
|
||||
if (!itemRef.second || !itemRef.second.is<sol::table>())
|
||||
throw identifier + "register_item expects a table as the second paremeter";
|
||||
sol::table itemTable = itemRef.second.as<sol::table>();
|
||||
|
||||
// Basic item properties
|
||||
auto nameOpt = itemTable.get<sol::optional<std::string>>("name");
|
||||
auto texturesOpt = itemTable.get<sol::optional<sol::table>> ("textures");
|
||||
auto maxStack = itemTable.get_or("stack", 64);
|
||||
|
||||
if (!nameOpt) throw identifier + " is missing name property!";
|
||||
if (!texturesOpt) throw identifier + " is missing textures property!";
|
||||
|
||||
//Convert Textures Table to Vector
|
||||
std::vector<std::string> textures;
|
||||
std::vector<sptr<AtlasRef>> textureRefs;
|
||||
for (auto pair : *texturesOpt) {
|
||||
if (!pair.second.is<std::string>()) throw "textures table has non-string value";
|
||||
textures.push_back(pair.second.as<std::string>());
|
||||
if (atlas) textureRefs.push_back((*atlas)[pair.second.as<std::string>()]);
|
||||
}
|
||||
if (textures.size() == 0) {
|
||||
textures.push_back("_missing");
|
||||
if (atlas) textureRefs.push_back((*atlas)["_missing"]);
|
||||
}
|
||||
|
||||
// Creat the definition
|
||||
CraftItemDef* itemDef = new CraftItemDef(
|
||||
identifier,
|
||||
defs.size(),
|
||||
*nameOpt,
|
||||
maxStack,
|
||||
textures,
|
||||
textureRefs
|
||||
);
|
||||
|
||||
if (atlas) itemDef->createModel(*atlas);
|
||||
defs.registerDef(itemDef);
|
||||
}
|
||||
}
|
||||
|
||||
static void server(sol::table& core, ServerDefs& defs) {
|
||||
registerItems(core.get<sol::table>("registered_items"), defs.defs, nullptr);
|
||||
}
|
||||
|
||||
static void client(sol::table& core, LocalDefs& defs) {
|
||||
registerItems(core.get<sol::table>("registered_items"), defs.defs, &defs.textures);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,42 @@
|
|||
//
|
||||
// Created by aurailus on 2020-01-10.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sol2/sol.hpp>
|
||||
#include "../../def/LocalDefs.h"
|
||||
#include "../../def/ServerDefs.h"
|
||||
#include "../../def/gen/BiomeDef.h"
|
||||
|
||||
namespace RegisterKeybinds {
|
||||
static void registerKeybinds(sol::table source, LuaInputManager& manager) {
|
||||
|
||||
// Register all of the items in the zepha.registered_keybinds table
|
||||
for (auto keybindRef : source) {
|
||||
|
||||
// Basic properties
|
||||
std::string identifier = keybindRef.first.as<std::string>();
|
||||
|
||||
if (!keybindRef.second || !keybindRef.second.is<sol::table>())
|
||||
throw identifier + "'s definition table is not a table!";
|
||||
sol::table keybindTbl = keybindRef.second.as<sol::table>();
|
||||
|
||||
ushort def = keybindTbl.get<ushort>("default");
|
||||
|
||||
auto onPress = keybindTbl.get<sol::optional<sol::function>>("on_press");
|
||||
auto onRelease = keybindTbl.get<sol::optional<sol::function>>("on_release");
|
||||
|
||||
if (onPress) manager.bindOnDown(def, *onPress);
|
||||
if (onRelease) manager.bindOnUp(def, *onRelease);
|
||||
}
|
||||
}
|
||||
|
||||
// static void server(sol::table& core, ServerDefs& defs) {
|
||||
// registerItems(core.get<sol::table>("registered_items"), defs.defs, nullptr);
|
||||
// }
|
||||
|
||||
static void client(sol::table& core, LuaInputManager& manager) {
|
||||
registerKeybinds(core.get<sol::table>("registered_keybinds"), manager);
|
||||
}
|
||||
};
|
|
@ -1,59 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 2019-11-12.
|
||||
//
|
||||
|
||||
#include "ServerRegisterBiomes.h"
|
||||
|
||||
ServerRegisterBiomes::ServerRegisterBiomes(sol::table& core, ServerDefs &defs) {
|
||||
//Register all of the biomes in the zepha.registered_biomes table.
|
||||
for (auto biomeRef : core.get<sol::table>("registered_biomes")) {
|
||||
//Get the unique identifier of the biome
|
||||
std::string identifier = biomeRef.first.as<std::string>();
|
||||
|
||||
//Make sure the biome table is actually a table, and get it.
|
||||
if (!biomeRef.second || !biomeRef.second.is<sol::table>()) throw identifier + "'s definition table is not a table!";
|
||||
sol::table biomeTable = biomeRef.second.as<sol::table>();
|
||||
|
||||
//Get biome properties and throw errors if required ones are missing
|
||||
auto temperature = biomeTable.get_or<float>("temperature", -10000);
|
||||
auto humidity = biomeTable.get_or<float>("humidity", -10000);
|
||||
auto roughness = biomeTable.get_or<float>("roughness", -10000);
|
||||
|
||||
if (temperature == -10000) throw identifier + " is missing temperature property!";
|
||||
if (temperature < -1 || temperature > 1) throw identifier + "'s temperature property is out of range!";
|
||||
if (humidity == -10000) throw identifier + " is missing humidity property!";
|
||||
if (humidity < 0 || humidity > 1) throw identifier + "'s humidity property is out of range!";
|
||||
if (roughness == -10000) throw identifier + " is missing roughness property!";
|
||||
if (roughness < 0 || roughness > 1) throw identifier + "'s roughness property is out of range!";
|
||||
|
||||
//Get the blocks for the terrain to be made out of.
|
||||
auto blocksList = biomeTable.get<sol::optional<sol::table>>("blocks");
|
||||
if (!blocksList) throw identifier + "'s definition is missing blocks list.";
|
||||
|
||||
auto topBlock = (*blocksList).get<sol::optional<std::string>>("top");
|
||||
auto soilBlock = (*blocksList).get<sol::optional<std::string>>("soil");
|
||||
auto rockBlock = (*blocksList).get<sol::optional<std::string>>("rock");
|
||||
|
||||
if (!topBlock) throw identifier + "'s blocks property is missing a `top` block.";
|
||||
if (!soilBlock) throw identifier + "'s blocks property is missing a `soil` block.";
|
||||
if (!rockBlock) throw identifier + "'s blocks property is missing a `rock` block.";
|
||||
|
||||
auto biomeTint = biomeTable.get<sol::optional<std::string>>("biome_tint");
|
||||
|
||||
if (!biomeTint) throw identifier + "'s blocks property is missing a `biome_tint`.";
|
||||
|
||||
BiomeDef* biomeDef = new BiomeDef(
|
||||
identifier, defs.biomes.size(),
|
||||
temperature, humidity, roughness,
|
||||
defs.defs.blockFromStr(*topBlock).index,
|
||||
defs.defs.blockFromStr(*soilBlock).index,
|
||||
defs.defs.blockFromStr(*rockBlock).index,
|
||||
glm::vec3(Util::hexToColorVec((*biomeTint)))
|
||||
);
|
||||
|
||||
//Add Biome Definition to the Gen
|
||||
defs.biomes.registerBiome(biomeDef);
|
||||
}
|
||||
|
||||
defs.biomes.generateVoronoi();
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 2019-11-12.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sol2/sol.hpp>
|
||||
#include "../../def/ServerDefs.h"
|
||||
#include "../../def/gen/BiomeDef.h"
|
||||
|
||||
class ServerRegisterBiomes {
|
||||
public:
|
||||
ServerRegisterBiomes(sol::table& core, ServerDefs& defs);
|
||||
};
|
|
@ -1,219 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 29/06/19.
|
||||
//
|
||||
|
||||
#include "ServerRegisterBlocks.h"
|
||||
|
||||
ServerRegisterBlocks::ServerRegisterBlocks(sol::table& core, ServerDefs &defs) {
|
||||
//Register all of the blocks in the zepha.registered_blocks table.
|
||||
for (auto blockRef : core.get<sol::table>("registered_blocks")) {
|
||||
//Get the unique identifier of the block
|
||||
std::string identifier = blockRef.first.as<std::string>();
|
||||
|
||||
//Make sure the block table is actually a table, and get it.
|
||||
if (!blockRef.second || !blockRef.second.is<sol::table>())
|
||||
throw identifier + "'s definition table is not a table!";
|
||||
sol::table blockTable = blockRef.second.as<sol::table>();
|
||||
|
||||
//Get block properties and throw errors if required ones are missing
|
||||
auto nameOpt = blockTable.get<sol::optional<std::string>>("name");
|
||||
auto modelStrOpt = blockTable.get<sol::optional<std::string>>("model");
|
||||
auto texturesOpt = blockTable.get<sol::optional<sol::table>> ("textures");
|
||||
auto selectionOpt = blockTable.get<sol::optional<sol::table>> ("selection_box");
|
||||
auto ldTexturesOpt= blockTable.get<sol::optional<sol::table>> ("lowdef_textures");
|
||||
|
||||
if (!nameOpt) throw identifier + " is missing name property!";
|
||||
if (!texturesOpt) throw identifier + " is missing textures property!";
|
||||
|
||||
bool visible = blockTable.get_or("visible", true);
|
||||
bool culls = blockTable.get_or("culls", true);
|
||||
bool solid = blockTable.get_or("solid", true);
|
||||
auto ldRender = blockTable.get_or("lowdef_render", true);
|
||||
auto maxStack = blockTable.get_or("stack", 64);
|
||||
|
||||
//Get the identifier for the blockModel, and then get the model from the zepha.registered_blockmodels table.
|
||||
std::string modelStr = (modelStrOpt ? *modelStrOpt : "default:cube");
|
||||
auto modelOpt = core.get<sol::table>("registered_blockmodels").get<sol::optional<sol::table>>(modelStr);
|
||||
if (!modelOpt) throw identifier + " specifies invalid model " + modelStr + "!";
|
||||
|
||||
//Create a vector of selection boxes
|
||||
std::vector<SelectionBox> sBoxes;
|
||||
if (selectionOpt) {
|
||||
for (auto pair : *selectionOpt) {
|
||||
sol::table s = pair.second;
|
||||
sBoxes.push_back({{s[1], s[2], s[3]}, {s[4], s[5], s[6]}});
|
||||
}
|
||||
} else {
|
||||
sBoxes.push_back({{0, 0, 0}, {1, 1, 1}});
|
||||
}
|
||||
|
||||
//Create a block model from the above properties
|
||||
sol::table model = *modelOpt;
|
||||
BlockModel blockModel;
|
||||
|
||||
blockModel.culls = culls;
|
||||
blockModel.visible = visible;
|
||||
|
||||
//Convert Textures Table to Vector
|
||||
std::vector<std::string> textures;
|
||||
for (auto pair : *texturesOpt) {
|
||||
if (!pair.second.is<std::string>()) throw "Textures table has non-string value!";
|
||||
textures.push_back(pair.second.as<std::string>());
|
||||
}
|
||||
if (textures.size() == 0) textures.push_back("_missing");
|
||||
|
||||
//Convert LowDef Textures Table to Vector
|
||||
std::vector<std::string> lowdef_textures;
|
||||
if (ldTexturesOpt) {
|
||||
for (auto pair : *ldTexturesOpt) {
|
||||
if (!pair.second.is<std::string>()) throw "Textures table has non-string value!";
|
||||
lowdef_textures.push_back(pair.second.as<std::string>());
|
||||
}
|
||||
if (lowdef_textures.size() == 0) lowdef_textures.push_back("_missing");
|
||||
}
|
||||
else {
|
||||
lowdef_textures = textures;
|
||||
}
|
||||
|
||||
//Add Mesh Mods
|
||||
sol::optional<sol::table> meshModTable = model.get<sol::optional<sol::table>>("mesh_mods");
|
||||
if (meshModTable) {
|
||||
for (auto modEntry : (*meshModTable)) {
|
||||
auto modTable = modEntry.second.as<sol::table>();
|
||||
std::string meshMod = modTable.get_or<std::string>("type", "none");
|
||||
|
||||
if (meshMod == "none") { continue; }
|
||||
else if (meshMod == "offset_x") {
|
||||
blockModel.meshMods.emplace_back(
|
||||
MeshMod::OFFSET_X, modTable.get_or<float>("amplitude", 1));
|
||||
}
|
||||
else if (meshMod == "offset_y") {
|
||||
blockModel.meshMods.emplace_back(
|
||||
MeshMod::OFFSET_Y, modTable.get_or<float>("amplitude", 1));
|
||||
}
|
||||
else if (meshMod == "offset_z") {
|
||||
blockModel.meshMods.emplace_back(
|
||||
MeshMod::OFFSET_Z, modTable.get_or<float>("amplitude", 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Convert all of the mesh parts to C++ Objects and add them to blockModel
|
||||
model.get<sol::table>("parts").for_each([&](sol::object key, sol::object value) {
|
||||
|
||||
//Make sure LocalMeshPart is in fact a table
|
||||
if (!value.is<sol::table>()) throw "Meshpart is not a table";
|
||||
sol::table meshPartTable = value.as<sol::table>();
|
||||
|
||||
//Get The points table, and make sure it's valid
|
||||
auto points_optional = meshPartTable.get<sol::optional<sol::table>>("points");
|
||||
if (!points_optional) throw "Meshpart is missing a points table (Local)";
|
||||
|
||||
sol::table points = *points_optional;
|
||||
|
||||
if (points.size() % 20 != 0) throw "Points array is ill-formed. (Not a multiple of 20 values)";
|
||||
|
||||
//Populate the Vertices and Indices vectors from the points table
|
||||
std::vector<BlockModelVertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
|
||||
for (int i = 1; i <= points.size()/5; i++) {
|
||||
int offset = (i - 1) * 5 + 1;
|
||||
|
||||
glm::vec3 pos(points[offset], points[offset + 1], points[offset + 2]);
|
||||
glm::vec2 tex(points[offset + 3], points[offset + 4]);
|
||||
|
||||
vertices.push_back({pos, {0, 0, 0}, tex, {0, 0}});
|
||||
}
|
||||
|
||||
int ind = 0;
|
||||
for (int i = 1; i <= points.size() / 20; i++) {
|
||||
indices.push_back(ind);
|
||||
indices.push_back(ind + 1);
|
||||
indices.push_back(ind + 2);
|
||||
indices.push_back(ind + 2);
|
||||
indices.push_back(ind + 3);
|
||||
indices.push_back(ind);
|
||||
ind += 4;
|
||||
}
|
||||
|
||||
//Create a MeshPart object
|
||||
MeshPart meshPart(std::move(vertices), std::move(indices), nullptr, false);
|
||||
|
||||
//Add ShaderMod
|
||||
sol::optional<sol::table> shaderModTable = meshPartTable.get<sol::optional<sol::table>>("shader_mod");
|
||||
if (shaderModTable) {
|
||||
std::string shaderMod = (*shaderModTable).get_or<std::string>("type", "none");
|
||||
|
||||
if (shaderMod == "none") {
|
||||
meshPart.shaderMod = ShaderMod::NONE;
|
||||
}
|
||||
else if (shaderMod == "rotate_x") {
|
||||
meshPart.shaderMod = ShaderMod::ROTATE_X;
|
||||
meshPart.modValue = (*shaderModTable).get_or<float>("speed", 1);
|
||||
}
|
||||
else if (shaderMod == "rotate_y") {
|
||||
meshPart.shaderMod = ShaderMod::ROTATE_Y;
|
||||
meshPart.modValue = (*shaderModTable).get_or<float>("speed", 1);
|
||||
}
|
||||
else if (shaderMod == "rotate_z") {
|
||||
meshPart.shaderMod = ShaderMod::ROTATE_Z;
|
||||
meshPart.modValue = (*shaderModTable).get_or<float>("speed", 1);
|
||||
}
|
||||
else if (shaderMod == "sway_attached") {
|
||||
meshPart.shaderMod = ShaderMod::SWAY_ATTACHED;
|
||||
meshPart.modValue = (*shaderModTable).get_or<float>("amplitude", 1);
|
||||
}
|
||||
else if (shaderMod == "sway_full_block") {
|
||||
meshPart.shaderMod = ShaderMod::SWAY_FULL_BLOCK;
|
||||
meshPart.modValue = (*shaderModTable).get_or<float>("amplitude", 1);
|
||||
}
|
||||
}
|
||||
|
||||
//Add the meshpart to the proper face vector
|
||||
std::string face = meshPartTable.get_or<std::string>("face", "nocull");
|
||||
|
||||
Dir d = face == "top" ? Dir::TOP :
|
||||
face == "bottom" ? Dir::BOTTOM :
|
||||
face == "left" ? Dir::LEFT :
|
||||
face == "right" ? Dir::RIGHT :
|
||||
face == "front" ? Dir::FRONT :
|
||||
face == "back" ? Dir::BACK :
|
||||
face == "nocull" ? Dir::NO_CULL :
|
||||
Dir::INVALID;
|
||||
|
||||
if (d == Dir::INVALID)
|
||||
throw "Face value \"" + face + "\" is not one of 'top', 'bottom', 'left', 'right', 'front', 'back', 'nocull'.";
|
||||
|
||||
blockModel.parts[static_cast<int>(d)].push_back(meshPart);
|
||||
});
|
||||
|
||||
BlockModel lowdefBlockModel = BlockModel::createCube({});
|
||||
lowdefBlockModel.culls = ldRender;
|
||||
lowdefBlockModel.visible = ldRender;
|
||||
|
||||
BlockDef* blockDef = new BlockDef(identifier, defs.defs.size(), *nameOpt, maxStack, lowdefBlockModel, solid, std::move(sBoxes), {});
|
||||
|
||||
//Bind Callbacks
|
||||
auto on_place = blockTable.get<sol::optional<sol::function>>("on_place");
|
||||
if (on_place) blockDef->callbacks.insert({Callback::PLACE, *on_place});
|
||||
|
||||
auto on_break = blockTable.get<sol::optional<sol::function>>("on_break");
|
||||
if (on_break) blockDef->callbacks.insert({Callback::BREAK, *on_break});
|
||||
|
||||
auto on_construct = blockTable.get<sol::optional<sol::function>>("on_construct");
|
||||
if (on_construct) blockDef->callbacks.insert({Callback::CONSTRUCT, *on_construct});
|
||||
|
||||
auto after_construct = blockTable.get<sol::optional<sol::function>>("after_construct");
|
||||
if (after_construct) blockDef->callbacks.insert({Callback::AFTER_CONSTRUCT, *after_construct});
|
||||
|
||||
auto on_destruct = blockTable.get<sol::optional<sol::function>>("on_destruct");
|
||||
if (on_destruct) blockDef->callbacks.insert({Callback::DESTRUCT, *on_destruct});
|
||||
|
||||
auto after_destruct = blockTable.get<sol::optional<sol::function>>("after_destruct");
|
||||
if (after_destruct) blockDef->callbacks.insert({Callback::AFTER_DESTRUCT, *after_destruct});
|
||||
|
||||
//Add Block Definition to the Atlas
|
||||
defs.defs.registerDef(blockDef);
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 29/06/19.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <sol2/sol.hpp>
|
||||
#include "../../def/ServerDefs.h"
|
||||
#include "../../def/item/BlockModel.h"
|
||||
|
||||
class ServerRegisterBlocks {
|
||||
public:
|
||||
ServerRegisterBlocks(sol::table& core, ServerDefs& defs);
|
||||
};
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 01/10/19.
|
||||
//
|
||||
|
||||
#include "ServerRegisterItems.h"
|
||||
|
||||
ServerRegisterItems::ServerRegisterItems(sol::table& core, ServerDefs &defs) {
|
||||
//Register all of the items in the zepha.registered_items table.
|
||||
for (auto itemRef : core.get<sol::table>("registered_items")) {
|
||||
//Get the unique identifier of the item
|
||||
std::string identifier = itemRef.first.as<std::string>();
|
||||
|
||||
//Make sure the block table is actually a table, and get it.
|
||||
if (!itemRef.second || !itemRef.second.is<sol::table>()) throw identifier + "'s definition table is not a table!";
|
||||
sol::table itemTable = itemRef.second.as<sol::table>();
|
||||
|
||||
//Get item properties and throw errors if required ones are missing
|
||||
auto nameOpt = itemTable.get<sol::optional<std::string>>("name");
|
||||
auto texturesOpt = itemTable.get<sol::optional<sol::table>> ("textures");
|
||||
|
||||
if (!nameOpt) throw identifier + " is missing name property!";
|
||||
if (!texturesOpt) throw identifier + " is missing textures property!";
|
||||
|
||||
auto maxStack = itemTable.get_or("stack", 64);
|
||||
|
||||
//Convert Textures Table to Vector
|
||||
std::vector<std::string> textures;
|
||||
for (auto pair : *texturesOpt) {
|
||||
if (!pair.second.is<std::string>()) throw "Textures table has non-string value!";
|
||||
textures.push_back(pair.second.as<std::string>());
|
||||
}
|
||||
if (textures.size() == 0) textures.push_back("_missing");
|
||||
|
||||
CraftItemDef* itemDef = new CraftItemDef(identifier, defs.defs.size(), *nameOpt, maxStack, textures, {});
|
||||
|
||||
//Add Block Definition to the Atlas
|
||||
defs.defs.registerDef(itemDef);
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 01/10/19.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sol2/sol.hpp>
|
||||
#include "../../def/ServerDefs.h"
|
||||
|
||||
class ServerRegisterItems {
|
||||
public:
|
||||
ServerRegisterItems(sol::table& core, ServerDefs& defs);
|
||||
|
||||
};
|
|
@ -38,6 +38,17 @@ vector.subtract = function(v1, v2)
|
|||
return vector.add(v1, vector.negative(v2))
|
||||
end
|
||||
|
||||
-- vector.multiply
|
||||
-- Multiply v1 by a vector or number
|
||||
vector.multiply = function(v1, m)
|
||||
if type(v1) ~= "table" then return nil end
|
||||
if type(m) == "table" then
|
||||
return {x = (v1.x or 0) * (m.x or 0), y = (v1.y or 0) * (m.y or 0), z = (v1.z or 0) * (m.z or 0)}
|
||||
elseif type(m) == "number" then
|
||||
return {x = (v1.x or 0) * m, y = (v1.y or 0) * m, z = (v1.z or 0) * m}
|
||||
else return nil end
|
||||
end
|
||||
|
||||
-- vector.abs
|
||||
-- Return the absolute value of v
|
||||
vector.abs = function(v)
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
zepha.register_biome("zeus:default:desert", {
|
||||
temperature = 40/100,
|
||||
humidity = 20/100,
|
||||
roughness = 10/100,
|
||||
environment = {
|
||||
temperature = 40/100,
|
||||
humidity = 20/100,
|
||||
roughness = 10/100
|
||||
},
|
||||
blocks = {
|
||||
top = "zeus:default:sand",
|
||||
soil = "zeus:default:sand",
|
||||
|
|
|
@ -1,35 +1,42 @@
|
|||
local noise = {
|
||||
module = "add",
|
||||
sources = {
|
||||
{ -- Elevation
|
||||
module = "scale_bias",
|
||||
source = {
|
||||
module = "perlin",
|
||||
seed = zepha.seed,
|
||||
frequency = 0.002,
|
||||
octaves = 8
|
||||
},
|
||||
scale = 250,
|
||||
bias = 32
|
||||
},
|
||||
{ -- Features
|
||||
module = "scale_bias",
|
||||
source = {
|
||||
module = "perlin",
|
||||
seed = zepha.seed,
|
||||
frequency = 0.2,
|
||||
octaves = 3,
|
||||
},
|
||||
scale = 6,
|
||||
bias = 6
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
zepha.register_biome("zeus:default:plains", {
|
||||
temperature = 15/100,
|
||||
humidity = 80/100,
|
||||
roughness = 20/100,
|
||||
environment = {
|
||||
temperature = 15/100,
|
||||
humidity = 80/100,
|
||||
roughness = 20/100,
|
||||
},
|
||||
blocks = {
|
||||
top = "zeus:default:tallgrass_1",
|
||||
soil = "zeus:default:grass",
|
||||
rock = "zeus:default:stone"
|
||||
},
|
||||
biome_tint = "#aaed45"
|
||||
})
|
||||
|
||||
zepha.register_biome("zeus:default:lush_plains", {
|
||||
temperature = 15/100,
|
||||
humidity = 95/100,
|
||||
roughness = 20/100,
|
||||
blocks = {
|
||||
top = "zeus:default:grass",
|
||||
soil = "zeus:default:dirt",
|
||||
rock = "zeus:default:stone"
|
||||
},
|
||||
biome_tint = "#05ff1e"
|
||||
})
|
||||
|
||||
zepha.register_biome("zeus:default:dry_plains", {
|
||||
temperature = 15/100,
|
||||
humidity = 40/100,
|
||||
roughness = 20/100,
|
||||
blocks = {
|
||||
top = "zeus:default:grass",
|
||||
soil = "zeus:default:dirt",
|
||||
rock = "zeus:default:stone"
|
||||
},
|
||||
biome_tint = "#e6fa61"
|
||||
biome_tint = "#aaed45",
|
||||
noise = noise
|
||||
})
|
|
@ -1,7 +1,9 @@
|
|||
zepha.register_biome("zeus:default:rocklands", {
|
||||
temperature = 0/100,
|
||||
humidity = 0/100,
|
||||
roughness = 50/100,
|
||||
environment = {
|
||||
temperature = 0/100,
|
||||
humidity = 0/100,
|
||||
roughness = 50/100
|
||||
},
|
||||
blocks = {
|
||||
top = "zeus:default:cobblestone",
|
||||
soil = "zeus:default:stone",
|
||||
|
|
|
@ -18,12 +18,19 @@ zepha.register_entity("zeus:default:dropped_item", {
|
|||
self.tick = 0
|
||||
self.time = static.time or 0
|
||||
self.speed = static.speed or 20
|
||||
self.velocityY = static.velocityY or -100
|
||||
|
||||
self.delete = false
|
||||
self.scooping = false
|
||||
|
||||
if not zepha.registered_blocks[static.object] then self.object.scale = 1/2
|
||||
local angle = math.random() * (math.pi*2)
|
||||
local amp = (math.random() + 0.5) * 5
|
||||
local x = math.sin(angle) * amp
|
||||
local z = math.cos(angle) * amp
|
||||
|
||||
|
||||
self.vel = static.vel or v{x, -85, z}
|
||||
|
||||
if not zepha.registered_blocks[self.item] then self.object.scale = 1/2
|
||||
else self.object.scale = 1/3 end
|
||||
end,
|
||||
on_update = function(self, delta)
|
||||
|
@ -40,21 +47,25 @@ zepha.register_entity("zeus:default:dropped_item", {
|
|||
if self.scooping then return end
|
||||
|
||||
if not collides(self.object) then
|
||||
self.velocityY = math.min(self.velocityY + 300 * delta, 480)
|
||||
self.vel.y = math.min(self.vel.y + 300 * delta, 480)
|
||||
end
|
||||
|
||||
local iter = 1
|
||||
while not collides(self.object) and iter <= math.abs(self.velocityY * delta) do
|
||||
while not collides(self.object) and iter <= math.abs(self.vel.y * delta) do
|
||||
local interval = 0
|
||||
if self.velocityY < 0 then interval = 1/16 else interval = -1/16 end
|
||||
if self.vel.y < 0 then interval = 1/16 else interval = -1/16 end
|
||||
self.object.pos = vector.add(self.object.pos, v{0, interval, 0})
|
||||
iter = iter + 0.25
|
||||
end
|
||||
|
||||
self.object.pos = vector.add(self.object.pos, vector.multiply(v{self.vel.x, 0, self.vel.z}, delta))
|
||||
self.vel.x = self.vel.x * 0.6
|
||||
self.vel.z = self.vel.z * 0.6
|
||||
|
||||
self.object.visual_offset = v{0, math.sin(self.time * 2) / 8, 0}
|
||||
|
||||
if collides(self.object) then
|
||||
self.velocityY = 0
|
||||
self.vel.y = 0
|
||||
self.time = self.time + delta
|
||||
end
|
||||
|
||||
|
@ -76,7 +87,7 @@ zepha.register_entity("zeus:default:dropped_item", {
|
|||
end,
|
||||
on_serialize = function(self)
|
||||
return {
|
||||
velocityY = self.velocityY,
|
||||
vel = self.vel,
|
||||
time = self.time,
|
||||
speed = self.speed
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ if zepha.server then return end -- Only run the following code on the client.
|
|||
local shit_adding = false
|
||||
local main = zepha.player:get_inventory():get_list("main")
|
||||
|
||||
zepha.register_keybind("add_shit_b", {
|
||||
zepha.register_keybind("zeus:inventory:add_shit_b", {
|
||||
description = "Add testing items to inventory",
|
||||
default = zepha.keys.b,
|
||||
on_press = function()
|
||||
|
@ -16,7 +16,7 @@ zepha.register_keybind("add_shit_b", {
|
|||
end
|
||||
})
|
||||
|
||||
zepha.register_keybind("add_shit_i", {
|
||||
zepha.register_keybind("zeus:inventory:add_shit_i", {
|
||||
description = "Add testing items to inventory",
|
||||
default = zepha.keys.n,
|
||||
on_press = function()
|
||||
|
@ -43,7 +43,7 @@ zepha.delay(function()
|
|||
return true
|
||||
end, 0)
|
||||
|
||||
zepha.register_keybind("open_inventory", {
|
||||
zepha.register_keybind("zeus:inventory:open_inventory", {
|
||||
description = "Open Inventory",
|
||||
default = zepha.keys.e,
|
||||
on_press = function()
|
||||
|
|
Loading…
Reference in New Issue