Confirmedusers, editor, Administrators
886
edits
CreativeMD (talk | contribs) |
CreativeMD (talk | contribs) |
||
Line 134: | Line 134: | ||
distance = properties["distance"].AsInt(1); | distance = properties["distance"].AsInt(1); | ||
pull = properties["pull"].AsBool(false); | pull = properties["pull"].AsBool(false); | ||
</syntaxhighlight> | |||
---- | |||
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> | </syntaxhighlight> | ||