Exemplo n.º 1
1
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            Log.Warn("Player " + player.Username + " should be banned for hacking!");

            var block = world.GetBlock(blockCoordinates);
            if (block is Tnt)
            {
                world.SetBlock(new Air() {Coordinates = block.Coordinates});
                new PrimedTnt(world)
                {
                    KnownPosition = new PlayerLocation(blockCoordinates.X, blockCoordinates.Y, blockCoordinates.Z),
                    Fuse = (byte) (new Random().Next(0, 20) + 10)
                }.SpawnEntity();
            }
            else if (block.IsSolid)
            {
                var affectedBlock = world.GetBlock(GetNewCoordinatesFromFace(blockCoordinates, BlockFace.Up));
                if (affectedBlock.Id == 0)
                {
                    var fire = new Fire
                    {
                        Coordinates = affectedBlock.Coordinates
                    };
                    world.SetBlock(fire);
                }
            }
        }
Exemplo n.º 2
0
        public override void Release(Level world, Player player, BlockCoordinates blockCoordinates, long timeUsed)
        {
            float force = CalculateForce(timeUsed);
            if (force <= 0) return;

            Arrow arrow = new Arrow(player, world);
            arrow.KnownPosition = (PlayerLocation) player.KnownPosition.Clone();
            arrow.KnownPosition.Y += 1.62f;

            arrow.Velocity = arrow.KnownPosition.GetDirection()*(force*2.0f*1.5f);
            arrow.KnownPosition.Yaw = (float) arrow.Velocity.GetYaw();
            arrow.KnownPosition.Pitch = (float) arrow.Velocity.GetPitch();

            //Arrow arrow2 = new Arrow(player, world)
            //{
            //	KnownPosition = (PlayerLocation)arrow.KnownPosition.Clone(),
            //	Velocity = arrow.Velocity,
            //	BroadcastMovement = true
            //};
            ////arrow2.HealthManager.Ignite();
            //arrow2.SpawnEntity();
            arrow.BroadcastMovement = false;
            arrow.DespawnOnImpact = true;
            arrow.SpawnEntity();
        }
Exemplo n.º 3
0
        public override void UseItem(Level world, Player player, BlockCoordinates targetCoordinates, BlockFace face, Vector3 faceCoords)
        {
            //if (player.GameMode != GameMode.Creative)
            //{
            //	Item itemStackInHand = player.Inventory.GetItemInHand();
            //	itemStackInHand.Count--;

            //	if (itemStackInHand.Count <= 0)
            //	{
            //		// set empty
            //		player.Inventory.Slots[player.Inventory.Slots.IndexOf(itemStackInHand)] = new ItemAir();
            //	}
            //}

            _block.Coordinates = GetNewCoordinatesFromFace(targetCoordinates, face);
            _block.Metadata = (byte) Metadata;

            if ((player.GetBoundingBox() - 0.01f).Intersects(_block.GetBoundingBox()))
            {
                Log.Debug("Can't build where you are standing: " + _block.GetBoundingBox());
                return;
            }
            if (!_block.CanPlace(world, face)) return;

            if (_block.PlaceBlock(world, player, targetCoordinates, face, faceCoords)) return; // Handled

            world.SetBlock(_block);
        }
Exemplo n.º 4
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            var coor = GetNewCoordinatesFromFace(blockCoordinates, face);
            if (face == BlockFace.Up) // On top of block
            {
                Block skull = new Block(144);
                skull.Coordinates = coor;
                skull.Metadata = 1; // Skull on floor, rotation in block entity
                world.SetBlock(skull);
            }
            else if (face == BlockFace.Down) // At the bottom of block
            {
                // Doesn't work, ignore if that happen.
                return;
            }
            else
            {
                Block skull = new Block(144);
                skull.Coordinates = coor;
                skull.Metadata = (byte) face; // Skull on floor, rotation in block entity
                world.SetBlock(skull);
            }

            // Then we create and set the sign block entity that has all the intersting data

            var skullBlockEntity = new SkullBlockEntity
            {
                Coordinates = coor,
                Rotation = (byte)((int)(Math.Floor(((player.KnownPosition.Yaw)) * 16 / 360) + 0.5) & 0x0f),
                SkullType = (byte) Metadata
            };

            world.SetBlockEntity(skullBlockEntity);
        }
