public override void BlockUpdate(World world, Vector3 updatedBlock, Vector3 modifiedBlock) { if (!(world.GetBlock(updatedBlock + Vector3.Down) is FarmlandBlock)) { var entity = new ItemEntity(updatedBlock + new Vector3(0.5), new ItemStack(new PumpkinSeedsItem())); entity.ApplyRandomVelocity(); world.SetBlock(updatedBlock, new AirBlock()); world.OnSpawnEntity(entity); return; } if (!world.UpdatePending(updatedBlock)) { var possibleLocations = new List <Vector3>(new[] { updatedBlock + Vector3.Left, updatedBlock + Vector3.Right, updatedBlock + Vector3.Forwards, updatedBlock + Vector3.Backwards }); bool found = false; for (int i = 0; i < possibleLocations.Count; i++) { if (world.GetBlock(possibleLocations[i]) is PumpkinBlock) { found = true; } } if (!found) { ScheduleGrowth(world, updatedBlock); } } base.BlockUpdate(world, updatedBlock, modifiedBlock); }
public override void BlockUpdate(World world, Vector3 updatedBlock, Vector3 modifiedBlock) { if (!(world.GetBlock(updatedBlock + Vector3.Down) is FarmlandBlock)) { var entity = new ItemEntity(updatedBlock + new Vector3(0.5), new ItemStack(new PotatoItem())); entity.ApplyRandomVelocity(); world.SetBlock(updatedBlock, new AirBlock()); world.OnSpawnEntity(entity); } base.BlockUpdate(world, updatedBlock, modifiedBlock); }
public override void BlockUpdate(World world, Vector3 updatedBlock, Vector3 modifiedBlock) { var below = world.GetBlock(updatedBlock + Vector3.Down); if (!(below is SandBlock || below is CactusBlock)) { world.SetBlock(updatedBlock, new AirBlock()); var entity = new ItemEntity(updatedBlock + new Vector3(0.5), new ItemStack(this)); entity.ApplyRandomVelocity(); world.OnSpawnEntity(entity); } base.BlockUpdate(world, updatedBlock, modifiedBlock); }
public override void BlockUpdate(World world, Vector3 updatedBlock, Vector3 modifiedBlock) { var block = world.GetBlock(updatedBlock + Vector3.Down); if (!(block is SugarCaneBlock || block is DirtBlock || block is GrassBlock || block is SandBlock)) { world.SetBlock(updatedBlock, new AirBlock()); var entity = new ItemEntity(updatedBlock + new Vector3(0.5), new ItemStack(new SugarCanesItem())); entity.ApplyRandomVelocity(); world.OnSpawnEntity(entity); } base.BlockUpdate(world, updatedBlock, modifiedBlock); }
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); } } } } }