Modding:WorldGen API: Difference between revisions

From Vintage Story Wiki
Undo revision 16177 by Grimdian (talk)
m (typo)
(Undo revision 16177 by Grimdian (talk))
Tag: Undo
Line 64: Line 64:
private void PlaceTreasureChestInFrontOfPlayer(IServerPlayer player, int groupId, CmdArgs args)
private void PlaceTreasureChestInFrontOfPlayer(IServerPlayer player, int groupId, CmdArgs args)
{
{
     ushort blockID = api.WorldManager.GetBlockId("chest-south");
     // Old, don't work on latest version
     Block chest = api.WorldManager.GetBlockType(blockID);
    // ushort blockID = api.WorldManager.GetBlockId("chest-south");
     chest.TryPlaceBlockForWorldGen(api.World.BlockAccessor, player.Entity.Pos.HorizontalAheadCopy(2).AsBlockPos, BlockFacing.UP);
     // Block chest = api.WorldManager.GetBlockType(blockID);
    // 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 72: Line 79:


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 213: Line 219:
<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);
chest.TryPlaceBlockForWorldGen(api.World.BlockAccessor, pos, BlockFacing.UP, null);
IBlockEntityContainer chestEntity = (IBlockEntityContainer)api.World.BlockAccessor.GetBlockEntity(pos);
IBlockEntityContainer chestEntity = (IBlockEntityContainer)api.World.BlockAccessor.GetBlockEntity(pos);
AddItemStacks(chestEntity, MakeItemStacks());
AddItemStacks(chestEntity, MakeItemStacks());
Line 226: Line 232:
Add the following to '''StartServerSide'''
Add the following to '''StartServerSide'''
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
this.api.Event.ChunkColumnGeneration(OnChunkColumnGeneration, EnumWorldGenPass.Vegetation, "standard");
this.api.Event.ChunkColumnGeneration(OnChunkColumnGeneration, EnumWorldGenPass.Vegetation, "standart");
</syntaxhighlight>
</syntaxhighlight>


205

edits