Ejemplo n.º 1
0
        private bool canStandUp()
        {
            tmpCollBox.Set(CollisionBox);
            tmpCollBox.Y2  = Properties.HitBoxSize.Y;
            tmpCollBox.Y1 += 1f; // Don't care about the bottom block
            bool collide = World.CollisionTester.IsColliding(World.BlockAccessor, tmpCollBox, Pos.XYZ, false);;

            return(!collide);
        }
        public void Check()
        {
            if (entity is EntityPlayer)
            {
                EntityPlayer plr  = (EntityPlayer)entity;
                EnumGameMode mode = entity.World.PlayerByUid(plr.PlayerUID).WorldData.CurrentGameMode;
                if (mode == EnumGameMode.Creative || mode == EnumGameMode.Spectator)
                {
                    return;
                }
            }

            BlockPos pos = new BlockPos(
                (int)(entity.ServerPos.X + entity.LocalEyePos.X),
                (int)(entity.ServerPos.Y + entity.LocalEyePos.Y),
                (int)(entity.ServerPos.Z + entity.LocalEyePos.Z)
                );

            Block block = entity.World.BlockAccessor.GetBlock(pos);

            Cuboidf[] collisionboxes = block.GetCollisionBoxes(entity.World.BlockAccessor, pos);

            Cuboidf box = new Cuboidf();

            if (collisionboxes == null)
            {
                return;
            }

            for (int i = 0; i < collisionboxes.Length; i++)
            {
                box.Set(collisionboxes[i]);
                box.OmniGrowBy(-padding);
                tmp.Set(pos.X + box.X1, pos.Y + box.Y1, pos.Z + box.Z1, pos.X + box.X2, pos.Y + box.Y2, pos.Z + box.Z2);
                box.OmniGrowBy(padding);

                if (tmp.Contains(entity.ServerPos.X + entity.LocalEyePos.X, entity.ServerPos.Y + entity.LocalEyePos.Y, entity.ServerPos.Z + entity.LocalEyePos.Z))
                {
                    Cuboidd EntitySuffocationBox = entity.CollisionBox.ToDouble();

                    if (tmp.Intersects(EntitySuffocationBox))
                    {
                        DamageSource dmgsrc = new DamageSource()
                        {
                            Source = EnumDamageSource.Block, SourceBlock = block, Type = EnumDamageType.Suffocation
                        };
                        entity.ReceiveDamage(dmgsrc, 1f);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void OnEvery250Ms(float dt)
        {
            // Random checks for breaking this block if heavy entity above and unsupported below

            IWorldAccessor world = Api.World;
            Vec3d          pos3d = center.AddCopy(Pos);
            BlockPos       down  = Pos.DownCopy();

            // If this block is unsupported, do an entity weight + block breaking check
            if (!CheckSupport(world.BlockAccessor, down))
            {
                Entity[] entities = world.GetEntitiesAround(pos3d, 1.0f, 1.5f, (e) => (e?.Properties.Weight > WEIGHTLIMIT));
                for (int i = 0; i < entities.Length; i++)
                {
                    Entity    entity = entities[i];
                    Cuboidd   eBox   = new Cuboidd();
                    EntityPos pos    = entity.Pos;
                    eBox.Set(entity.SelectionBox).Translate(pos.X, pos.Y, pos.Z);

                    Cuboidf bBox = new Cuboidf();
                    bBox.Set(this.Block.CollisionBoxes[0]);
                    bBox.Translate(Pos.X, Pos.Y, Pos.Z);

                    // Check entity yPos actually intersects with this block (approximately)
                    if (eBox.MinY <= bBox.MaxY + 0.01 && eBox.MinY >= bBox.MinY - 0.01)
                    {
                        // Check whether supported enough on any surrounding side
                        bool checkSouth = eBox.MaxZ > bBox.Z2;
                        bool checkNorth = eBox.MinZ < bBox.Z1;
                        bool checkWest  = eBox.MinX < bBox.X1;
                        bool checkEast  = eBox.MinZ > bBox.X2;

                        bool           supported = false;
                        IBlockAccessor access    = world.BlockAccessor;
                        if (checkEast)
                        {
                            supported |= CheckSupport(access, down.EastCopy());
                        }
                        if (checkEast && checkNorth)
                        {
                            supported |= CheckSupport(access, down.EastCopy().North());
                        }
                        if (checkEast && checkSouth)
                        {
                            supported |= CheckSupport(access, down.EastCopy().South());
                        }
                        if (checkWest)
                        {
                            supported |= CheckSupport(access, down.WestCopy());
                        }
                        if (checkWest && checkNorth)
                        {
                            supported |= CheckSupport(access, down.WestCopy().North());
                        }
                        if (checkWest && checkSouth)
                        {
                            supported |= CheckSupport(access, down.WestCopy().South());
                        }
                        if (checkNorth)
                        {
                            supported |= CheckSupport(access, down.NorthCopy());
                        }
                        if (checkSouth)
                        {
                            supported |= CheckSupport(access, down.SouthCopy());
                        }

                        if (!supported)
                        {
                            // Break the block and the entity will fall :)

                            // ## TODO
                        }
                    }
                }
            }

            return;
        }