Modding:World Access: Difference between revisions
From Vintage Story Wiki
Line 109: | Line 109: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
And the final result: | And the complete code and final result: | ||
<syntaxhighlight lang="c#"> | |||
private void OnPlayerJoin(IServerPlayer byPlayer) | |||
{ | |||
BlockPos plrpos = byPlayer.Entity.Pos.AsBlockPos; | |||
Block firebrickblock = api.World.GetBlock(new AssetLocation("claybricks-fire")); | |||
ushort blockId = firebrickblock.BlockId; | |||
api.World.BlockAccessor.SetBlock(blockId, plrpos.DownCopy()); | |||
// Check a 3x3x3 area for logs | |||
int quantityLogs = 0; | |||
api.World.BlockAccessor.WalkBlocks( | |||
plrpos.AddCopy(-3, -3, -3), | |||
plrpos.AddCopy(3, 3, 3), | |||
(block, pos) => quantityLogs += block.Code.Path.Contains("log") ? 1 : 0 | |||
); | |||
byPlayer.SendMessage(GlobalConstants.GeneralChatGroup, "You have " + quantityLogs + " logs nearby you", EnumChatType.Notification); | |||
} | |||
</syntaxhighlight> | |||
[[File:SetblockTut.png|500px]] | [[File:SetblockTut.png|500px]] | ||
I hope this taught you the basics of accessing the world. | I hope this taught you the basics of accessing the world. |