Exemplo n.º 5
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            if (player.GameMode != GameMode.Creative)
            {
                Item itemStackInHand = player.Inventory.GetItemInHand();
                itemStackInHand.Count--;

                if (itemStackInHand.Count <= 0)
                {
                    // set empty
                    player.Inventory.Slots[player.Inventory.Slots.IndexOf(itemStackInHand)] = new ItemAir();
                }
            }

            var coor = GetNewCoordinatesFromFace(blockCoordinates, face);
            Chest chest = new Chest
            {
                Coordinates = coor,
            };

            if (!chest.CanPlace(world, face)) return;

            chest.PlaceBlock(world, player, coor, face, faceCoords);

            // Then we create and set the sign block entity that has all the intersting data

            ChestBlockEntity chestBlockEntity = new ChestBlockEntity
            {
                Coordinates = coor
            };

            world.SetBlockEntity(chestBlockEntity);
        }
Exemplo n.º 6
0
		public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
		{
			if (player.GameMode != GameMode.Creative)
			{
				ItemStack itemStackInHand = player.Inventory.GetItemInHand();
				itemStackInHand.Count--;

				if (itemStackInHand.Count <= 0)
				{
					// set empty
					player.Inventory.Slots[player.Inventory.Slots.IndexOf(itemStackInHand)] = new ItemStack();
				}
			}

			var coor = GetNewCoordinatesFromFace(blockCoordinates, face);
			EnchantingTable table = new EnchantingTable
			{
				Coordinates = coor,
				Metadata = (byte) Metadata
			};

			if (!table.CanPlace(world, face)) return;

			table.PlaceBlock(world, player, coor, face, faceCoords);

			// Then we create and set the sign block entity that has all the intersting data

			EnchantingTableBlockEntity tableBlockEntity = new EnchantingTableBlockEntity
			{
				Coordinates = coor
			};

			world.SetBlockEntity(tableBlockEntity);
		}
Exemplo n.º 7
0
        public MapEntity(Level level, long mapId = EntityManager.EntityIdUndefined)
            : base(-1, level)
        {
            if (mapId != EntityManager.EntityIdUndefined)
            {
                EntityId = mapId;
            }
            else
            {
                EntityId = level.EntityManager.AddEntity(null, this) + 0xFFFF;
            }

            ImageProvider = new MapImageProvider();

            MapInfo mapInfo = new MapInfo
            {
                MapId = EntityId,
                UpdateType = 6,
                Direction = 0,
                X = 0,
                Z = 0,
                Col = 128,
                Row = 128,
                XOffset = 0,
                ZOffset = 0
            };

            MapInfo = mapInfo;
        }
Exemplo n.º 8
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.º 9
0
        // 000 001 010 011 100
        public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            byte direction = player.GetDirection();

            byte upper = (byte) ((faceCoords.Y > 0.5 && face != BlockFace.Up) || face == BlockFace.Down ? 0x04 : 0x00);

            switch (direction)
            {
                case 0:
                    Metadata = (byte) (0 | upper);
                    break;
                case 1:
                    Metadata = (byte) (2 | upper);
                    break;
                case 2:
                    Metadata = (byte) (1 | upper);
                    break;
                case 3:
                    Metadata = (byte) (3 | upper);
                    break;
            }

            world.SetBlock(this);
            return true;
        }
Exemplo n.º 10
0
		public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
		{
			Metadata = (byte) face;

			world.SetBlock(this);
			return true;
		}
