Пример #1
0
 public PrimedTNTEntity(Level level)
     : base(50, level)
 {
     Height = 0.98;
     Width = 0.98;
     Length = 0.98;
 }
Пример #2
0
 public override bool PlaceBlock(Level world, Player player, Vector3 blockCoordinates, BlockFace face, Vector3 mouseLocation)
 {
     var prevblock = world.GetBlock(Coordinates);
     if (prevblock.Id == Id && prevblock.Metadata == Metadata)
     {
         DoubleSlab ds = new DoubleSlab(Metadata) {Coordinates = Coordinates};
         world.SetBlock(ds);
     }
     else if (prevblock.Id == Id && prevblock.Metadata != Metadata)
     {
         if (player.Gamemode != Gamemode.Creative)
         {
             player.Inventory.AddItem((short)Id, Metadata, 1);
         }
         return true;
     }
     else
     {
         bool upper = ((mouseLocation.Y >= 8 && face != BlockFace.PositiveY) || face == BlockFace.NegativeY);
         BitArray b = new BitArray(new byte[] {Metadata});
         b[3] = upper;
         Metadata = ConvertToByte(b);
         world.SetBlock(this);
     }
     return true;
 }
Пример #3
0
 public override void UseItem(Level world, Player player, Vector3 blockCoordinates, BlockFace face)
 {
     blockCoordinates = GetNewCoordinatesFromFace(blockCoordinates, face);
     var d = new BlockRedstoneDust {Coordinates = blockCoordinates};
     //d.SetPowerLevel(new Random().Next(0,15));
     world.SetBlock(d, true, true);
 }
Пример #4
0
        public override bool PlaceBlock(Level world, Player player, Vector3 blockCoordinates, BlockFace face, Vector3 mouseLocation)
        {
            var rawbits = new BitArray(new byte[] { 0x00 });

            byte direction = player.GetDirection();
            if (face == BlockFace.PositiveY)
            {
                switch (direction)
                {
                    case 0:
                        //South
                        rawbits[1] = true;
                        rawbits[2] = true;
                        break;
                    case 1:
                        //West
                        rawbits[0] = true;
                        rawbits[2] = true;
                        break;
                    case 2:
                        //North
                        rawbits[1] = true;
                        rawbits[2] = true;
                        break;
                    case 3:
                        //East
                        rawbits[0] = true;
                        rawbits[2] = true;
                        break;
                }
            }
            else if (face == BlockFace.NegativeY)
            {
                rawbits[0] = true;
                rawbits[1] = true;
                rawbits[2] = true;
            }
            else if (face == BlockFace.PositiveZ)
            {
                rawbits[0] = true;
                rawbits[1] = true;
            }
            else if (face == BlockFace.NegativeZ)
            {
                rawbits[2] = true;
            }
            else if (face == BlockFace.PositiveX)
            {
                rawbits[0] = true;
            }
            else if (face == BlockFace.NegativeX)
            {
                rawbits[1] = true;
            }

            Metadata = ConvertToByte(rawbits);

            world.SetBlock(this);
            return true;
        }
Пример #5
0
        public override void UseItem(Level world, Player player, Vector3 blockCoordinates, BlockFace face)
        {
            blockCoordinates = GetNewCoordinatesFromFace(blockCoordinates, face);
            var bl = world.GetBlock(blockCoordinates);

            var slot = 0;
            var hand0 = player.Inventory.GetItemInHand(0);
            var hand1 = player.Inventory.GetItemInHand(1);
            if (hand0.Id == Id)
            {
                slot = player.Inventory.CurrentSlot + 36;
            }
            else if (hand1.Id == Id)
            {
                slot = 45;
            }

            //player.SendChat("Block: " + bl.Id, ChatColor.Bold);
            if (bl.Id == 65535) return;

            if (bl.Id == 8)
            {
                //Water
                player.Inventory.SetSlot(slot, 326, 0, 1);
                world.SetBlock(new BlockAir() {Coordinates = blockCoordinates}, true, true);
            }

            if (bl.Id == 10)
            {
                //lava
                player.Inventory.SetSlot(slot, 327, 0, 1);
                world.SetBlock(new BlockAir() { Coordinates = blockCoordinates }, true, true);
            }
        }
