/// <summary> /// This method is called for scheduled updates. /// </summary> protected virtual void ScheduledUpdate(World world, Vector3i position, uint data) {}
/// <summary> /// This method is called on blocks next to a position that was changed. /// </summary> /// <param name="world">The containing world.</param> /// <param name="position">The block position.</param> /// <param name="data">The data of the block next to the changed position.</param> /// <param name="side">The side of the block where the change happened.</param> public virtual void BlockUpdate(World world, Vector3i position, uint data, BlockSide side) {}
/// <summary> /// This method is called randomly on some blocks every update. /// </summary> public virtual void RandomUpdate(World world, Vector3i position, uint data) {}
/// <summary> /// Override this to change the block destruction checks. /// </summary> /// <param name="world">The world in which the placement occurs.</param> /// <param name="position">The position at which the placement is requested.</param> /// <param name="data">The block data.</param> /// <param name="entity">The entity that performs placement.</param> /// <returns></returns> protected virtual bool CanDestroy(World world, Vector3i position, uint data, PhysicsEntity? entity) { return true; }
/// <summary> /// Override this to change the block destruction logic. /// The block destruction must always be successful. If checks are required, override <see cref="CanDestroy" />. /// </summary> /// <param name="world">The world in which the placement occurs.</param> /// <param name="position">The position at which the placement is requested.</param> /// <param name="data">The block data.</param> /// <param name="entity">The entity that performs placement.</param> protected virtual void DoDestroy(World world, Vector3i position, uint data, PhysicsEntity? entity) { world.SetDefaultBlock(position); }
/// <summary> /// Override this to change the block placement logic. /// The block placement must always be successful. If checks are required, override <see cref="CanPlace" />. /// </summary> /// <param name="world">The world in which the placement occurs.</param> /// <param name="position">The position at which the placement is requested.</param> /// <param name="entity">The entity that performs placement.</param> protected virtual void DoPlace(World world, Vector3i position, PhysicsEntity? entity) { world.SetBlock(this.AsInstance(), position); }
/// <summary> /// Override this to provide change the block placement checks. /// </summary> /// <param name="world">The world in which the placement occurs.</param> /// <param name="position">The position at which the placement is requested.</param> /// <param name="entity">The entity that performs placement.</param> /// <returns>True if placement is possible.</returns> public virtual bool CanPlace(World world, Vector3i position, PhysicsEntity? entity) { return true; }
/// <summary> /// Returns the bounding box of this block if it would be at the given position. /// </summary> /// <param name="world">The world in which the block is.</param> /// <param name="position">The position of the block.</param> /// <returns>The bounding box.</returns> public BoundingBox GetBoundingBox(World world, Vector3i position) { BlockInstance? instance = world.GetBlock(position); return (instance?.Block == this ? GetBoundingBox(instance.Data) : boundingBox).Translated(position); }
/// <summary> /// Schedule the destruction of this block. /// </summary> /// <param name="world">The world in which the block is located.</param> /// <param name="position">The position of the block that will be scheduled to be destroyed.</param> protected void ScheduleDestroy(World world, Vector3i position) { Chunk?chunk = world.GetChunkWithPosition(position); chunk?.ScheduleBlockTick(new BlockTick(position, this, TickOperation.Destroy), ScheduledDestroyOffset); }
/// <summary> /// Schedules a tick according to the given tick offset; /// </summary> /// <param name="world">The world in which the block is.</param> /// <param name="position">The position of the block a tick should be scheduled for.</param> /// <param name="tickOffset">The offset in frames to when the block should be ticked.</param> protected void ScheduleTick(World world, Vector3i position, int tickOffset) { Chunk?chunk = world.GetChunkWithPosition(position); chunk?.ScheduleBlockTick(new BlockTick(position, this, TickOperation.Tick), tickOffset); }