Exemplo n.º 11
0
        public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            byte direction = player.GetDirection();

            switch (face)
            {
                case BlockFace.South: // ok
                    Metadata = 0;
                    break;
                case BlockFace.North:
                    Metadata = 1;
                    break;
                case BlockFace.West:
                    Metadata = 2;
                    break;
                case BlockFace.East: // ok
                    Metadata = 3;
                    break;
            }

            Log.Warn($"Direction={direction}, face={face}, metadata={Metadata}");

            world.SetBlock(this);

            return true;
        }
Exemplo n.º 12
0
        public override bool Interact(Level currentLevel, Player player, BlockCoordinates blockCoordinates, BlockFace face)
        {
            Sign signEntity = currentLevel.GetBlockEntity(blockCoordinates) as Sign;
            if (signEntity == null) return false;

            string world = signEntity.Text1;

            if (player.Level.LevelId.Equals(world)) return true;

            if (!Worlds.ContainsKey(player.Level.LevelId))
            {
                Worlds.Add(player.Level.LevelId, player.Level);
            }

            if (!Worlds.ContainsKey(world))
            {
                var mobHuntLevel = new MobHuntLevel(world, new FlatlandWorldProvider());
                mobHuntLevel.Initialize();
                Worlds.Add(world, mobHuntLevel);
            }

            Level level = Worlds[world];
            player.SpawnLevel(level);
            level.BroadcastTextMessage(string.Format("{0} teleported to world <{1}>.", player.Username, level.LevelId));

            return true;
        }
Exemplo n.º 13
0
        public ServerInfo(Level level, ConcurrentDictionary<IPEndPoint, PlayerNetworkSession> playerSessions)
        {
            _level = level;
            PlayerSessions = playerSessions;
            ThroughPut = new Timer(delegate(object state)
            {
                NumberOfPlayers = PlayerSessions.Count;

                int threads;
                int portThreads;
                ThreadPool.GetAvailableThreads(out threads, out portThreads);
                double kbitPerSecondOut = TotalPacketSizeOut*8/1000000D;
                double kbitPerSecondIn = TotalPacketSizeIn*8/1000000D;
                Log.InfoFormat("TT {4:00}ms Ly {6:00}ms {5} Pl(s) Pkt(#/s) ({0} {2}) ACKs {1}/s Tput(Mbit/s) ({3:F} {7:F}) Avail {8}kb Threads {9} Compl.ports {10}",
                    NumberOfPacketsOutPerSecond,
                    NumberOfAckSent,
                    NumberOfPacketsInPerSecond,
                    kbitPerSecondOut,
                    _level.LastTickProcessingTime,
                    NumberOfPlayers,
                    Latency,
                    kbitPerSecondIn, AvailableBytes/1000,
                    threads,
                    portThreads);

                NumberOfAckSent = 0;
                TotalPacketSizeOut = 0;
                TotalPacketSizeIn = 0;
                NumberOfPacketsOutPerSecond = 0;
                NumberOfPacketsInPerSecond = 0;
            }, null, 1000, 1000);
        }
Exemplo n.º 14
0
		private void SetDoubleSlab(Level world, BlockCoordinates coordinates)
		{
			Block slab = BlockFactory.GetBlockById((byte) (Id - 1));
			slab.Coordinates = coordinates;
			slab.Metadata = (byte) Metadata;
			world.SetBlock(slab);
		}