Пример #6
0
 public override void UseItem(Level world, Player player, Vector3 blockCoordinates, BlockFace face)
 {
     if (player.Inventory.GetItemInHand(1).Id == 259 || player.Inventory.GetItemInHand(0).Id == 259)
     {
         this.BreakBlock(world);
         new PrimedTNTEntity(world){KnownPosition = Coordinates.ToPlayerLocation()}.SpawnEntity();
     }
 }
Пример #7
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, Vector3 centerCoordinates, float size, bool fire = false)
 {
     _size = size;
     _centerCoordinates = centerCoordinates;
     _world = world;
     _coordsSet = true;
     _fire = fire;
 }
Пример #8
0
        public override void DoPhysics(Level level)
        {
            CheckForHarden(level, (int) Coordinates.X, (int) Coordinates.Y, (int) Coordinates.Z);

            if (level.GetBlock(Coordinates).Id == Id)
            {
                SetToFlowing(level);
            }
        }
Пример #9
0
 protected Projectile(Player shooter, int entityTypeId, Level level)
     : base(entityTypeId, level)
 {
     Shooter = shooter;
     Ttl = 0;
     DespawnOnImpact = true;
     Collided = false;
     KnownPosition = new PlayerLocation(shooter.KnownPosition.X, shooter.KnownPosition.Y, shooter.KnownPosition.Z) {Yaw = shooter.KnownPosition.Yaw, Pitch = shooter.KnownPosition.Pitch};
 }
Пример #10
0
        public ItemEntity(Level level, ItemStack item)
            : base(2, level)
        {
            Item = item;

            Height = 0.25;
            Width = 0.25;
            Length = 0.25;

            PickupDelay = 10;
            TimeToLive = 20*(5*60);
        }
Пример #11
0
        public override bool PlaceBlock(Level world, Player player, Vector3 blockCoordinates, BlockFace face, Vector3 mouseLocation)
        {
            var direction = player.GetDirection();
            var coordinates = GetNewCoordinatesFromFace(blockCoordinates, face);

            Block block = new Door(Id);
            block.Coordinates = coordinates;
            block.Metadata = direction;

            var x = (int) blockCoordinates.X;
            var y = (int) blockCoordinates.Y;
            var z = (int) blockCoordinates.Z;

            var xd = 0;
            var zd = 0;

            if (direction == 0) zd = 1;
            if (direction == 1) xd = -1;
            if (direction == 2) zd = -1;
            if (direction == 3) xd = 1;

            var i1 = (world.GetBlock(new Vector3(x - xd, y, z - zd)).IsSolid ? 1 : 0) +
                     (world.GetBlock(new Vector3(x - xd, y + 1, z - zd)).IsSolid ? 1 : 0);
            var j1 = (world.GetBlock(new Vector3(x + xd, y, z + zd)).IsSolid ? 1 : 0) +
                     (world.GetBlock(new Vector3(x + xd, y + 1, z + zd)).IsSolid ? 1 : 0);
            var flag = world.GetBlock(new Vector3(x - xd, y, z - zd)).Id == block.Id ||
                       world.GetBlock(new Vector3(x - xd, y + 1, z - zd)).Id == block.Id;
            var flag1 = world.GetBlock(new Vector3(x + xd, y, z + zd)).Id == block.Id ||
                        world.GetBlock(new Vector3(x + xd, y + 1, z + zd)).Id == block.Id;
            var flag2 = false;

            if (flag && !flag1)
            {
                flag2 = true;
            }
            else if (j1 > i1)
            {
                flag2 = true;
            }

            var c2 = coordinates;
            c2.Y++;

            Block blockUpper = new Door(Id);
            blockUpper.Coordinates = c2;
            blockUpper.Metadata = (byte) (0x08 | (flag2 ? 1 : 0));

            world.SetBlock(block);
            world.SetBlock(blockUpper);

            return true;
        }
Пример #12
0
        public SnowballEntity(Player shooter, Level level)
            : base(shooter, 61, level)
        {
            Width = 0.25;
            Length = 0.25;
            Height = 0.25;

            Gravity = 0.03;
            Drag = 0.01;

            Ttl = 9999999;
            ObjectType = ObjectType.Snowball;
        }
