MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / placeMaterial

Method placeMaterial

source/game/scripting/StarWorldLuaBindings.cpp:2020–2059  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2018 }
2019
2020 bool WorldEnvironmentCallbacks::placeMaterial(World* world, Vec2I const& arg1, String const& arg2, String const& arg3, Maybe<int> const& arg4, bool arg5) {
2021 auto tilePosition = arg1;
2022
2023 PlaceMaterial placeMaterial;
2024
2025 std::string layerName = arg2.utf8();
2026 auto split = layerName.find_first_of('+');
2027 if (split != NPos) {
2028 auto overrideName = layerName.substr(split + 1);
2029 layerName = layerName.substr(0, split);
2030 if (overrideName == "empty" || overrideName == "none")
2031 placeMaterial.collisionOverride = TileCollisionOverride::Empty;
2032 else if (overrideName == "block")
2033 placeMaterial.collisionOverride = TileCollisionOverride::Block;
2034 else if (overrideName == "platform")
2035 placeMaterial.collisionOverride = TileCollisionOverride::Platform;
2036 else
2037 throw StarException(strf("Unsupported collision override {}", overrideName));
2038 }
2039
2040 if (layerName == "foreground")
2041 placeMaterial.layer = TileLayer::Foreground;
2042 else if (layerName == "background")
2043 placeMaterial.layer = TileLayer::Background;
2044 else
2045 throw StarException(strf("Unsupported tile layer {}", layerName));
2046
2047 auto materialName = arg3;
2048 auto materialDatabase = Root::singleton().materialDatabase();
2049 if (!materialDatabase->materialNames().contains(materialName))
2050 throw StarException(strf("Unknown material name {}", materialName));
2051 placeMaterial.material = materialDatabase->materialId(materialName);
2052
2053 if (arg4)
2054 placeMaterial.materialHueShift = (MaterialHue)*arg4;
2055
2056 bool allowOverlap = arg5;
2057
2058 return world->modifyTile(tilePosition, placeMaterial, allowOverlap);
2059 }
2060
2061 bool WorldEnvironmentCallbacks::replaceMaterials(World* world,
2062 List<Vec2I> const& tilePositions,

Callers

nothing calls this directly

Calls 9

StarExceptionClass · 0.85
strfFunction · 0.85
singletonClass · 0.85
materialDatabaseMethod · 0.80
materialNamesMethod · 0.80
substrMethod · 0.45
containsMethod · 0.45
materialIdMethod · 0.45
modifyTileMethod · 0.45

Tested by

no test coverage detected