Exemplo n.º 15
0
        public override void Release(Level world, Player player, BlockCoordinates blockCoordinates, long timeUsed)
        {
            float force = CalculateForce(timeUsed);
            if (force <= 0) return;

            Arrow arrow = new Arrow(player, world);
            arrow.KnownPosition = (PlayerLocation) player.KnownPosition.Clone();
            arrow.KnownPosition.Y += 1.62f;

            float yaw = arrow.KnownPosition.Yaw;
            float pitch = arrow.KnownPosition.Pitch;

            var vx = -Math.Sin(yaw/180f*Math.PI)*Math.Cos(pitch/180f*Math.PI);
            var vy = -Math.Sin(pitch/180f*Math.PI);
            var vz = Math.Cos(yaw/180f*Math.PI)*Math.Cos(pitch/180f*Math.PI);

            arrow.Velocity = new Vector3(vx, vy, vz)*(force*2.0f*1.5f);

            var k = Math.Sqrt((arrow.Velocity.X*arrow.Velocity.X) + (arrow.Velocity.Z*arrow.Velocity.Z));
            arrow.KnownPosition.Yaw = (float) (Math.Atan2(arrow.Velocity.X, arrow.Velocity.Z)*180f/Math.PI);
            arrow.KnownPosition.Pitch = (float) (Math.Atan2(arrow.Velocity.Y, k)*180f/Math.PI);

            //Arrow arrow2 = new Arrow(player, world)
            //{
            //	KnownPosition = (PlayerLocation)arrow.KnownPosition.Clone(),
            //	Velocity = arrow.Velocity,
            //	BroadcastMovement = true
            //};
            ////arrow2.HealthManager.Ignite();
            //arrow2.SpawnEntity();
            arrow.BroadcastMovement = false;
            arrow.DespawnOnImpact = true;
            arrow.SpawnEntity();
        }
Exemplo n.º 16
0
        public override void BreakBlock(Level level)
        {
            BlockCoordinates direction = new BlockCoordinates();
            switch (Metadata & 0x07)
            {
                case 0:
                    direction = Level.East;
                    break; // West
                case 1:
                    direction = Level.North;
                    break; // North
                case 2:
                    direction = Level.West;
                    break; // East
                case 3:
                    direction = Level.South;
                    break; // South
            }

            // Remove bed
            if ((Metadata & 0x08) != 0x08)
            {
                direction = direction*-1;
            }

            level.SetBlock(new Air {Coordinates = Coordinates + direction});
            level.SetBlock(new Air {Coordinates = Coordinates});
        }
Exemplo n.º 17
0
		public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
		{
			if (face == BlockFace.Down) return true;

			switch (face)
			{
				case BlockFace.Up:
					Metadata = 5;
					break;
				case BlockFace.East:
					Metadata = 4;
					break;
				case BlockFace.West:
					Metadata = 3;
					break;
				case BlockFace.North:
					Metadata = 2;
					break;
				case BlockFace.South:
					Metadata = 1;
					break;
			}

			world.SetBlock(this);
			return true;
		}
Exemplo n.º 18
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            var coor = GetNewCoordinatesFromFace(blockCoordinates, face);
            if (face == BlockFace.Up) // On top of block
            {
                // Standing Sign
                var sign = new StandingSign();
                sign.Coordinates = coor;
                // metadata for sign is a value 0-15 that signify the orientation of the sign. Same as PC metadata.
                sign.Metadata = (byte) ((int) (Math.Floor((player.KnownPosition.Yaw + 180)*16/360) + 0.5) & 0x0f);
                world.SetBlock(sign);
            }
            else if (face == BlockFace.North) // At the bottom of block
            {
                // Doesn't work, ignore if that happen.
                return;
            }
            else
            {
                // Wall sign
                var sign = new WallSign();
                sign.Coordinates = coor;
                sign.Metadata = (byte) face;
                world.SetBlock(sign);
            }

            // Then we create and set the sign block entity that has all the intersting data

            var signBlockEntity = new Sign
            {
                Coordinates = coor
            };

            world.SetBlockEntity(signBlockEntity);
        }
Exemplo n.º 19
0
 public Spider(Level level)
     : base((int) EntityType.Spider, level)
 {
     Width = Length = 1.4;
     Height = 0.9;
     HealthManager.MaxHealth = 160;
     HealthManager.ResetHealth();
 }