Пример #13
0
        public Player(Level level)
            : base(-1, level)
        {
            _chunksUsed = new List<Tuple<int, int>>();
            Inventory = new PlayerInventoryManager(this);
            Level = level;

            Width = 0.6;
            Height = 1.62;
            Length = 0.6;
            IsOperator = false;
            Loaded = false;
        }
Пример #14
0
        public Entity(int entityTypeId, Level level)
        {
            Height = 1;
            Width = 1;
            Length = 1;
            Drag = 0;
            Gravity = 0;

            EntityId = EntityManager.GetEntityId();
            Level = level;
            EntityTypeId = entityTypeId;
            KnownPosition = new PlayerLocation(0, 0, 0);
            HealthManager = new HealthManager(this);
        }
Пример #15
0
        public void SetPowerLevel(int target, Level lvl)
        {
            if (target < 0 || target > 15) throw new IndexOutOfRangeException("target");

            var newbits = new BitArray(new int[] { target });
            var rawbits = new BitArray(new byte[] { Metadata });

            rawbits[0] = newbits[0];
            rawbits[1] = newbits[1];
            rawbits[2] = newbits[2];
            rawbits[3] = newbits[3];

            Metadata = ConvertToByte(rawbits);
            lvl.SetBlock(this);
        }
Пример #16
0
        private void CheckForHarden(Level world, int x, int y, int z)
        {
            var block = world.GetBlock(new Vector3(x, y, z));
            {
                var harden = false;
                if (block is BlockFlowingLava || block is BlockStationaryLava)
                {
                    if (IsWater(world, x, y, z))
                    {
                        harden = true;
                    }

                    if (harden || IsWater(world, x, y, z + 1))
                    {
                        harden = true;
                    }

                    if (harden || IsWater(world, x - 1, y, z))
                    {
                        harden = true;
                    }

                    if (harden || IsWater(world, x + 1, y, z))
                    {
                        harden = true;
                    }

                    if (harden || IsWater(world, x, y + 1, z))
                    {
                        harden = true;
                    }

                    if (harden)
                    {
                        int meta = block.Metadata;

                        if (meta == 0)
                        {
                            world.SetBlock(new BlockObsidian {Coordinates = new Vector3(x, y, z)});
                        }
                        else if (meta <= 4)
                        {
                            world.SetBlock(new BlockCobbleStone {Coordinates = new Vector3(x, y, z)});
                        }
                    }
                }
            }
        }
Пример #17
0
        public override void UseItem(Level world, Player player, Vector3 blockCoordinates, BlockFace face)
        {
            blockCoordinates = GetNewCoordinatesFromFace(blockCoordinates, face);
            if (face == BlockFace.PositiveY)
            {
                var bss = new BlockStandingSign
                {
                    Coordinates = blockCoordinates,
                    Metadata = 0x00
                };

                var rawbytes = new BitArray(new byte[] {bss.Metadata});

                var direction = player.GetDirection();
                switch (direction)
                {
                    case 0:
                        //South
                        rawbytes[2] = true;
                        break;
                    case 1:
                        //West
                        rawbytes[3] = true;
                        break;
                    case 2:
                        //North DONE
                        rawbytes[2] = true;
                        rawbytes[3] = true;
                        break;
                    case 3:
                        //East

                        break;
                }
                bss.Metadata = ConvertToByte(rawbytes);
                world.SetBlock(bss);
                new SignEditorOpen(player.Wrapper)
                {
                    Coordinates = blockCoordinates
                }.Write();
            }
            else
            {
                //TODO: implement wall signs
            }
        }
Пример #18
0
 public override void UseItem(Level world, Player player, Vector3 blockCoordinates, BlockFace face)
 {
     var blockatpos = world.GetBlock(blockCoordinates);
     if (!(blockatpos is BlockAir))
     {
         BitArray b = new BitArray(new byte[] {blockatpos.Metadata});
         ConsoleFunctions.WriteLine("\n\n");
         ConsoleFunctions.WriteInfoLine("------------------------------------");
         ConsoleFunctions.WriteInfoLine("Block: " + blockatpos);
         ConsoleFunctions.WriteInfoLine("------------------------------------");
         for (int i = 0; i < b.Count; i++)
         {
             ConsoleFunctions.WriteInfoLine("Bit " + i + ": " + b[i]);
         }
         ConsoleFunctions.WriteInfoLine("------------------------------------\n\n");
         player.SendChat("Info tool used, Metadata written to chat!", ChatColor.Gold);
     }
 }
