void BlockChanged(object sender, BlockChangedEventArgs e) { if (!Enabled) { return; } Vector3I p = e.Coords; int index = (p.Y * length + p.Z) * width + p.X; if (e.Block == 0) { Action <int, byte> delete = OnDelete[e.OldBlock]; if (delete != null) { delete(index, e.OldBlock); } } else { Action <int, byte> place = OnPlace[e.Block]; if (place != null) { place(index, e.Block); } } }
void BlockChanged(object sender, BlockChangedEventArgs e) { if (!Enabled) { return; } Vector3I p = e.Coords; int index = (p.Y * length + p.Z) * width + p.X; BlockID block = e.Block; if (block == Block.Air && IsEdgeWater(p.X, p.Y, p.Z)) { block = Block.StillWater; game.UpdateBlock(p.X, p.Y, p.Z, Block.StillWater); } if (e.Block == 0) { PhysicsAction delete = OnDelete[e.OldBlock]; if (delete != null) { delete(index, e.OldBlock); } } else { PhysicsAction place = OnPlace[block]; if (place != null) { place(index, block); } } ActivateNeighbours(p.X, p.Y, p.Z, index); }
void BlockChanged(object sender, BlockChangedEventArgs e) { if (!Enabled) { return; } Vector3I p = e.Coords; int index = (p.Y * length + p.Z) * width + p.X; BlockRaw newB = (BlockRaw)e.Block, oldB = (BlockRaw)e.OldBlock; if (newB == Block.Air && IsEdgeWater(p.X, p.Y, p.Z)) { newB = Block.StillWater; game.UpdateBlock(p.X, p.Y, p.Z, Block.StillWater); } if (newB == Block.Air) { PhysicsAction delete = OnDelete[oldB]; if (delete != null) { delete(p, oldB); } } else { PhysicsAction place = OnPlace[newB]; if (place != null) { place(p, newB); } } ActivateNeighbours(p.X, p.Y, p.Z, index); }
private void ModelBlockChangedEventHandler(object sender, BlockChangedEventArgs e) { if (!e.Disappeared) { if (!_blocksByPosition.Keys.Contains(e.BlockUpdated.Position)) { // Create a new BlockControl. var blockControl = TetrisControlHelper.BlockControlFactory(e.BlockUpdated, Scale); _blocksByPosition.Add(e.BlockUpdated.Position, blockControl); _sprites.Add(blockControl); } else { // In this case we come across a overdrawn block, that is, has been called 'appeared' twice. // Should this scenario happen, we simply ignore this. // TODO: Check if this scenario is reasonable. } } else { if (_blocksByPosition.Keys.Contains(e.BlockUpdated.Position)) { _sprites.Remove(_blocksByPosition[e.BlockUpdated.Position]); _blocksByPosition.Remove(e.BlockUpdated.Position); } } }
void BlockChanged(object sender, BlockChangedEventArgs e) { if (mark1.X == int.MaxValue) { mark1 = e.Coords; game.UpdateBlock(mark1.X, mark1.Y, mark1.Z, e.OldBlock); game.Chat.Add("&eCuboid: &fMark 1 placed at (" + e.Coords + "), place mark 2.", MessageType.ClientStatus3); } else { mark2 = e.Coords; DoCuboid(); game.Chat.Add(null, MessageType.ClientStatus3); if (!persist) { game.UserEvents.BlockChanged -= BlockChanged; } else { mark1 = new Vector3I(int.MaxValue); game.Chat.Add("&eCuboid: &fPlace or delete a block.", MessageType.ClientStatus3); } } }
void PlayBlockSound(object sender, BlockChangedEventArgs e) { if (e.Block == 0) { PlayDigSound(BlockInfo.DigSounds[e.OldBlock]); } else if (!game.ClassicMode) { PlayDigSound(BlockInfo.StepSounds[e.Block]); } }
private void HandleOnBlockChanged(object sender, BlockChangedEventArgs e) { foreach (MinecraftClient client in EntityManager.GetClientsInWorld(e.World)) { client.SendPacket(new BlockChangePacket((int)e.Position.X, (byte)e.Position.Y, (int)e.Position.Z, e.Value.Id, e.Value.Metadata)); } }
void BlockChanged(object sender, BlockChangedEventArgs e) { if (e.Block == 0) { return; } SetAnimationClick(false); }
void BlockChanged(object sender, BlockChangedEventArgs e) { if (e.Block == 0) { return; } ClickAnim(false); }
void BlockChanged(object sender, BlockChangedEventArgs e) { if (!Enabled) { return; } Vector3I p = e.Coords; int index = (p.Y * length + p.Z) * width + p.X; byte block = e.Block; if (block == Block.Air && IsEdgeWater(p.X, p.Y, p.Z)) { block = Block.StillWater; game.UpdateBlock(p.X, p.Y, p.Z, Block.StillWater); } if (e.Block == 0) { Action <int, byte> delete = OnDelete[e.OldBlock]; if (delete != null) { delete(index, e.OldBlock); } } else { Action <int, byte> place = OnPlace[block]; if (place != null) { place(index, block); } } if (p.X > 0) { Activate(index - 1); } if (p.X < map.Width - 1) { Activate(index + 1); } if (p.Z > 0) { Activate(index - map.Width); } if (p.Z < map.Length - 1) { Activate(index + map.Width); } if (p.Y > 0) { Activate(index - oneY); } if (p.Y < map.Height - 1) { Activate(index + oneY); } }
void BreakBlockEffect(object sender, BlockChangedEventArgs e) { if (e.Block != 0) { return; } Vector3I position = e.Coords; byte block = e.OldBlock; Vector3 startPos = new Vector3(position.X, position.Y, position.Z); int texLoc = game.BlockInfo.GetTextureLoc(block, Side.Left), texIndex = 0; TextureRec baseRec = game.TerrainAtlas1D.GetTexRec(texLoc, 1, out texIndex); float uScale = (1 / 16f), vScale = (1 / 16f) * game.TerrainAtlas1D.invElementSize; Vector3 minBB = game.BlockInfo.MinBB[block]; Vector3 maxBB = game.BlockInfo.MaxBB[block]; int minU = Math.Min((int)(minBB.X * 16), (int)(minBB.Z * 16)); int maxU = Math.Min((int)(maxBB.X * 16), (int)(maxBB.Z * 16)); int minV = (int)(16 - maxBB.Y * 16), maxV = (int)(16 - minBB.Y * 16); int maxUsedU = maxU, maxUsedV = maxV; // This way we can avoid creating particles which outside the bounds and need to be clamped if (minU < 12 && maxU > 12) { maxUsedU = 12; } if (minV < 12 && maxV > 12) { maxUsedV = 12; } for (int i = 0; i < 30; i++) { double velX = rnd.NextDouble() * 0.8 - 0.4; // [-0.4, 0.4] double velZ = rnd.NextDouble() * 0.8 - 0.4; double velY = rnd.NextDouble() + 0.2; Vector3 velocity = new Vector3((float)velX, (float)velY, (float)velZ); double xOffset = rnd.NextDouble() - 0.5; // [-0.5, 0.5] double yOffset = (rnd.NextDouble() - 0.125) * maxBB.Y; double zOffset = rnd.NextDouble() - 0.5; Vector3 pos = startPos + new Vector3(0.5f + (float)xOffset, (float)yOffset, 0.5f + (float)zOffset); TextureRec rec = baseRec; rec.U1 = baseRec.U1 + rnd.Next(minU, maxUsedU) * uScale; rec.V1 = baseRec.V1 + rnd.Next(minV, maxUsedV) * vScale; rec.U2 = Math.Min(baseRec.U1 + maxU * uScale, rec.U1 + 4 * uScale) - 0.01f * uScale; rec.V2 = Math.Min(baseRec.V1 + maxV * vScale, rec.V1 + 4 * vScale) - 0.01f * vScale; double life = 0.3 + rnd.NextDouble() * 0.7; TerrainParticle p = AddParticle(terrainParticles, ref terrainCount, false); p.ResetState(pos, velocity, life); p.rec = rec; p.texLoc = texLoc; } }
void BlockChanged(object sender, BlockChangedEventArgs e) { Vector3I p = e.Coords; BlockID block = game.Inventory.Selected; if (e.Block == 0) { classic.SendSetBlock(p.X, p.Y, p.Z, false, block); } else { classic.SendSetBlock(p.X, p.Y, p.Z, true, e.Block); } }
void BlockChanged(object sender, BlockChangedEventArgs e) { Vector3I p = e.Coords; byte block = game.Inventory.HeldBlock; if (e.Block == 0) { SendSetBlock(p.X, p.Y, p.Z, false, block); } else { SendSetBlock(p.X, p.Y, p.Z, true, e.Block); } }
void HandleBlockChanged(object sender, BlockChangedEventArgs e) { transform.position = new Vector3(block.X, block.Y, -1.0f); if (block.State == BlockState.Empty || block.State == BlockState.WaitingToEmpty) { spriteRenderer.enabled = false; } else { spriteRenderer.enabled = true; spriteRenderer.transform.localScale = Vector3.one; spriteRenderer.color = Colors[block.Type]; } block.name = "Block[x=" + block.X.ToString() + ", y=" + block.Y.ToString() + ", type=" + block.Type.ToString() + ", state=" + block.State.ToString() + "]"; }
void BlockChanged( object sender, BlockChangedEventArgs e ) { if( mark1.X == int.MaxValue ) { mark1 = e.Coords; game.UpdateBlock( mark1.X, mark1.Y, mark1.Z, e.OldBlock ); game.Chat.Add( "&eCuboid: &fMark 1 placed at (" + e.Coords + "), place mark 2.", MessageType.ClientStatus3 ); } else { mark2 = e.Coords; DoCuboid(); game.Chat.Add( null, MessageType.ClientStatus3 ); if( !persist ) { game.UserEvents.BlockChanged -= BlockChanged; } else { mark1 = new Vector3I( int.MaxValue ); game.Chat.Add( "&eCuboid: &fPlace or delete a block.", MessageType.ClientStatus3 ); } } }
private void ModelBlockChangedEventHandler(object sender, BlockChangedEventArgs e) { if (!e.Disappeared) { if (!_blocksByPosition.Keys.Contains(e.BlockUpdated.Position)) { // Create a new BlockControl. var blockControl = TetrisControlHelper.AnnotatedBlockControlFactory(e.BlockUpdated, RenderColors, Scale); _blocksByPosition.Add(e.BlockUpdated.Position, blockControl); _sprites.Add(blockControl); } } else { if (_blocksByPosition.Keys.Contains(e.BlockUpdated.Position)) { _sprites.Remove(_blocksByPosition[e.BlockUpdated.Position]); _blocksByPosition.Remove(e.BlockUpdated.Position); } } }
void BreakBlockEffect(object sender, BlockChangedEventArgs e) { if (e.Block != 0) { return; } Vector3I position = e.Coords; BlockID block = e.OldBlock; Vector3 worldPos = new Vector3(position.X, position.Y, position.Z); int texLoc = game.BlockInfo.GetTextureLoc(block, Side.Left), texIndex = 0; TextureRec baseRec = game.TerrainAtlas1D.GetTexRec(texLoc, 1, out texIndex); float uScale = (1 / 16f), vScale = (1 / 16f) * game.TerrainAtlas1D.invElementSize; Vector3 minBB = game.BlockInfo.MinBB[block]; Vector3 maxBB = game.BlockInfo.MaxBB[block]; int minU = Math.Min((int)(minBB.X * 16), (int)(minBB.Z * 16)); int maxU = Math.Min((int)(maxBB.X * 16), (int)(maxBB.Z * 16)); int minV = (int)(16 - maxBB.Y * 16), maxV = (int)(16 - minBB.Y * 16); int maxUsedU = maxU, maxUsedV = maxV; // This way we can avoid creating particles which outside the bounds and need to be clamped if (minU < 12 && maxU > 12) { maxUsedU = 12; } if (minV < 12 && maxV > 12) { maxUsedV = 12; } const int gridSize = 4; // gridOffset gives the centre of the cell on a grid const float cellCentre = (1f / gridSize) * 0.5f; for (int x = 0; x < gridSize; x++) { for (int y = 0; y < gridSize; y++) { for (int z = 0; z < gridSize; z++) { float cellX = (float)x / gridSize, cellY = (float)y / gridSize, cellZ = (float)z / gridSize; Vector3 cell = new Vector3(cellCentre + cellX, cellCentre / 2 + cellY, cellCentre + cellZ); if (cell.X < minBB.X || cell.X > maxBB.X || cell.Y < minBB.Y || cell.Y > maxBB.Y || cell.Z < minBB.Z || cell.Z > maxBB.Z) { continue; } double velX = cellCentre + (cellX - 0.5f) + (rnd.NextDouble() * 0.4 - 0.2); // centre random offset around [-0.2, 0.2] double velY = cellCentre + (cellY - 0.0f) + (rnd.NextDouble() * 0.4 - 0.2); double velZ = cellCentre + (cellZ - 0.5f) + (rnd.NextDouble() * 0.4 - 0.2); Vector3 velocity = new Vector3((float)velX, (float)velY, (float)velZ); TextureRec rec = baseRec; rec.U1 = baseRec.U1 + rnd.Next(minU, maxUsedU) * uScale; rec.V1 = baseRec.V1 + rnd.Next(minV, maxUsedV) * vScale; rec.U2 = Math.Min(baseRec.U1 + maxU * uScale, rec.U1 + 4 * uScale) - 0.01f * uScale; rec.V2 = Math.Min(baseRec.V1 + maxV * vScale, rec.V1 + 4 * vScale) - 0.01f * vScale; double life = 0.3 + rnd.NextDouble() * 1.2; TerrainParticle p = AddParticle(terrainParticles, ref terrainCount, false); p.ResetState(worldPos + cell, velocity, life); p.rec = rec; p.texLoc = (byte)texLoc; p.block = block; } } } }
private void HandleOnBlockChanged(object sender, BlockChangedEventArgs e) { foreach (var client in GetClientsInWorld(e.World)) client.SendPacket(new BlockChangePacket(e.Position, e.Value)); this.ProcessSendQueue(); }