Exemplo n.º 20
0
 public Cow(Level level)
     : base(EntityType.Cow, level)
 {
     Width = Length = 0.9;
     Height = 1.4;
     HealthManager.MaxHealth = 100;
     HealthManager.ResetHealth();
 }
Exemplo n.º 21
0
 public Bat(Level level)
     : base(EntityType.Bat, level)
 {
     Width = Length = 0.5;
     Height = 0.9;
     HealthManager.MaxHealth = 60;
     HealthManager.ResetHealth();
 }
Exemplo n.º 22
0
 public Pig(Level level)
     : base(EntityType.Pig, level)
 {
     Width = Length = 0.9;
     Height = 0.9;
     HealthManager.MaxHealth = 100;
     HealthManager.ResetHealth();
 }
Exemplo n.º 23
0
 protected Projectile(Player shooter, int entityTypeId, Level level)
     : base(entityTypeId, level)
 {
     Shooter = shooter;
     Ttl = 0;
     DespawnOnImpact = true;
     BroadcastMovement = false;
 }
Exemplo n.º 24
0
 public Rabbit(Level level)
     : base(EntityType.Rabbit, level)
 {
     Width = Length = 0.6;
     Height = 0.7;
     HealthManager.MaxHealth = 100;
     HealthManager.ResetHealth();
 }
Exemplo n.º 25
0
 public Silverfish(Level level)
     : base((int) EntityType.Silverfish, level)
 {
     Width = Length = 0.4;
     Height = 0.3;
     HealthManager.MaxHealth = 80;
     HealthManager.ResetHealth();
 }
Exemplo n.º 26
0
 public Enderman(Level level)
     : base(EntityType.Enderman, level)
 {
     Width = Length = 0.6;
     Height = 2.9;
     HealthManager.MaxHealth = 400;
     HealthManager.ResetHealth();
 }
Exemplo n.º 27
0
 public SnowGolem(Level level)
     : base(EntityType.SnowGolem, level)
 {
     Width = Length = 0.7;
     Height = 1.9;
     HealthManager.MaxHealth = 40;
     HealthManager.ResetHealth();
 }
Exemplo n.º 28
0
		public Pet(Player owner, Level level, int id = 12) : base(id, level)
		{
			IsBaby = true;
			IsInRage = false;
			Owner = owner;
			HealthManager = new PetHealthManager(this);
			Age = 0;
		}
Exemplo n.º 29
0
 public Sheep(Level level)
     : base(EntityType.Sheep, level)
 {
     Width = Length = 0.9;
     Height = 1.3;
     HealthManager.MaxHealth = 80;
     HealthManager.ResetHealth();
 }
Exemplo n.º 30
0
		/// <summary>
		///     Use this for Explosion an explosion only!
		/// </summary>
		/// <param name="world"></param>
		/// <param name="centerCoordinates"></param>
		/// <param name="size"></param>
		/// <param name="fire"></param>
		public Explosion(Level world, BlockCoordinates centerCoordinates, float size, bool fire = false)
		{
			_size = size;
			_centerCoordinates = centerCoordinates;
			_world = world;
			CoordsSet = true;
			Fire = fire;
		}
Exemplo n.º 31
0
 public LevelEventArgs(Player player, Level level)
 {
     Player = player;
     Level  = level;
 }
Exemplo n.º 32
0
 public BlockBreakEventArgs(Player player, Level level, Block block, List <Item> drops) : base(player, level)
 {
     Block = block;
     Drops = drops;
 }
Exemplo n.º 33
0
 public GunProjectile(MiNET.Player shooter, MiNET.Worlds.Level level, int damage = 2, bool isCritical = false) : base(shooter, level, damage, isCritical)
 {
 }
Exemplo n.º 34
0
 public BlockPlaceEventArgs(Player player, Level level, Block targetBlock, Block existingBlock) : base(player, level)
 {
     TargetBlock   = targetBlock;
     ExistingBlock = existingBlock;
 }