Пример #19
0
 public override void UseItem(Level world, Player player, Vector3 blockCoordinates, BlockFace face)
 {
     blockCoordinates = GetNewCoordinatesFromFace(blockCoordinates, face);
     //var slot = player.Inventory.CurrentSlot + 36;
     //player.Inventory.SetSlot(slot, 325, 0, 1); //'Empty' the bucket.
     var hand0 = player.Inventory.GetItemInHand(0);
     var hand1 = player.Inventory.GetItemInHand(1);
     if (hand0.Id == Id)
     {
         var slot = player.Inventory.CurrentSlot + 36;
         player.Inventory.SetSlot(slot, 325, 0, 1);
     }
     else if (hand1.Id == Id)
     {
         var slot = 45;
         player.Inventory.SetSlot(slot, 325, 0, 1);
     }
     world.SetBlock(new BlockFlowingWater {Coordinates = blockCoordinates}, true, true); //Place the water
     //	world.GetBlock(blockCoordinates).OnTick(world); //Update the water
 }
Пример #20
0
 public override bool PlaceBlock(Level world, Player player, Vector3 blockCoordinates, BlockFace face, Vector3 mouseLocation)
 {
     byte direction = player.GetDirection();
     byte upper = (byte)((mouseLocation.Y >= 8 && face != BlockFace.PositiveY) || face == BlockFace.NegativeY ? 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;
 }
Пример #21
0
 public override void UseItem(Level world, Player player, Vector3 blockCoordinates, BlockFace face)
 {
     blockCoordinates = GetNewCoordinatesFromFace(blockCoordinates, face);
     var block = world.GetBlock(blockCoordinates);
     ConsoleFunctions.WriteInfoLine("Block: " + block.Id);
     if (block.Id != 46)
     {
         var affectedBlock = world.GetBlock(blockCoordinates);
         if (affectedBlock.Id == 0)
         {
             var fire = new BlockFire
             {
                 Coordinates = affectedBlock.Coordinates
             };
             world.SetBlock(fire);
         }
     }
     else
     {
         new PrimedTNTEntity(world) {KnownPosition = blockCoordinates.ToPlayerLocation()}.SpawnEntity();
     }
 }
Пример #22
0
        private void SetToStill(Level world, int x, int y, int z)
        {
            var meta = world.GetBlock(new Vector3(x, y, z)).Metadata;

            var stillBlock = BlockFactory.GetBlockById((byte) (Id + 1));
            stillBlock.Metadata = meta;
            stillBlock.Coordinates = new Vector3(x, y, z);
            world.SetBlock(stillBlock, applyPhysics: false);
        }
Пример #23
0
 private bool IsWater(Level world, int x, int y, int z)
 {
     var block = world.GetBlock(new Vector3(x, y, z));
     return block is BlockFlowingWater || block is BlockStationaryWater;
 }
Пример #24
0
        private int GetSmallestFlowDecay(Level world, int x, int y, int z, int decay)
        {
            var blockDecay = GetFlowDecay(world, x, y, z);

            if (blockDecay < 0)
            {
                return decay;
            }

            if (blockDecay == 0)
            {
                ++_adjacentSources;
            }

            if (blockDecay >= 8)
            {
                blockDecay = 0;
            }

            return decay >= 0 && blockDecay >= decay ? decay : blockDecay;
        }
Пример #25
0
        private bool[] GetOptimalFlowDirections(Level world, int x, int y, int z)
        {
            int l;
            int x2;

            for (l = 0; l < 4; ++l)
            {
                _flowCost[l] = 1000;
                x2 = x;
                var z2 = z;

                if (l == 0)
                {
                    x2 = x - 1;
                }

                if (l == 1)
                {
                    ++x2;
                }

                if (l == 2)
                {
                    z2 = z - 1;
                }

                if (l == 3)
                {
                    ++z2;
                }

                if (!BlocksFluid(world, x2, y, z2) &&
                    (!IsSameMaterial(world.GetBlock(new Vector3(x2, y, z2))) || world.GetBlock(new Vector3(x2, y, z2)).Metadata != 0))
                {
                    if (BlocksFluid(world, x2, y - 1, z2))
                    {
                        _flowCost[l] = CalculateFlowCost(world, x2, y, z2, 1, l);
                    }
                    else
                    {
                        _flowCost[l] = 0;
                    }
                }
            }

            l = _flowCost[0];

            for (x2 = 1; x2 < 4; ++x2)
            {
                if (_flowCost[x2] < l)
                {
                    l = _flowCost[x2];
                }
            }

            for (x2 = 0; x2 < 4; ++x2)
            {
                _optimalFlowDirections[x2] = _flowCost[x2] == l;
            }

            return _optimalFlowDirections;
        }
Пример #26
0
 private int GetFlowDecay(Level world, int x, int y, int z)
 {
     var block = world.GetBlock(new Vector3(x, y, z));
     return IsSameMaterial(block) ? block.Metadata : -1;
 }
Пример #27
0
        private void Flow(Level world, int x, int y, int z, int decay)
        {
            if (CanBeFlownInto(world, x, y, z))
            {
                var oldBlock = world.GetBlock(new Vector3(x, y, z));
                if (oldBlock is Flowing || oldBlock.Id == 0)
                {
                }
                else
                {
                    oldBlock.DoDrop(world);
                }
                oldBlock.BreakBlock(world);

                var newBlock = BlockFactory.GetBlockById(Id);
                newBlock.Coordinates = new Vector3(x, y, z);
                newBlock.Metadata = (byte) decay;
                world.SetBlock(newBlock, applyPhysics: true);
                world.ScheduleBlockTick(newBlock, TickRate());
            }
        }
Пример #28
0
 public override void DoPhysics(Level level)
 {
     CheckForHarden(level, (int) Coordinates.X, (int) Coordinates.Y, (int) Coordinates.Z);
     level.ScheduleBlockTick(this, TickRate());
 }
Пример #29
0
        public override void OnTick(Level level)
        {
            var world = level;
            var random = new Random();

            var x = (int) Coordinates.X;
            var y = (int) Coordinates.Y;
            var z = (int) Coordinates.Z;

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

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

            var flag = true;
            var tickRate = TickRate();

            if (currentDecay > 0)
            {
                var 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);
                var newDecay = smallestFlowDecay + multiplier;
                if (newDecay >= 8 || smallestFlowDecay < 0)
                {
                    newDecay = -1;
                }

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

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

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

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

                if (newDecay == currentDecay)
                {
                    if (flag)
                    {
                        SetToStill(world, x, y, z);
                    }
                }
                else
                {
                    currentDecay = newDecay;
                    if (newDecay < 0)
                    {
                        world.SetBlock(new BlockAir {Coordinates = new Vector3(x, y, z)});
                    }
                    else
                    {
                        world.ApplyPhysics(x, y, z);
                        world.ScheduleBlockTick(this, tickRate); // Schedule tick
                    }
                }
            }
            else
            {
                SetToStill(world, x, y, z);
            }

            if (CanBeFlownInto(world, x, y - 1, z))
            {
                if (this is BlockFlowingLava &&
                    (world.GetBlock(new Vector3(x, y - 1, z)) is BlockFlowingWater ||
                     world.GetBlock(new Vector3(x, y - 1, z)) is BlockStationaryWater))
                {
                    world.SetBlock(new BlockCobbleStone {Coordinates = new Vector3(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)))
            {
                var optimalFlowDirections = GetOptimalFlowDirections(world, x, y, z);

                var 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);
                }
            }
        }
Пример #30
0
        private bool CanBeFlownInto(Level world, int x, int y, int z)
        {
            var block = world.GetBlock(new Vector3(x, y, z));

            return !IsSameMaterial(block) && (!(block is BlockFlowingLava) && !(block is BlockStationaryLava)) &&
                   !BlocksFluid(block);
        }