Exemplo n.º 1
0
		public override bool Interact(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face)
		{
			Metadata = (byte) (Metadata | (0x8));
			world.SetBlock(this);
			world.ScheduleBlockTick(this, TickRate);
			return true;
		}
Exemplo n.º 2
0
		private void SetToFlowing(Level world)
		{
			Block flowingBlock = BlockFactory.GetBlockById((byte) (Id - 1));
			flowingBlock.Metadata = Metadata;
			flowingBlock.Coordinates = Coordinates;
			world.SetBlock(flowingBlock, applyPhysics: false);
			world.ScheduleBlockTick(flowingBlock, 5);
		}
Exemplo n.º 3
0
		public override void OnTick(Level world)
		{
			Random random = new Random();

			int x = Coordinates.X;
			int y = Coordinates.Y;
			int z = Coordinates.Z;

			int currentDecay = GetFlowDecay(world, x, y, z);
			byte multiplier = 1;

			if (this is FlowingLava)
			{
				multiplier = 2;
			}

			bool flag = true;
			int tickRate = TickRate();

			if (currentDecay > 0)
			{
				int smallestFlowDecay = -100;
				_adjacentSources = 0;
				smallestFlowDecay = GetSmallestFlowDecay(world, x - 1, y, z, smallestFlowDecay);
				smallestFlowDecay = GetSmallestFlowDecay(world, x + 1, y, z, smallestFlowDecay);
				smallestFlowDecay = GetSmallestFlowDecay(world, x, y, z - 1, smallestFlowDecay);
				smallestFlowDecay = GetSmallestFlowDecay(world, x, y, z + 1, smallestFlowDecay);
				int newDecay = smallestFlowDecay + multiplier;
				if (newDecay >= 8 || smallestFlowDecay < 0)
				{
					newDecay = -1;
				}

				if (GetFlowDecay(world, x, y + 1, z) >= 0)
				{
					int topFlowDecay = GetFlowDecay(world, x, y + 1, z);

					if (topFlowDecay >= 8)
					{
						newDecay = topFlowDecay;
					}
					else
					{
						newDecay = topFlowDecay + 8;
					}
				}

				if (_adjacentSources >= 2 && this is FlowingWater)
				{
					if (world.GetBlock(x, y - 1, z).IsSolid)
					{
						newDecay = 0;
					}
					else if (IsSameMaterial(world.GetBlock(x, y - 1, z)) && world.GetBlock(x, y - 1, z).Metadata == 0)
					{
						newDecay = 0;
					}
				}

				if (this is FlowingLava && currentDecay < 8 && newDecay < 8 && newDecay > currentDecay && random.Next(4) != 0)
				{
					//newDecay = currentDecay;
					//flag = false;
					tickRate *= 4;
				}

				if (newDecay == currentDecay)
				{
					if (flag)
					{
						SetToStill(world, x, y, z);
					}
				}
				else
				{
					currentDecay = newDecay;
					if (newDecay < 0)
					{
						world.SetAir(x, y, z);
					}
					else
					{
						world.SetData(x, y, z, (byte) newDecay);
						world.ApplyPhysics(x, y, z);
						world.ScheduleBlockTick(this, tickRate); // Schedule tick
					}
				}
			}
			else
			{
				SetToStill(world, x, y, z);
			}

			if (CanBeFlownInto(world, x, y - 1, z) /* || world.GetBlock(x, y - 1, z) is Flowing*/)
			{
				if (this is FlowingLava && (world.GetBlock(x, y - 1, z) is FlowingWater || world.GetBlock(x, y - 1, z) is StationaryWater))
				{
					world.SetBlock(new Cobblestone {Coordinates = new BlockCoordinates(x, y - 1, z)});
					return;
				}

				if (currentDecay >= 8)
				{
					Flow(world, x, y - 1, z, currentDecay);
				}
				else
				{
					Flow(world, x, y - 1, z, currentDecay + 8);
				}
			}
			else if (currentDecay >= 0 && (currentDecay == 0 || BlocksFluid(world, x, y - 1, z)))
			{
				bool[] optimalFlowDirections = GetOptimalFlowDirections(world, x, y, z);

				int newDecay = currentDecay + multiplier;
				if (currentDecay >= 8)
				{
					newDecay = 1;
				}

				if (newDecay >= 8)
				{
					return;
				}

				if (optimalFlowDirections[0])
				{
					Flow(world, x - 1, y, z, newDecay);
				}

				if (optimalFlowDirections[1])
				{
					Flow(world, x + 1, y, z, newDecay);
				}

				if (optimalFlowDirections[2])
				{
					Flow(world, x, y, z - 1, newDecay);
				}

				if (optimalFlowDirections[3])
				{
					Flow(world, x, y, z + 1, newDecay);
				}
			}
		}
Exemplo n.º 4
0
		private void Flow(Level world, int x, int y, int z, int decay)
		{
			if (CanBeFlownInto(world, x, y, z))
			{
				//Block block = world.GetBlock(x, y, z);

				//if (this is FlowingLava)
				//{
				//	this.fizz(world, i, j, k);
				//}
				//else
				//{
				//	block.DoDrop(world, i, j, k, world.getData(i, j, k), 0);
				//}

				Block newBlock = BlockFactory.GetBlockById(Id);
				newBlock.Coordinates = new BlockCoordinates(x, y, z);
				newBlock.Metadata = (byte) decay;
				world.SetBlock(newBlock, applyPhysics: true);
				world.ScheduleBlockTick(newBlock, TickRate());
			}
		}
Exemplo n.º 5
0
		public override void DoPhysics(Level level)
		{
			CheckForHarden(level, Coordinates.X, Coordinates.Y, Coordinates.Z);
			level.ScheduleBlockTick(this, TickRate());
		}
Exemplo n.º 6
0
		public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
		{
			CheckForHarden(world, blockCoordinates.X, blockCoordinates.Y, blockCoordinates.Z);
			world.ScheduleBlockTick(this, TickRate());
			return false;
		}