Modding:Advanced Items: Difference between revisions

From Vintage Story Wiki
No edit summary
Line 86: Line 86:
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 152: Line 156:
         }
         }


         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;
         }
         }


Confirmedusers, editor, Administrators
886

edits