public override void OnItemUsedOnBlock(World world, Vector3 clickedBlock, Vector3 clickedSide, Vector3 cursorPosition, Entity usedBy) { var block = world.GetBlock(clickedBlock); var player = usedBy as PlayerEntity; var client = Server.EntityManager.GetClient(player); client.SendChat(block.GetType().Name + ": " + block.Id + " (" + block.Metadata + ")"); }
public override void OnItemUsed(World world, Vector3 clickedBlock, Vector3 clickedSide, Vector3 cursorPosition, Entity usedBy) { var clicked = world.GetBlock(clickedBlock); if (clicked.OnBlockRightClicked(clickedBlock, clickedSide, cursorPosition, world, usedBy)) { if (OnBlockPlaced(world, clickedBlock + clickedSide, clickedBlock, clickedSide, cursorPosition, usedBy)) { if ((clickedBlock + clickedSide).Y >= 0 && (clickedBlock + clickedSide).Y <= Chunk.Height) world.SetBlock(clickedBlock + clickedSide, this); } } }
/// <summary> /// Spawns a bolt of lightning in the given world /// at the given position. /// </summary> public void SpawnLightning(World world, Vector3 position) { var chunk = world.GetChunk(World.WorldToChunkCoordinates(position)); var block = World.FindBlockPosition(position); int y = chunk.GetHeight((byte)block.X, (byte)block.Z) + 1; var strike = new Vector3(position.X, y, position.Z); if (world.GetBlock(strike + Vector3.Down).Transparency == Transparency.Opaque) world.SetBlock(strike, new FireBlock()); var clients = Server.EntityManager.GetClientsInWorld(world); foreach (var minecraftClient in clients) minecraftClient.SendPacket(new SpawnGlobalEntityPacket(EntityManager.nextEntityId++, 1, (int)strike.X, (int)strike.Y, (int)strike.Z)); }
public override void OnItemUsedOnBlock(World world, Vector3 clickedBlock, Vector3 clickedSide, Vector3 cursorPosition, Entity usedBy) { var clicked = world.GetBlock(clickedBlock); var player = usedBy as PlayerEntity; if (player.GameMode != GameMode.Creative) { var item = player.Inventory[player.SelectedSlot]; player.Inventory[player.SelectedSlot] = new ItemStack(item.Id, (sbyte)(item.Count - 1), item.Metadata, item.Nbt); } if (clicked.OnBlockRightClicked(clickedBlock, clickedSide, cursorPosition, world, usedBy)) { if (OnBlockPlaced(world, clickedBlock + clickedSide, clickedBlock, clickedSide, cursorPosition, usedBy)) { if ((clickedBlock + clickedSide).Y >= 0 && (clickedBlock + clickedSide).Y <= Chunk.Height) world.SetBlock(clickedBlock + clickedSide, this); } } }
/// <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 override void OnItemUsedOnBlock(World world, Vector3 clickedBlock, Vector3 clickedSide, Vector3 cursorPosition, Entity usedBy) { var clicked = world.GetBlock(clickedBlock); var player = usedBy as PlayerEntity; if (player.GameMode != GameMode.Creative) { var item = player.Inventory[player.SelectedSlot]; player.Inventory[player.SelectedSlot] = new ItemStack(item.Id, (sbyte)(item.Count - 1), item.Metadata, item.Nbt); } if (clicked.OnBlockRightClicked(clickedBlock, clickedSide, cursorPosition, world, usedBy)) { if (OnBlockPlaced(world, clickedBlock + clickedSide, clickedBlock, clickedSide, cursorPosition, usedBy)) { if ((clickedBlock + clickedSide).Y >= 0 && (clickedBlock + clickedSide).Y <= Chunk.Height) { world.SetBlock(clickedBlock + clickedSide, this); } } } }
/// <summary> /// Spawns a bolt of lightning in the given world /// at the given position. /// </summary> public void SpawnLightning(World world, Vector3 position) { var chunk = world.GetChunk(World.WorldToChunkCoordinates(position)); var block = World.FindBlockPosition(position); byte y = (byte)(chunk.GetHeight((byte)block.X, (byte)block.Z) + 1); var strike = new Vector3(position.X, y, position.Z); if (world.GetBlock(strike + Vector3.Down).Transparency == Transparency.Opaque) world.SetBlock(strike, new FireBlock()); var clients = GetClientsInWorld(world); foreach (var minecraftClient in clients) minecraftClient.SendPacket(new SpawnLightningPacket(EntityManager.nextEntityId++, strike)); ProcessSendQueue(); }
/// <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)); } } } }