Modding:Adding Block Behavior/ru: Difference between revisions

From Vintage Story Wiki
Created page with "Следующее, что нам нужно изменить, - это сам метод взаимодействия, чтобы он позаботился о рассто..."
(Created page with "Теперь мы можем проанализировать два свойства следующим образом:")
(Created page with "Следующее, что нам нужно изменить, - это сам метод взаимодействия, чтобы он позаботился о рассто...")
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 ==
== Adding another block ==
681

edits