protected void GenerateCircle(ChunkColumn chunk, Vector3 location, int radius, Block block) { for (var I = -radius; I <= radius; I = (I + 1)) { for (var j = -radius; j <= radius; j = (j + 1)) { var max = (int) Math.Sqrt((I*I) + (j*j)); if (max <= radius) { var X = location.X + I; var Z = location.Z + j; if (X < 0 || X >= 16 || Z < 0 || Z >= 256) continue; var x = (int) X; var y = (int) location.Y; var z = (int) Z; if (chunk.GetBlock(x, y, z).Equals(0)) { chunk.SetBlock(x, y, z, block); } } } } }
public static void GenerateColumn(ChunkColumn chunk, Vector3 location, int height, Block block) { for (var o = 0; o < height; o++) { var x = (int) location.X; var y = (int) location.Y + o; var z = (int) location.Z; chunk.SetBlock(x, y, z, block); } }
private bool IsSameMaterial(Block block) { if (this is BlockFlowingWater && (block is BlockFlowingWater || block is BlockStationaryWater)) return true; if (this is BlockFlowingLava && (block is BlockFlowingLava || block is BlockStationaryLava)) return true; return false; }
private bool BlocksFluid(Block block) { return block.IsSolid; }
public void SetBlock(Block block, bool broadcast = true, bool applyPhysics = true) { var chunk = Generator.GenerateChunkColumn(new Vector2((int) block.Coordinates.X >> 4, (int) block.Coordinates.Z >> 4)); chunk.SetBlock(Mod(block.Coordinates.X), (int)block.Coordinates.Y, Mod(block.Coordinates.Z), block); chunk.IsDirty = true; if (applyPhysics) ApplyPhysics((int) block.Coordinates.X, (int) block.Coordinates.Y, (int) block.Coordinates.Z); if (!broadcast) return; var packet = new BlockChange(null) { BlockId = block.Id, MetaData = block.Metadata, Location = block.Coordinates }; BroadcastPacket(packet); }
public void SetBlock(Vector3 coordinates, Block block) { block.Coordinates = coordinates; SetBlock(block); }
public void ScheduleBlockTick(Block block, int tickRate) { //if (!BlockWithTicks.ContainsKey(block.Coordinates)) //{ BlockWithTicks[block.Coordinates] = CurrentWorldTime + tickRate; //} }
public override void OnTick() { base.OnTick(); if (Ttl <= 0 || KnownPosition.Y <= 0 || Collided) { DespawnEntity(); } Ttl--; Entity entityCollided = CheckEntityCollide(KnownPosition.ToVector3(), Velocity); bool collided = false; if (entityCollided != null) { entityCollided.HealthManager.TakeHit(Shooter, 2, DamageCause.Projectile); collided = true; } else { //collided = CheckBlockCollide(KnownPosition); if (!collided) { var velocity2 = Velocity; velocity2 *= (1.0d - Drag); velocity2 -= new Vector3(0, Gravity, 0); double distance = velocity2.Distance; velocity2 = velocity2.Normalize() / 2; for (int i = 0; i < Math.Ceiling(distance) * 2; i++) { PlayerLocation nextPos = (PlayerLocation)KnownPosition.Clone(); nextPos.X += (float)velocity2.X * i; nextPos.Y += (float)velocity2.Y * i; nextPos.Z += (float)velocity2.Z * i; Vector3 coord = new Vector3(nextPos.ToVector3()); Block block = Level.GetBlock(coord); collided = block.Id != 0 && (block.GetBoundingBox()).Contains(nextPos.ToVector3()); if (collided) { var substBlock = new Block(57) { Coordinates = block.Coordinates }; Level.SetBlock(substBlock); KnownPosition = nextPos; SetIntersectLocation(block.GetBoundingBox(), KnownPosition); break; } } } } if (collided) { Collided = collided; Velocity = Vector3.Zero; } else { KnownPosition.X += (float)Velocity.X; KnownPosition.Y += (float)Velocity.Y; KnownPosition.Z += (float)Velocity.Z; Velocity *= (1.0 - Drag); Velocity -= new Vector3(0, Gravity, 0); var k = Math.Sqrt((Velocity.X * Velocity.X) + (Velocity.Z * Velocity.Z)); KnownPosition.Yaw = (float)(Math.Atan2(Velocity.X, Velocity.Z) * 180f / Math.PI); KnownPosition.Pitch = (float)(Math.Atan2(Velocity.Y, k) * 180f / Math.PI); } BroadcastMoveAndMotion(); }
protected void GenerateVanillaLeaves(ChunkColumn chunk, Vector3 location, int radius, Block block) { var radiusOffset = radius; for (var yOffset = -radius; yOffset <= radius; yOffset = (yOffset + 1)) { var y = location.Y + yOffset; if (y > 256) continue; GenerateVanillaCircle(chunk, new Vector3(location.X, y, location.Z), radiusOffset, block); if (yOffset != -radius && yOffset%2 == 0) radiusOffset--; } }
protected void GenerateVanillaCircle(ChunkColumn chunk, Vector3 location, int radius, Block block, double corner = 0) { for (var I = -radius; I <= radius; I = (I + 1)) { for (var j = -radius; j <= radius; j = (j + 1)) { var max = (int) Math.Sqrt((I*I) + (j*j)); if (max <= radius) { if (I.Equals(-radius) && j.Equals(-radius) || I.Equals(-radius) && j.Equals(radius) || I.Equals(radius) && j.Equals(-radius) || I.Equals(radius) && j.Equals(radius)) { if (corner + radius*0.2 < 0.4 || corner + radius*0.2 > 0.7 || corner.Equals(0)) continue; } var x = location.X + I; var z = location.Z + j; if (chunk.GetBlock((int) x, (int) location.Y, (int) z).Equals(0)) { chunk.SetBlock((int) x, (int) location.Y, (int) z, block); } } } } }
public void SetBlock(int x, int y, int z, Block block) { var index = x + 16*z + 16*16*y; if (index >= 0 && index < Blocks.Length) { Blocks[index] = block.Id; Metadata[index] = block.Metadata; } }