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

Method spawnItem

source/game/scripting/StarWorldLuaBindings.cpp:878–914  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

876 }
877
878 Maybe<EntityId> WorldCallbacks::spawnItem(World* world,
879 Json const& itemType,
880 Vec2F const& worldPosition,
881 Maybe<size_t> const& inputCount,
882 Json const& inputParameters,
883 Maybe<Vec2F> const& initialVelocity,
884 Maybe<float> const& intangibleTime) {
885 Vec2F const position = worldPosition;
886
887 try {
888 ItemDescriptor descriptor;
889 if (itemType.isType(Json::Type::String)) {
890 size_t count = inputCount.value(1);
891
892 Json parameters = inputParameters ? inputParameters : JsonObject();
893
894 descriptor = ItemDescriptor(itemType.toString(), count, parameters);
895 } else {
896 descriptor = ItemDescriptor(itemType);
897 }
898
899 if (auto itemDrop = ItemDrop::createRandomizedDrop(descriptor, position)) {
900 if (initialVelocity)
901 itemDrop->setVelocity(*initialVelocity);
902 if (intangibleTime)
903 itemDrop->setIntangibleTime(*intangibleTime);
904 world->addEntity(itemDrop);
905 return itemDrop->inWorld() ? itemDrop->entityId() : Maybe<EntityId>();
906 }
907
908 Logger::warn("Could not spawn item, item empty in WorldCallbacks::spawnItem");
909 } catch (StarException const& exception) {
910 Logger::warn("Could not spawn Item of kind '{}', exception caught: {}", itemType, outputException(exception, false));
911 }
912
913 return {};
914 }
915
916 List<EntityId> WorldCallbacks::spawnTreasure(
917 World* world, Vec2F const& position, String const& pool, float level, Maybe<uint64_t> seed) {

Callers

nothing calls this directly

Calls 10

ItemDescriptorClass · 0.85
setIntangibleTimeMethod · 0.80
entityIdMethod · 0.80
outputExceptionFunction · 0.50
isTypeMethod · 0.45
valueMethod · 0.45
toStringMethod · 0.45
setVelocityMethod · 0.45
addEntityMethod · 0.45
inWorldMethod · 0.45

Tested by

no test coverage detected