/// <summary> /// Called when a block update occurs. Default handler will handle /// common activities such as destroying blocks that lose support - /// make sure you call it if you don't want to lose this functionality. /// </summary> public virtual void BlockUpdate(World world, Vector3 updatedBlock, Vector3 modifiedBlock) { if (RequiresSupport) { // Ensure that it hasn't lost support var block = world.GetBlock(updatedBlock + SupportDirection); if (block is AirBlock) { world.SetBlock(updatedBlock, new AirBlock()); ItemStack[] drops; bool spawnEntity = GetDrop(null, out drops); if (spawnEntity) { foreach (var drop in drops) { world.OnSpawnEntity(new ItemEntity(updatedBlock + new Vector3(0.5), drop)); } } } } }
public virtual void OnBlockMined(World world, Vector3 destroyedBlock, PlayerEntity player) { if (Hardness != -1) { var slot = player.Inventory[player.SelectedSlot]; world.SetBlock(destroyedBlock, new AirBlock()); if (CanHarvest(slot.AsItem() as ToolItem) && player.GameMode != GameMode.Creative) { ItemStack[] drops; bool spawnEntity = GetDrop(slot.AsItem() as ToolItem, out drops); if (spawnEntity) { foreach (var drop in drops) { var entity = new ItemEntity(destroyedBlock + new Vector3(0.5), drop); entity.ApplyRandomVelocity(); world.OnSpawnEntity(entity); } } } } }
/// <summary> /// Called when a block update occurs. Default handler will handle /// common activities such as destroying blocks that lose support - /// make sure you call it if you don't want to lose this functionality. /// </summary> public virtual void BlockUpdate(World world, Vector3 updatedBlock, Vector3 modifiedBlock) { if (RequiresSupport) { // Ensure that it hasn't lost support var block = world.GetBlock(updatedBlock + SupportDirection); if (block is AirBlock) { world.SetBlock(updatedBlock, new AirBlock()); ItemStack[] drops; bool spawnEntity = GetDrop(null, out drops); if (spawnEntity) { foreach (var drop in drops) world.OnSpawnEntity(new ItemEntity(updatedBlock + new Vector3(0.5), drop)); } } } }