Confirmedusers, Bureaucrats, editor, Administrators
1,522
edits
VeryGoodDog (talk | contribs) m (VeryGoodDog moved page World Access to Modding:World Access) |
|||
(5 intermediate revisions by 3 users not shown) | |||
Line 4: | Line 4: | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
public class SampleMod : | public class SampleMod : ModSystem | ||
{ | { | ||
ICoreServerAPI api; | ICoreServerAPI api; | ||
Line 25: | Line 25: | ||
* during world generation we'd have to register to the [[WorldGen API|appropriate world gen events]]. | * during world generation we'd have to register to the [[WorldGen API|appropriate world gen events]]. | ||
* when the player runs a custom command we need to register one: <code>api.RegisterCommand("test", "a test command", "", OnCommand);</code> | * when the player runs a custom command we need to register one: <code>api.RegisterCommand("test", "a test command", "", OnCommand);</code> | ||
* when a player joins the game: <code>api.Event.PlayerJoin | * when a player joins the game: <code>api.Event.PlayerJoin += OnPlayerJoin;</code> | ||
Let's register to the player join event. | Let's register to the player join event. | ||
Line 33: | Line 33: | ||
{ | { | ||
this.api = api; | this.api = api; | ||
api.Event.PlayerJoin | api.Event.PlayerJoin += OnPlayerJoin; | ||
} | } | ||
Line 46: | Line 46: | ||
* Count the amount log blocks around the player in a 3 block radius | * Count the amount log blocks around the player in a 3 block radius | ||
Now, blocks are always uniquely identified by a number of characters called the block code. If you want to find out a blocks code, a simple way of doing it is to start the game, enable the debug info mode via the command .edi and look at a block in the creative inventory: | Now, blocks are always uniquely identified by a number of characters called the block code. If you want to find out a blocks code, a simple way of doing it is to start the game, enable the debug info mode via the command <code>.edi</code> and look at a block in the creative inventory: | ||
[[File:Blockcode.png]] | [[File:Blockcode.png]] | ||
Line 74: | Line 74: | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
// Check a | // Check a 7x7x7 area for logs | ||
int quantityLogs = 0; | int quantityLogs = 0; | ||
for (int x = -3; x <= 3; x++) | for (int x = -3; x <= 3; x++) | ||
Line 120: | Line 120: | ||
api.World.BlockAccessor.SetBlock(blockId, plrpos.DownCopy()); | api.World.BlockAccessor.SetBlock(blockId, plrpos.DownCopy()); | ||
// Check a | // Check a 7x7x7 area for logs | ||
int quantityLogs = 0; | int quantityLogs = 0; | ||
api.World.BlockAccessor.WalkBlocks( | api.World.BlockAccessor.WalkBlocks( | ||
Line 136: | Line 136: | ||
I hope this taught you the basics of accessing the world. More ways to access blocks and entities will be added here in the future. | I hope this taught you the basics of accessing the world. More ways to access blocks and entities will be added here in the future. | ||
{{Navbox/modding|Vintage Story}} |