Modding:WorldGen API: Difference between revisions

From Vintage Story Wiki
m
typo
m (typo)
Line 64: Line 64:
private void PlaceTreasureChestInFrontOfPlayer(IServerPlayer player, int groupId, CmdArgs args)
private void PlaceTreasureChestInFrontOfPlayer(IServerPlayer player, int groupId, CmdArgs args)
{
{
     // Old, don't work on latest version
     ushort blockID = api.WorldManager.GetBlockId("chest-south");
    // ushort blockID = api.WorldManager.GetBlockId("chest-south");
     Block chest = api.WorldManager.GetBlockType(blockID);
     // Block chest = api.WorldManager.GetBlockType(blockID);
     chest.TryPlaceBlockForWorldGen(api.World.BlockAccessor, player.Entity.Pos.HorizontalAheadCopy(2).AsBlockPos, BlockFacing.UP);
    // chest.TryPlaceBlockForWorldGen(api.World.BlockAccessor, player.Entity.Pos.HorizontalAheadCopy(2).AsBlockPos, BlockFacing.UP);
 
    // New, work on latest version
    Block chest = api.World.GetBlock(new AssetLocation("chest-south"));
     chest.TryPlaceBlockForWorldGen(api.World.BlockAccessor,  
        player.Entity.Pos.HorizontalAheadCopy(2).AsBlockPos, BlockFacing.UP, null
    );
}
}
</syntaxhighlight>
</syntaxhighlight>
Line 79: Line 72:


Now if you run the mod from Visual Studio by pressing "Start" at the top you should be able to execute the '''/treasure''' command in the game. Once you do that you will have a fancy new chest appear in front of you with no items. Well I guess it's time for us to add some items.
Now if you run the mod from Visual Studio by pressing "Start" at the top you should be able to execute the '''/treasure''' command in the game. Once you do that you will have a fancy new chest appear in front of you with no items. Well I guess it's time for us to add some items.


== Adding items to our chest ==
== Adding items to our chest ==
Line 219: Line 213:
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
BlockPos pos = player.Entity.Pos.HorizontalAheadCopy(2).AsBlockPos;
BlockPos pos = player.Entity.Pos.HorizontalAheadCopy(2).AsBlockPos;
chest.TryPlaceBlockForWorldGen(api.World.BlockAccessor, pos, BlockFacing.UP, null);
chest.TryPlaceBlockForWorldGen(api.World.BlockAccessor, pos, BlockFacing.UP);
IBlockEntityContainer chestEntity = (IBlockEntityContainer)api.World.BlockAccessor.GetBlockEntity(pos);
IBlockEntityContainer chestEntity = (IBlockEntityContainer)api.World.BlockAccessor.GetBlockEntity(pos);
AddItemStacks(chestEntity, MakeItemStacks());
AddItemStacks(chestEntity, MakeItemStacks());
Line 232: Line 226:
Add the following to '''StartServerSide'''
Add the following to '''StartServerSide'''
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
this.api.Event.ChunkColumnGeneration(OnChunkColumnGeneration, EnumWorldGenPass.Vegetation, "standart");
this.api.Event.ChunkColumnGeneration(OnChunkColumnGeneration, EnumWorldGenPass.Vegetation, "standard");
</syntaxhighlight>
</syntaxhighlight>


205

edits