Modding:Advanced Items: Difference between revisions

From Vintage Story Wiki
m
Double checked information and updated version
No edit summary
m (Double checked information and updated version)
(12 intermediate revisions by 4 users not shown)
Line 1: Line 1:
__FORCETOC__
__FORCETOC__
{{GameVersion|1.15}}


It's highly recommended to read [[Basic Item]] first. Additionally this tutorial requires a development environment. If you don't have one already you should read the tutorial [[Setting up your Development Environment]].
It's highly recommended to read [[Basic Item]] first. Additionally this tutorial requires a development environment. If you don't have one already you should read the tutorial [[Setting up your Development Environment]].
Line 9: Line 10:
== Item Assets ==
== Item Assets ==


First of all we need to create a new item, including a texture and a lang file. Those assets are pretty straight forward and you can download them [http://wiki.vintagestory.at/images/c/cd/Tunnler_-_No_CS_File.zip here]. Just place the file in your mods folder and you are ready to start programming.
First of all we need to create a new item, including a texture and a lang file. Those assets are pretty straight forward and you can download them [https://wiki.vintagestory.at/images/c/cd/Tunnler_-_No_CS_File.zip here]. Just place the file in your mods folder and you are ready to start programming.


There is only one new property in your json item file called <code>class</code>:
There is only one new property in your json item file called <code>class</code>:
Line 20: Line 21:
== The Item Class ==
== The Item Class ==


If you have read the [[Advanced Blocks]] Tutorial already, this should be fimilar to you.
If you have read the [[Advanced Blocks]] Tutorial already, this should be familar to you.


In order to register your item class, we need to create a mod, which is basically a class exendting ModBase:
In order to register your item class, we need to create a mod, which is basically a class exendting ModSystem:


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
public class TunnlerMod : ModBase
public class TunnlerMod : ModSystem
{
{
      
      
Line 34: Line 35:


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
public class TunnlerMod : ModBase
public class TunnlerMod : ModSystem
{
{
     public override void Start(ICoreAPI api)
     public override void Start(ICoreAPI api)
Line 86: Line 87:
Now we can implement <code>OnBlockBroken</code> rather easily, by taken care of every possible axis the player could face:
Now we can implement <code>OnBlockBroken</code> rather easily, by taken care of every possible axis the player could face:
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
public override void OnBlockBroken(IWorldAccessor world, IEntity byEntity, IItemSlot itemslot, BlockSelection blockSel)
public override bool OnBlockBrokenWith(IWorldAccessor world, Entity byEntity, ItemSlot itemslot, BlockSelection blockSel)
{
{
     base.OnBlockBroken(world, byEntity, itemslot, blockSel);
     if (base.OnBlockBrokenWith(world, byEntity, itemslot, blockSel))
    if (byEntity is IEntityPlayer)
     {
     {
         IPlayer player = world.PlayerByUid((byEntity as IEntityPlayer).PlayerUID);
         if (byEntity is EntityPlayer)
        switch (blockSel.Face.Axis)
         {
         {
             case EnumAxis.X:
             IPlayer player = world.PlayerByUid((byEntity as EntityPlayer).PlayerUID);
                destroyBlocks(world, blockSel.Position.AddCopy(0, -1, -1), blockSel.Position.AddCopy(0, 1, 1), player);
            switch (blockSel.Face.Axis)
                break;
            {
            case EnumAxis.Y:
                case EnumAxis.X:
                destroyBlocks(world, blockSel.Position.AddCopy(-1, 0, -1), blockSel.Position.AddCopy(1, 0, 1), player);
                    destroyBlocks(world, blockSel.Position.AddCopy(0, -1, -1), blockSel.Position.AddCopy(0, 1, 1), player);
                break;
                    break;
            case EnumAxis.Z:
                case EnumAxis.Y:
                destroyBlocks(world, blockSel.Position.AddCopy(-1, -1, 0), blockSel.Position.AddCopy(1, 1, 0), player);
                    destroyBlocks(world, blockSel.Position.AddCopy(-1, 0, -1), blockSel.Position.AddCopy(1, 0, 1), player);
                break;
                    break;
                case EnumAxis.Z:
                    destroyBlocks(world, blockSel.Position.AddCopy(-1, -1, 0), blockSel.Position.AddCopy(1, 1, 0), player);
                    break;
            }
         }
         }
     }      
        return true;
     }
    return false;
}
}
</syntaxhighlight>
</syntaxhighlight>
Line 119: Line 124:
namespace ExampleMods
namespace ExampleMods
{
{
     public class TunnlerMod : ModBase
     public class TunnlerMod : ModSystem
     {
     {


Line 152: Line 157:
         }
         }


         public override void OnBlockBroken(IWorldAccessor world, IEntity byEntity, IItemSlot itemslot, BlockSelection blockSel)
         public override bool OnBlockBrokenWith(IWorldAccessor world, Entity byEntity, ItemSlot itemslot, BlockSelection blockSel)
         {
         {
             base.OnBlockBroken(world, byEntity, itemslot, blockSel);
             if (base.OnBlockBrokenWith(world, byEntity, itemslot, blockSel))
            if (byEntity is IEntityPlayer)
             {
             {
                 IPlayer player = world.PlayerByUid((byEntity as IEntityPlayer).PlayerUID);
                 if (byEntity is EntityPlayer)
                switch (blockSel.Face.Axis)
                 {
                 {
                     case EnumAxis.X:
                     IPlayer player = world.PlayerByUid((byEntity as EntityPlayer).PlayerUID);
                        destroyBlocks(world, blockSel.Position.AddCopy(0, -1, -1), blockSel.Position.AddCopy(0, 1, 1), player);
                    switch (blockSel.Face.Axis)
                        break;
                    {
                    case EnumAxis.Y:
                        case EnumAxis.X:
                        destroyBlocks(world, blockSel.Position.AddCopy(-1, 0, -1), blockSel.Position.AddCopy(1, 0, 1), player);
                            destroyBlocks(world, blockSel.Position.AddCopy(0, -1, -1), blockSel.Position.AddCopy(0, 1, 1), player);
                        break;
                            break;
                    case EnumAxis.Z:
                        case EnumAxis.Y:
                        destroyBlocks(world, blockSel.Position.AddCopy(-1, -1, 0), blockSel.Position.AddCopy(1, 1, 0), player);
                            destroyBlocks(world, blockSel.Position.AddCopy(-1, 0, -1), blockSel.Position.AddCopy(1, 0, 1), player);
                        break;
                            break;
                        case EnumAxis.Z:
                            destroyBlocks(world, blockSel.Position.AddCopy(-1, -1, 0), blockSel.Position.AddCopy(1, 1, 0), player);
                            break;
                    }
                 }
                 }
             }      
                return true;
             }
            return false;
         }
         }


Line 178: Line 187:
</syntaxhighlight>
</syntaxhighlight>


You can also download the file directly: [http://wiki.vintagestory.at/images/a/ad/Tunnler.cs Tunnler.cs].
You can also download the file directly: [https://wiki.vintagestory.at/images/a/ad/Tunnler.cs Tunnler.cs].


== Testing ==
== Testing ==
Line 188: Line 197:
== Distribution ==
== Distribution ==


In order to finish your mod, you need to place your *.cs file in the zip archive. Once that is done you can share it with other people. It will work in the same way as ordinary mods, you can install it by copying it into the <code>mods</code> folder.
In order to finish everything, open the modtools and type in <code>pack <your mod id></code>. Now you can take the zip file and share it with other people. It will work in the same way as ordinary mods, you can install it by copying it into the <code>mods</code> folder.
 
= Mod Download =


Here is the complete example mod: [http://wiki.vintagestory.at/images/6/66/Tunnler.zip Tunnler.zip]
Here is my version:
* for VS v1.9: [https://wiki.vintagestory.at/images/7/7b/Tunnler_vs1.9_v1.0.0.zip Tunnler_vs1.9_v1.0.0.zip]
* for VS v1.8: [https://wiki.vintagestory.at/images/6/66/Tunnler.zip Tunnler.zip]




{{Navbox/modding|Vintage Story}}
{{Navbox/modding|Vintage Story}}
editor
72

edits