Modding:Adding Block Behavior/ru: Difference between revisions

From Vintage Story Wiki
Created page with "Блок будет толкать два блока вместо одного, и игрок может тянуть его, крадясь, щелкая правой кно..."
(Created page with "Итак, какие свойства мы можем добавить? * толчок расстояние * собрать блок, если игрок крадется")
(Created page with "Блок будет толкать два блока вместо одного, и игрок может тянуть его, крадясь, щелкая правой кно...")
(8 intermediate revisions by the same user not shown)
Line 118: Line 118:
* собрать блок, если игрок крадется
* собрать блок, если игрок крадется


First of all, we need to override the method in our block behavior class ...
Прежде всего, нам нужно переопределить метод в нашем классе поведения блока ...


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
Line 127: Line 127:
</syntaxhighlight>
</syntaxhighlight>


Additionally we need to add two fields, one for the distance and another one if the player should pull the block while sneaking ...
Кроме того, нам нужно добавить два поля, одно для расстояния и другое, если игрок должен вытащить блок когда крадется ...


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
Line 134: Line 134:
</syntaxhighlight>
</syntaxhighlight>


Now we can parse the two properties like so:
Теперь мы можем проанализировать два свойства следующим образом:


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
Line 143: Line 143:
----
----


The next thing we need to change is the interact method itself, so that it takes care of the distance and the pull properties ...
Следующее, что нам нужно изменить, - это сам метод взаимодействия, чтобы он позаботился о расстоянии и свойствах вытягивания ...
<syntaxhighlight lang="c#">
        public override bool OnPlayerInteract(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling)
        {
            BlockPos pos = blockSel.Position.AddCopy(pull && byPlayer.WorldData.EntityControls.Sneak ? blockSel.Face : blockSel.Face.GetOpposite(), distance);
            if (world.BlockAccessor.GetBlock(pos).IsReplacableBy(block))
            {
                world.BlockAccessor.SetBlock(0, blockSel.Position);
                world.BlockAccessor.SetBlock(block.BlockId, pos);
            }
            handling = EnumHandling.PreventDefault;
            return true;
        }
</syntaxhighlight>


== Adding another block ==
== Добавление другого блока ==


Let's create another block using this behavior, but this time we will configure some additional properties ...
Давайте создадим еще один блок, используя это поведение, но на этот раз мы настроим некоторые дополнительные свойства ...


<syntaxhighlight lang="json">
<syntaxhighlight lang="json">
Line 174: Line 161:
</syntaxhighlight>
</syntaxhighlight>


The block will be pushed two blocks instead of one and the player can pull it by sneaking while right clicking.
Блок будет толкать два блока вместо одного, и игрок может тянуть его, крадясь, щелкая правой кнопкой мыши.


= Mod Download =
= Загрузка мода =


* for VS 1.9: [https://wiki.vintagestory.at/images/7/7b/Advancedmoving_v1.0.0.zip AdvancedMoving_v1.0.0.zip]
* Для VS 1.9: [https://wiki.vintagestory.at/images/7/7b/Advancedmoving_v1.0.0.zip AdvancedMoving_v1.0.0.zip]
* for VS 1.6: [https://wiki.vintagestory.at/images/7/72/AdvancedMoving.zip AdvancedMoving.zip]
* Для VS 1.6: [https://wiki.vintagestory.at/images/7/72/AdvancedMoving.zip AdvancedMoving.zip]






{{Navbox/modding|Vintage Story}}
{{Navbox/modding|Vintage Story}}
681

edits